| 679 | } |
| 680 | |
| 681 | void LuaEngine::handleError(lua_State* state, int res) { |
| 682 | if (res != LUA_OK) { |
| 683 | if (lua_islightuserdata(state, -1)) { |
| 684 | void* error = lua_touserdata(state, -1); |
| 685 | if (error == &s_luaInstructionLimitExceptionKey) { |
| 686 | lua_pop(state, 1); |
| 687 | throw LuaInstructionLimitReached(); |
| 688 | } |
| 689 | if (error == &s_luaRecursionLimitExceptionKey) { |
| 690 | lua_pop(state, 1); |
| 691 | throw LuaRecursionLimitReached(); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | String error; |
| 696 | if (lua_isstring(state, -1)) |
| 697 | error = strf("Error code {}, {}", res, lua_tostring(state, -1)); |
| 698 | else |
| 699 | error = strf("Error code {}, <unknown error>", res); |
| 700 | |
| 701 | lua_pop(state, 1); |
| 702 | |
| 703 | // This seems terrible, but as far as I can tell, this is exactly what the |
| 704 | // stock lua repl does. |
| 705 | if (error.endsWith("<eof>")) |
| 706 | throw LuaIncompleteStatementException(error.takeUtf8()); |
| 707 | else |
| 708 | throw LuaException(error.takeUtf8()); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | int LuaEngine::pcallWithTraceback(lua_State* state, int nargs, int nresults) { |
| 713 | int msghPosition = lua_gettop(state) - nargs; |
nothing calls this directly
no test coverage detected