# HG changeset patch # User Matthew Wild # Date 1337438356 -3600 # Node ID 27cda15104f2fd7001413e005929d6ca49c9c228 # Parent 36df30395c44dc501c6974f1728bc81e2b1e00f3 modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash) diff -r 36df30395c44 -r 27cda15104f2 core/moduleapi.lua --- a/core/moduleapi.lua Sat May 19 15:35:49 2012 +0100 +++ b/core/moduleapi.lua Sat May 19 15:39:16 2012 +0100 @@ -70,12 +70,7 @@ end function api:hook_object_event(object, event, handler, priority) - 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 }; + self.event_handlers:set(object, event, handler, true); return object.add_handler(event, handler, priority); end diff -r 36df30395c44 -r 27cda15104f2 core/modulemanager.lua --- a/core/modulemanager.lua Sat May 19 15:35:49 2012 +0100 +++ b/core/modulemanager.lua Sat May 19 15:39:16 2012 +0100 @@ -10,6 +10,9 @@ local log = logger.init("modulemanager"); local config = require "core.configmanager"; local pluginloader = require "util.pluginloader"; +local set = require "util.set"; + +local new_multitable = require "util.multitable".new; local hosts = hosts; local prosody = prosody; @@ -26,8 +29,6 @@ return xpcall(function() return f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end); end -local set = require "util.set"; - local autoload_modules = {"presence", "message", "iq", "offline", "c2s", "s2s"}; local component_inheritable_modules = {"tls", "dialback", "iq", "s2s"}; @@ -91,8 +92,8 @@ end end - for event, data in pairs(mod.module.event_handlers) do - data.object.remove_handler(event, data.handler); + for object, event, handler in mod.module.event_handlers:iter(nil, nil, nil) do + object.remove_handler(event, handler); end if mod.module.items then -- remove items @@ -132,7 +133,7 @@ if module_has_method(mod, "add_host") then local _log = logger.init(host..":"..module_name); local host_module_api = setmetatable({ - host = host, event_handlers = {}, items = {}; + host = host, event_handlers = new_multitable(), items = {}; _log = _log, log = function (self, ...) return _log(...); end; },{ __index = modulemap["*"][module_name].module; @@ -159,7 +160,7 @@ local _log = logger.init(host..":"..module_name); local api_instance = setmetatable({ name = module_name, host = host, path = err, - _log = _log, log = function (self, ...) return _log(...); end, event_handlers = {} } + _log = _log, log = function (self, ...) return _log(...); end, event_handlers = new_multitable() } , { __index = api }); local pluginenv = setmetatable({ module = api_instance }, { __index = _G });