** Do the work for 'lua_resume' in protected mode. Most of the work ** depends on the status of the coroutine: initial state, suspended ** inside a hook, or regularly suspended (optionally with a continuation ** function), plus erroneous cases: non-suspended coroutine or dead ** coroutine. */
| 914 | ** coroutine. |
| 915 | */ |
| 916 | static void resume (lua_State *L, void *ud) { |
| 917 | int n = *(cast(int*, ud)); /* number of arguments */ |
| 918 | StkId firstArg = L->top.p - n; /* first argument */ |
| 919 | CallInfo *ci = L->ci; |
| 920 | if (L->status == LUA_OK) /* starting a coroutine? */ |
| 921 | ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */ |
| 922 | else { /* resuming from previous yield */ |
| 923 | lua_assert(L->status == LUA_YIELD); |
| 924 | L->status = LUA_OK; /* mark that it is running (again) */ |
| 925 | if (isLua(ci)) { /* yielded inside a hook? */ |
| 926 | /* undo increment made by 'luaG_traceexec': instruction was not |
| 927 | executed yet */ |
| 928 | lua_assert(ci->callstatus & CIST_HOOKYIELD); |
| 929 | ci->u.l.savedpc--; |
| 930 | L->top.p = firstArg; /* discard arguments */ |
| 931 | luaV_execute(L, ci); /* just continue running Lua code */ |
| 932 | } |
| 933 | else { /* 'common' yield */ |
| 934 | if (ci->u.c.k != NULL) { /* does it have a continuation function? */ |
| 935 | lua_unlock(L); |
| 936 | n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */ |
| 937 | lua_lock(L); |
| 938 | api_checknelems(L, n); |
| 939 | } |
| 940 | luaD_poscall(L, ci, n); /* finish 'luaD_call' */ |
| 941 | } |
| 942 | unroll(L, NULL); /* run continuation */ |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | |
| 947 | /* |
nothing calls this directly
no test coverage detected