Software /
code /
prosody
Comparison
core/modulemanager.lua @ 4642:c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 21 Apr 2012 20:09:03 +0100 |
parent | 4641:2b3ee52fba32 |
child | 4643:9008fc396fb1 |
comparison
equal
deleted
inserted
replaced
4641:2b3ee52fba32 | 4642:c1602c07d14d |
---|---|
130 | 130 |
131 if modulemap[host][module_name] then | 131 if modulemap[host][module_name] then |
132 log("warn", "%s is already loaded for %s, so not loading again", module_name, host); | 132 log("warn", "%s is already loaded for %s, so not loading again", module_name, host); |
133 return nil, "module-already-loaded"; | 133 return nil, "module-already-loaded"; |
134 elseif modulemap["*"][module_name] then | 134 elseif modulemap["*"][module_name] then |
135 local mod = modulemap["*"][module_name]; | |
136 if module_has_method(mod, "add_host") then | |
137 local _log = logger.init(host..":"..module_name); | |
138 local host_module_api = setmetatable({ | |
139 host = host, event_handlers = {}, items = {}; | |
140 _log = _log, log = function (self, ...) return _log(...); end; | |
141 },{ | |
142 __index = modulemap["*"][module_name].module; | |
143 }); | |
144 local ok, result, module_err = call_module_method(mod, "add_host", host_module_api); | |
145 if not ok or result == false then return nil, ok and module_err or result; end | |
146 local host_module = setmetatable({ module = host_module_api }, { __index = mod }); | |
147 modulemap[host][module_name] = host_module; | |
148 return host_module; | |
149 end | |
135 return nil, "global-module-already-loaded"; | 150 return nil, "global-module-already-loaded"; |
136 end | 151 end |
137 | 152 |
138 | 153 |
139 local mod, err = pluginloader.load_code(module_name); | 154 local mod, err = pluginloader.load_code(module_name); |