From daae15eb57164f0eea14e6e12907d3c84fb04e79 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 31 Jul 2023 22:06:44 +0100 Subject: [PATCH] EventEmitter: improve debug logging --- worldeditadditions_core/utils/EventEmitter.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/worldeditadditions_core/utils/EventEmitter.lua b/worldeditadditions_core/utils/EventEmitter.lua index 4632606..adbde5a 100644 --- a/worldeditadditions_core/utils/EventEmitter.lua +++ b/worldeditadditions_core/utils/EventEmitter.lua @@ -58,8 +58,12 @@ end -- @param event_name string The name of the event to emit. -- @param args table|any The argument(s) to pass to listener functions. It is strongly advised you pass a table here. function EventEmitter.emit(this, event_name, args) + if this.debug then + listeners = 0 + if this.events[event_name] ~= nil then listeners = #this.events[event_name] end + print("DEBUG:EventEmitter emit", event_name, "listeners", listeners, "args", wea_c.inspect(args)) + end if this.events[event_name] == nil then return end - if this.debug then print("DEBUG:EventEmitter emit", event_name, "args", wea_c.inspect(args)) end for index,next_func in ipairs(this.events[event_name]) do next_func(args)