Software /
code /
prosody
Comparison
core/moduleapi.lua @ 4534:7a0a31c4f6c5
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.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Jan 2012 18:49:11 +0000 |
parent | 4531:c778ce7e3c78 |
child | 4538:d0a89c1c43fd |
comparison
equal
deleted
inserted
replaced
4533:c6480d17be1e | 4534:7a0a31c4f6c5 |
---|---|
64 | 64 |
65 function api:fire_event(...) | 65 function api:fire_event(...) |
66 return (hosts[self.host] or prosody).events.fire_event(...); | 66 return (hosts[self.host] or prosody).events.fire_event(...); |
67 end | 67 end |
68 | 68 |
69 function api:hook_object_event(object, event, handler, priority) | |
70 self.event_handlers[handler] = { name = event, priority = priority, object = object }; | |
71 return object.add_handler(event, handler, priority); | |
72 end | |
73 | |
69 function api:hook(event, handler, priority) | 74 function api:hook(event, handler, priority) |
70 hooks:set(self.host, self.name, event, handler, true); | 75 return self:hook_object_event((hosts[self.host] or prosody).events, event, handler, priority); |
71 (hosts[self.host] or prosody).events.add_handler(event, handler, priority); | |
72 end | 76 end |
73 | 77 |
74 function api:hook_global(event, handler, priority) | 78 function api:hook_global(event, handler, priority) |
75 hooks:set("*", self.name, event, handler, true); | 79 return self:hook_object_event(prosody.events, event, handler, priority); |
76 prosody.events.add_handler(event, handler, priority); | |
77 end | 80 end |
78 | 81 |
79 function api:hook_stanza(xmlns, name, handler, priority) | 82 function api:hook_stanza(xmlns, name, handler, priority) |
80 if not handler and type(name) == "function" then | 83 if not handler and type(name) == "function" then |
81 -- If only 2 options then they specified no xmlns | 84 -- If only 2 options then they specified no xmlns |