Copied from lcorolib.c, with error handling modifications
| 860 | |
| 861 | // Copied from lcorolib.c, with error handling modifications |
| 862 | static 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 | |
| 908 | static int dfhack_coresume (lua_State *L) { |
| 909 | lua_State *co = lua_tothread(L, 1); |
no test coverage detected