MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / lua_pcallk

Function lua_pcallk

source/extern/lua/lapi.c:948–989  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

luaB_pcallFunction · 0.85
luaB_xpcallFunction · 0.85

Calls 3

index2addrFunction · 0.85
luaD_pcallFunction · 0.85
luaD_callFunction · 0.85

Tested by

no test coverage detected