From b786222be52e49914c1b0b1cfb63e25cb24122ca Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 13 Aug 2006 03:03:27 +0000 Subject: [PATCH] Include the lua call stack when panicking. --- stepmania/src/LuaManager.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 9ff310eb7e..78ccb3fce1 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -141,12 +141,35 @@ static int LuaPanic( lua_State *L ) { RString sErr; LuaHelpers::PopStack( sErr, L ); + + lua_Debug ar; + int level = 0; + + while( lua_getstack(L, level++, &ar) ) + { + if( !lua_getinfo(L, "nSluf", &ar) ) + break; + // The function is now on the top of the stack. + const char *file = ar.source[0] == '@' ? ar.source + 1 : ar.short_src; + const char *name; + vector vArgs; + + for( int i = 1; i <= ar.nups && (name = lua_getupvalue(L, -1, i)); ++i ) + { + // XXX: do we need to do local variables for lua functions instead? + vArgs.push_back( ssprintf("%s = %s", name, lua_tostring(L, -1)) ); + lua_pop( L, 1 ); // pop value + } + lua_pop( L, 1 ); // pop function + + name = ar.name ? ar.name : "[UNKNOWN]"; + sErr += ssprintf( "\n%s %s %s( %s ) %s:%d", ar.namewhat, ar.what, name, + join(",", vArgs).c_str(), file, ar.currentline ); + } RageException::Throw( "%s", sErr.c_str() ); } - - // Actor registration static vector *g_vRegisterActorTypes = NULL;