When I have two scripts with the same function names and arguments run in different threads with SUPPOSEDLY different environments, the second thread ends up overwriting the definitions of the first and the first thread's state gets garbage collected!
// My thread instancing function
lua_State* LuaInstance::RunInstance(const std::string& fileName)
{
lua_State* L = lua_newthread(m_state);
// Give new thread it's own global table
lua_newtable(L);
lua_newtable(L);
lua_pushliteral(L, "__index");
lua_pushvalue(L, LUA_GLOBALSINDEX); // Original globals
lua_settable(L, -3);
lua_setmetatable(L, -2);
lua_replace(L, LUA_GLOBALSINDEX); // Replace LB's globals
// Run script off new thread
luaL_dofile(L, fileName.c_str());
return L;
}
I'm basically trying to get it so that I can call multiple scripts like this (For a game engine):
-- Script 1
function Init(self)
-- Do some stuff
end
-- Script 2
function Init(self)
-- Do some other stuff
end