| 808 | |
| 809 | |
| 810 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, |
| 811 | lua_KFunction k) { |
| 812 | CallInfo *ci; |
| 813 | luai_userstateyield(L, nresults); |
| 814 | lua_lock(L); |
| 815 | ci = L->ci; |
| 816 | api_checknelems(L, nresults); |
| 817 | if (l_unlikely(!yieldable(L))) { |
| 818 | if (L != G(L)->mainthread) |
| 819 | luaG_runerror(L, "attempt to yield across a C-call boundary"); |
| 820 | else |
| 821 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 822 | } |
| 823 | L->status = LUA_YIELD; |
| 824 | ci->u2.nyield = nresults; /* save number of results */ |
| 825 | if (isLua(ci)) { /* inside a hook? */ |
| 826 | lua_assert(!isLuacode(ci)); |
| 827 | api_check(L, nresults == 0, "hooks cannot yield values"); |
| 828 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
| 829 | } |
| 830 | else { |
| 831 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 832 | ci->u.c.ctx = ctx; /* save context */ |
| 833 | luaD_throw(L, LUA_YIELD); |
| 834 | } |
| 835 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
| 836 | lua_unlock(L); |
| 837 | return 0; /* return to 'luaD_hook' */ |
| 838 | } |
| 839 | |
| 840 | |
| 841 | /* |
nothing calls this directly
no test coverage detected