diff --git a/src/lib/lua.cc b/src/lib/lua.cc index c68fdc1..ced2a24 100644 --- a/src/lib/lua.cc +++ b/src/lib/lua.cc @@ -264,6 +264,10 @@ std::shared_ptr Lua::getglobal(const std::string &v) { return o; } +void Lua::gc() { + lua_gc(L_, LUA_GCCOLLECT, 0); +} + LuaObj::LuaObj(lua_State *L, int i) : L_(L) { lua_pushvalue(L, i); id_ = luaL_ref(L, LUA_REGISTRYINDEX); diff --git a/src/lib/lua.h b/src/lib/lua.h index 6eedd87..c2d00c4 100644 --- a/src/lib/lua.h +++ b/src/lib/lua.h @@ -34,6 +34,8 @@ class Lua { std::shared_ptr newthreadx(lua_State *L, int nargs); + void gc(); + template std::shared_ptr newthread(I ... input); diff --git a/src/lua_gears.cc b/src/lua_gears.cc index 4e70092..9e1f704 100644 --- a/src/lua_gears.cc +++ b/src/lua_gears.cc @@ -23,6 +23,10 @@ bool LuaTranslation::Next() { } } +LuaTranslation::~LuaTranslation() { + lua_->gc(); +} + static std::vector split_string(const std::string& str, const std::string& delimiter) { std::vector result; size_t pos = 0; diff --git a/src/lua_gears.h b/src/lua_gears.h index d763970..8c44c6f 100644 --- a/src/lua_gears.h +++ b/src/lua_gears.h @@ -24,6 +24,8 @@ class LuaTranslation : public Translation { return c_; } + virtual ~LuaTranslation(); + private: Lua *lua_; an c_;