Make Lua hook timeout configurable

This commit is contained in:
Tamás Bálint Misius 2023-10-03 17:34:43 +02:00
parent b89d29b744
commit e635a45251
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
3 changed files with 5 additions and 1 deletions

View File

@ -259,7 +259,7 @@ int luacon_elementwrite(lua_State* l)
void luacon_hook(lua_State * l, lua_Debug * ar)
{
auto *luacon_ci = static_cast<LuaScriptInterface *>(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();

View File

@ -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();

View File

@ -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;