Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local filePath = ".persistence"
- function store(sName, stuff)
- local tempTable = {}
- if fs.exists(filePath) then
- local handle = fs.open(filePath, "r")
- local stuff = handle.readAll()
- handle.close()
- tempTable = textutils.unserialize(stuff)
- end
- tempTable[sName] = stuff -- tempTable[sName]: "I'm stuff."
- local handle = fs.open(filePath, "w")
- handle.write(textutils.serialize(stuff))
- handle.close()
- end
- function pull(sName)
- local tempTable = {}
- if fs.exists(filePath) then
- local handle = fs.open(filePath, "r")
- local stuff = handle.readAll()
- handle.close()
- tempTable = textutils.unserialize(stuff)
- end
- return tempTable
- end
- persistent = {}
- setmetatable(persistent,{
- __index = pull, __newindex = store
- })
Advertisement
Add Comment
Please, Sign In to add comment