aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
Diffstat (limited to 'core/modulemanager.lua')
-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;