diff --git a/stepmania/src/GameManager.cpp b/stepmania/src/GameManager.cpp index 757868b0da..9670811f56 100644 --- a/stepmania/src/GameManager.cpp +++ b/stepmania/src/GameManager.cpp @@ -2645,6 +2645,25 @@ static Style g_Styles[] = #define NUM_STYLES ARRAYLEN(g_Styles) + +GameManager::GameManager() +{ + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "GAMEMAN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } +} + +GameManager::~GameManager() +{ + // Unregister with Lua. + LUA->UnsetGlobal( "GAMEMAN" ); +} + void GameManager::GetStylesForGame( const Game *pGame, vector& aStylesAddTo, bool editor ) const { for( unsigned s=0; s::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( GAMEMAN ) - { - lua_pushstring(L, "GAMEMAN"); - GAMEMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/GameManager.h b/stepmania/src/GameManager.h index 2ec7d5b5a7..7383a5bb78 100644 --- a/stepmania/src/GameManager.h +++ b/stepmania/src/GameManager.h @@ -14,6 +14,9 @@ struct lua_State; class GameManager { public: + GameManager(); + ~GameManager(); + void GetStylesForGame( const Game* pGame, vector& aStylesAddTo, bool editor=false ) const; void GetStepsTypesForGame( const Game* pGame, vector& aStepsTypeAddTo ) const; const Style* GetEditorStyleForStepsType( StepsType st ) const; diff --git a/stepmania/src/GameSoundManager.cpp b/stepmania/src/GameSoundManager.cpp index df7cee8d44..eecf085a8c 100644 --- a/stepmania/src/GameSoundManager.cpp +++ b/stepmania/src/GameSoundManager.cpp @@ -15,6 +15,7 @@ #include "Steps.h" #include "LightsManager.h" #include "SongUtil.h" +#include "LuaManager.h" GameSoundManager *SOUND = NULL; @@ -397,10 +398,22 @@ GameSoundManager::GameSoundManager() g_Shutdown = false; MusicThread.SetName( "Music thread" ); MusicThread.Create( MusicThread_start, this ); + + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "SOUND" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } } GameSoundManager::~GameSoundManager() { + // Unregister with Lua. + LUA->UnsetGlobal( "SOUND" ); + /* Signal the mixing thread to quit. */ LOG->Trace("Shutting down music start thread ..."); g_Mutex->Lock(); @@ -744,16 +757,6 @@ public: ADD_METHOD( PlayOnce ); Luna::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( SOUND ) - { - lua_pushstring(L, "SOUND"); - SOUND->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 3a063d50cf..c0ce85f8c2 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -118,10 +118,22 @@ GameState::GameState() : /* Don't reset yet; let the first screen do it, so we can * use PREFSMAN and THEME. */ // Reset(); + + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "GAMESTATE" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } } GameState::~GameState() { + // Unregister with Lua. + LUA->UnsetGlobal( "GAMESTATE" ); + FOREACH_PlayerNumber( p ) SAFE_DELETE( m_pPlayerState[p] ); FOREACH_MultiPlayer( p ) @@ -2116,16 +2128,6 @@ public: ADD_METHOD( GetCurrentStyle ); Luna::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( GAMESTATE ) - { - lua_pushstring(L, "GAMESTATE"); - GAMESTATE->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index 9318596c1c..a6d80549d1 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -12,6 +12,7 @@ #include "RageUtil_WorkerThread.h" #include "arch/arch.h" #include "arch/MemoryCard/MemoryCardDriver_Null.h" +#include "LuaManager.h" MemoryCardManager* MEMCARDMAN = NULL; // global and accessable from anywhere in our program @@ -259,6 +260,15 @@ MemoryCardManager::MemoryCardManager() { ASSERT( g_pWorker == NULL ); + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "MEMCARDMAN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } + g_pWorker = new ThreadedMemoryCardWorker; m_bCardsLocked = false; @@ -286,6 +296,9 @@ MemoryCardManager::MemoryCardManager() MemoryCardManager::~MemoryCardManager() { + // Unregister with Lua. + LUA->UnsetGlobal( "MESSAGEMAN" ); + ASSERT( g_pWorker != NULL ); SAFE_DELETE(g_pWorker); @@ -715,16 +728,6 @@ public: ADD_METHOD( IsAnyPlayerUsingMemoryCard ); Luna::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( MEMCARDMAN ) - { - lua_pushstring(L, "MEMCARDMAN"); - MEMCARDMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index f152e22de7..f7d20bd9c9 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -25,10 +25,21 @@ NoteSkinManager::NoteSkinManager() { GAME_BASE_NOTESKIN_NAME.Load( "NoteSkinManager", "GameBaseNoteSkin" ); m_pCurGame = NULL; + + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "NOTESKIN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } } NoteSkinManager::~NoteSkinManager() { + // Unregister with Lua. + LUA->UnsetGlobal( "NOTESKIN" ); } void NoteSkinManager::RefreshNoteSkinData( const Game* pGame ) @@ -322,16 +333,6 @@ public: ADD_METHOD( GetGameBaseNoteSkinName ); Luna::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( NOTESKIN ) - { - lua_pushstring(L, "NOTESKIN"); - NOTESKIN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 567e9cdce7..f6b528706a 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -9,6 +9,7 @@ #include "Preference.h" #include "RageLog.h" #include "SpecialFiles.h" +#include "LuaManager.h" //DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden //PREFERENCES_INI_PATH // overlay on Defaults.ini, contains the user's choices @@ -333,6 +334,15 @@ PrefsManager::PrefsManager() : { Init(); ReadPrefsFromDisk(); + + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "PREFSMAN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } } #undef TRUE_IF_DEBUG @@ -345,6 +355,8 @@ void PrefsManager::Init() PrefsManager::~PrefsManager() { + // Unregister with Lua. + LUA->UnsetGlobal( "PREFSMAN" ); } void PrefsManager::SetCurrentGame( const RString &sGame ) @@ -598,16 +610,6 @@ public: ADD_METHOD( SetPreferenceToDefault ); Luna::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( PREFSMAN ) - { - lua_pushstring(L, "PREFSMAN"); - PREFSMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 33eb765e47..d54991575c 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -63,6 +63,15 @@ RString COURSE_GROUP_COLOR_NAME( size_t i ) { return ssprintf( "CourseGroupColor SongManager::SongManager() { + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "SONGMAN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } + NUM_SONG_GROUP_COLORS .Load( "SongManager", "NumSongGroupColors" ); SONG_GROUP_COLOR .Load( "SongManager", SONG_GROUP_COLOR_NAME, NUM_SONG_GROUP_COLORS ); NUM_COURSE_GROUP_COLORS .Load( "SongManager", "NumCourseGroupColors" ); @@ -71,6 +80,9 @@ SongManager::SongManager() SongManager::~SongManager() { + // Unregister with Lua. + LUA->UnsetGlobal( "SONGMAN" ); + // Courses depend on Songs and Songs don't depend on Courses. // So, delete the Courses first. FreeCourses(); @@ -1886,16 +1898,6 @@ public: ADD_METHOD( GetExtraStageInfo ); Luna::Register( L ); - - // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reinit Lua just before - // initializing the display. - if( SONGMAN ) - { - lua_pushstring(L, "SONGMAN"); - SONGMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } };