should close on the lua state encapsulation to use it in labmdas

This commit is contained in:
Bluub
2021-06-18 11:51:58 +02:00
parent b355aed333
commit 4f6dd75c5d
3 changed files with 11 additions and 7 deletions
+5 -4
View File
@@ -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)
+4 -1
View File
@@ -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
+2 -2
View File
@@ -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);