diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index d9ca9d6bfa..f04ef9957e 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -252,31 +252,57 @@ namespace Lua *L = LUA->Get(); RString sError; - if( !LuaHelpers::RunScript(L, sScript, "@" + sFile, sError, 0, 1) ) + if( !LuaHelpers::LoadScript(L, sScript, "@" + sFile, sError) ) { - lua_pop( L, 1 ); LUA->Release( L ); sError = ssprintf( "Lua runtime error: %s", sError.c_str() ); Dialog::OK( sError, "LUA_ERROR" ); return NULL; } - if( lua_type(L, -1) != LUA_TTABLE ) - { - lua_pop( L, 1 ); - LUA->Release( L ); - sError = ssprintf( "%s: must return a table", sFile.c_str() ); - Dialog::OK( sError, "LUA_ERROR" ); - return NULL; - } - - XNode *pRet = XmlFileUtil::XNodeFromTable( L ); + XNode *pRet = ActorUtil::LoadXNodeFromStackShowErrors( L ); LUA->Release( L ); return pRet; } } +XNode *ActorUtil::LoadXNodeFromStackShowErrors( Lua *L ) +{ + LuaReference func; + lua_pushvalue( L, -1 ); + func.SetFromStack( L ); + + RString sError; + if( !LuaHelpers::RunScriptOnStack(L, sError, 0, 1) ) + { + lua_pop( L, 1 ); + LUA->Release( L ); + sError = ssprintf( "Lua runtime error: %s", sError.c_str() ); + Dialog::OK( sError, "LUA_ERROR" ); + return NULL; + } + + if( lua_type(L, -1) != LUA_TTABLE ) + { + lua_pop( L, 1 ); + + func.PushSelf( L ); + lua_Debug debug; + lua_getinfo( L, ">nS", &debug ); + + sError = ssprintf( "%s: must return a table", debug.short_src ); + LUA->Release( L ); + + Dialog::OK( sError, "LUA_ERROR" ); + return NULL; + } + + XNode *pRet = XmlFileUtil::XNodeFromTable( L ); + + return pRet; +} + /* * If pParent is non-NULL, it's the parent node when nesting XML, which is * used only by ActorUtil::LoadFromNode. diff --git a/stepmania/src/ActorUtil.h b/stepmania/src/ActorUtil.h index 73ea3bfb41..a6fac28bed 100644 --- a/stepmania/src/ActorUtil.h +++ b/stepmania/src/ActorUtil.h @@ -71,6 +71,7 @@ namespace ActorUtil RString GetSourcePath( const XNode *pNode ); RString GetWhere( const XNode *pNode ); bool GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut ); + XNode *LoadXNodeFromStackShowErrors( Lua *L ); bool ResolvePath( RString &sPath, const RString &sName );