aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-01-22 18:49:11 +0000
committerMatthew Wild <mwild1@gmail.com>2012-01-22 18:49:11 +0000
commit15a073672027cdf47822ad280e00185970ba0bdd (patch)
tree75289a0c3f4d8ad01ec4bba79bc52fb3d10a388e /core/modulemanager.lua
parent6924d7bfb5c9bcd125a5b872bd9fb7fc6d1b5322 (diff)
downloadprosody-15a073672027cdf47822ad280e00185970ba0bdd.tar.gz
prosody-15a073672027cdf47822ad280e00185970ba0bdd.zip
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r--core/modulemanager.lua22
1 files changed, 5 insertions, 17 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 9f90e34e..f86298c9 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -48,10 +48,6 @@ local api = _G.require "core.moduleapi"; -- Module API container
local modulemap = { ["*"] = {} };
-local modulehelpers = setmetatable({}, { __index = _G });
-
-local hooks = multitable_new();
-
local NULL = {};
-- Load modules when a host is activated
@@ -100,19 +96,11 @@ local function do_unload_module(host, name)
log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err);
end
end
- -- unhook event handlers hooked by module:hook
- for event, handlers in pairs(hooks:get(host, name) or NULL) do
- for handler in pairs(handlers or NULL) do
- (hosts[host] or prosody).events.remove_handler(event, handler);
- end
- end
- -- unhook event handlers hooked by module:hook_global
- for event, handlers in pairs(hooks:get("*", name) or NULL) do
- for handler in pairs(handlers or NULL) do
- prosody.events.remove_handler(event, handler);
- end
+
+ for handler, event in pairs(mod.module.event_handlers) do
+ event.object.remove_handler(event.name, handler);
end
- hooks:remove(host, name);
+
if mod.module.items then -- remove items
for key,t in pairs(mod.module.items) do
for i = #t,1,-1 do
@@ -153,7 +141,7 @@ local function do_load_module(host, module_name)
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 }
+ _log = _log, log = function (self, ...) return _log(...); end, event_handlers = {} }
, { __index = api });
local pluginenv = setmetatable({ module = api_instance }, { __index = _G });