From: Matthew Wild Date: Fri, 18 May 2012 22:53:02 +0000 (+0100) Subject: moduleapi, modulemanager: Re-structure module.event_handlers so that the same handler... X-Git-Url: https://git.enpas.org/?a=commitdiff_plain;h=73750f46ca6f829f85f7d7274ed24f96fc83182b;p=prosody.git moduleapi, modulemanager: Re-structure module.event_handlers so that the same handler can harmlessly handle multiple events (thanks Zash) --- diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 44c84de1..96f1d3ea 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -70,7 +70,12 @@ function api:fire_event(...) 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 diff --git a/core/modulemanager.lua b/core/modulemanager.lua index b9f221c8..417dedbe 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -91,8 +91,8 @@ local function do_unload_module(host, name) 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