Software /
code /
prosody
Diff
core/modulemanager.lua @ 4896:27cda15104f2
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 19 May 2012 15:39:16 +0100 |
parent | 4893:98ff89ab5d1d |
child | 5021:85b2689dbcfe |
line wrap: on
line diff
--- 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 });