Software /
code /
prosody
Comparison
core/moduleapi.lua @ 4896:27cda15104f2
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 19 May 2012 15:39:16 +0100 |
parent | 4893:98ff89ab5d1d |
child | 4954:318624ffe74e |
child | 5021:85b2689dbcfe |
comparison
equal
deleted
inserted
replaced
4895:36df30395c44 | 4896:27cda15104f2 |
---|---|
68 function api:fire_event(...) | 68 function api:fire_event(...) |
69 return (hosts[self.host] or prosody).events.fire_event(...); | 69 return (hosts[self.host] or prosody).events.fire_event(...); |
70 end | 70 end |
71 | 71 |
72 function api:hook_object_event(object, event, handler, priority) | 72 function api:hook_object_event(object, event, handler, priority) |
73 local handlers = self.event_handlers[event]; | 73 self.event_handlers:set(object, event, handler, true); |
74 if not handlers then | |
75 handlers = {}; | |
76 self.event_handlers[event] = handlers; | |
77 end | |
78 handlers[event] = { handler = handler, priority = priority, object = object }; | |
79 return object.add_handler(event, handler, priority); | 74 return object.add_handler(event, handler, priority); |
80 end | 75 end |
81 | 76 |
82 function api:unhook_object_event(object, event, handler) | 77 function api:unhook_object_event(object, event, handler) |
83 return object.remove_handler(event, handler); | 78 return object.remove_handler(event, handler); |