** 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. */
| 724 | ** coroutine. |
| 725 | */ |
| 726 | static void resume (lua_State *L, void *ud) { |
| 727 | int n = *(cast(int*, ud)); /* number of arguments */ |
| 728 | StkId firstArg = L->top - n; /* first argument */ |
| 729 | CallInfo *ci = L->ci; |
| 730 | if (L->status == LUA_OK) /* starting a coroutine? */ |
| 731 | ccall(L, firstArg - 1, LUA_MULTRET, 1); /* just call its body */ |
| 732 | else { /* resuming from previous yield */ |
| 733 | lua_assert(L->status == LUA_YIELD); |
| 734 | L->status = LUA_OK; /* mark that it is running (again) */ |
| 735 | luaE_incCstack(L); /* control the C stack */ |
| 736 | if (isLua(ci)) { /* yielded inside a hook? */ |
| 737 | L->top = firstArg; /* discard arguments */ |
| 738 | luaV_execute(L, ci); /* just continue running Lua code */ |
| 739 | } |
| 740 | else { /* 'common' yield */ |
| 741 | if (ci->u.c.k != NULL) { /* does it have a continuation function? */ |
| 742 | lua_unlock(L); |
| 743 | n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */ |
| 744 | lua_lock(L); |
| 745 | api_checknelems(L, n); |
| 746 | } |
| 747 | luaD_poscall(L, ci, n); /* finish 'luaD_call' */ |
| 748 | } |
| 749 | unroll(L, NULL); /* run continuation */ |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | |
| 754 | /* |
no test coverage detected