simplify singleton registration. Add the singleton global
to Lua when the singleton is constructed, and not in the binding class. The binding just adds the class bindings (the same as for a non-singleton class). This way, the binding is available to Lua as soon as the class is constructed.
This commit is contained in:
@@ -226,6 +226,15 @@ void RegisterScreenClass( const RString& sClassName, CreateScreenFn pfn )
|
||||
|
||||
ScreenManager::ScreenManager()
|
||||
{
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring( L, "SCREENMAN" );
|
||||
this->PushSelf( L );
|
||||
lua_settable( L, LUA_GLOBALSINDEX );
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
g_pSharedBGA = new Actor;
|
||||
|
||||
m_bZeroNextUpdate = false;
|
||||
@@ -249,6 +258,9 @@ ScreenManager::~ScreenManager()
|
||||
for( unsigned i=0; i<g_OverlayScreens.size(); i++ )
|
||||
SAFE_DELETE( g_OverlayScreens[i] );
|
||||
g_OverlayScreens.clear();
|
||||
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "SCREENMAN" );
|
||||
}
|
||||
|
||||
/* This is called when we start up, and when the theme changes or is reloaded. */
|
||||
@@ -942,16 +954,6 @@ public:
|
||||
ADD_METHOD( ScreenIsPrepped );
|
||||
|
||||
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( SCREENMAN )
|
||||
{
|
||||
lua_pushstring(L, "SCREENMAN");
|
||||
SCREENMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -7,12 +7,27 @@
|
||||
#include "PrefsManager.h"
|
||||
#include "Steps.h"
|
||||
#include "StyleUtil.h"
|
||||
#include "LuaManager.h"
|
||||
|
||||
StatsManager* STATSMAN = NULL; // global object accessable from anywhere in the program
|
||||
|
||||
|
||||
StatsManager::StatsManager()
|
||||
{
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring( L, "STATSMAN" );
|
||||
STATSMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
LUA->Release( L );
|
||||
}
|
||||
}
|
||||
|
||||
StatsManager::~StatsManager()
|
||||
{
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "STATSMAN" );
|
||||
}
|
||||
|
||||
void StatsManager::Reset()
|
||||
@@ -253,16 +268,6 @@ public:
|
||||
ADD_METHOD( GetWorstGrade );
|
||||
|
||||
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( STATSMAN )
|
||||
{
|
||||
lua_pushstring(L, "STATSMAN");
|
||||
STATSMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class StatsManager
|
||||
{
|
||||
public:
|
||||
StatsManager();
|
||||
~StatsManager();
|
||||
|
||||
void Reset();
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ ThemeManager::ThemeManager()
|
||||
{
|
||||
THEME = this; // so that we can Register THEME on construction
|
||||
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring(L, "THEME");
|
||||
this->PushSelf( L );
|
||||
lua_settable( L, LUA_GLOBALSINDEX );
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
/* We don't have any theme loaded until SwitchThemeAndLanguage is called. */
|
||||
m_sCurThemeName = "";
|
||||
m_bPseudoLocalize = false;
|
||||
@@ -161,6 +170,9 @@ ThemeManager::~ThemeManager()
|
||||
{
|
||||
g_vThemes.clear();
|
||||
SAFE_DELETE( g_pLoadedThemeData );
|
||||
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "THEME" );
|
||||
}
|
||||
|
||||
void ThemeManager::GetThemeNames( vector<RString>& AddTo )
|
||||
@@ -1150,16 +1162,6 @@ public:
|
||||
ADD_METHOD( GetNumSelectableThemes );
|
||||
|
||||
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( THEME )
|
||||
{
|
||||
lua_pushstring(L, "THEME");
|
||||
THEME->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user