aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/events.lua13
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