aboutsummaryrefslogtreecommitdiffstats
path: root/core/moduleapi.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-01-22 18:49:11 +0000
committerMatthew Wild <mwild1@gmail.com>2012-01-22 18:49:11 +0000
commit15a073672027cdf47822ad280e00185970ba0bdd (patch)
tree75289a0c3f4d8ad01ec4bba79bc52fb3d10a388e /core/moduleapi.lua
parent6924d7bfb5c9bcd125a5b872bd9fb7fc6d1b5322 (diff)
downloadprosody-15a073672027cdf47822ad280e00185970ba0bdd.tar.gz
prosody-15a073672027cdf47822ad280e00185970ba0bdd.zip
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Diffstat (limited to 'core/moduleapi.lua')
-rw-r--r--core/moduleapi.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index ee960709..3a28ec62 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -66,14 +66,17 @@ function api:fire_event(...)
return (hosts[self.host] or prosody).events.fire_event(...);
end
+function api:hook_object_event(object, event, handler, priority)
+ self.event_handlers[handler] = { name = event, priority = priority, object = object };
+ return object.add_handler(event, handler, priority);
+end
+
function api:hook(event, handler, priority)
- hooks:set(self.host, self.name, event, handler, true);
- (hosts[self.host] or prosody).events.add_handler(event, handler, priority);
+ return self:hook_object_event((hosts[self.host] or prosody).events, event, handler, priority);
end
function api:hook_global(event, handler, priority)
- hooks:set("*", self.name, event, handler, true);
- prosody.events.add_handler(event, handler, priority);
+ return self:hook_object_event(prosody.events, event, handler, priority);
end
function api:hook_stanza(xmlns, name, handler, priority)