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

Function lua_pcallk

xrepo/packages/l/lua/port/lua/src/lapi.c:1046–1087  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected