** 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. */
| 783 | ** coroutine. |
| 784 | */ |
| 785 | static void resume (lua_State *L, void *ud) { |
| 786 | int n = *(cast(int*, ud)); /* number of arguments */ |
| 787 | StkId firstArg = L->top.p - n; /* first argument */ |
| 788 | CallInfo *ci = L->ci; |
| 789 | if (L->status == LUA_OK) /* starting a coroutine? */ |
| 790 | ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */ |
| 791 | else { /* resuming from previous yield */ |
| 792 | lua_assert(L->status == LUA_YIELD); |
| 793 | L->status = LUA_OK; /* mark that it is running (again) */ |
| 794 | if (isLua(ci)) { /* yielded inside a hook? */ |
| 795 | /* undo increment made by 'luaG_traceexec': instruction was not |
| 796 | executed yet */ |
| 797 | lua_assert(ci->callstatus & CIST_HOOKYIELD); |
| 798 | ci->u.l.savedpc--; |
| 799 | L->top.p = firstArg; /* discard arguments */ |
| 800 | luaV_execute(L, ci); /* just continue running Lua code */ |
| 801 | } |
| 802 | else { /* 'common' yield */ |
| 803 | if (ci->u.c.k != NULL) { /* does it have a continuation function? */ |
| 804 | lua_unlock(L); |
| 805 | n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */ |
| 806 | lua_lock(L); |
| 807 | api_checknelems(L, n); |
| 808 | } |
| 809 | luaD_poscall(L, ci, n); /* finish 'luaD_call' */ |
| 810 | } |
| 811 | unroll(L, NULL); /* run continuation */ |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | |
| 816 | /* |
nothing calls this directly
no test coverage detected