Comparison

core/modulemanager.lua @ 1247:4721e4124692

modulemanager: module:hook now allows global modules to hook events on the prosody.events object
author Waqas Hussain <waqas20@gmail.com>
date Sun, 31 May 2009 00:51:13 +0500
parent 1231:6f251813f1e5
child 1248:9a482f76a20a
comparison
equal deleted inserted replaced
1246:3622ed42b92c 1247:4721e4124692
18 local multitable_new = require "util.multitable".new; 18 local multitable_new = require "util.multitable".new;
19 local register_actions = require "core.actions".register; 19 local register_actions = require "core.actions".register;
20 local st = require "util.stanza"; 20 local st = require "util.stanza";
21 21
22 local hosts = hosts; 22 local hosts = hosts;
23 local prosody = prosody;
23 24
24 local loadfile, pcall = loadfile, pcall; 25 local loadfile, pcall = loadfile, pcall;
25 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv; 26 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv;
26 local pairs, ipairs = pairs, ipairs; 27 local pairs, ipairs = pairs, ipairs;
27 local t_insert, t_concat = table.insert, table.concat; 28 local t_insert, t_concat = table.insert, table.concat;
356 357
357 function api:hook(event, handler) 358 function api:hook(event, handler)
358 if self.host ~= '*' then 359 if self.host ~= '*' then
359 hosts[self.host].events.add_handler(event, handler); 360 hosts[self.host].events.add_handler(event, handler);
360 else 361 else
361 self:log("error", "Global module attempting to hook a host-specific event: %s", event); 362 prosody.events.add_handler(event, handler);
362 end 363 end
363 end 364 end
364 365
365 -------------------------------------------------------------------- 366 --------------------------------------------------------------------
366 367