Software /
code /
prosody
Comparison
core/moduleapi.lua @ 4893:98ff89ab5d1d
moduleapi, modulemanager: Re-structure module.event_handlers so that the same handler can harmlessly handle multiple events (thanks Zash)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 18 May 2012 23:53:02 +0100 |
parent | 4854:dab55c6f7710 |
child | 4896:27cda15104f2 |
comparison
equal
deleted
inserted
replaced
4892:6c8074f47ca4 | 4893:98ff89ab5d1d |
---|---|
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 self.event_handlers[handler] = { name = event, priority = priority, object = object }; | 73 local handlers = self.event_handlers[event]; |
74 if not handlers then | |
75 handlers = {}; | |
76 self.event_handlers[event] = handlers; | |
77 end | |
78 handlers[event] = { handler = handler, priority = priority, object = object }; | |
74 return object.add_handler(event, handler, priority); | 79 return object.add_handler(event, handler, priority); |
75 end | 80 end |
76 | 81 |
77 function api:unhook_object_event(object, event, handler) | 82 function api:unhook_object_event(object, event, handler) |
78 return object.remove_handler(event, handler); | 83 return object.remove_handler(event, handler); |