diff --git a/lib/LuaGate/sources/LuaGate.cpp b/lib/LuaGate/sources/LuaGate.cpp index a2aba27a..c1099553 100644 --- a/lib/LuaGate/sources/LuaGate.cpp +++ b/lib/LuaGate/sources/LuaGate.cpp @@ -7,19 +7,20 @@ namespace LuaG { State::State() - : _state(luaL_newstate()) + : _state(luaL_newstate()), _shouldClose(true) { luaL_openlibs(_state); } - State::State(lua_State *L) - : _state(L) + State::State(lua_State *L, bool shouldClose) + : _state(L), _shouldClose(shouldClose) { } State::~State() { - lua_close(_state); + if (_shouldClose) + lua_close(_state); } lua_State *State::getState(void) diff --git a/lib/LuaGate/sources/LuaGate.hpp b/lib/LuaGate/sources/LuaGate.hpp index 9344677a..d79880a0 100644 --- a/lib/LuaGate/sources/LuaGate.hpp +++ b/lib/LuaGate/sources/LuaGate.hpp @@ -14,12 +14,15 @@ namespace LuaG private: //! @brief Lua state lua_State *_state; + + //! @brief Should close the state at destruction + bool _shouldClose; public: //! @brief ctor State(); //! @brief ctor - State(lua_State *L); + State(lua_State *L, bool shouldClose = false); //! @brief dtor diff --git a/sources/Map/LuaMap.hpp b/sources/Map/LuaMap.hpp index 1e3ff4cd..073fbbb1 100644 --- a/sources/Map/LuaMap.hpp +++ b/sources/Map/LuaMap.hpp @@ -24,7 +24,7 @@ namespace BBM //! @brief push table of table of the map static int getMap(lua_State *L) { - //LuaG::State state(L); + LuaG::State state(L); int index = 1; const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1)); @@ -66,7 +66,7 @@ namespace BBM //! @brief get array of nodes, path from a to b static int getPath(lua_State *L) { - //LuaG::State state(L); + LuaG::State state(L); const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1)); lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE);