fix(piluaprogram): add destructor to close Lua state

luaL_newstate() allocates a Lua state (~2-4 MB with libraries)
in the constructor, but there was no destructor to call lua_close().
Every PILuaProgram instance leaked its entire Lua state.
Add ~PILuaProgram() that calls lua_close(PRIVATE->lua_state).
This commit is contained in:
2026-08-10 16:26:13 +03:00
parent 9294cd7b7b
commit 4d2c268710
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -30,6 +30,11 @@ PILuaProgram::PILuaProgram() {
}
PILuaProgram::~PILuaProgram() {
lua_close(PRIVATE->lua_state);
}
bool PILuaProgram::load(const PIString & script) {
int ret = luaL_dostring(PRIVATE->lua_state, script.dataUTF8());
if (ret != 0) return false;
+4
View File
@@ -41,6 +41,10 @@ public:
//! \~russian Создает объект Lua-программы и открывает стандартные библиотеки Lua.
PILuaProgram();
//! \~english Closes the Lua state and releases all associated resources.
//! \~russian Закрывает Lua state и освобождает все связанные ресурсы.
~PILuaProgram();
//! \~english Loads and executes Lua source code from \a script.
//! \~russian Загружает и выполняет исходный код Lua из \a script.
bool load(const PIString & script);