storage.lua 594 B

123456789101112131415161718192021222324252627
  1. mailbox.load = function()
  2. local path = minetest.get_worldpath() .. "/mailboxes.txt"
  3. local file = io.open(path, "r")
  4. if file then
  5. local data = file:read("*all")
  6. local db = minetest.deserialize(data)
  7. file:close()
  8. if type(db) == "table" then
  9. mailbox.boxes = db
  10. end
  11. end
  12. end
  13. mailbox.save = function()
  14. local str = minetest.serialize(mailbox.boxes)
  15. if type(str) ~= "string" then return end -- Failsafe.
  16. local path = minetest.get_worldpath() .. "/mailboxes.txt"
  17. local file = io.open(path, "w")
  18. if file then
  19. file:write(str)
  20. file:close()
  21. end
  22. end