luaaa
luaaa copied to clipboard
Classes can only be bound to a single lua_State
When using the class binding functions, it appears that once a class has been bound to a lua_State, another lua_State cannot also have access to the given class while the first lua_State still exists.
As a minimal display of the issue, referencing the Cat class from your example code:
lua_State* state1 = luaL_newstate();
lua_State* state2 = luaL_newstate();
luaaa::LuaClass<Cat> lc1(state1, "AwesomeCat");
lc1.ctor();
luaaa::LuaClass<Cat> lc2(state2, "AwesomeCat");
lc2.ctor();
lua_close(state1);
lua_close(state2);
Results in the following assertion failure:
luaaa.hpp:979: luaaa::LuaClass< <template-parameter-1-1> >::LuaClass(lua_State*, const char*, const luaL_Reg*) [with TCLASS = Cat; lua_State = lua_State; luaL_Reg = luaL_Reg]: Assertion `klassName == nullptr' failed.
Meanwhile, if you close the first state before proceeding to the second, there isn't a problem.
lua_State* state1 = luaL_newstate();
lua_State* state2 = luaL_newstate();
luaaa::LuaClass<Cat> lc1(state1, "AwesomeCat");
lc1.ctor();
lua_close(state1);
luaaa::LuaClass<Cat> lc2(state2, "AwesomeCat");
lc2.ctor();
lua_close(state2);
Using LuaModule in this way does not appear to have the same issue.