MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / lua_pcallk

Function lua_pcallk

3rd/lua-5.4.3/src/lapi.c:1036–1077  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1034
1035
1036LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
1037 lua_KContext ctx, lua_KFunction k) {
1038 struct CallS c;
1039 int status;
1040 ptrdiff_t func;
1041 lua_lock(L);
1042 api_check(L, k == NULL || !isLua(L->ci),
1043 "cannot use continuations inside hooks");
1044 api_checknelems(L, nargs+1);
1045 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
1046 checkresults(L, nargs, nresults);
1047 if (errfunc == 0)
1048 func = 0;
1049 else {
1050 StkId o = index2stack(L, errfunc);
1051 api_check(L, ttisfunction(s2v(o)), "error handler must be a function");
1052 func = savestack(L, o);
1053 }
1054 c.func = L->top - (nargs+1); /* function to be called */
1055 if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */
1056 c.nresults = nresults; /* do a 'conventional' protected call */
1057 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
1058 }
1059 else { /* prepare continuation (call is already protected by 'resume') */
1060 CallInfo *ci = L->ci;
1061 ci->u.c.k = k; /* save continuation */
1062 ci->u.c.ctx = ctx; /* save context */
1063 /* save information for error recovery */
1064 ci->u2.funcidx = cast_int(savestack(L, c.func));
1065 ci->u.c.old_errfunc = L->errfunc;
1066 L->errfunc = func;
1067 setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */
1068 ci->callstatus |= CIST_YPCALL; /* function can do error recovery */
1069 luaD_call(L, c.func, nresults); /* do the call */
1070 ci->callstatus &= ~CIST_YPCALL;
1071 L->errfunc = ci->u.c.old_errfunc;
1072 status = LUA_OK; /* if it is here, there were no errors */
1073 }
1074 adjustresults(L, nresults);
1075 lua_unlock(L);
1076 return status;
1077}
1078
1079
1080LUA_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