Exemple #1
0
LuaState::LuaState(bool initStandardLibrary, bool multithreaded)
{
	m_state = lua_open();
	m_ownState = true;

	lua_setusergcfunction(m_state, LuaPlusGCFunction);

	SetupStateEx();

	GetHeadObject()->m_prev = NULL;
	GetHeadObject()->m_next = GetTailObject();
	GetTailObject()->m_prev = GetHeadObject();
	GetTailObject()->m_next = NULL;

#ifdef LUA_MTSUPPORT
	if (multithreaded)
	{
#ifdef WIN32
		// What about clean up?
		CRITICAL_SECTION* cs = new CRITICAL_SECTION;
		::InitializeCriticalSection(cs);
		lua_setlockfunctions(m_state, LSLock, LSUnlock, cs);
#endif WIN32
	}
#endif LUA_MTSUPPORT
	
	Init(initStandardLibrary);
}
LuaState::LuaState(bool initStandardLibrary, bool multithreaded)
{
	m_state = lua_newstate(luaHelper_defaultAlloc, luaHelper_ud);
	m_ownState = true;

	lua_setusergcfunction(m_state, LuaPlusGCFunction);
//jj    luaX_setnewthreadhandler( newthread_handler );
//jj    luaX_setfreethreadhandler( freethread_handler );

	SetupStateEx();

	GetHeadObject()->m_prev = NULL;
	GetHeadObject()->m_next = (LuaObject*)GetTailObject();
	GetTailObject()->m_prev = (LuaObject*)GetHeadObject();
	GetTailObject()->m_next = NULL;

#ifdef LUA_MTSUPPORT
	if (multithreaded)
	{
/*#ifdef WIN32
		// What about clean up?
		CRITICAL_SECTION* cs = new CRITICAL_SECTION;
		::InitializeCriticalSection(cs);
		lua_setlockfunctions(m_state, LSLock, LSUnlock, cs);
#endif // WIN32*/
	}
#endif // LUA_MTSUPPORT

//    luastateopen_thread(m_state);

    Init(initStandardLibrary);
}
LuaState::LuaState(lua_State* L, lua_State* L1)
{
	m_state = L1;

	m_ownState = false;

    GetHeadObject()->m_prev = NULL;
	GetHeadObject()->m_next = (LuaObject*)GetTailObject();
	GetTailObject()->m_prev = (LuaObject*)GetHeadObject();
	GetTailObject()->m_next = NULL;

    SetupStateEx();
}
Exemple #4
0
LuaState::LuaState(LuaState* parentState, bool initStandardLibrary)
{
	m_state = lua_newthread(*parentState);
	m_ownState = false;			// Threads are not closeable.

	GetHeadObject()->m_prev = NULL;
	GetHeadObject()->m_next = GetTailObject();
	GetTailObject()->m_prev = GetHeadObject();
	GetTailObject()->m_next = NULL;

	m_threadObj = LuaStackObject(parentState, parentState->GetTop());
	parentState->Pop();

	SetupStateEx();
}
LuaState::LuaState( lua_State* state )
{
	m_state = state;

	m_ownState = false;

//jj    luaX_setnewthreadhandler( newthread_handler );
//jj    luaX_setfreethreadhandler( freethread_handler );

    GetHeadObject()->m_prev = NULL;
	GetHeadObject()->m_next = (LuaObject*)GetTailObject();
	GetTailObject()->m_prev = (LuaObject*)GetHeadObject();
	GetTailObject()->m_next = NULL;

    SetupStateEx();

//    luastateopen_thread(m_state);
}
/**
	The LuaState class assumes ownership of the lua_State pointer and
	destroys it when destroyed.
**/
LuaState::~LuaState()
{
	if ( m_state  &&  m_ownState )
	{
		lua_close( m_state );

        MiniLuaObject* headObject = GetHeadObject();	(void)headObject;
		MiniLuaObject* tailObject = GetTailObject();	(void)tailObject;
		assert((MiniLuaObject*)headObject->m_next == tailObject && "There are still active LuaObjects referencing this state");
		luaplus_assert((MiniLuaObject*)headObject->m_next == tailObject);
	}
}