MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / handleError

Method handleError

source/core/StarLua.cpp:681–710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679}
680
681void 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
712int LuaEngine::pcallWithTraceback(lua_State* state, int nargs, int nresults) {
713 int msghPosition = lua_gettop(state) - nargs;

Callers

nothing calls this directly

Calls 5

lua_touserdataFunction · 0.85
lua_isstringFunction · 0.85
strfFunction · 0.85
endsWithMethod · 0.45
takeUtf8Method · 0.45

Tested by

no test coverage detected