diff options
author | Matthew Wild <mwild1@gmail.com> | 2008-10-03 22:17:20 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2008-10-03 22:17:20 +0100 |
commit | 4ac420e3b0324843b9647aeeb908a65e4c5a8e2e (patch) | |
tree | 6b5fa94c284e080cd852089e0b375d998023606a /core/modulemanager.lua | |
parent | 6db3d039b3d8d55c9e03ebdc776cf1a23dd826c2 (diff) | |
download | prosody-4ac420e3b0324843b9647aeeb908a65e4c5a8e2e.tar.gz prosody-4ac420e3b0324843b9647aeeb908a65e4c5a8e2e.zip |
Add support for arbitrary events and event hooks
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r-- | core/modulemanager.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua index ad92b41b..2779746e 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -4,6 +4,7 @@ local log = require "util.logger".init("modulemanager") local loadfile, pcall = loadfile, pcall; local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv; local pairs, ipairs = pairs, ipairs; +local t_insert = table.insert; local type = type; local tostring, print = tostring, print; @@ -90,3 +91,25 @@ function handle_stanza(origin, stanza) log("debug", "Stanza unhandled by any modules"); return false; -- we didn't handle it end + +do + local event_handlers = {}; + + function modulehelpers.add_event_hook(name, handler) + if not event_handlers[name] then + event_handlers[name] = {}; + end + t_insert(event_handlers[name] , handler); + end + + function fire_event(name, ...) + local event_handlers = event_handlers[name]; + if event_handlers then + for name, handler in ipairs(event_handlers) do + handler(...); + end + end + end +end + +return _M; |