From f6d369372f87b6ebb4d65726ff4f74772e61711c Mon Sep 17 00:00:00 2001 From: Kyzentun Keeslala Date: Wed, 8 Jul 2015 15:39:00 -0600 Subject: [PATCH] Changed HOOKS singleton to register itself with lua correctly so that it can be used by lua. --- src/StepMania.cpp | 1 + src/arch/ArchHooks/ArchHooks.cpp | 25 +++++++++++++------------ src/arch/ArchHooks/ArchHooks.h | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/StepMania.cpp b/src/StepMania.cpp index 06867c7863..076e0da850 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -977,6 +977,7 @@ int sm_main(int argc, char* argv[]) HOOKS->Init(); LUA = new LuaManager; + HOOKS->RegisterWithLua(); // Initialize the file extension type lists so everything can ask ActorUtil // what the type of a file is. diff --git a/src/arch/ArchHooks/ArchHooks.cpp b/src/arch/ArchHooks/ArchHooks.cpp index 104d685845..5ba40f84b1 100644 --- a/src/arch/ArchHooks/ArchHooks.cpp +++ b/src/arch/ArchHooks/ArchHooks.cpp @@ -67,6 +67,19 @@ RString ArchHooks::GetClipboard() return ""; } +/* XXX: Most singletons register with lua in their constructor. ArchHooks is + * instantiated before Lua, so we encounter a dependency problem when + * trying to register HOOKS. Work around it by registering HOOKS function + * which sm_main will call after instantiating Lua. */ +void ArchHooks::RegisterWithLua() +{ + Lua *L = LUA->Get(); + lua_pushstring( L, "HOOKS" ); + HOOKS->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); +} + // lua start #include "LuaBinding.h" #include "LuaReference.h" @@ -85,18 +98,6 @@ public: }; LUA_REGISTER_CLASS( ArchHooks ); -/* XXX: ArchHooks is instantiated before Lua, so we encounter a dependency problem when - * trying to register HOOKS. Work around it by registering HOOKS in a static function, - * which LuaManager will call when it is instantiated. */ -void LuaFunc_Register_Hooks( lua_State *L ) -{ - lua_pushstring( L, "HOOKS" ); - HOOKS->PushSelf( L ); - lua_settable( L, LUA_GLOBALSINDEX ); -} - -REGISTER_WITH_LUA_FUNCTION( LuaFunc_Register_Hooks ); - /* * (c) 2003-2004 Glenn Maynard, Chris Danford * All rights reserved. diff --git a/src/arch/ArchHooks/ArchHooks.h b/src/arch/ArchHooks/ArchHooks.h index 04ce5304ee..d1b6d5fcac 100644 --- a/src/arch/ArchHooks/ArchHooks.h +++ b/src/arch/ArchHooks/ArchHooks.h @@ -123,6 +123,7 @@ public: // Lua void PushSelf( lua_State *L ); + void RegisterWithLua(); private: /* This are helpers for GetMicrosecondsSinceStart on systems with a timer