diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index bde1d593e2..8190188b77 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -39,7 +39,7 @@ void GameCommand::Init() m_sModifiers = ""; m_sAnnouncer = ""; m_sScreen = ""; - m_sLuaFunction = ""; + m_LuaFunction.Unset(); m_pSong = NULL; m_pSteps = NULL; m_pCourse = NULL; @@ -213,7 +213,7 @@ void GameCommand::Load( int iIndex, const Commands& cmds ) else if( sName == "lua" ) { - m_sLuaFunction = sValue; + m_LuaFunction.SetFromExpression( sValue ); } else if( sName == "screen" ) @@ -628,8 +628,17 @@ void GameCommand::Apply( const vector &vpns ) const if( m_sModifiers != "" ) FOREACH_CONST( PlayerNumber, vpns, pn ) GAMESTATE->ApplyModifiers( *pn, m_sModifiers ); - if( m_sLuaFunction != "" ) - LUA->RunScript( m_sLuaFunction, "in", 0 ); + if( m_LuaFunction.IsSet() ) + { + FOREACH_CONST( PlayerNumber, vpns, pn ) + { + m_LuaFunction.PushSelf( LUA->L ); + ASSERT( !lua_isnil(LUA->L, -1) ); + + lua_pushnumber( LUA->L, *pn ); // 1st parameter + lua_call( LUA->L, 1, 0 ); // call function with 1 argument and 0 results + } + } if( m_sScreen != "" ) SCREENMAN->SetNewScreen( m_sScreen ); if( m_pSong ) diff --git a/stepmania/src/GameCommand.h b/stepmania/src/GameCommand.h index 351c908669..6f99e92add 100644 --- a/stepmania/src/GameCommand.h +++ b/stepmania/src/GameCommand.h @@ -6,6 +6,7 @@ #include "GameConstantsAndTypes.h" #include "PlayerNumber.h" #include "Difficulty.h" +#include "LuaReference.h" #include class Song; @@ -47,7 +48,7 @@ public: CString m_sAnnouncer; CString m_sModifiers; CString m_sScreen; - CString m_sLuaFunction; + LuaExpression m_LuaFunction; Song* m_pSong; Steps* m_pSteps; Course* m_pCourse;