| 833 | |
| 834 | |
| 835 | LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, |
| 836 | int *nresults) { |
| 837 | int status; |
| 838 | lua_lock(L); |
| 839 | if (L->status == LUA_OK) { /* may be starting a coroutine */ |
| 840 | if (L->ci != &L->base_ci) /* not in base level? */ |
| 841 | return resume_error(L, "cannot resume non-suspended coroutine", nargs); |
| 842 | else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */ |
| 843 | return resume_error(L, "cannot resume dead coroutine", nargs); |
| 844 | } |
| 845 | else if (L->status != LUA_YIELD) /* ended with errors? */ |
| 846 | return resume_error(L, "cannot resume dead coroutine", nargs); |
| 847 | L->nCcalls = (from) ? getCcalls(from) : 0; |
| 848 | if (getCcalls(L) >= LUAI_MAXCCALLS) |
| 849 | return resume_error(L, "C stack overflow", nargs); |
| 850 | L->nCcalls++; |
| 851 | luai_userstateresume(L, nargs); |
| 852 | api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); |
| 853 | status = luaD_rawrunprotected(L, resume, &nargs); |
| 854 | /* continue running after recoverable errors */ |
| 855 | status = precover(L, status); |
| 856 | if (l_likely(!errorstatus(status))) |
| 857 | lua_assert(status == L->status); /* normal end or yield */ |
| 858 | else { /* unrecoverable error */ |
| 859 | L->status = cast_byte(status); /* mark thread as 'dead' */ |
| 860 | luaD_seterrorobj(L, status, L->top.p); /* push error message */ |
| 861 | L->ci->top.p = L->top.p; |
| 862 | } |
| 863 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield |
| 864 | : cast_int(L->top.p - (L->ci->func.p + 1)); |
| 865 | lua_unlock(L); |
| 866 | return status; |
| 867 | } |
| 868 | |
| 869 | |
| 870 | LUA_API int lua_isyieldable (lua_State *L) { |
no test coverage detected