Dimitriye98

Persistance API

Sep 9th, 2012
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.52 KB | None | 0 0
  1. if not fs.exists("/.persistance") then
  2.     fs.makeDir("/.persistance")
  3. end
  4.  
  5. function store(sName, stuff)
  6.     local filePath = fs.combine("/.persistance", 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("/.persistance", sName)
  17.     local handle = fs.open(filePath, "r")
  18.     local stuff = handle.readAll()
  19.     handle.close()
  20.     return textutils.unserialize(stuff)
  21. end
Advertisement
Add Comment
Please, Sign In to add comment