Merge 0.10->trunk
[prosody.git] / core / modulemanager.lua
index e629b00571c49dee40e96183f443aca2f2e67693..7bed17950e0c435eeac929d4cde535c153a00649 100644 (file)
@@ -13,6 +13,7 @@ local pluginloader = require "util.pluginloader";
 local set = require "util.set";
 
 local new_multitable = require "util.multitable".new;
+local api = require "core.moduleapi"; -- Module API container
 
 local hosts = hosts;
 local prosody = prosody;
@@ -22,7 +23,8 @@ local setmetatable, rawget = setmetatable, rawget;
 local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert;
 
 local debug_traceback = debug.traceback;
-local unpack, select = unpack, select;
+local select = select;
+local unpack = table.unpack or unpack; --luacheck: ignore 113
 local pcall = function(f, ...)
        local n = select("#", ...);
        local params = {...};
@@ -35,9 +37,9 @@ local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s
 -- We need this to let modules access the real global namespace
 local _G = _G;
 
-module "modulemanager"
+local _ENV = nil;
 
-local api = _G.require "core.moduleapi".init(_M); -- Module API container
+local load_modules_for_host, load, unload, reload, get_module, get_items, get_modules, is_loaded, module_has_method, call_module_method;
 
 -- [host] = { [module] = module_env }
 local modulemap = { ["*"] = {} };
@@ -123,7 +125,9 @@ local function do_load_module(host, module_name, state)
        end
 
        if modulemap[host][module_name] then
-               log("debug", "%s is already loaded for %s, so not loading again", module_name, host);
+               if not modulemap["*"][module_name] then
+                       log("debug", "%s is already loaded for %s, so not loading again", module_name, host);
+               end
                return nil, "module-already-loaded";
        elseif modulemap["*"][module_name] then
                local mod = modulemap["*"][module_name];
@@ -317,4 +321,15 @@ function call_module_method(module, method, ...)
        end
 end
 
-return _M;
+return {
+       load_modules_for_host = load_modules_for_host;
+       load = load;
+       unload = unload;
+       reload = reload;
+       get_module = get_module;
+       get_items = get_items;
+       get_modules = get_modules;
+       is_loaded = is_loaded;
+       module_has_method = module_has_method;
+       call_module_method = call_module_method;
+};