Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("lib\\textutils")
- tableIO = {}
- function tableIO.load(fileName, tableVar)
- local file = io.open(fileName,"r")
- if file ~= nil then
- local data = file:read("*a")
- file:close()
- local tData = textutils.unserialize(data)
- if tableVar and type(tableVar) == "table" then
- tableVar = tData
- else
- return tData
- end
- else
- error("file not found")
- end
- end
- function tableIO.save(fileName,tableVar)
- if tableVar and type(tableVar) == "table" and fileName and type(fileName) == "string" then
- local dataString = textutils.serialize(tableVar)
- local file = io.open(fileName,"w")
- file:write(dataString)
- file:close()
- return true
- else
- error("Expected string,table got "..type(fileName)..","..type(tableVar))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement