modpol.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. -- ===================================================================
  2. -- /modpol.lua
  3. -- Modular Politics (modpol) core
  4. -- ===================================================================
  5. -- Basic tables
  6. -- Main API table
  7. if not modpol then modpol = {} end
  8. -- Table for modpol data
  9. modpol.orgs = {
  10. }
  11. -- Record of every state change should appear here
  12. modpol.ledger = {
  13. }
  14. -- ===================================================================
  15. -- Locate framework top-level directory.
  16. -- This function is intended for use under Linux and/or UNIX only.
  17. -- It
  18. -- returns a relative or absolute path for the framework top-level
  19. -- directory without a trailing slash.
  20. -- if your application has a different method of getting the script directory,
  21. -- then feel free to overwrite this in an init.lua or other such file by first
  22. -- defining the modpol table and then defining the get_script_dir() function
  23. local get_script_dir = modpol.get_script_dir or function()
  24. local str = debug.getinfo (2, "S").source:sub (2)
  25. str = str:match ("(.*/)") or "."
  26. str = str:gsub ("/$", "", 1)
  27. return str
  28. end
  29. -- Absolute or relative path to script directory.
  30. local topdir = get_script_dir()
  31. modpol.topdir = topdir
  32. print (topdir)
  33. -- ===================================================================
  34. -- Load dependencies
  35. -- OldCoder utilities
  36. dofile (topdir .. "/util/ocutil/ocutil.lua")
  37. -- ===================================================================
  38. -- Persistent storage
  39. -- must implement modpol.load_storage() and modpol.store_data()
  40. -- Select a storage method
  41. -- -- preferably, declare this in the init.lua that calls modpol.lua This is the default.
  42. -- Works with CLI:
  43. modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/storage-local.lua"
  44. -- Works with Minetest 5:
  45. --modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/storage-mod_storage.lua")
  46. --execute the storage file
  47. dofile (modpol.storage_file_path)
  48. -- If available, load persistent storage into active tables
  49. modpol.load_storage()
  50. -- ===================================================================
  51. -- ModPol core features
  52. dofile (topdir .. "/modpol/api.lua")
  53. -- ===================================================================
  54. -- Final checks
  55. -- create instance if not present
  56. if (modpol.orgs["instance"] == nil) then
  57. modpol.add_org("instance", modpol.list_users())
  58. end
  59. modpol.ocutil.log ("modpol loaded")
  60. -- ===================================================================
  61. -- End of file.