From 8415b4466dbbd0f0eea8b8b9f729b27e14f98512 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 13 Mar 2005 00:01:05 +0000 Subject: [PATCH] fix VC7 template error: move templated methods out of LuaManager --- stepmania/src/LuaFunctions.h | 6 ++-- stepmania/src/LuaManager.cpp | 6 ++-- stepmania/src/LuaManager.h | 58 +++++++++++++++--------------- stepmania/src/OptionRowHandler.cpp | 4 +-- stepmania/src/Preference.cpp | 4 +-- stepmania/src/PrefsManager.cpp | 2 +- stepmania/src/Song.cpp | 4 +-- stepmania/src/SongManager.cpp | 4 +-- 8 files changed, 45 insertions(+), 43 deletions(-) diff --git a/stepmania/src/LuaFunctions.h b/stepmania/src/LuaFunctions.h index 1952f97662..d08ce44e36 100644 --- a/stepmania/src/LuaFunctions.h +++ b/stepmania/src/LuaFunctions.h @@ -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 */ diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index db56f40d24..95b20cc679 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -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; } } diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index c5da270445..b108139316 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -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 + void ReadArrayFromTable( vector aOut, lua_State *L = NULL ); + template + void PushStack( const T &val, lua_State *L = NULL ); + template + bool PopStack( T &val, lua_State *L = NULL ); + template + void CreateTableFromArray( const vector &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 &aOut, lua_State *L = NULL ); lua_State *L; - template - static void PushStack( const T &val, lua_State *L = NULL ); - - template - static bool PopStack( T &val, lua_State *L = NULL ); }; + namespace LuaHelpers { template @@ -112,27 +117,22 @@ namespace LuaHelpers lua_pop( L, 1 ); } } -} - -template -void LuaManager::PushStack( const T &val, lua_State *L) -{ - if( L == NULL ) - L = LUA->L; - LuaHelpers::Push( val, L ); -} - -template -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 + void PushStack( const T &val, lua_State *L ) + { + if( L == NULL ) + L = LUA->L; + LuaHelpers::Push( val, L ); + } + template + 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 void CreateTableFromArray( const vector &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 ); } }; \ diff --git a/stepmania/src/OptionRowHandler.cpp b/stepmania/src/OptionRowHandler.cpp index e89d30f8b1..852c9aa278 100644 --- a/stepmania/src/OptionRowHandler.cpp +++ b/stepmania/src/OptionRowHandler.cpp @@ -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 */ diff --git a/stepmania/src/Preference.cpp b/stepmania/src/Preference.cpp index b1b768b111..82912597ad 100644 --- a/stepmania/src/Preference.cpp +++ b/stepmania/src/Preference.cpp @@ -52,11 +52,11 @@ void IPreference::SetFromStack( lua_State *L ) } \ void Preference::PushValue( lua_State *L ) const \ { \ - LuaManager::PushStack( m_currentValue, L ); \ + LuaHelpers::PushStack( m_currentValue, L ); \ } \ void Preference::SetFromStack( lua_State *L ) \ { \ - LuaManager::PopStack( m_currentValue, L ); \ + LuaHelpers::PopStack( m_currentValue, L ); \ } READFROM_AND_WRITETO( int ) diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 2e70c499ba..b167ac7831 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -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 ) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 82d13e45ed..58bf5e1fbf 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -1471,14 +1471,14 @@ public: static int GetAllSteps( T* p, lua_State *L ) { const vector &v = p->GetAllSteps(); - CreateTableFromArray( v, L ); + LuaHelpers::CreateTableFromArray( v, L ); return 1; } static int GetStepsByStepsType( T* p, lua_State *L ) { StepsType st = (StepsType)IArg(1); const vector &v = p->GetStepsByStepsType( st ); - CreateTableFromArray( v, L ); + LuaHelpers::CreateTableFromArray( v, L ); return 1; } static int GetSongDir( T* p, lua_State *L ) { lua_pushstring(L, p->GetSongDir() ); return 1; } diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index c55377ee66..5fc8b1111b 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1270,14 +1270,14 @@ public: static int GetAllSongs( T* p, lua_State *L ) { const vector &v = p->GetAllSongs(); - CreateTableFromArray( v, L ); + LuaHelpers::CreateTableFromArray( v, L ); return 1; } static int GetAllCourses( T* p, lua_State *L ) { vector v; p->GetAllCourses( v, BArg(1) ); - CreateTableFromArray( v, L ); + LuaHelpers::CreateTableFromArray( 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; }