From b547efa5e766adc1caf0ee318b9a20e62d2ba03e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 28 Jan 2005 20:08:29 +0000 Subject: [PATCH] have ActorCommands push themself --- stepmania/src/Actor.cpp | 3 +-- stepmania/src/ActorCommands.cpp | 9 ++++++--- stepmania/src/ActorCommands.h | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 67d97b9581..48f158b1e7 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -677,8 +677,7 @@ void Actor::AddRotationR( float rot ) void Actor::RunCommands( const ActorCommands& cmds ) { - lua_pushstring(LUA->L, cmds.GetFunctionName()); // function name - lua_gettable(LUA->L, LUA_GLOBALSINDEX); // function to be called + cmds.PushSelf( LUA->L ); this->PushSelf( LUA->L ); // 1st parameter lua_call(LUA->L, 1, 0); // call function with 1 argument and 0 results } diff --git a/stepmania/src/ActorCommands.cpp b/stepmania/src/ActorCommands.cpp index d9edc34e2c..26aeb77945 100644 --- a/stepmania/src/ActorCommands.cpp +++ b/stepmania/src/ActorCommands.cpp @@ -35,7 +35,7 @@ ActorCommands::ActorCommands( const ActorCommands& cpy ) * the function by reference, so we don't make a new function unless we're actually * changed. */ ostringstream s; - s << m_sLuaFunctionName << " = " << cpy.GetFunctionName(); + s << m_sLuaFunctionName << " = " << cpy.m_sLuaFunctionName; CString s2 = s.str(); LUA->RunScript( s2 ); @@ -50,9 +50,12 @@ ActorCommands &ActorCommands::operator=( const ActorCommands& cpy ) return *this; } -CString ActorCommands::GetFunctionName() const +void ActorCommands::PushSelf( lua_State *L ) const { - return m_sLuaFunctionName; + lua_pushstring( L, m_sLuaFunctionName ); // function name + lua_gettable( L, LUA_GLOBALSINDEX ); // function to be called + + ASSERT_M( !lua_isnil(L, -1), m_sLuaFunctionName.c_str() ) } void ActorCommands::Register( const Commands& cmds ) diff --git a/stepmania/src/ActorCommands.h b/stepmania/src/ActorCommands.h index 9ad8879b26..26e11e7925 100644 --- a/stepmania/src/ActorCommands.h +++ b/stepmania/src/ActorCommands.h @@ -6,6 +6,8 @@ #include "RageUtil_AutoPtr.h" class Commands; +struct lua_State; + class ActorCommands { public: @@ -14,8 +16,7 @@ public: ActorCommands( const ActorCommands& cpy ); ActorCommands &operator=( const ActorCommands& cpy ); - - CString GetFunctionName() const; + void PushSelf( lua_State *L ) const; private: void Register( const Commands& cmds );