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