MCPcopy Create free account
hub / github.com/DFHack/dfhack / resume

Function resume

depends/lua/src/ldo.c:619–645  ·  view source on GitHub ↗

** Do the work for 'lua_resume' in protected mode. Most of the work ** depends on the status of the coroutine: initial state, suspended ** inside a hook, or regularly suspended (optionally with a continuation ** function), plus erroneous cases: non-suspended coroutine or dead ** coroutine. */

Source from the content-addressed store, hash-verified

617** coroutine.
618*/
619static void resume (lua_State *L, void *ud) {
620 int n = *(cast(int*, ud)); /* number of arguments */
621 StkId firstArg = L->top - n; /* first argument */
622 CallInfo *ci = L->ci;
623 if (L->status == LUA_OK) { /* starting a coroutine? */
624 if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */
625 luaV_execute(L); /* call it */
626 }
627 else { /* resuming from previous yield */
628 lua_assert(L->status == LUA_YIELD);
629 L->status = LUA_OK; /* mark that it is running (again) */
630 ci->func = restorestack(L, ci->extra);
631 if (isLua(ci)) /* yielded inside a hook? */
632 luaV_execute(L); /* just continue running Lua code */
633 else { /* 'common' yield */
634 if (ci->u.c.k != NULL) { /* does it have a continuation function? */
635 lua_unlock(L);
636 n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */
637 lua_lock(L);
638 api_checknelems(L, n);
639 firstArg = L->top - n; /* yield results come from continuation */
640 }
641 luaD_poscall(L, ci, firstArg, n); /* finish 'luaD_precall' */
642 }
643 unroll(L, NULL); /* run continuation */
644 }
645}
646
647
648LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {

Callers

nothing calls this directly

Calls 4

luaD_precallFunction · 0.85
luaV_executeFunction · 0.85
luaD_poscallFunction · 0.85
unrollFunction · 0.85

Tested by

no test coverage detected