Software /
code /
prosody
Diff
core/modulemanager.lua @ 1259:6bd11bca9725
modulemanager: Keep track of event handlers added by module:hook, and remove them on module unload
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 31 May 2009 13:31:20 +0500 |
parent | 1253:60156584c442 |
child | 1309:a544e68a0989 |
line wrap: on
line diff
--- a/core/modulemanager.lua Sun May 31 02:20:30 2009 +0500 +++ b/core/modulemanager.lua Sun May 31 13:31:20 2009 +0500 @@ -49,6 +49,7 @@ local features_table = multitable_new(); local handler_table = multitable_new(); local hooked = multitable_new(); +local hooks = multitable_new(); local event_hooks = multitable_new(); local NULL = {}; @@ -165,6 +166,13 @@ end end event_hooks:remove(host, name); + -- 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 + hooks:remove(host, name); return true; end @@ -356,6 +364,7 @@ end function api:hook(event, handler) + hooks:set(self.host, self.name, event, handler, true); (hosts[self.host] or prosody).events.add_handler(event, handler); end