simplify singleton registration

This commit is contained in:
Glenn Maynard
2006-09-21 04:42:45 +00:00
parent 2b7e2849fd
commit 578c6d5726
8 changed files with 95 additions and 70 deletions
+12 -10
View File
@@ -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<T>::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);
}
}
};