| 1004 | |
| 1005 | |
| 1006 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, |
| 1007 | lua_KFunction k) { |
| 1008 | CallInfo *ci; |
| 1009 | luai_userstateyield(L, nresults); |
| 1010 | lua_lock(L); |
| 1011 | ci = L->ci; |
| 1012 | api_checkpop(L, nresults); |
| 1013 | if (l_unlikely(!yieldable(L))) { |
| 1014 | if (L != mainthread(G(L))) |
| 1015 | luaG_runerror(L, "attempt to yield across a C-call boundary"); |
| 1016 | else |
| 1017 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 1018 | } |
| 1019 | L->status = LUA_YIELD; |
| 1020 | ci->u2.nyield = nresults; /* save number of results */ |
| 1021 | if (isLua(ci)) { /* inside a hook? */ |
| 1022 | lua_assert(!isLuacode(ci)); |
| 1023 | api_check(L, nresults == 0, "hooks cannot yield values"); |
| 1024 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
| 1025 | } |
| 1026 | else { |
| 1027 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 1028 | ci->u.c.ctx = ctx; /* save context */ |
| 1029 | luaD_throw(L, LUA_YIELD); |
| 1030 | } |
| 1031 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
| 1032 | lua_unlock(L); |
| 1033 | return 0; /* return to 'luaD_hook' */ |
| 1034 | } |
| 1035 | |
| 1036 | |
| 1037 | /* |
nothing calls this directly
no test coverage detected