From 89adfeefbfb954272bd53a172c07e3633186198e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jan 2012 19:10:13 +0000 Subject: util.helpers: After nearly 'fixing' this code, I conclude it instead only deserves a bigger smile --- util/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/helpers.lua') diff --git a/util/helpers.lua b/util/helpers.lua index 11356176..a8c8c612 100644 --- a/util/helpers.lua +++ b/util/helpers.lua @@ -28,7 +28,7 @@ function log_events(events, name, logger) end function revert_log_events(events) - events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :) + events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :)) end function get_upvalue(f, get_name) -- cgit v1.2.3 From de1fd4aaf27ca216bcbfeeeb197845078311aa13 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Apr 2012 18:54:34 +0100 Subject: util.helpers: Add show_events(), to show the events and handlers in a util.events object --- util/helpers.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'util/helpers.lua') diff --git a/util/helpers.lua b/util/helpers.lua index a8c8c612..ad23dd79 100644 --- a/util/helpers.lua +++ b/util/helpers.lua @@ -6,6 +6,8 @@ -- COPYING file in the source package for more information. -- +local debug = require "util.debug"; + module("helpers", package.seeall); -- Helper functions for debugging @@ -31,6 +33,33 @@ function revert_log_events(events) events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :)) end +function show_events(events) + 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 ""); + end + event_handler_arrays[event] = handler_strings; + end + table.sort(events_array); + local i = 1; + repeat + 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; + return table.concat(events_array, "\n"); +end + function get_upvalue(f, get_name) local i, name, value = 0; repeat -- cgit v1.2.3