| 917 | |
| 918 | |
| 919 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, |
| 920 | lua_KContext ctx, lua_KFunction k) { |
| 921 | struct CallS c; |
| 922 | int status; |
| 923 | ptrdiff_t func; |
| 924 | lua_lock(L); |
| 925 | api_check(k == NULL || !isLua(L->ci), |
| 926 | "cannot use continuations inside hooks"); |
| 927 | api_checknelems(L, nargs+1); |
| 928 | api_check(L->status == LUA_OK, "cannot do calls on non-normal thread"); |
| 929 | checkresults(L, nargs, nresults); |
| 930 | if (errfunc == 0) |
| 931 | func = 0; |
| 932 | else { |
| 933 | StkId o = index2addr(L, errfunc); |
| 934 | api_checkstackindex(errfunc, o); |
| 935 | func = savestack(L, o); |
| 936 | } |
| 937 | c.func = L->top - (nargs+1); /* function to be called */ |
| 938 | if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */ |
| 939 | c.nresults = nresults; /* do a 'conventional' protected call */ |
| 940 | status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); |
| 941 | } |
| 942 | else { /* prepare continuation (call is already protected by 'resume') */ |
| 943 | CallInfo *ci = L->ci; |
| 944 | ci->u.c.k = k; /* save continuation */ |
| 945 | ci->u.c.ctx = ctx; /* save context */ |
| 946 | /* save information for error recovery */ |
| 947 | ci->extra = savestack(L, c.func); |
| 948 | ci->u.c.old_errfunc = L->errfunc; |
| 949 | L->errfunc = func; |
| 950 | setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */ |
| 951 | ci->callstatus |= CIST_YPCALL; /* function can do error recovery */ |
| 952 | luaD_call(L, c.func, nresults, 1); /* do the call */ |
| 953 | ci->callstatus &= ~CIST_YPCALL; |
| 954 | L->errfunc = ci->u.c.old_errfunc; |
| 955 | status = LUA_OK; /* if it is here, there were no errors */ |
| 956 | } |
| 957 | adjustresults(L, nresults); |
| 958 | lua_unlock(L); |
| 959 | return status; |
| 960 | } |
| 961 | |
| 962 | |
| 963 | LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, |
no test coverage detected