| 964 | |
| 965 | |
| 966 | LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, |
| 967 | int *nresults) { |
| 968 | TStatus status; |
| 969 | lua_lock(L); |
| 970 | if (L->status == LUA_OK) { /* may be starting a coroutine */ |
| 971 | if (L->ci != &L->base_ci) /* not in base level? */ |
| 972 | return resume_error(L, "cannot resume non-suspended coroutine", nargs); |
| 973 | else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */ |
| 974 | return resume_error(L, "cannot resume dead coroutine", nargs); |
| 975 | } |
| 976 | else if (L->status != LUA_YIELD) /* ended with errors? */ |
| 977 | return resume_error(L, "cannot resume dead coroutine", nargs); |
| 978 | L->nCcalls = (from) ? getCcalls(from) : 0; |
| 979 | if (getCcalls(L) >= LUAI_MAXCCALLS) |
| 980 | return resume_error(L, "C stack overflow", nargs); |
| 981 | L->nCcalls++; |
| 982 | luai_userstateresume(L, nargs); |
| 983 | api_checkpop(L, (L->status == LUA_OK) ? nargs + 1 : nargs); |
| 984 | status = luaD_rawrunprotected(L, resume, &nargs); |
| 985 | /* continue running after recoverable errors */ |
| 986 | status = precover(L, status); |
| 987 | if (l_likely(!errorstatus(status))) |
| 988 | lua_assert(status == L->status); /* normal end or yield */ |
| 989 | else { /* unrecoverable error */ |
| 990 | L->status = status; /* mark thread as 'dead' */ |
| 991 | luaD_seterrorobj(L, status, L->top.p); /* push error message */ |
| 992 | L->ci->top.p = L->top.p; |
| 993 | } |
| 994 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield |
| 995 | : cast_int(L->top.p - (L->ci->func.p + 1)); |
| 996 | lua_unlock(L); |
| 997 | return APIstatus(status); |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | LUA_API int lua_isyieldable (lua_State *L) { |
no test coverage detected