Comparison

core/modulemanager.lua @ 9562:acf74ad0b795

Many things: switch from hacky multi-arg xpcall implementations to a standard util.xpcall
author Matthew Wild <mwild1@gmail.com>
date Fri, 26 Oct 2018 19:32:00 +0100 (2018-10-26)
parent 8916:e727747279a0
child 9563:732314eb3258
comparison
equal deleted inserted replaced
9561:cfc7b2f7251e 9562:acf74ad0b795
16 local api = require "core.moduleapi"; -- Module API container 16 local api = require "core.moduleapi"; -- Module API container
17 17
18 local prosody = prosody; 18 local prosody = prosody;
19 local hosts = prosody.hosts; 19 local hosts = prosody.hosts;
20 20
21 local xpcall = xpcall; 21 local xpcall = require "util.xpcall".xpcall;
22 local setmetatable, rawget = setmetatable, rawget; 22 local setmetatable, rawget = setmetatable, rawget;
23 local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert; 23 local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert;
24 24
25 local debug_traceback = debug.traceback; 25 local debug_traceback = debug.traceback;
26 local select = select; 26 local select = select;
27 local unpack = table.unpack or unpack; --luacheck: ignore 113 27 local unpack = table.unpack or unpack; --luacheck: ignore 113
28 local pcall = function(f, ...)
29 local n = select("#", ...);
30 local params = {...};
31 return xpcall(function() return f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end);
32 end
33 28
34 local autoload_modules = {prosody.platform, "presence", "message", "iq", "offline", "c2s", "s2s", "s2s_auth_certs"}; 29 local autoload_modules = {prosody.platform, "presence", "message", "iq", "offline", "c2s", "s2s", "s2s_auth_certs"};
35 local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s"}; 30 local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s"};
36 31
37 -- We need this to let modules access the real global namespace 32 -- We need this to let modules access the real global namespace
181 end 176 end
182 177
183 api_instance.path = err; 178 api_instance.path = err;
184 179
185 modulemap[host][module_name] = pluginenv; 180 modulemap[host][module_name] = pluginenv;
186 local ok, err = pcall(mod); 181 local ok, err = xpcall(mod, debug.traceback);
187 if ok then 182 if ok then
188 -- Call module's "load" 183 -- Call module's "load"
189 if module_has_method(pluginenv, "load") then 184 if module_has_method(pluginenv, "load") then
190 ok, err = call_module_method(pluginenv, "load"); 185 ok, err = call_module_method(pluginenv, "load");
191 if not ok then 186 if not ok then