lockable Lua object; "Lua" alias to replace "lua_State"
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "RageFile.h"
|
#include "RageFile.h"
|
||||||
|
#include "RageThreads.h"
|
||||||
#include "arch/Dialog/Dialog.h"
|
#include "arch/Dialog/Dialog.h"
|
||||||
#include "Foreach.h"
|
#include "Foreach.h"
|
||||||
|
|
||||||
@@ -152,6 +153,7 @@ LuaManager::LuaManager()
|
|||||||
LUA = this; // so that LUA is available when we call the Register functions
|
LUA = this; // so that LUA is available when we call the Register functions
|
||||||
|
|
||||||
L = NULL;
|
L = NULL;
|
||||||
|
m_pLock = new RageMutex( "Lua" );
|
||||||
|
|
||||||
ResetState();
|
ResetState();
|
||||||
}
|
}
|
||||||
@@ -159,8 +161,23 @@ LuaManager::LuaManager()
|
|||||||
LuaManager::~LuaManager()
|
LuaManager::~LuaManager()
|
||||||
{
|
{
|
||||||
lua_close( L );
|
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()
|
void LuaManager::RegisterTypes()
|
||||||
{
|
{
|
||||||
for( const LuaFunctionList *p = g_LuaFunctions; p; p=p->next )
|
for( const LuaFunctionList *p = g_LuaFunctions; p; p=p->next )
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
#define LUA_MANAGER_H
|
#define LUA_MANAGER_H
|
||||||
|
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
|
typedef lua_State Lua;
|
||||||
typedef void (*RegisterWithLuaFn)(lua_State*);
|
typedef void (*RegisterWithLuaFn)(lua_State*);
|
||||||
|
class RageMutex;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@@ -49,6 +51,9 @@ public:
|
|||||||
LuaManager();
|
LuaManager();
|
||||||
~LuaManager();
|
~LuaManager();
|
||||||
|
|
||||||
|
Lua *Get();
|
||||||
|
void Release( Lua *&p );
|
||||||
|
|
||||||
void PrepareExpression( CString &sInOut ); // strip "//" comments and "+"
|
void PrepareExpression( CString &sInOut ); // strip "//" comments and "+"
|
||||||
|
|
||||||
bool RunScriptFile( const CString &sFile );
|
bool RunScriptFile( const CString &sFile );
|
||||||
@@ -96,6 +101,8 @@ public:
|
|||||||
lua_State *L;
|
lua_State *L;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
RageMutex *m_pLock;
|
||||||
|
|
||||||
/* Register all subscribing types. There's no harm in registering when already registered. */
|
/* Register all subscribing types. There's no harm in registering when already registered. */
|
||||||
void RegisterTypes();
|
void RegisterTypes();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user