فهرست منبع

cleaned up module template!

Luke Miller 2 سال پیش
والد
کامیت
826f9600b5
2فایلهای تغییر یافته به همراه18 افزوده شده و 18 حذف شده
  1. 5 17
      modpol/modules/join_org_class.lua
  2. 13 1
      modpol/orgs/process.lua

+ 5 - 17
modpol/modules/join_org_class.lua

@@ -2,22 +2,12 @@
 -- Module that enables a user to join an org
 
 JoinOrg = {}
-JoinOrg_mt = { __index = JoinOrg }
 
-
-function JoinOrg.create(initiator, org, id)
-    local inst = {
-        name = "Join an org",
-        desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
-        initiator = initiator,
-        org = org,
-        id = id,
-        votes_yes = 0
-    }
-    setmetatable(inst, JoinOrg_mt)
-    return inst
-
-end
+JoinOrg.setup = {
+    name = "Join an org",
+    desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
+    votes_yes = 0
+}
 
 function JoinOrg:initiate(result)
     modpol.interactions.binary_poll_user(
@@ -33,8 +23,6 @@ function JoinOrg:initiate(result)
         end
     )
 
-    
-
     if result then result() end
 
 end

+ 13 - 1
modpol/orgs/process.lua

@@ -22,7 +22,19 @@ function modpol.orgs:call_module(module_name, initiator)
     end
 
     local module = modpol.modules[module_name]
-    local new_process = module.create(initiator, self, index)
+
+    local new_process = {
+        metatable = {__index = module},
+        initiator = initiator,
+        org = self,
+        id = index
+    }
+
+    for k, v in pairs(module.setup) do
+        new_process[k] = v
+    end
+
+    setmetatable(new_process, new_process.metatable)
 
     self.processes[index] = new_process