modpol.lua 2.1 KB

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