aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-10-03 22:17:20 +0100
committerMatthew Wild <mwild1@gmail.com>2008-10-03 22:17:20 +0100
commit4ac420e3b0324843b9647aeeb908a65e4c5a8e2e (patch)
tree6b5fa94c284e080cd852089e0b375d998023606a
parent6db3d039b3d8d55c9e03ebdc776cf1a23dd826c2 (diff)
downloadprosody-4ac420e3b0324843b9647aeeb908a65e4c5a8e2e.tar.gz
prosody-4ac420e3b0324843b9647aeeb908a65e4c5a8e2e.zip
Add support for arbitrary events and event hooks
-rw-r--r--core/modulemanager.lua23
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;