diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 08b7efb47b..1c056bd00d 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -459,7 +459,7 @@ bool LuaHelpers::RunScriptFile( const RString &sFile ) } -bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iReturnValues ) +bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iArgs, int iReturnValues ) { // load string { @@ -473,9 +473,12 @@ bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName } } + // move the function above the params + lua_insert( L, lua_gettop(L) - iArgs ); + // evaluate { - int ret = lua_pcall( L, 0, iReturnValues, 0 ); + int ret = lua_pcall( L, iArgs, iReturnValues, 0 ); if( ret ) { LuaHelpers::Pop( L, sError ); @@ -491,7 +494,7 @@ bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RString &sName ) { RString sError; - if( !LuaHelpers::RunScript(L, "return " + sExpression, sName.empty()? RString("in"):sName, sError, 1) ) + if( !LuaHelpers::RunScript(L, "return " + sExpression, sName.empty()? RString("in"):sName, sError, 0, 1) ) { sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() ); Dialog::OK( sError, "LUA_ERROR" ); @@ -627,7 +630,7 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri } RString sError; - if( !LuaHelpers::RunScript( L, sLuaFunction, sName, sError, 1 ) ) + if( !LuaHelpers::RunScript(L, sLuaFunction, sName, sError, 0, 1) ) LOG->Warn( "Compiling \"%s\": %s", sLuaFunction.c_str(), sError.c_str() ); /* The function is now on the stack. */ diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index ade711f1dd..f155c4185c 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -49,7 +49,7 @@ namespace LuaHelpers /* Run a script with the given name. The given number of return values are left on * the Lua stack. On error, nils are left on the stack, sError is set and * false is returned. */ - bool RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iReturnValues = 0 ); + bool RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iArgs = 0, int iReturnValues = 0 ); /* Run the given expression, returning a single value, and leave the return value on the * stack. On error, push nil. */