From 03a3062940ebfc4e8f0b3efc5930c71f8d07b604 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 31 Dec 2024 10:25:26 +0300 Subject: [PATCH] fix error handling in events and runnables --- res/scripts/stdlib.lua | 5 ++++- src/logic/scripting/lua/lua_engine.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 714725d0..611a94d2 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -172,7 +172,10 @@ local __post_runnables = {} function __process_post_runnables() if #__post_runnables then for _, func in ipairs(__post_runnables) do - func() + local status, result = pcall(func) + if not status then + debug.log("error in post_runnable: "..result) + end end __post_runnables = {} end diff --git a/src/logic/scripting/lua/lua_engine.cpp b/src/logic/scripting/lua/lua_engine.cpp index 8d40221c..e51e5e18 100644 --- a/src/logic/scripting/lua/lua_engine.cpp +++ b/src/logic/scripting/lua/lua_engine.cpp @@ -136,10 +136,12 @@ bool lua::emit_event( getglobal(L, "events"); getfield(L, "emit"); pushstring(L, name); - call_nothrow(L, args(L) + 1); - bool result = toboolean(L, -1); - pop(L, 2); - return result; + if (call_nothrow(L, args(L) + 1)) { + bool result = toboolean(L, -1); + pop(L, 2); + return result; + } + return false; } State* lua::get_main_state() {