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:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user