lockable Lua object; "Lua" alias to replace "lua_State"
This commit is contained in:
@@ -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 )
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user