fix VC7 template error: move templated methods out of LuaManager
This commit is contained in:
@@ -71,7 +71,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARGS( #func, 1 ); \
|
||||
REQ_ARG( #func, 1, string ); \
|
||||
CString str; \
|
||||
LUA->PopStack( str ); \
|
||||
LuaHelpers::PopStack( str ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
@@ -83,8 +83,8 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARG( #func, 2, string ); \
|
||||
CString str1; \
|
||||
CString str2; \
|
||||
LUA->PopStack( str2 ); \
|
||||
LUA->PopStack( str1 ); \
|
||||
LuaHelpers::PopStack( str2 ); \
|
||||
LuaHelpers::PopStack( str1 ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -141,7 +141,7 @@ void LuaManager::SetGlobal( const CString &sName )
|
||||
static int LuaPanic( lua_State *L )
|
||||
{
|
||||
CString sErr;
|
||||
LUA->PopStack( sErr );
|
||||
LuaHelpers::PopStack( sErr );
|
||||
|
||||
RageException::Throw( "%s", sErr.c_str() );
|
||||
}
|
||||
@@ -270,7 +270,7 @@ bool LuaManager::RunScript( const CString &sScript, const CString &sName, CStrin
|
||||
|
||||
if( ret )
|
||||
{
|
||||
LuaManager::PopStack( sError );
|
||||
LuaHelpers::PopStack( sError );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -280,7 +280,7 @@ bool LuaManager::RunScript( const CString &sScript, const CString &sName, CStrin
|
||||
int ret = lua_pcall( L, 0, iReturnValues, 0 );
|
||||
if( ret )
|
||||
{
|
||||
LuaManager::PopStack( sError );
|
||||
LuaHelpers::PopStack( sError );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-28
@@ -26,6 +26,15 @@ namespace LuaHelpers
|
||||
bool FromStack( int &Object, int iOffset, lua_State *L );
|
||||
bool FromStack( void *&Object, int iOffset, lua_State *L );
|
||||
bool FromStack( CString &Object, int iOffset, lua_State *L );
|
||||
|
||||
template<class T>
|
||||
void ReadArrayFromTable( vector<T> aOut, lua_State *L = NULL );
|
||||
template<class T>
|
||||
void PushStack( const T &val, lua_State *L = NULL );
|
||||
template<class T>
|
||||
bool PopStack( T &val, lua_State *L = NULL );
|
||||
template<class T>
|
||||
void CreateTableFromArray( const vector<T> &aIn, lua_State *L = NULL );
|
||||
};
|
||||
|
||||
class LuaManager
|
||||
@@ -67,8 +76,8 @@ public:
|
||||
|
||||
void Fail( const CString &err );
|
||||
|
||||
void SetGlobal( const CString &sName, int val ) { PushStack(val); SetGlobal( sName ); }
|
||||
void SetGlobal( const CString &sName, bool val ) { PushStack(val); SetGlobal( sName ); }
|
||||
void SetGlobal( const CString &sName, int val ) { LuaHelpers::PushStack(val); SetGlobal( sName ); }
|
||||
void SetGlobal( const CString &sName, bool val ) { LuaHelpers::PushStack(val); SetGlobal( sName ); }
|
||||
void UnsetGlobal( const CString &sName ) { PushStackNil(); SetGlobal( sName ); }
|
||||
|
||||
void PushStackNil();
|
||||
@@ -84,13 +93,9 @@ public:
|
||||
static void ReadArrayFromTableB( vector<bool> &aOut, lua_State *L = NULL );
|
||||
|
||||
lua_State *L;
|
||||
template<class T>
|
||||
static void PushStack( const T &val, lua_State *L = NULL );
|
||||
|
||||
template<class T>
|
||||
static bool PopStack( T &val, lua_State *L = NULL );
|
||||
};
|
||||
|
||||
|
||||
namespace LuaHelpers
|
||||
{
|
||||
template<class T>
|
||||
@@ -112,27 +117,22 @@ namespace LuaHelpers
|
||||
lua_pop( L, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaManager::PushStack( const T &val, lua_State *L)
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
LuaHelpers::Push( val, L );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool LuaManager::PopStack( T &val, lua_State *L)
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
bool bRet = LuaHelpers::FromStack( val, -1, L );
|
||||
lua_pop( L, 1 );
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void PushStack( const T &val, lua_State *L )
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
LuaHelpers::Push( val, L );
|
||||
}
|
||||
template<class T>
|
||||
bool PopStack( T &val, lua_State *L )
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
bool bRet = LuaHelpers::FromStack( val, -1, L );
|
||||
lua_pop( L, 1 );
|
||||
return bRet;
|
||||
}
|
||||
template<class T>
|
||||
void CreateTableFromArray( const vector<T> &aIn, lua_State *L )
|
||||
{
|
||||
@@ -146,6 +146,8 @@ bool LuaManager::PopStack( T &val, lua_State *L)
|
||||
lua_rawseti( L, -2, i+1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define REGISTER_WITH_LUA_FUNCTION( Fn ) \
|
||||
class Register##Fn { public: Register##Fn() { LuaManager::Register( Fn ); } }; \
|
||||
|
||||
@@ -727,7 +727,7 @@ public:
|
||||
lua_pushvalue( LUA->L, 1 );
|
||||
|
||||
/* Argument 3 (pn): */
|
||||
LUA->PushStack( (int) pn );
|
||||
LuaHelpers::PushStack( (int) pn );
|
||||
|
||||
ASSERT( lua_gettop(LUA->L) == 6 ); /* vbSelectedOut, m_iLuaTable, function, self, arg, arg */
|
||||
|
||||
@@ -771,7 +771,7 @@ public:
|
||||
lua_pushvalue( LUA->L, 1 );
|
||||
|
||||
/* Argument 3 (pn): */
|
||||
LUA->PushStack( (int) pn );
|
||||
LuaHelpers::PushStack( (int) pn );
|
||||
|
||||
ASSERT( lua_gettop(LUA->L) == 6 ); /* vbSelectedOut, m_iLuaTable, function, self, arg, arg */
|
||||
|
||||
|
||||
@@ -52,11 +52,11 @@ void IPreference::SetFromStack( lua_State *L )
|
||||
} \
|
||||
void Preference<type>::PushValue( lua_State *L ) const \
|
||||
{ \
|
||||
LuaManager::PushStack( m_currentValue, L ); \
|
||||
LuaHelpers::PushStack( m_currentValue, L ); \
|
||||
} \
|
||||
void Preference<type>::SetFromStack( lua_State *L ) \
|
||||
{ \
|
||||
LuaManager::PopStack( m_currentValue, L ); \
|
||||
LuaHelpers::PopStack( m_currentValue, L ); \
|
||||
}
|
||||
|
||||
READFROM_AND_WRITETO( int )
|
||||
|
||||
@@ -862,7 +862,7 @@ int LuaFunc_GetPreference( lua_State *L )
|
||||
REQ_ARG( "GetPreference", 1, string );
|
||||
|
||||
CString sName;
|
||||
LUA->PopStack( sName );
|
||||
LuaHelpers::PopStack( sName );
|
||||
|
||||
IPreference *pPref = PREFSMAN->GetPreferenceByName( sName );
|
||||
if( pPref == NULL )
|
||||
|
||||
@@ -1471,14 +1471,14 @@ public:
|
||||
static int GetAllSteps( T* p, lua_State *L )
|
||||
{
|
||||
const vector<Steps*> &v = p->GetAllSteps();
|
||||
CreateTableFromArray<Steps*>( v, L );
|
||||
LuaHelpers::CreateTableFromArray<Steps*>( v, L );
|
||||
return 1;
|
||||
}
|
||||
static int GetStepsByStepsType( T* p, lua_State *L )
|
||||
{
|
||||
StepsType st = (StepsType)IArg(1);
|
||||
const vector<Steps*> &v = p->GetStepsByStepsType( st );
|
||||
CreateTableFromArray<Steps*>( v, L );
|
||||
LuaHelpers::CreateTableFromArray<Steps*>( v, L );
|
||||
return 1;
|
||||
}
|
||||
static int GetSongDir( T* p, lua_State *L ) { lua_pushstring(L, p->GetSongDir() ); return 1; }
|
||||
|
||||
@@ -1270,14 +1270,14 @@ public:
|
||||
static int GetAllSongs( T* p, lua_State *L )
|
||||
{
|
||||
const vector<Song*> &v = p->GetAllSongs();
|
||||
CreateTableFromArray<Song*>( v, L );
|
||||
LuaHelpers::CreateTableFromArray<Song*>( v, L );
|
||||
return 1;
|
||||
}
|
||||
static int GetAllCourses( T* p, lua_State *L )
|
||||
{
|
||||
vector<Course*> v;
|
||||
p->GetAllCourses( v, BArg(1) );
|
||||
CreateTableFromArray<Course*>( v, L );
|
||||
LuaHelpers::CreateTableFromArray<Course*>( v, L );
|
||||
return 1;
|
||||
}
|
||||
static int FindSong( T* p, lua_State *L ) { Song *pS = p->FindSong(SArg(1)); if(pS) pS->PushSelf(L); else lua_pushnil(L); return 1; }
|
||||
|
||||
Reference in New Issue
Block a user