diff options
author | 2010-12-07 16:59:13 -0500 | |
---|---|---|
committer | 2010-12-07 16:59:13 -0500 | |
commit | eff79c94b8366831cb2a31651f677fb85de70ea8 (patch) | |
tree | 725fd8b665b550cbdae3941c32641abffb4d9ffc /core/events.lua | |
parent | e572c0c30f53caa46e87167f7609ee9f8e7727da (diff) |
Fix infinite recursion errors caused in events.
Diffstat (limited to 'core/events.lua')
-rw-r--r-- | core/events.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/core/events.lua b/core/events.lua index a0cc2bdd..80003bf9 100644 --- a/core/events.lua +++ b/core/events.lua @@ -154,6 +154,8 @@ function disconnect(event, index) table.remove(handlers, index) end +local error_emitted = false + --- -- Calls all handlers for the given event in sequence (effectively "generating" -- the event). @@ -167,7 +169,16 @@ function emit(event, ...) local handlers = _M[plural] if not handlers then return end for _, f in ipairs(handlers) do - local result = f(unpack{...}) + local ok, result = pcall(f, unpack{...}) + if not ok then + if not error_emitted then + error_emitted = true + emit('error', result) + error_emitted = false + else + io.stderr:write(result) + end + end if type(result) == 'boolean' then return result end end end |