| 705 | |
| 706 | |
| 707 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, |
| 708 | lua_KFunction k) { |
| 709 | CallInfo *ci = L->ci; |
| 710 | luai_userstateyield(L, nresults); |
| 711 | lua_lock(L); |
| 712 | api_checknelems(L, nresults); |
| 713 | if (unlikely(!yieldable(L))) { |
| 714 | if (L != G(L)->mainthread) |
| 715 | luaG_runerror(L, "attempt to yield across a C-call boundary"); |
| 716 | else |
| 717 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 718 | } |
| 719 | L->status = LUA_YIELD; |
| 720 | if (isLua(ci)) { /* inside a hook? */ |
| 721 | lua_assert(!isLuacode(ci)); |
| 722 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
| 723 | ci->u2.nyield = 0; /* no results */ |
| 724 | } |
| 725 | else { |
| 726 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 727 | ci->u.c.ctx = ctx; /* save context */ |
| 728 | ci->u2.nyield = nresults; /* save number of results */ |
| 729 | luaD_throw(L, LUA_YIELD); |
| 730 | } |
| 731 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
| 732 | lua_unlock(L); |
| 733 | return 0; /* return to 'luaD_hook' */ |
| 734 | } |
| 735 | |
| 736 | |
| 737 | /* |
nothing calls this directly
no test coverage detected