From e635a45251af9abe3d82afdaac07217192d914d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Tue, 3 Oct 2023 17:34:43 +0200 Subject: [PATCH] Make Lua hook timeout configurable --- src/lua/LegacyLuaAPI.cpp | 2 +- src/lua/LuaScriptInterface.cpp | 3 +++ src/lua/LuaScriptInterface.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index b9702b219..32e009e16 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -259,7 +259,7 @@ int luacon_elementwrite(lua_State* l) void luacon_hook(lua_State * l, lua_Debug * ar) { auto *luacon_ci = static_cast(commandInterface); - if (ar->event == LUA_HOOKCOUNT && Platform::GetTime() - luacon_ci->luaExecutionStart > 3000) + if (ar->event == LUA_HOOKCOUNT && int(Platform::GetTime() - luacon_ci->luaExecutionStart) > luacon_ci->luaHookTimeout) { luaL_error(l, "Error: Script not responding"); luacon_ci->luaExecutionStart = Platform::GetTime(); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index adc8e2416..3a14b1a30 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1,6 +1,7 @@ #include "bzip2/bz2wrap.h" #include "common/VariantIndex.h" #include "Config.h" +#include "prefs/GlobalPrefs.h" #include "LuaScriptInterface.h" @@ -272,6 +273,8 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): currentCommand(false), textInputRefcount(0) { + auto &prefs = GlobalPrefs::Ref(); + luaHookTimeout = prefs.Get("LuaHookTimeout", 3000); luacon_model = m; luacon_controller = c; luacon_sim = m->GetSimulation(); diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index a030fc2ec..708537405 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -212,6 +212,7 @@ public: static void LuaSetProperty(lua_State* l, StructProperty property, intptr_t propertyAddress, int stackPos); static void LuaSetParticleProperty(lua_State* l, int particleID, StructProperty property, intptr_t propertyAddress, int stackPos); + int luaHookTimeout; ui::Window * Window; lua_State *l; long unsigned int luaExecutionStart = 0;