Software /
code /
prosody
Changeset
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 |
parents | 4892:6c8074f47ca4 |
children | 4894:c874dc4ccbd7 |
files | core/moduleapi.lua core/modulemanager.lua |
diffstat | 2 files changed, 8 insertions(+), 3 deletions(-) [+] |
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
--- a/core/modulemanager.lua Fri May 18 04:24:33 2012 +0100 +++ b/core/modulemanager.lua Fri May 18 23:53:02 2012 +0100 @@ -91,8 +91,8 @@ end end - for handler, event in pairs(mod.module.event_handlers) do - event.object.remove_handler(event.name, handler); + for event, data in pairs(mod.module.event_handlers) do + data.object.remove_handler(event, data.handler); end if mod.module.items then -- remove items