lua stack check

This commit is contained in:
Glenn Maynard
2006-01-14 06:53:09 +00:00
parent 8091e105de
commit f4a634034c
+15
View File
@@ -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;
}