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

Function error_tostring

library/LuaTools.cpp:534–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532static int DFHACK_EXCEPTION_META_TOKEN = 0;
533
534static void error_tostring(lua_State *L, bool keep_old = false)
535{
536 lua_rawgetp(L, LUA_REGISTRYINDEX, &DFHACK_TOSTRING_TOKEN);
537 if (keep_old)
538 lua_pushvalue(L, -2);
539 else
540 lua_swap(L);
541
542 bool ok = lua_pcall(L, 1, 1, 0) == LUA_OK;
543
544 const char *msg = lua_tostring(L, -1);
545 if (!msg)
546 {
547 msg = "tostring didn't return a string";
548 ok = false;
549 }
550
551 if (!ok)
552 {
553 lua_pushfstring(L, "(invalid error: %s)", msg);
554 lua_remove(L, -2);
555 }
556}
557
558static void report_error(lua_State *L, color_ostream *out = NULL, bool pop = false)
559{

Callers 3

report_errorFunction · 0.85
convert_to_exceptionFunction · 0.85

Calls 4

lua_rawgetpFunction · 0.85
lua_pushvalueFunction · 0.85
lua_swapFunction · 0.85
lua_pushfstringFunction · 0.85

Tested by

no test coverage detected