From 734f09abe6422237bbe8078cb8365d385a22e93d Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 3 Dec 2022 16:56:23 +0100 Subject: [PATCH] Run Lua GC in every frame --- apps/openmw/mwlua/luamanagerimp.cpp | 4 ++++ docs/source/reference/modding/settings/lua.rst | 12 ++++++++++++ files/settings-default.cfg | 3 +++ 3 files changed, 19 insertions(+) diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index 862deb0d3a..d98bb557b4 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -131,6 +131,10 @@ namespace MWLua void LuaManager::update() { static const bool luaDebug = Settings::Manager::getBool("lua debug", "Lua"); + static const int gcStepCount = Settings::Manager::getInt("gc steps per frame", "Lua"); + if (gcStepCount > 0) + lua_gc(mLua.sol(), LUA_GCSTEP, gcStepCount); + if (mPlayer.isEmpty()) return; // The game is not started yet. diff --git a/docs/source/reference/modding/settings/lua.rst b/docs/source/reference/modding/settings/lua.rst index 4433067952..510f59dc5d 100644 --- a/docs/source/reference/modding/settings/lua.rst +++ b/docs/source/reference/modding/settings/lua.rst @@ -26,3 +26,15 @@ If one, a separate thread is used. Values >1 are not yet supported. This setting can only be configured by editing the settings configuration file. + +gc steps per frame +------------------ + +:Type: integer +:Range: >= 0 +:Default: 100 + +Lua garbage collector steps per frame. The higher the value the more time Lua runtime can spend on freeing unused memory. + +This setting can only be configured by editing the settings configuration file. + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 8a6fc40fd7..779739eae5 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1141,6 +1141,9 @@ lua debug = false # If zero, Lua scripts are processed in the main thread. lua num threads = 1 +# Lua garbage collector steps per frame. +gc steps per frame = 100 + [Stereo] # Enable/disable stereo view. This setting is ignored in VR. stereo enabled = false