core/modulemanager.lua

changeset 1259
6bd11bca9725
parent 1253
60156584c442
child 1309
a544e68a0989
equal deleted inserted replaced
1254:c199be608546 1259:6bd11bca9725
47 local modulehelpers = setmetatable({}, { __index = _G }); 47 local modulehelpers = setmetatable({}, { __index = _G });
48 48
49 local features_table = multitable_new(); 49 local features_table = multitable_new();
50 local handler_table = multitable_new(); 50 local handler_table = multitable_new();
51 local hooked = multitable_new(); 51 local hooked = multitable_new();
52 local hooks = multitable_new();
52 local event_hooks = multitable_new(); 53 local event_hooks = multitable_new();
53 54
54 local NULL = {}; 55 local NULL = {};
55 56
56 -- Load modules when a host is activated 57 -- Load modules when a host is activated
163 handler_info[handlers[1]] = nil; 164 handler_info[handlers[1]] = nil;
164 stanza_handlers:remove(param[1], param[2], param[3], param[4]); 165 stanza_handlers:remove(param[1], param[2], param[3], param[4]);
165 end 166 end
166 end 167 end
167 event_hooks:remove(host, name); 168 event_hooks:remove(host, name);
169 -- unhook event handlers hooked by module:hook
170 for event, handlers in pairs(hooks:get(host, name) or NULL) do
171 for handler in pairs(handlers or NULL) do
172 (hosts[host] or prosody).events.remove_handler(event, handler);
173 end
174 end
175 hooks:remove(host, name);
168 return true; 176 return true;
169 end 177 end
170 178
171 function reload(host, name, ...) 179 function reload(host, name, ...)
172 local mod = get_module(host, name); 180 local mod = get_module(host, name);
354 function api:fire_event(...) 362 function api:fire_event(...)
355 return (hosts[self.host] or prosody).events.fire_event(...); 363 return (hosts[self.host] or prosody).events.fire_event(...);
356 end 364 end
357 365
358 function api:hook(event, handler) 366 function api:hook(event, handler)
367 hooks:set(self.host, self.name, event, handler, true);
359 (hosts[self.host] or prosody).events.add_handler(event, handler); 368 (hosts[self.host] or prosody).events.add_handler(event, handler);
360 end 369 end
361 370
362 -------------------------------------------------------------------- 371 --------------------------------------------------------------------
363 372

mercurial