lua stack check
This commit is contained in:
@@ -191,15 +191,30 @@ LuaManager::~LuaManager()
|
||||
delete m_pLock;
|
||||
}
|
||||
|
||||
/* Keep track of Lua stack, and enforce that when we release Lua, the stack is
|
||||
* back where it was when we locked it. */
|
||||
static int g_iStackCounts[32];
|
||||
static int g_iNumStackCounts = 0;
|
||||
Lua *LuaManager::Get()
|
||||
{
|
||||
m_pLock->Lock();
|
||||
if( g_iNumStackCounts < ARRAYSIZE(g_iStackCounts) )
|
||||
{
|
||||
g_iStackCounts[g_iNumStackCounts] = lua_gettop(L);
|
||||
}
|
||||
++g_iNumStackCounts;
|
||||
return L;
|
||||
}
|
||||
|
||||
void LuaManager::Release( Lua *&p )
|
||||
{
|
||||
ASSERT( p == L );
|
||||
ASSERT( g_iNumStackCounts != 0 );
|
||||
--g_iNumStackCounts;
|
||||
if( g_iNumStackCounts < ARRAYSIZE(g_iStackCounts) )
|
||||
{
|
||||
ASSERT( g_iStackCounts[g_iNumStackCounts] == lua_gettop(L) );
|
||||
}
|
||||
m_pLock->Unlock();
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user