diff --git a/modpol/modules/template.lua b/modpol/modules/template.lua new file mode 100644 index 0000000..52144ec --- /dev/null +++ b/modpol/modules/template.lua @@ -0,0 +1,29 @@ + + +Module = {} + +Module.setup = { + name = "Module Name", + desc = "Description of the module" +} + +-- defines the input parameters to the module initiate function +-- when calling a module from within another module +-- variables not defined in config will be ignored +-- default values set in config can be overridden +Module.config = { + votes_required = 5 + voting_type = "majority" +} + +-- Modules have access to the following instance variables +-- self.org (the org the module was called in) +-- self.initiator (the user that callced the module) +-- self.id (the process id of the module instance) + +function Module:initiate(config, result) + -- call interaction functions here! + + -- call result function + if result then result() end +end \ No newline at end of file diff --git a/modpol/orgs/process.lua b/modpol/orgs/process.lua index 5ede0ed..a24dd6b 100644 --- a/modpol/orgs/process.lua +++ b/modpol/orgs/process.lua @@ -1,4 +1,4 @@ -function modpol.orgs:call_module(module_name, initiator) +function modpol.orgs:call_module(module_name, initiator, config, result) if not modpol.modules[module_name] then modpol.ocutil.log('Error in ' .. self.name .. ':call_module -> module "' .. name .. '" not found') return @@ -23,13 +23,15 @@ function modpol.orgs:call_module(module_name, initiator) local module = modpol.modules[module_name] + -- setting default params local new_process = { metatable = {__index = module}, initiator = initiator, org = self, id = index } - + + -- copying default fields from setup for k, v in pairs(module.setup) do new_process[k] = v end @@ -38,7 +40,14 @@ function modpol.orgs:call_module(module_name, initiator) self.processes[index] = new_process - self.processes[index]:initiate() + -- sets default values for undeclared config variables + for k, v in pairs(module.config) do + if config[k] == nil then + config[k] = v + end + end + + self.processes[index]:initiate(config, result)) return index end