diff --git a/stepmania/src/ActorCommands.cpp b/stepmania/src/ActorCommands.cpp index b9565d207c..f42f820a01 100644 --- a/stepmania/src/ActorCommands.cpp +++ b/stepmania/src/ActorCommands.cpp @@ -71,7 +71,13 @@ void ActorCommands::Register() CString s2 = s.str(); - LUA->RunScript( s2, "in", 1 ); + CString sError; + if( !LUA->RunScript( s2, "in", sError, 1 ) ) + { + /* We're compiling a generated script, so it should never fail. */ + FAIL_M( ssprintf("Compiling \"%s\": %s", s2.c_str(), sError.c_str()) ); + } + /* The function is now on the stack. */ this->SetFromStack(); diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 90a078b29f..9a48a0bf6b 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -261,10 +261,18 @@ bool LuaManager::RunScriptFile( const CString &sFile ) return false; } - return RunScript( sScript, sFile ); + CString sError; + if( !RunScript( sScript, sFile, sError ) ) + { + sError = ssprintf( "Lua runtime error: %s", sError.c_str() ); + Dialog::OK( sError, "LUA_ERROR" ); + return false; + } + + return true; } -bool LuaManager::RunScript( const CString &sScript, const CString &sName, int iReturnValues ) +bool LuaManager::RunScript( const CString &sScript, const CString &sName, CString &sError, int iReturnValues ) { // load string { @@ -274,10 +282,7 @@ bool LuaManager::RunScript( const CString &sScript, const CString &sName, int iR if( ret ) { - CString err; - LuaManager::PopStack( err ); - CString sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sScript.c_str(), err.c_str() ); - Dialog::OK( sError, "LUA_ERROR" ); + LuaManager::PopStack( sError ); return false; } @@ -303,8 +308,13 @@ bool LuaManager::RunScript( const CString &sScript, const CString &sName, int iR bool LuaManager::RunExpression( const CString &sExpression ) { - if( !RunScript( "return " + sExpression, "in", 1 ) ) + CString sError; + if( !RunScript( "return " + sExpression, "in", sError, 1 ) ) + { + sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sExpression.c_str(), sError.c_str() ); + Dialog::OK( sError, "LUA_ERROR" ); return false; + } return true; } diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index 608d74a31d..ef3a35639d 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -22,7 +22,7 @@ public: void ResetState(); /* Run a complete script in the global environment, which returns no value. */ - bool RunScript( const CString &sScript, const CString &sName, int iReturnValues = 0 ); + bool RunScript( const CString &sScript, const CString &sName, CString &sError, int iReturnValues = 0 ); /* Run an expression in the global environment, returning the given type. */ bool RunExpressionB( const CString &str );