core/modulemanager.lua

changeset 1333
d74441a2f3e8
parent 1330
baad431dabc5
child 1334
6846c5cc9ce2
equal deleted inserted replaced
1332:f7fed9f77455 1333:d74441a2f3e8
126 setfenv(mod, pluginenv); 126 setfenv(mod, pluginenv);
127 if not hosts[host] then hosts[host] = { type = "component", host = host, connected = false, s2sout = {} }; end 127 if not hosts[host] then hosts[host] = { type = "component", host = host, connected = false, s2sout = {} }; end
128 128
129 local success, ret = pcall(mod); 129 local success, ret = pcall(mod);
130 if not success then 130 if not success then
131 log("error", "Error initialising module '%s': %s", name or "nil", ret or "nil"); 131 log("error", "Error initialising module '%s': %s", module_name or "nil", ret or "nil");
132 return nil, ret; 132 return nil, ret;
133 end 133 end
134 134
135 -- Use modified host, if the module set one 135 -- Use modified host, if the module set one
136 modulemap[api_instance.host][module_name] = pluginenv; 136 modulemap[api_instance.host][module_name] = pluginenv;
371 function api:hook(event, handler, priority) 371 function api:hook(event, handler, priority)
372 hooks:set(self.host, self.name, event, handler, true); 372 hooks:set(self.host, self.name, event, handler, true);
373 (hosts[self.host] or prosody).events.add_handler(event, handler, priority); 373 (hosts[self.host] or prosody).events.add_handler(event, handler, priority);
374 end 374 end
375 375
376 function api:hook_stanza(xmlns, name, handler, priority)
377 if not handler and type(name) == "function" then
378 -- If only 2 options then they specified no xmlns
379 xmlns, name, handler, priority = nil, xmlns, name, handler;
380 elseif not (handler and name) then
381 self:log("warn", "Error: Insufficient parameters to module:hook_stanza()");
382 return;
383 end
384 return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority);
385 end
386
376 -------------------------------------------------------------------- 387 --------------------------------------------------------------------
377 388
378 local actions = {}; 389 local actions = {};
379 390
380 function actions.load(params) 391 function actions.load(params)

mercurial