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

Function resume_helper

library/LuaTools.cpp:862–906  ·  view source on GitHub ↗

Copied from lcorolib.c, with error handling modifications

Source from the content-addressed store, hash-verified

860
861// Copied from lcorolib.c, with error handling modifications
862static int resume_helper(lua_State *L, lua_State *co, int narg, int nres)
863{
864 if (!co) {
865 lua_pop(L, narg);
866 push_simple_error(L, "coroutine expected in resume");
867 return LUA_ERRRUN;
868 }
869 if (!lua_checkstack(co, narg)) {
870 lua_pop(L, narg);
871 push_simple_error(L, "too many arguments to resume");
872 return LUA_ERRRUN;
873 }
874 if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
875 lua_pop(L, narg);
876 push_simple_error(L, "cannot resume dead coroutine");
877 return LUA_ERRRUN;
878 }
879 lua_xmove(L, co, narg);
880 int status = lua_resume(co, L, narg);
881 if (Lua::IsSuccess(status))
882 {
883 int nact = lua_gettop(co);
884 if (nres == LUA_MULTRET)
885 nres = nact;
886 else if (nres < nact)
887 lua_settop(co, nact = nres);
888 if (!lua_checkstack(L, nres + 1)) {
889 lua_settop(co, 0);
890 push_simple_error(L, "too many results to resume");
891 return LUA_ERRRUN;
892 }
893 int ttop = lua_gettop(L) + nres;
894 lua_xmove(co, L, nact);
895 lua_settop(L, ttop);
896 }
897 else
898 {
899 lua_xmove(co, L, 1);
900
901 // A cross-thread version of dfhack_onerror
902 if (lua_checkstack(L, LUA_MINSTACK))
903 convert_to_exception(L, 0, co);
904 }
905 return status;
906}
907
908static int dfhack_coresume (lua_State *L) {
909 lua_State *co = lua_tothread(L, 1);

Callers 4

dfhack_coresumeFunction · 0.85
dfhack_saferesumeFunction · 0.85
dfhack_coauxwrapFunction · 0.85
SafeResumeMethod · 0.85

Calls 9

push_simple_errorFunction · 0.85
lua_checkstackFunction · 0.85
lua_statusFunction · 0.85
lua_gettopFunction · 0.85
lua_xmoveFunction · 0.85
lua_resumeFunction · 0.85
IsSuccessFunction · 0.85
lua_settopFunction · 0.85
convert_to_exceptionFunction · 0.85

Tested by

no test coverage detected