More work on redirect

This commit is contained in:
2026-06-02 18:34:03 -04:00
parent 6c9f75bfac
commit d951d2ab61
12 changed files with 298 additions and 201 deletions

View File

@@ -43,33 +43,46 @@ int traceback_coroutine(lua_State *L) {
firstpart = 0;
continue;
}
lua_getinfo(L, "Snl", &ar);
lua_getinfo(L, "Snlf", &ar);
eng::string storedname;
{
lua_getfield(L, LUA_REGISTRYINDEX, "funcnames");
lua_pushvalue(L, -2);
lua_rawget(L, -2);
const char *fname = lua_tostring(L, -1);
if (fname) storedname = fname;
lua_pop(L, 3);
}
if ((!any) && (*ar.what == 'C') && (ar.name != 0)) {
if (strcmp(ar.name, "__newindex") == 0) continue;
}
if ((ar.currentline > 0) || (*ar.namewhat != 0) || (*ar.what != 'C')) {
any = true;
lua_pushliteral(L, "\n\t");
if (strcmp(ar.short_src, "<console>")==0)
{
lua_pushstring(L, "in the console");
if (strcmp(ar.short_src, "<console>")==0) {
lua_pushstring(L, "in the console in");
} else if (strcmp(ar.short_src, "[C]")==0) {
lua_pushstring(L, "in builtin C++ ");
} else if (ar.currentline > 0) {
lua_pushfstring(L, "in %s line %d in", ar.short_src, ar.currentline);
} else {
lua_pushfstring(L, "in %s in", ar.short_src);
}
else
{
lua_pushfstring(L, "in %s", ar.short_src);
if (ar.currentline > 0)
lua_pushfstring(L, " line %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 top-level expression ");
else if (*ar.what == 'C' || *ar.what == 't')
lua_pushliteral(L, " in unknown C function");
else
lua_pushfstring(L, " in function on line %d", ar.linedefined);
if (!storedname.empty()) {
lua_pushfstring(L, " function " LUA_QS, storedname.c_str());
} else if (*ar.namewhat != 0) {
lua_pushfstring(L, " function " LUA_QS, ar.name);
} else if (*ar.what == 'm') {
lua_pushfstring(L, " top-level expression ");
} else {
lua_pushliteral(L, " unknown function");
}
if (1 + lua_gettop(L) - top > 5) {
lua_concat(L, 1 + lua_gettop(L) - top);
}