Lines Matching +full:- +full:l

43 ** Error-recovery functions
58 #define LUAI_THROW(L,c) throw(c) argument
59 #define LUAI_TRY(L,c,a) \ argument
60 try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
66 #define LUAI_THROW(L,c) _longjmp((c)->b, 1) argument
67 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } argument
73 #define LUAI_THROW(L,c) longjmp((c)->b, 1) argument
74 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } argument
91 void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { in luaD_seterrorobj() argument
94 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ in luaD_seterrorobj()
98 setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); in luaD_seterrorobj()
107 setobjs2s(L, oldtop, L->top.p - 1); /* error message on current top */ in luaD_seterrorobj()
111 L->top.p = oldtop + 1; in luaD_seterrorobj()
115 l_noret luaD_throw (lua_State *L, int errcode) { in luaD_throw() argument
116 if (L->errorJmp) { /* thread has an error handler? */ in luaD_throw()
117 L->errorJmp->status = errcode; /* set status */ in luaD_throw()
118 LUAI_THROW(L, L->errorJmp); /* jump to it */ in luaD_throw()
121 global_State *g = G(L); in luaD_throw()
122 errcode = luaE_resetthread(L, errcode); /* close all upvalues */ in luaD_throw()
123 if (g->mainthread->errorJmp) { /* main thread has a handler? */ in luaD_throw()
124 setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */ in luaD_throw()
125 luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ in luaD_throw()
128 if (g->panic) { /* panic function? */ in luaD_throw()
129 lua_unlock(L); in luaD_throw()
130 g->panic(L); /* call panic function (last chance to jump out) */ in luaD_throw()
138 int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { in luaD_rawrunprotected() argument
139 l_uint32 oldnCcalls = L->nCcalls; in luaD_rawrunprotected()
142 lj.previous = L->errorJmp; /* chain new error handler */ in luaD_rawrunprotected()
143 L->errorJmp = &lj; in luaD_rawrunprotected()
144 LUAI_TRY(L, &lj, in luaD_rawrunprotected()
145 (*f)(L, ud); in luaD_rawrunprotected()
147 L->errorJmp = lj.previous; /* restore old error handler */ in luaD_rawrunprotected()
148 L->nCcalls = oldnCcalls; in luaD_rawrunprotected()
165 static void relstack (lua_State *L) { in relstack() argument
168 L->top.offset = savestack(L, L->top.p); in relstack()
169 L->tbclist.offset = savestack(L, L->tbclist.p); in relstack()
170 for (up = L->openupval; up != NULL; up = up->u.open.next) in relstack()
171 up->v.offset = savestack(L, uplevel(up)); in relstack()
172 for (ci = L->ci; ci != NULL; ci = ci->previous) { in relstack()
173 ci->top.offset = savestack(L, ci->top.p); in relstack()
174 ci->func.offset = savestack(L, ci->func.p); in relstack()
182 static void correctstack (lua_State *L) { in correctstack() argument
185 L->top.p = restorestack(L, L->top.offset); in correctstack()
186 L->tbclist.p = restorestack(L, L->tbclist.offset); in correctstack()
187 for (up = L->openupval; up != NULL; up = up->u.open.next) in correctstack()
188 up->v.p = s2v(restorestack(L, up->v.offset)); in correctstack()
189 for (ci = L->ci; ci != NULL; ci = ci->previous) { in correctstack()
190 ci->top.p = restorestack(L, ci->top.offset); in correctstack()
191 ci->func.p = restorestack(L, ci->func.offset); in correctstack()
193 ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */ in correctstack()
212 int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { in luaD_reallocstack() argument
213 int oldsize = stacksize(L); in luaD_reallocstack()
216 int oldgcstop = G(L)->gcstopem; in luaD_reallocstack()
218 relstack(L); /* change pointers to offsets */ in luaD_reallocstack()
219 G(L)->gcstopem = 1; /* stop emergency collection */ in luaD_reallocstack()
220 newstack = luaM_reallocvector(L, L->stack.p, oldsize + EXTRA_STACK, in luaD_reallocstack()
222 G(L)->gcstopem = oldgcstop; /* restore emergency collection */ in luaD_reallocstack()
224 correctstack(L); /* change offsets back to pointers */ in luaD_reallocstack()
226 luaM_error(L); in luaD_reallocstack()
229 L->stack.p = newstack; in luaD_reallocstack()
230 correctstack(L); /* change offsets back to pointers */ in luaD_reallocstack()
231 L->stack_last.p = L->stack.p + newsize; in luaD_reallocstack()
242 int luaD_growstack (lua_State *L, int n, int raiseerror) { in luaD_growstack() argument
243 int size = stacksize(L); in luaD_growstack()
248 lua_assert(stacksize(L) == ERRORSTACKSIZE); in luaD_growstack()
250 luaD_throw(L, LUA_ERRERR); /* error inside message handler */ in luaD_growstack()
255 int needed = cast_int(L->top.p - L->stack.p) + n; in luaD_growstack()
261 return luaD_reallocstack(L, newsize, raiseerror); in luaD_growstack()
265 luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); in luaD_growstack()
267 luaG_runerror(L, "stack overflow"); in luaD_growstack()
276 static int stackinuse (lua_State *L) { in stackinuse() argument
279 StkId lim = L->top.p; in stackinuse()
280 for (ci = L->ci; ci != NULL; ci = ci->previous) { in stackinuse()
281 if (lim < ci->top.p) lim = ci->top.p; in stackinuse()
283 lua_assert(lim <= L->stack_last.p + EXTRA_STACK); in stackinuse()
284 res = cast_int(lim - L->stack.p) + 1; /* part of stack in use */ in stackinuse()
300 void luaD_shrinkstack (lua_State *L) { in luaD_shrinkstack() argument
301 int inuse = stackinuse(L); in luaD_shrinkstack()
305 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) { in luaD_shrinkstack()
307 luaD_reallocstack(L, nsize, 0); /* ok if that fails */ in luaD_shrinkstack()
310 condmovestack(L,{},{}); /* (change only for debugging) */ in luaD_shrinkstack()
311 luaE_shrinkCI(L); /* shrink CI list */ in luaD_shrinkstack()
315 void luaD_inctop (lua_State *L) { in luaD_inctop() argument
316 luaD_checkstack(L, 1); in luaD_inctop()
317 L->top.p++; in luaD_inctop()
325 ** called. (Both 'L->hook' and 'L->hookmask', which trigger this
328 void luaD_hook (lua_State *L, int event, int line, in luaD_hook() argument
330 lua_Hook hook = L->hook; in luaD_hook()
331 if (hook && L->allowhook) { /* make sure there is a hook */ in luaD_hook()
333 CallInfo *ci = L->ci; in luaD_hook()
334 ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ in luaD_hook()
335 ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ in luaD_hook()
342 ci->u2.transferinfo.ftransfer = ftransfer; in luaD_hook()
343 ci->u2.transferinfo.ntransfer = ntransfer; in luaD_hook()
345 if (isLua(ci) && L->top.p < ci->top.p) in luaD_hook()
346 L->top.p = ci->top.p; /* protect entire activation register */ in luaD_hook()
347 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ in luaD_hook()
348 if (ci->top.p < L->top.p + LUA_MINSTACK) in luaD_hook()
349 ci->top.p = L->top.p + LUA_MINSTACK; in luaD_hook()
350 L->allowhook = 0; /* cannot call hooks inside a hook */ in luaD_hook()
351 ci->callstatus |= mask; in luaD_hook()
352 lua_unlock(L); in luaD_hook()
353 (*hook)(L, &ar); in luaD_hook()
354 lua_lock(L); in luaD_hook()
355 lua_assert(!L->allowhook); in luaD_hook()
356 L->allowhook = 1; in luaD_hook()
357 ci->top.p = restorestack(L, ci_top); in luaD_hook()
358 L->top.p = restorestack(L, top); in luaD_hook()
359 ci->callstatus &= ~mask; in luaD_hook()
369 void luaD_hookcall (lua_State *L, CallInfo *ci) { in luaD_hookcall() argument
370 L->oldpc = 0; /* set 'oldpc' for new function */ in luaD_hookcall()
371 if (L->hookmask & LUA_MASKCALL) { /* is call hook on? */ in luaD_hookcall()
372 int event = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL in luaD_hookcall()
374 Proto *p = ci_func(ci)->p; in luaD_hookcall()
375 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ in luaD_hookcall()
376 luaD_hook(L, event, -1, 1, p->numparams); in luaD_hookcall()
377 ci->u.l.savedpc--; /* correct 'pc' */ in luaD_hookcall()
387 static void rethook (lua_State *L, CallInfo *ci, int nres) { in rethook() argument
388 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ in rethook()
389 StkId firstres = L->top.p - nres; /* index of first result */ in rethook()
393 Proto *p = ci_func(ci)->p; in rethook()
394 if (p->is_vararg) in rethook()
395 delta = ci->u.l.nextraargs + p->numparams + 1; in rethook()
397 ci->func.p += delta; /* if vararg, back to virtual 'func' */ in rethook()
398 ftransfer = cast(unsigned short, firstres - ci->func.p); in rethook()
399 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ in rethook()
400 ci->func.p -= delta; in rethook()
402 if (isLua(ci = ci->previous)) in rethook()
403 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */ in rethook()
412 StkId luaD_tryfuncTM (lua_State *L, StkId func) { in luaD_tryfuncTM() argument
415 checkstackGCp(L, 1, func); /* space for metamethod */ in luaD_tryfuncTM()
416 tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */ in luaD_tryfuncTM()
418 luaG_callerror(L, s2v(func)); /* nothing to call */ in luaD_tryfuncTM()
419 for (p = L->top.p; p > func; p--) /* open space for metamethod */ in luaD_tryfuncTM()
420 setobjs2s(L, p, p-1); in luaD_tryfuncTM()
421 L->top.p++; /* stack space pre-allocated by the caller */ in luaD_tryfuncTM()
422 setobj2s(L, func, tm); /* metamethod is the new function to be called */ in luaD_tryfuncTM()
433 l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { in moveresults() argument
438 L->top.p = res; in moveresults()
444 setobjs2s(L, res, L->top.p - nres); /* move it to proper place */ in moveresults()
445 L->top.p = res + 1; in moveresults()
450 default: /* two/more results and/or to-be-closed variables */ in moveresults()
451 if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ in moveresults()
452 L->ci->callstatus |= CIST_CLSRET; /* in case of yields */ in moveresults()
453 L->ci->u2.nres = nres; in moveresults()
454 res = luaF_close(L, res, CLOSEKTOP, 1); in moveresults()
455 L->ci->callstatus &= ~CIST_CLSRET; in moveresults()
456 if (L->hookmask) { /* if needed, call hook after '__close's */ in moveresults()
457 ptrdiff_t savedres = savestack(L, res); in moveresults()
458 rethook(L, L->ci, nres); in moveresults()
459 res = restorestack(L, savedres); /* hook can move stack */ in moveresults()
468 firstresult = L->top.p - nres; /* index of first result */ in moveresults()
472 setobjs2s(L, res + i, firstresult + i); in moveresults()
475 L->top.p = res + wanted; /* top points after the last result */ in moveresults()
485 void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { in luaD_poscall() argument
486 int wanted = ci->nresults; in luaD_poscall()
487 if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted))) in luaD_poscall()
488 rethook(L, ci, nres); in luaD_poscall()
490 moveresults(L, ci->func.p, nres, wanted); in luaD_poscall()
492 lua_assert(!(ci->callstatus & in luaD_poscall()
494 L->ci = ci->previous; /* back to caller (after closing variables) */ in luaD_poscall()
499 #define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L)) argument
502 l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, in prepCallInfo() argument
504 CallInfo *ci = L->ci = next_ci(L); /* new frame */ in prepCallInfo()
505 ci->func.p = func; in prepCallInfo()
506 ci->nresults = nret; in prepCallInfo()
507 ci->callstatus = mask; in prepCallInfo()
508 ci->top.p = top; in prepCallInfo()
516 l_sinline int precallC (lua_State *L, StkId func, int nresults, in precallC() argument
520 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ in precallC()
521 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C, in precallC()
522 L->top.p + LUA_MINSTACK); in precallC()
523 lua_assert(ci->top.p <= L->stack_last.p); in precallC()
524 if (l_unlikely(L->hookmask & LUA_MASKCALL)) { in precallC()
525 int narg = cast_int(L->top.p - func) - 1; in precallC()
526 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); in precallC()
528 lua_unlock(L); in precallC()
529 n = (*f)(L); /* do the actual call */ in precallC()
530 lua_lock(L); in precallC()
531 api_checknelems(L, n); in precallC()
532 luaD_poscall(L, ci, n); in precallC()
541 ** results, if it was a C function, or -1 for a Lua function.
543 int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, in luaD_pretailcall() argument
548 return precallC(L, func, LUA_MULTRET, clCvalue(s2v(func))->f); in luaD_pretailcall()
550 return precallC(L, func, LUA_MULTRET, fvalue(s2v(func))); in luaD_pretailcall()
552 Proto *p = clLvalue(s2v(func))->p; in luaD_pretailcall()
553 int fsize = p->maxstacksize; /* frame size */ in luaD_pretailcall()
554 int nfixparams = p->numparams; in luaD_pretailcall()
556 checkstackGCp(L, fsize - delta, func); in luaD_pretailcall()
557 ci->func.p -= delta; /* restore 'func' (if vararg) */ in luaD_pretailcall()
559 setobjs2s(L, ci->func.p + i, func + i); in luaD_pretailcall()
560 func = ci->func.p; /* moved-down function */ in luaD_pretailcall()
563 ci->top.p = func + 1 + fsize; /* top for new function */ in luaD_pretailcall()
564 lua_assert(ci->top.p <= L->stack_last.p); in luaD_pretailcall()
565 ci->u.l.savedpc = p->code; /* starting point */ in luaD_pretailcall()
566 ci->callstatus |= CIST_TAIL; in luaD_pretailcall()
567 L->top.p = func + narg1; /* set top */ in luaD_pretailcall()
568 return -1; in luaD_pretailcall()
571 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ in luaD_pretailcall()
572 /* return luaD_pretailcall(L, ci, func, narg1 + 1, delta); */ in luaD_pretailcall()
588 CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { in luaD_precall() argument
592 precallC(L, func, nresults, clCvalue(s2v(func))->f); in luaD_precall()
595 precallC(L, func, nresults, fvalue(s2v(func))); in luaD_precall()
599 Proto *p = clLvalue(s2v(func))->p; in luaD_precall()
600 int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */ in luaD_precall()
601 int nfixparams = p->numparams; in luaD_precall()
602 int fsize = p->maxstacksize; /* frame size */ in luaD_precall()
603 checkstackGCp(L, fsize, func); in luaD_precall()
604 L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize); in luaD_precall()
605 ci->u.l.savedpc = p->code; /* starting point */ in luaD_precall()
607 setnilvalue(s2v(L->top.p++)); /* complete missing arguments */ in luaD_precall()
608 lua_assert(ci->top.p <= L->stack_last.p); in luaD_precall()
612 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ in luaD_precall()
613 /* return luaD_precall(L, func, nresults); */ in luaD_precall()
623 ** plus increment number of non-yieldable calls).
628 l_sinline void ccall (lua_State *L, StkId func, int nResults, l_uint32 inc) { in ccall() argument
630 L->nCcalls += inc; in ccall()
631 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) { in ccall()
632 checkstackp(L, 0, func); /* free any use of EXTRA_STACK */ in ccall()
633 luaE_checkcstack(L); in ccall()
635 if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */ in ccall()
636 ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */ in ccall()
637 luaV_execute(L, ci); /* call it */ in ccall()
639 L->nCcalls -= inc; in ccall()
646 void luaD_call (lua_State *L, StkId func, int nResults) { in luaD_call() argument
647 ccall(L, func, nResults, 1); in luaD_call()
654 void luaD_callnoyield (lua_State *L, StkId func, int nResults) { in luaD_callnoyield() argument
655 ccall(L, func, nResults, nyci); in luaD_callnoyield()
675 static int finishpcallk (lua_State *L, CallInfo *ci) { in finishpcallk() argument
680 StkId func = restorestack(L, ci->u2.funcidx); in finishpcallk()
681 L->allowhook = getoah(ci->callstatus); /* restore 'allowhook' */ in finishpcallk()
682 func = luaF_close(L, func, status, 1); /* can yield or raise an error */ in finishpcallk()
683 luaD_seterrorobj(L, status, func); in finishpcallk()
684 luaD_shrinkstack(L); /* restore stack size in case of overflow */ in finishpcallk()
687 ci->callstatus &= ~CIST_YPCALL; in finishpcallk()
688 L->errfunc = ci->u.c.old_errfunc; in finishpcallk()
708 static void finishCcall (lua_State *L, CallInfo *ci) { in finishCcall() argument
710 if (ci->callstatus & CIST_CLSRET) { /* was returning? */ in finishCcall()
711 lua_assert(hastocloseCfunc(ci->nresults)); in finishCcall()
712 n = ci->u2.nres; /* just redo 'luaD_poscall' */ in finishCcall()
718 lua_assert(ci->u.c.k != NULL && yieldable(L)); in finishCcall()
719 if (ci->callstatus & CIST_YPCALL) /* was inside a 'lua_pcallk'? */ in finishCcall()
720 status = finishpcallk(L, ci); /* finish it */ in finishCcall()
721 adjustresults(L, LUA_MULTRET); /* finish 'lua_callk' */ in finishCcall()
722 lua_unlock(L); in finishCcall()
723 n = (*ci->u.c.k)(L, status, ci->u.c.ctx); /* call continuation */ in finishCcall()
724 lua_lock(L); in finishCcall()
725 api_checknelems(L, n); in finishCcall()
727 luaD_poscall(L, ci, n); /* finish 'luaD_call' */ in finishCcall()
734 ** interruption long-jumps out of the loop).
736 static void unroll (lua_State *L, void *ud) { in unroll() argument
739 while ((ci = L->ci) != &L->base_ci) { /* something in the stack */ in unroll()
741 finishCcall(L, ci); /* complete its execution */ in unroll()
743 luaV_finishOp(L); /* finish interrupted instruction */ in unroll()
744 luaV_execute(L, ci); /* execute down to higher C 'boundary' */ in unroll()
754 static CallInfo *findpcall (lua_State *L) { in findpcall() argument
756 for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */ in findpcall()
757 if (ci->callstatus & CIST_YPCALL) in findpcall()
769 static int resume_error (lua_State *L, const char *msg, int narg) { in resume_error() argument
770 L->top.p -= narg; /* remove args from the stack */ in resume_error()
771 setsvalue2s(L, L->top.p, luaS_new(L, msg)); /* push error message */ in resume_error()
772 api_incr_top(L); in resume_error()
773 lua_unlock(L); in resume_error()
782 ** function), plus erroneous cases: non-suspended coroutine or dead
785 static void resume (lua_State *L, void *ud) { in resume() argument
787 StkId firstArg = L->top.p - n; /* first argument */ in resume()
788 CallInfo *ci = L->ci; in resume()
789 if (L->status == LUA_OK) /* starting a coroutine? */ in resume()
790 ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */ in resume()
792 lua_assert(L->status == LUA_YIELD); in resume()
793 L->status = LUA_OK; /* mark that it is running (again) */ in resume()
795 L->top.p = firstArg; /* discard arguments */ in resume()
796 luaV_execute(L, ci); /* just continue running Lua code */ in resume()
799 if (ci->u.c.k != NULL) { /* does it have a continuation function? */ in resume()
800 lua_unlock(L); in resume()
801 n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */ in resume()
802 lua_lock(L); in resume()
803 api_checknelems(L, n); in resume()
805 luaD_poscall(L, ci, n); /* finish 'luaD_call' */ in resume()
807 unroll(L, NULL); /* run continuation */ in resume()
820 static int precover (lua_State *L, int status) { in precover() argument
822 while (errorstatus(status) && (ci = findpcall(L)) != NULL) { in precover()
823 L->ci = ci; /* go down to recovery functions */ in precover()
825 status = luaD_rawrunprotected(L, unroll, NULL); in precover()
831 LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, in lua_resume() argument
834 lua_lock(L); in lua_resume()
835 if (L->status == LUA_OK) { /* may be starting a coroutine */ in lua_resume()
836 if (L->ci != &L->base_ci) /* not in base level? */ in lua_resume()
837 return resume_error(L, "cannot resume non-suspended coroutine", nargs); in lua_resume()
838 else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */ in lua_resume()
839 return resume_error(L, "cannot resume dead coroutine", nargs); in lua_resume()
841 else if (L->status != LUA_YIELD) /* ended with errors? */ in lua_resume()
842 return resume_error(L, "cannot resume dead coroutine", nargs); in lua_resume()
843 L->nCcalls = (from) ? getCcalls(from) : 0; in lua_resume()
844 if (getCcalls(L) >= LUAI_MAXCCALLS) in lua_resume()
845 return resume_error(L, "C stack overflow", nargs); in lua_resume()
846 L->nCcalls++; in lua_resume()
847 luai_userstateresume(L, nargs); in lua_resume()
848 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); in lua_resume()
849 status = luaD_rawrunprotected(L, resume, &nargs); in lua_resume()
851 status = precover(L, status); in lua_resume()
853 lua_assert(status == L->status); /* normal end or yield */ in lua_resume()
855 L->status = cast_byte(status); /* mark thread as 'dead' */ in lua_resume()
856 luaD_seterrorobj(L, status, L->top.p); /* push error message */ in lua_resume()
857 L->ci->top.p = L->top.p; in lua_resume()
859 *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield in lua_resume()
860 : cast_int(L->top.p - (L->ci->func.p + 1)); in lua_resume()
861 lua_unlock(L); in lua_resume()
866 LUA_API int lua_isyieldable (lua_State *L) { in lua_isyieldable() argument
867 return yieldable(L); in lua_isyieldable()
871 LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, in lua_yieldk() argument
874 luai_userstateyield(L, nresults); in lua_yieldk()
875 lua_lock(L); in lua_yieldk()
876 ci = L->ci; in lua_yieldk()
877 api_checknelems(L, nresults); in lua_yieldk()
878 if (l_unlikely(!yieldable(L))) { in lua_yieldk()
879 if (L != G(L)->mainthread) in lua_yieldk()
880 luaG_runerror(L, "attempt to yield across a C-call boundary"); in lua_yieldk()
882 luaG_runerror(L, "attempt to yield from outside a coroutine"); in lua_yieldk()
884 L->status = LUA_YIELD; in lua_yieldk()
885 ci->u2.nyield = nresults; /* save number of results */ in lua_yieldk()
888 api_check(L, nresults == 0, "hooks cannot yield values"); in lua_yieldk()
889 api_check(L, k == NULL, "hooks cannot continue after yielding"); in lua_yieldk()
892 if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ in lua_yieldk()
893 ci->u.c.ctx = ctx; /* save context */ in lua_yieldk()
894 luaD_throw(L, LUA_YIELD); in lua_yieldk()
896 lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ in lua_yieldk()
897 lua_unlock(L); in lua_yieldk()
914 static void closepaux (lua_State *L, void *ud) { in closepaux() argument
916 luaF_close(L, pcl->level, pcl->status, 0); in closepaux()
924 int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status) { in luaD_closeprotected() argument
925 CallInfo *old_ci = L->ci; in luaD_closeprotected()
926 lu_byte old_allowhooks = L->allowhook; in luaD_closeprotected()
929 pcl.level = restorestack(L, level); pcl.status = status; in luaD_closeprotected()
930 status = luaD_rawrunprotected(L, &closepaux, &pcl); in luaD_closeprotected()
934 L->ci = old_ci; in luaD_closeprotected()
935 L->allowhook = old_allowhooks; in luaD_closeprotected()
946 int luaD_pcall (lua_State *L, Pfunc func, void *u, in luaD_pcall() argument
949 CallInfo *old_ci = L->ci; in luaD_pcall()
950 lu_byte old_allowhooks = L->allowhook; in luaD_pcall()
951 ptrdiff_t old_errfunc = L->errfunc; in luaD_pcall()
952 L->errfunc = ef; in luaD_pcall()
953 status = luaD_rawrunprotected(L, func, u); in luaD_pcall()
955 L->ci = old_ci; in luaD_pcall()
956 L->allowhook = old_allowhooks; in luaD_pcall()
957 status = luaD_closeprotected(L, old_top, status); in luaD_pcall()
958 luaD_seterrorobj(L, status, restorestack(L, old_top)); in luaD_pcall()
959 luaD_shrinkstack(L); /* restore stack size in case of overflow */ in luaD_pcall()
961 L->errfunc = old_errfunc; in luaD_pcall()
979 static void checkmode (lua_State *L, const char *mode, const char *x) { in checkmode() argument
981 luaO_pushfstring(L, in checkmode()
983 luaD_throw(L, LUA_ERRSYNTAX); in checkmode()
988 static void f_parser (lua_State *L, void *ud) { in f_parser() argument
991 int c = zgetc(p->z); /* read first character */ in f_parser()
993 checkmode(L, p->mode, "binary"); in f_parser()
994 cl = luaU_undump(L, p->z, p->name); in f_parser()
997 checkmode(L, p->mode, "text"); in f_parser()
998 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); in f_parser()
1000 lua_assert(cl->nupvalues == cl->p->sizeupvalues); in f_parser()
1001 luaF_initupvals(L, cl); in f_parser()
1005 int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, in luaD_protectedparser() argument
1009 incnny(L); /* cannot yield during parsing */ in luaD_protectedparser()
1014 luaZ_initbuffer(L, &p.buff); in luaD_protectedparser()
1015 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc); in luaD_protectedparser()
1016 luaZ_freebuffer(L, &p.buff); in luaD_protectedparser()
1017 luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); in luaD_protectedparser()
1018 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); in luaD_protectedparser()
1019 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); in luaD_protectedparser()
1020 decnny(L); in luaD_protectedparser()