lockable Lua object; "Lua" alias to replace "lua_State"

This commit is contained in:
Glenn Maynard
2005-06-15 08:16:28 +00:00
parent d748e6bbef
commit e3a8b72639
2 changed files with 24 additions and 0 deletions
+17
View File
@@ -5,6 +5,7 @@
#include "RageUtil.h"
#include "RageLog.h"
#include "RageFile.h"
#include "RageThreads.h"
#include "arch/Dialog/Dialog.h"
#include "Foreach.h"
@@ -152,6 +153,7 @@ LuaManager::LuaManager()
LUA = this; // so that LUA is available when we call the Register functions
L = NULL;
m_pLock = new RageMutex( "Lua" );
ResetState();
}
@@ -159,8 +161,23 @@ LuaManager::LuaManager()
LuaManager::~LuaManager()
{
lua_close( L );
delete m_pLock;
}
Lua *LuaManager::Get()
{
m_pLock->Lock();
return L;
}
void LuaManager::Release( Lua *&p )
{
ASSERT( p == L );
m_pLock->Unlock();
p = NULL;
}
void LuaManager::RegisterTypes()
{
for( const LuaFunctionList *p = g_LuaFunctions; p; p=p->next )
+7
View File
@@ -2,7 +2,9 @@
#define LUA_MANAGER_H
struct lua_State;
typedef lua_State Lua;
typedef void (*RegisterWithLuaFn)(lua_State*);
class RageMutex;
extern "C"
{
@@ -49,6 +51,9 @@ public:
LuaManager();
~LuaManager();
Lua *Get();
void Release( Lua *&p );
void PrepareExpression( CString &sInOut ); // strip "//" comments and "+"
bool RunScriptFile( const CString &sFile );
@@ -96,6 +101,8 @@ public:
lua_State *L;
private:
RageMutex *m_pLock;
/* Register all subscribing types. There's no harm in registering when already registered. */
void RegisterTypes();
};