mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Merge branch 'traceback' into 'next'
Traceback See merge request STJr/SRB2!974
This commit is contained in:
commit
dd18915570
3 changed files with 249 additions and 161 deletions
File diff suppressed because it is too large
Load diff
|
@ -78,6 +78,58 @@ FUNCNORETURN static int LUA_Panic(lua_State *L)
|
|||
#endif
|
||||
}
|
||||
|
||||
#define LEVELS1 12 // size of the first part of the stack
|
||||
#define LEVELS2 10 // size of the second part of the stack
|
||||
|
||||
// Error handler used with pcall() when loading scripts or calling hooks
|
||||
// Takes a string with the original error message,
|
||||
// appends the traceback to it, and return the result
|
||||
int LUA_GetErrorMessage(lua_State *L)
|
||||
{
|
||||
int level = 1;
|
||||
int firstpart = 1; // still before eventual `...'
|
||||
lua_Debug ar;
|
||||
|
||||
lua_pushliteral(L, "\nstack traceback:");
|
||||
while (lua_getstack(L, level++, &ar))
|
||||
{
|
||||
if (level > LEVELS1 && firstpart)
|
||||
{
|
||||
// no more than `LEVELS2' more levels?
|
||||
if (!lua_getstack(L, level + LEVELS2, &ar))
|
||||
level--; // keep going
|
||||
else
|
||||
{
|
||||
lua_pushliteral(L, "\n ..."); // too many levels
|
||||
while (lua_getstack(L, level + LEVELS2, &ar)) // find last levels
|
||||
level++;
|
||||
}
|
||||
firstpart = 0;
|
||||
continue;
|
||||
}
|
||||
lua_pushliteral(L, "\n ");
|
||||
lua_getinfo(L, "Snl", &ar);
|
||||
lua_pushfstring(L, "%s:", ar.short_src);
|
||||
if (ar.currentline > 0)
|
||||
lua_pushfstring(L, "%d:", ar.currentline);
|
||||
if (*ar.namewhat != '\0') // is there a name?
|
||||
lua_pushfstring(L, " in function " LUA_QS, ar.name);
|
||||
else
|
||||
{
|
||||
if (*ar.what == 'm') // main?
|
||||
lua_pushfstring(L, " in main chunk");
|
||||
else if (*ar.what == 'C' || *ar.what == 't')
|
||||
lua_pushliteral(L, " ?"); // C function or tail call
|
||||
else
|
||||
lua_pushfstring(L, " in function <%s:%d>",
|
||||
ar.short_src, ar.linedefined);
|
||||
}
|
||||
lua_concat(L, lua_gettop(L));
|
||||
}
|
||||
lua_concat(L, lua_gettop(L));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Moved here from lib_getenum.
|
||||
int LUA_PushGlobals(lua_State *L, const char *word)
|
||||
{
|
||||
|
@ -410,11 +462,13 @@ static inline void LUA_LoadFile(MYFILE *f, char *name)
|
|||
|
||||
lua_lumploading = true; // turn on loading flag
|
||||
|
||||
if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, 0)) {
|
||||
lua_pushcfunction(gL, LUA_GetErrorMessage);
|
||||
if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, lua_gettop(gL) - 1)) {
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
|
||||
lua_pop(gL,1);
|
||||
}
|
||||
lua_gc(gL, LUA_GCCOLLECT, 0);
|
||||
lua_pop(gL, 1); // Pop error handler
|
||||
|
||||
lua_lumploading = false; // turn off again
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ void LUA_ClearExtVars(void);
|
|||
|
||||
extern boolean lua_lumploading; // is LUA_LoadLump being called?
|
||||
|
||||
int LUA_GetErrorMessage(lua_State *L);
|
||||
void LUA_LoadLump(UINT16 wad, UINT16 lump);
|
||||
#ifdef LUA_ALLOW_BYTECODE
|
||||
void LUA_DumpFile(const char *filename);
|
||||
|
|
Loading…
Reference in a new issue