tompy90

Persistence API

May 4th, 2013
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. if not fs.exists("/.persistence") then
  2.         fs.makeDir("/.persistence")
  3. end
  4.  
  5. function store(sName, stuff)
  6.         local filePath = fs.combine("/.persistence", sName)
  7.         if stuff == nil then
  8.                 return fs.delete(filePath)
  9.         end
  10.         local handle = fs.open(filePath, "w")
  11.         handle.write(textutils.serialize(stuff))
  12.         handle.close()
  13. end
  14.  
  15. function pull(sName)
  16.    local filePath = fs.combine("/.persistence", sName)
  17.    if fs.exists(filePath) then
  18.          local handle = fs.open(filePath, "r")
  19.          local stuff = handle.readAll()
  20.          handle.close()
  21.          return textutils.unserialize(stuff)
  22.    else
  23.          return nil
  24.    end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment