1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00

event core - log where the error comes from

This commit is contained in:
Gerkiz 2021-02-01 00:00:02 +01:00
parent 1bba0eb9bf
commit 8062179602

View File

@ -20,33 +20,25 @@ local on_nth_tick_event_handlers = {}
if not remote.interfaces['interface'] then
remote.add_interface('interface', interface)
end ]]
local pcall = pcall
local xpcall = xpcall
local trace = debug.traceback
local log = log
local script_on_event = script.on_event
local script_on_nth_tick = script.on_nth_tick
local call_handlers
if _DEBUG then
function call_handlers(handlers, event)
if not handlers then
return log('Handlers was nil!')
end
local function handler_error(err)
log('\n\t' .. trace(err))
end
local function call_handlers(handlers, event)
if _DEBUG then
for i = 1, #handlers do
local handler = handlers[i]
handler(event)
end
end
else
function call_handlers(handlers, event)
if not handlers then
return log('Handlers was nil!')
end
else
for i = 1, #handlers do
local handler = handlers[i]
local success, error = pcall(handler, event)
if not success then
log(error)
end
xpcall(handlers[i], handler_error, event)
end
end
end