MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / lua_pcallk

Function lua_pcallk

lib/lua/src/lapi.c:1043–1084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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