Skip to content

Commit

Permalink
Add missing lua gc in DB Insert (#4596)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-bernardo authored Dec 13, 2023
1 parent 40bf60a commit 0f606ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,7 @@ void LuaScriptInterface::registerFunctions()

// DB Insert
registerClass("DBInsert", "", LuaScriptInterface::luaDBInsertCreate);
registerMetaMethod("DBInsert", "__gc", LuaScriptInterface::luaDBInsertDelete);

registerMethod("DBInsert", "addRow", LuaScriptInterface::luaDBInsertAddRow);
registerMethod("DBInsert", "execute", LuaScriptInterface::luaDBInsertExecute);
Expand Down Expand Up @@ -4445,6 +4446,16 @@ int LuaScriptInterface::luaDBInsertExecute(lua_State* L)
return 1;
}

int LuaScriptInterface::luaDBInsertDelete(lua_State* L)
{
DBInsert** insertPtr = getRawUserdata<DBInsert>(L, 1);
if (insertPtr && *insertPtr) {
delete *insertPtr;
*insertPtr = nullptr;
}
return 0;
}

// DB Transaction
int LuaScriptInterface::luaDBTransactionCreate(lua_State* L)
{
Expand Down
1 change: 1 addition & 0 deletions src/luascript.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ class LuaScriptInterface
static int luaDBInsertCreate(lua_State* L);
static int luaDBInsertAddRow(lua_State* L);
static int luaDBInsertExecute(lua_State* L);
static int luaDBInsertDelete(lua_State* L);

// DB Transaction
static int luaDBTransactionCreate(lua_State* L);
Expand Down

0 comments on commit 0f606ee

Please sign in to comment.