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

Function lua_pcallk

extlibs/lua/src/lapi.c:1002–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1000
1001
1002LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
1003 lua_KContext ctx, lua_KFunction k) {
1004 struct CallS c;
1005 int status;
1006 ptrdiff_t func;
1007 lua_lock(L);
1008 api_check(L, k == NULL || !isLua(L->ci),
1009 "cannot use continuations inside hooks");
1010 api_checknelems(L, nargs+1);
1011 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
1012 checkresults(L, nargs, nresults);
1013 if (errfunc == 0)
1014 func = 0;
1015 else {
1016 StkId o = index2stack(L, errfunc);
1017 api_check(L, ttisfunction(s2v(o)), "error handler must be a function");
1018 func = savestack(L, o);
1019 }
1020 c.func = L->top - (nargs+1); /* function to be called */
1021 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */
1022 c.nresults = nresults; /* do a 'conventional' protected call */
1023 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
1024 }
1025 else { /* prepare continuation (call is already protected by 'resume') */
1026 CallInfo *ci = L->ci;
1027 ci->u.c.k = k; /* save continuation */
1028 ci->u.c.ctx = ctx; /* save context */
1029 /* save information for error recovery */
1030 ci->u2.funcidx = cast_int(savestack(L, c.func));
1031 ci->u.c.old_errfunc = L->errfunc;
1032 L->errfunc = func;
1033 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */
1034 ci->callstatus |= CIST_YPCALL; /* function can do error recovery */
1035 luaD_call(L, c.func, nresults); /* do the call */
1036 ci->callstatus &= ~CIST_YPCALL;
1037 L->errfunc = ci->u.c.old_errfunc;
1038 status = LUA_OK; /* if it is here, there were no errors */
1039 }
1040 adjustresults(L, nresults);
1041 lua_unlock(L);
1042 return status;
1043}
1044
1045
1046LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,

Callers 2

luaB_pcallFunction · 0.85
luaB_xpcallFunction · 0.85

Calls 3

index2stackFunction · 0.85
luaD_pcallFunction · 0.85
luaD_callFunction · 0.85

Tested by

no test coverage detected