aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-26 06:58:21 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-26 06:58:21 +0100
commit9005efc19b223b78c011a908b5192ac681726eab (patch)
tree2f098d1c2fdc9ccc22a435a5dfe33ef3b695d133 /util
parentdbb3dc6a0112bac19582c811a788254e3cacef41 (diff)
downloadprosody-9005efc19b223b78c011a908b5192ac681726eab.tar.gz
prosody-9005efc19b223b78c011a908b5192ac681726eab.zip
util.helpers: show_events(): Make more robust, and allow filtering results to a specific event
Diffstat (limited to 'util')
-rw-r--r--util/helpers.lua20
1 files changed, 11 insertions, 9 deletions
diff --git a/util/helpers.lua b/util/helpers.lua
index ad23dd79..6103a319 100644
--- a/util/helpers.lua
+++ b/util/helpers.lua
@@ -33,30 +33,32 @@ function revert_log_events(events)
events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :))
end
-function show_events(events)
+function show_events(events, specific_event)
local event_handlers = events._handlers;
local events_array = {};
local event_handler_arrays = {};
for event in pairs(events._event_map) do
local handlers = event_handlers[event];
- table.insert(events_array, event);
- local handler_strings = {};
- for i, handler in ipairs(handlers) do
- local upvals = debug.string_from_var_table(debug.get_upvalues_table(handler));
- handler_strings[i] = " "..i..": "..tostring(handler)..(upvals and ("\n "..upvals) or "");
+ if handlers and (event == specific_event or not specific_event) then
+ table.insert(events_array, event);
+ local handler_strings = {};
+ for i, handler in ipairs(handlers) do
+ local upvals = debug.string_from_var_table(debug.get_upvalues_table(handler));
+ handler_strings[i] = " "..i..": "..tostring(handler)..(upvals and ("\n "..upvals) or "");
+ end
+ event_handler_arrays[event] = handler_strings;
end
- event_handler_arrays[event] = handler_strings;
end
table.sort(events_array);
local i = 1;
- repeat
+ while i <= #events_array do
local handlers = event_handler_arrays[events_array[i]];
for j=#handlers, 1, -1 do
table.insert(events_array, i+1, handlers[j]);
end
if i > 1 then events_array[i] = "\n"..events_array[i]; end
i = i + #handlers + 1
- until i == #events_array;
+ end
return table.concat(events_array, "\n");
end