| 532 | static int DFHACK_EXCEPTION_META_TOKEN = 0; |
| 533 | |
| 534 | static 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 | |
| 558 | static void report_error(lua_State *L, color_ostream *out = NULL, bool pop = false) |
| 559 | { |
no test coverage detected