# HG changeset patch # User Matthew Wild # Date 1335035343 -3600 # Node ID c1602c07d14dab3023bae9bd84c0ce1fbf4707ea # Parent 2b3ee52fba32c64209cf30d75b47d2d02c128041 modulemanager: Support for shared modules - function module.add_host(host_module) in a global module diff -r 2b3ee52fba32 -r c1602c07d14d core/modulemanager.lua --- a/core/modulemanager.lua Sat Apr 21 20:04:07 2012 +0100 +++ b/core/modulemanager.lua Sat Apr 21 20:09:03 2012 +0100 @@ -132,6 +132,21 @@ 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