storage-mod_storage.lua 939 B

1234567891011121314151617181920212223242526
  1. -- ===================================================================
  2. -- /storage-mod_storage.lua
  3. -- Persistent storage via Minetest's mod_storage method
  4. -- See https://dev.minetest.net/StorageRef
  5. -- Loads content of stored orgs and ledger from mod_storage
  6. modpol.load_storage = function()
  7. local mod_storage = minetest.get_mod_storage()
  8. -- load orgs
  9. local stored_orgs = minetest.deserialize(mod_storage:get_string("orgs"))
  10. if (stored_orgs ~= nil) then
  11. modpol.orgs = stored_orgs
  12. end
  13. -- load orgs
  14. local stored_ledger = minetest.deserialize(mod_storage:get_string("ledger"))
  15. if (stored_ledger ~= nil) then
  16. modpol.ledger = stored_ledger
  17. end
  18. end
  19. -- Stores content of current orgs and ledger to mod_storage
  20. modpol.store_data = function()
  21. -- write to storage
  22. mod_storage:set_string("orgs", minetest.serialize(modpol.orgs))
  23. mod_storage:set_string("ledger", minetest.serialize(modpol.ledger))
  24. end