CLuaFunctionRef::CLuaFunctionRef(lua_State* luaVM, int iFunction, const void* pFuncPtr) : m_ListNode(this) { m_luaVM = lua_getmainstate(luaVM); m_iFunction = iFunction; m_pFuncPtr = pFuncPtr; ms_AllRefList.push_back(this); }
// Make sure function refs can't be used after a VM has closed void CLuaFunctionRef::RemoveLuaFunctionRefsForVM( lua_State *luaVM ) { luaVM = lua_getmainstate ( luaVM ); if ( !luaVM ) return; uint uiCount = 0; for ( CIntrusiveList < CLuaFunctionRef >::iterator iter = ms_AllRefList.begin() ; iter != ms_AllRefList.end() ; ++iter ) { CLuaFunctionRef* ref = *iter; // Compare the main state values to see if its the same VM if ( ref->m_luaVM == luaVM ) { uiCount++; luaM_dec_use ( ref->m_luaVM, ref->m_iFunction, ref->m_pFuncPtr ); ref->m_luaVM = NULL; } } if ( uiCount ) OutputDebugLine( SString( "Server RemoveLuaFunctionRefsForVM: zeroed:%d total:%d", uiCount, ms_AllRefList.size() ) ); }