Posted 07 December 2012 - 08:40 PM
Now, I have a rather large amount of code (more than your average doorlock) and it is erroring in file.readLine(). file is defined and there is a file.close() line.
The error is:
EDIT:
And the problem was: fs.open can't tell where you are. Just me not knowing something.
The error is:
:54: attempt to index ? (a nil value)
Here is my code.Spoiler
tArgs = {...}
--Start of StrUtils by tomass1996 of computercraft.info
local function find(str, match, startIndex) --Finds @match in @str optionally after @startIndex
if not match then return nil end
str = tostring(str)
local _ = startIndex or 1
local _s = nil
local _e = nil
local _len = match:len()
while true do
local _t = str:sub( _ , _len + _ - 1)
if _t == match then
_s = _
_e = _ + _len - 1
break
end
_ = _ + 1
if _ > str:len() then break end
end
if _s == nil then return nil else return _s, _e end
end
local function seperate(str, divider) --Separates @str on @divider
if not divider then return nil end
str = tostring(str)
local start = {}
local endS = {}
local n=1
repeat
if n==1 then
start[n], endS[n] = find(str, divider)
else
start[n], endS[n] = find(str, divider, endS[n-1]+1)
end
n=n+1
until start[n-1]==nil
local subs = {}
for n=1, #start+1 do
if n==1 then
subs[n] = str:sub(1, start[n]-1)
elseif n==#start+1 then
subs[n] = str:sub(endS[n-1]+1)
else
subs[n] = str:sub(endS[n-1]+1, start[n]-1)
end
end
return subs
end
--Now, my stuff - this is the function that reads a file into a table
function readFileLines(filename)
file = fs.open(filename,"r")
local tLines = {}
repeat
line = file.readLine()
table.insert(tLines,line)
until line == nil
file.close()
return tLines
end
--And this - this is the interpreter
function runFile(runfilename)
local lines = readFileLines(runfilename)
local number = 1
repeat
if lines[number] == "ECHO" then print(lines[number+1])
end
until lines[number] == nil
end
runFile(tArgs[1])
And the problem was: fs.open can't tell where you are. Just me not knowing something.