Advertisement
Pinkishu

Untitled

Sep 6th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. require("lib\\textutils")
  2. tableIO = {}
  3.  
  4. function tableIO.load(fileName, tableVar)
  5.   local file = io.open(fileName,"r")
  6.   if file ~= nil then
  7.     local data = file:read("*a")
  8.     file:close()
  9.     local tData = textutils.unserialize(data)
  10.     if tableVar and type(tableVar) == "table" then
  11.       tableVar = tData
  12.     else
  13.       return tData
  14.     end
  15.   else
  16.     error("file not found")
  17.   end
  18. end
  19.  
  20. function tableIO.save(fileName,tableVar)
  21.   if tableVar and type(tableVar) == "table" and fileName and type(fileName) == "string" then
  22.     local dataString = textutils.serialize(tableVar)
  23.     local file = io.open(fileName,"w")
  24.     file:write(dataString)
  25.     file:close()
  26.     return true
  27.   else
  28.     error("Expected string,table got "..type(fileName)..","..type(tableVar))
  29.   end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement