aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-21 20:09:03 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-21 20:09:03 +0100
commitf51d5c0bd00c83ed10eae136e95dc49a0d61b684 (patch)
tree8635d2724e1715ce919859072cab050f5b9ee49d /core/modulemanager.lua
parent3f130834834b04f47b0c00bb5504e67e0744fa16 (diff)
downloadprosody-f51d5c0bd00c83ed10eae136e95dc49a0d61b684.tar.gz
prosody-f51d5c0bd00c83ed10eae136e95dc49a0d61b684.zip
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r--core/modulemanager.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 769041f9..e76f2624 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -132,6 +132,21 @@ local function do_load_module(host, module_name)
log("warn", "%s is already loaded for %s, so not loading again", module_name, host);
return nil, "module-already-loaded";
elseif modulemap["*"][module_name] then
+ local mod = modulemap["*"][module_name];
+ if module_has_method(mod, "add_host") then
+ local _log = logger.init(host..":"..module_name);
+ local host_module_api = setmetatable({
+ host = host, event_handlers = {}, items = {};
+ _log = _log, log = function (self, ...) return _log(...); end;
+ },{
+ __index = modulemap["*"][module_name].module;
+ });
+ local ok, result, module_err = call_module_method(mod, "add_host", host_module_api);
+ if not ok or result == false then return nil, ok and module_err or result; end
+ local host_module = setmetatable({ module = host_module_api }, { __index = mod });
+ modulemap[host][module_name] = host_module;
+ return host_module;
+ end
return nil, "global-module-already-loaded";
end