mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 00:53:00 +00:00
EventEmitter: add debug printing (disabled by default)
This commit is contained in:
parent
9806828760
commit
9a4b4beb76
1 changed files with 5 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
|
local wea_c = worldeditadditions_core
|
||||||
--- Event manager object.
|
--- Event manager object.
|
||||||
-- @class worldeditadditions_core.EventEmitter
|
-- @class worldeditadditions_core.EventEmitter
|
||||||
local EventEmitter = {}
|
local EventEmitter = {}
|
||||||
|
@ -11,6 +11,7 @@ EventEmitter.__name = "EventEmitter" -- A hack to allow identification in wea.in
|
||||||
function EventEmitter.new(tbl)
|
function EventEmitter.new(tbl)
|
||||||
if not tbl then tbl = {} end
|
if not tbl then tbl = {} end
|
||||||
tbl.events = { }
|
tbl.events = { }
|
||||||
|
tbl.debug = false
|
||||||
setmetatable(tbl, EventEmitter)
|
setmetatable(tbl, EventEmitter)
|
||||||
return tbl
|
return tbl
|
||||||
end
|
end
|
||||||
|
@ -58,6 +59,8 @@ end
|
||||||
-- @param args table|any The argument(s) to pass to listener functions. It is strongly advised you pass a table here.
|
-- @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)
|
function EventEmitter.emit(this, event_name, args)
|
||||||
if this.events[event_name] == nil then return 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
|
for index,next_func in ipairs(this.events[event_name]) do
|
||||||
next_func(args)
|
next_func(args)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue