MCPcopy Create free account
hub / github.com/DFHack/dfhack / dfhack_exception_tostring

Function dfhack_exception_tostring

library/LuaTools.cpp:706–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704}
705
706static int dfhack_exception_tostring(lua_State *L)
707{
708 luaL_checktype(L, 1, LUA_TTABLE);
709 lua_settop(L, 2);
710
711 if (lua_isnil(L, 2))
712 {
713 lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_EXCEPTION_META_TOKEN);
714 lua_getfield(L, -1, "verbose");
715 lua_insert(L, 2);
716 lua_settop(L, 2);
717 }
718
719 lua_getfield(L, 1, "verbose");
720
721 bool verbose =
722 lua_toboolean(L, 2) || lua_toboolean(L, 3) ||
723 (lua_isnil(L, 2) && lua_isnil(L, 3));
724
725 int base = lua_gettop(L);
726
727 if (verbose || lua_isnil(L, 3))
728 {
729 lua_getfield(L, 1, "where");
730 if (!lua_isstring(L, -1))
731 lua_pop(L, 1);
732 }
733
734 lua_getfield(L, 1, "message");
735 if (!lua_isstring(L, -1))
736 {
737 lua_pop(L, 1);
738 lua_pushstring(L, "(error message is not a string)");
739 }
740
741 if (verbose)
742 {
743 lua_pushstring(L, "\n");
744 lua_getfield(L, 1, "stacktrace");
745 if (!lua_isstring(L, -1))
746 lua_pop(L, 2);
747 }
748
749 lua_pushstring(L, "\ncaused by:\n");
750 lua_getfield(L, 1, "cause");
751 if (lua_isnil(L, -1))
752 lua_pop(L, 2);
753 else if (lua_istable(L, -1))
754 {
755 lua_pushcfunction(L, dfhack_exception_tostring);
756 lua_swap(L);
757 lua_pushvalue(L, 2);
758 if (lua_pcall(L, 2, 1, 0) != LUA_OK)
759 error_tostring(L);
760 }
761 else
762 error_tostring(L);
763

Callers

nothing calls this directly

Calls 12

luaL_checktypeFunction · 0.85
lua_settopFunction · 0.85
lua_rawgetpFunction · 0.85
lua_getfieldFunction · 0.85
lua_tobooleanFunction · 0.85
lua_gettopFunction · 0.85
lua_isstringFunction · 0.85
lua_pushstringFunction · 0.85
lua_swapFunction · 0.85
lua_pushvalueFunction · 0.85
error_tostringFunction · 0.85
lua_concatFunction · 0.85

Tested by

no test coverage detected