aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-09-03 12:59:43 +0100
committerMatthew Wild <mwild1@gmail.com>2020-09-03 12:59:43 +0100
commitc909bca762b655dd798b9f0f5c937feced7aa655 (patch)
tree4153e8bfdc225c44323fd205b47301d966339e7e /util
parent1cec1146460848a60dca8ebc85c97d7c45544c65 (diff)
downloadprosody-c909bca762b655dd798b9f0f5c937feced7aa655.tar.gz
prosody-c909bca762b655dd798b9f0f5c937feced7aa655.zip
util.events: Add set_debug_hook() method
Hook signature: ret = debug_hook(handler, event_name, event_data)
Diffstat (limited to 'util')
-rw-r--r--util/events.lua20
1 files changed, 19 insertions, 1 deletions
diff --git a/util/events.lua b/util/events.lua
index 0bf0ddcb..5205a457 100644
--- a/util/events.lua
+++ b/util/events.lua
@@ -26,6 +26,8 @@ local function new()
local wrappers = {};
-- Event map: event_map[handler_function] = priority_number
local event_map = {};
+ -- Debug hook, if any
+ local active_debug_hook = nil;
-- Called on-demand to build handlers entries
local function _rebuild_index(self, event)
local _handlers = event_map[event];
@@ -74,11 +76,16 @@ local function new()
end;
local function _fire_event(event_name, event_data)
local h = handlers[event_name];
- if h then
+ if h and not active_debug_hook then
for i=1,#h do
local ret = h[i](event_data);
if ret ~= nil then return ret; end
end
+ elseif h and active_debug_hook then
+ for i=1,#h do
+ local ret = active_debug_hook(h[i], event_name, event_data);
+ if ret ~= nil then return ret; end
+ end
end
end;
local function fire_event(event_name, event_data)
@@ -140,6 +147,13 @@ local function new()
end
end
end
+
+ local function set_debug_hook(new_hook)
+ local old_hook = active_debug_hook;
+ active_debug_hook = new_hook;
+ return old_hook;
+ end
+
return {
add_handler = add_handler;
remove_handler = remove_handler;
@@ -150,8 +164,12 @@ local function new()
add_handler = add_wrapper;
remove_handler = remove_wrapper;
};
+
add_wrapper = add_wrapper;
remove_wrapper = remove_wrapper;
+
+ set_debug_hook = set_debug_hook;
+
fire_event = fire_event;
_handlers = handlers;
_event_map = event_map;