| 948 | |
| 949 | |
| 950 | LUA_API int lua_pcallk(lua_State *L, int nargs, int nresults, int errfunc, |
| 951 | lua_KContext ctx, lua_KFunction k) { |
| 952 | struct CallS c; |
| 953 | int status; |
| 954 | ptrdiff_t func; |
| 955 | lua_lock(L); |
| 956 | api_check(L, k == nullptr || !isLua(L->ci), |
| 957 | "cannot use continuations inside hooks"); |
| 958 | api_checknelems(L, nargs + 1); |
| 959 | api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); |
| 960 | checkresults(L, nargs, nresults); |
| 961 | if (errfunc == 0) |
| 962 | func = 0; |
| 963 | else { |
| 964 | StkId o = index2addr(L, errfunc); |
| 965 | api_checkstackindex(L, errfunc, o); |
| 966 | func = savestack(L, o); |
| 967 | } |
| 968 | c.func = L->top - (nargs + 1); /* function to be called */ |
| 969 | if (k == nullptr || L->nny > 0) { /* no continuation or no yieldable? */ |
| 970 | c.nresults = nresults; /* do a 'conventional' protected call */ |
| 971 | status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); |
| 972 | } |
| 973 | else { /* prepare continuation (call is already protected by 'resume') */ |
| 974 | CallInfo *ci = L->ci; |
| 975 | ci->u.c.k = k; /* save continuation */ |
| 976 | ci->u.c.ctx = ctx; /* save context */ |
| 977 | /* save information for error recovery */ |
| 978 | ci->extra = savestack(L, c.func); |
| 979 | ci->u.c.old_errfunc = L->errfunc; |
| 980 | L->errfunc = func; |
| 981 | setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */ |
| 982 | ci->callstatus |= CIST_YPCALL; /* function can do error recovery */ |
| 983 | luaD_call(L, c.func, nresults); /* do the call */ |
| 984 | ci->callstatus &= ~CIST_YPCALL; |
| 985 | L->errfunc = ci->u.c.old_errfunc; |
| 986 | status = LUA_OK; /* if it is here, there were no errors */ |
| 987 | } |
| 988 | adjustresults(L, nresults); |
| 989 | lua_unlock(L); |
| 990 | return status; |
| 991 | } |
| 992 | |
| 993 | |
| 994 | LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, |
no test coverage detected