Posted 13 March 2013 - 11:47 PM
Here is my code:
I run the function and it all works, but i get a string instead of a table, so i cannot add my var string to it using table.insert()
function readFile(name)
local f = fs.open(name,"r")
local data = f.readAll()
f.close()
return textutils.unserialize(data)
end
function editFile(fileName,string,line)
if fileName == nil or string == nil then
error("String expected got nil")
elseif fileName ~= tostring(fileName) or string ~= tostring(string) then
error("String expected as file name got number")
else
data ={}
data = readFile(fileName)
if line == nil then
table.insert(data, string)
elseif line ~= tonumber(line) then
error("Number expected as line, got string.")
else
table.insert(data, line, string)
end
print(data)
end
end
I run the function and it all works, but i get a string instead of a table, so i cannot add my var string to it using table.insert()
Edited by