modpol.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. -- Record of every state change should appear here
  9. modpol.ledger = {
  10. }
  11. -- ===================================================================
  12. -- Locate framework top-level directory.
  13. -- This function is intended for use under Linux and/or UNIX only.
  14. -- It
  15. -- returns a relative or absolute path for the framework top-level
  16. -- directory without a trailing slash.
  17. -- if your application has a different method of getting the script directory,
  18. -- then feel free to overwrite this in an init.lua or other such file by first
  19. -- defining the modpol table and then defining the get_script_dir() function
  20. local get_script_dir = modpol.get_script_dir or 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 .. "/util/ocutil/ocutil.lua")
  34. -- Misc. utilities
  35. dofile (topdir .. "/util/misc.lua")
  36. -- ===================================================================
  37. -- Persistent storage
  38. -- must implement modpol.load_storage() and modpol.store_data()
  39. -- Select a storage method
  40. -- -- preferably, declare this in the init.lua that calls modpol.lua This is the default.
  41. -- Works with CLI:
  42. modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/storage-local.lua"
  43. -- Works with Minetest 5:
  44. --modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/storage-mod_storage.lua")
  45. --execute the storage file
  46. dofile (modpol.storage_file_path)
  47. -- If available, load persistent storage into active tables
  48. modpol.load_storage()
  49. -- ===================================================================
  50. -- Modpol modules
  51. modpol.modules = modpol.modules or {}
  52. -- TKTK need to specify modules to include
  53. -- ===================================================================
  54. -- Modpol core features
  55. dofile (topdir .. "/api.lua")
  56. -- ===================================================================
  57. -- Final checks
  58. -- sets org metatable on load
  59. if (modpol.orgs.array) then
  60. for id, org in ipairs(modpol.orgs.array) do
  61. if type(org) == 'table' then
  62. setmetatable(org, modpol.orgs)
  63. -- sets process metatable on load
  64. for id, process in ipairs(org.processes) do
  65. if type(process) == 'table' then
  66. setmetatable(process, modpol.modules[process.type])
  67. end
  68. end
  69. end
  70. end
  71. end
  72. -- create instance if not present
  73. modpol.instance = modpol.orgs.array[1] or modpol.orgs.init_instance()
  74. modpol.ocutil.log ("modpol loaded")
  75. -- ===================================================================
  76. -- End of file.