Software /
code /
prosody
Diff
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 |
line wrap: on
line diff
--- a/core/moduleapi.lua Fri May 18 04:24:33 2012 +0100 +++ b/core/moduleapi.lua Fri May 18 23:53:02 2012 +0100 @@ -70,7 +70,12 @@ end function api:hook_object_event(object, event, handler, priority) - self.event_handlers[handler] = { name = event, priority = priority, object = object }; + local handlers = self.event_handlers[event]; + if not handlers then + handlers = {}; + self.event_handlers[event] = handlers; + end + handlers[event] = { handler = handler, priority = priority, object = object }; return object.add_handler(event, handler, priority); end