diff --git a/stepmania/src/CharacterManager.cpp b/stepmania/src/CharacterManager.cpp index 31ff9655a6..75df685b21 100644 --- a/stepmania/src/CharacterManager.cpp +++ b/stepmania/src/CharacterManager.cpp @@ -3,6 +3,7 @@ #include "Character.h" #include "GameState.h" #include "Foreach.h" +#include "LuaManager.h" #define CHARACTERS_DIR "/Characters/" @@ -10,6 +11,15 @@ CharacterManager* CHARMAN = NULL; // global object accessable from anywhere in t CharacterManager::CharacterManager() { + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "CHARMAN" ); + CHARMAN->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } + for( unsigned i=0; iUnsetGlobal( "CHARMAN" ); } void CharacterManager::GetCharacters( vector &apCharactersOut ) @@ -127,16 +140,6 @@ public: ADD_METHOD( GetCharacter ); 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( CHARMAN ) - { - lua_pushstring(L, "CHARMAN"); - CHARMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp index e095ce8b4d..35f9cfc235 100644 --- a/stepmania/src/MessageManager.cpp +++ b/stepmania/src/MessageManager.cpp @@ -4,6 +4,7 @@ #include "RageUtil.h" #include "RageThreads.h" #include "EnumHelper.h" +#include "LuaManager.h" #include #include @@ -141,10 +142,20 @@ static map g_MessageToSubscribers; MessageManager::MessageManager() { + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "MESSAGEMAN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } } MessageManager::~MessageManager() { + // Unregister with Lua. + LUA->UnsetGlobal( "MESSAGEMAN" ); } void MessageManager::Subscribe( IMessageSubscriber* pSubscriber, const RString& sMessage ) @@ -304,16 +315,6 @@ public: ADD_METHOD( Broadcast ); 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( MESSAGEMAN ) - { - lua_pushstring(L, "MESSAGEMAN"); - MESSAGEMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index 50b8b13671..3d0999e9ae 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -7,6 +7,7 @@ #include "arch/arch_default.h" #include "Foreach.h" #include "Preference.h" +#include "LuaManager.h" RageInput* INPUTMAN = NULL; // globally accessable input device @@ -16,6 +17,15 @@ RageInput::RageInput() { LOG->Trace( "RageInput::RageInput()" ); + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "INPUTMAN" ); + INPUTMAN->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } + m_sDriverList = g_sInputDrivers; if( m_sDriverList.empty() ) m_sDriverList = DEFAULT_INPUT_DRIVER_LIST; @@ -28,6 +38,9 @@ RageInput::~RageInput() /* Delete optional devices. */ for( unsigned i = 0; i < m_pDevices.size(); ++i ) delete m_pDevices[i]; + + // Unregister with Lua. + LUA->UnsetGlobal( "INPUTMAN" ); } void RageInput::LoadDrivers() @@ -189,16 +202,6 @@ public: ADD_METHOD( GetDescriptions ); 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( INPUTMAN ) - { - lua_pushstring(L, "INPUTMAN"); - INPUTMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/UnlockManager.cpp b/stepmania/src/UnlockManager.cpp index 53d6714c00..3f564273b7 100644 --- a/stepmania/src/UnlockManager.cpp +++ b/stepmania/src/UnlockManager.cpp @@ -50,11 +50,26 @@ LuaFunction( UnlockRewardTypeToLocalizedString, UnlockRewardTypeToLocalizedStrin UnlockManager::UnlockManager() { + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "UNLOCKMAN" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } + UNLOCKMAN = this; Load(); } +UnlockManager::~UnlockManager() +{ + // Unregister with Lua. + LUA->UnsetGlobal( "UNLOCKMAN" ); +} + void UnlockManager::UnlockSong( const Song *song ) { const UnlockEntry *p = FindSong( song ); @@ -750,16 +765,6 @@ public: ADD_METHOD( GetStepsUnlockedByEntryID ); 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( UNLOCKMAN ) - { - lua_pushstring(L, "UNLOCKMAN"); - UNLOCKMAN->PushSelf( L ); - lua_settable(L, LUA_GLOBALSINDEX); - } } }; diff --git a/stepmania/src/UnlockManager.h b/stepmania/src/UnlockManager.h index de310a9dfe..347b007385 100644 --- a/stepmania/src/UnlockManager.h +++ b/stepmania/src/UnlockManager.h @@ -93,6 +93,7 @@ class UnlockManager public: UnlockManager(); + ~UnlockManager(); void Reload(); // returns # of points till next unlock - used for ScreenUnlock