You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
local Modules = {}
|
|
|
|
function Modules:new(obj)
|
|
obj = obj or {}
|
|
setmetatable(obj, self)
|
|
self.__index = self
|
|
obj:initialize()
|
|
return obj
|
|
end
|
|
|
|
function Modules:initialize()
|
|
self.modules = {}
|
|
end
|
|
|
|
function Modules:add(name, config)
|
|
local module = require('module/'..name)
|
|
self.modules[name] = { instance = module:new(), config = config }
|
|
end
|
|
|
|
function Modules:addInstance(name, instance, config)
|
|
self.modules[name] = { instance = instance, config = config }
|
|
end
|
|
|
|
function Modules:get(name)
|
|
if (self.modules[name] == nil) then
|
|
print("MODULE NOT LOADED: "..name)
|
|
end
|
|
return self.modules[name]['instance']
|
|
end
|
|
|
|
function Modules:configure()
|
|
for name, module in pairs(self.modules) do
|
|
module.instance:configure(module.config)
|
|
end
|
|
end
|
|
|
|
function Modules:call(method)
|
|
orders = {}
|
|
for name, module in pairs(self.modules) do
|
|
if (module.config ~= nil and module.config.order ~= nil) then
|
|
table.insert(orders, module.config.order)
|
|
end
|
|
end
|
|
|
|
table.sort(orders)
|
|
|
|
for idx,order in ipairs(orders) do
|
|
for name, module in pairs(self.modules) do
|
|
if (module.config ~= nil and module.config.order ~= nil and module.config.order == order) then
|
|
module['instance'][method](module['instance'])
|
|
end
|
|
end
|
|
end
|
|
|
|
for name, module in pairs(self.modules) do
|
|
if (module.config == nil or module.config.order == nil) then
|
|
module['instance'][method](module['instance'])
|
|
end
|
|
end
|
|
end
|
|
|
|
return Modules
|
|
|