| 605 | |
| 606 | |
| 607 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, |
| 608 | lua_KFunction k) { |
| 609 | CallInfo *ci = L->ci; |
| 610 | luai_userstateyield(L, nresults); |
| 611 | lua_lock(L); |
| 612 | api_checknelems(L, nresults); |
| 613 | if (L->nny > 0) { |
| 614 | if (L != G(L)->mainthread) |
| 615 | luaG_runerror(L, "attempt to yield across a C-call boundary"); |
| 616 | else |
| 617 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 618 | } |
| 619 | L->status = LUA_YIELD; |
| 620 | ci->extra = savestack(L, ci->func); /* save current 'func' */ |
| 621 | if (isLua(ci)) { /* inside a hook? */ |
| 622 | api_check(k == NULL, "hooks cannot continue after yielding"); |
| 623 | } |
| 624 | else { |
| 625 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 626 | ci->u.c.ctx = ctx; /* save context */ |
| 627 | ci->func = L->top - nresults - 1; /* protect stack below results */ |
| 628 | luaD_throw(L, LUA_YIELD); |
| 629 | } |
| 630 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
| 631 | lua_unlock(L); |
| 632 | return 0; /* return to 'luaD_hook' */ |
| 633 | } |
| 634 | |
| 635 | |
| 636 | int luaD_pcall (lua_State *L, Pfunc func, void *u, |
nothing calls this directly
no test coverage detected