| 873 | |
| 874 | |
| 875 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, |
| 876 | lua_KFunction k) { |
| 877 | CallInfo *ci; |
| 878 | luai_userstateyield(L, nresults); |
| 879 | lua_lock(L); |
| 880 | ci = L->ci; |
| 881 | api_checknelems(L, nresults); |
| 882 | if (l_unlikely(!yieldable(L))) { |
| 883 | if (L != G(L)->mainthread) |
| 884 | luaG_runerror(L, "attempt to yield across a C-call boundary"); |
| 885 | else |
| 886 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 887 | } |
| 888 | L->status = LUA_YIELD; |
| 889 | ci->u2.nyield = nresults; /* save number of results */ |
| 890 | if (isLua(ci)) { /* inside a hook? */ |
| 891 | lua_assert(!isLuacode(ci)); |
| 892 | api_check(L, nresults == 0, "hooks cannot yield values"); |
| 893 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
| 894 | } |
| 895 | else { |
| 896 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 897 | ci->u.c.ctx = ctx; /* save context */ |
| 898 | luaD_throw(L, LUA_YIELD); |
| 899 | } |
| 900 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
| 901 | lua_unlock(L); |
| 902 | return 0; /* return to 'luaD_hook' */ |
| 903 | } |
| 904 | |
| 905 | |
| 906 | /* |
nothing calls this directly
no test coverage detected