Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ldo.c File Reference
#include "lprefix.h"
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lapi.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lundump.h"
#include "lvm.h"
#include "lzio.h"

Go to the source code of this file.

Data Structures

struct  lua_longjmp
 
struct  CloseP
 
struct  SParser
 

Macros

#define ldo_c
 
#define LUA_CORE
 
#define errorstatus(s)   ((s) > LUA_YIELD)
 
#define LUAI_THROW(L, c)   longjmp((c)->b, 1)
 
#define LUAI_TRY(L, c, a)   if (setjmp((c)->b) == 0) { a }
 
#define luai_jmpbuf   jmp_buf
 
#define ERRORSTACKSIZE   (LUAI_MAXSTACK + 200)
 
#define next_ci(L)   (L->ci->next ? L->ci->next : luaE_extendCI(L))
 

Functions

void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop)
 
l_noret luaD_throw (lua_State *L, int errcode)
 
int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud)
 
static void correctstack (lua_State *L, StkId oldstack, StkId newstack)
 
int luaD_reallocstack (lua_State *L, int newsize, int raiseerror)
 
int luaD_growstack (lua_State *L, int n, int raiseerror)
 
static int stackinuse (lua_State *L)
 
void luaD_shrinkstack (lua_State *L)
 
void luaD_inctop (lua_State *L)
 
void luaD_hook (lua_State *L, int event, int line, int ftransfer, int ntransfer)
 
void luaD_hookcall (lua_State *L, CallInfo *ci)
 
static void rethook (lua_State *L, CallInfo *ci, int nres)
 
void luaD_tryfuncTM (lua_State *L, StkId func)
 
static void moveresults (lua_State *L, StkId res, int nres, int wanted)
 
void luaD_poscall (lua_State *L, CallInfo *ci, int nres)
 
void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1)
 
CallInfoluaD_precall (lua_State *L, StkId func, int nresults)
 
static void ccall (lua_State *L, StkId func, int nResults, int inc)
 
void luaD_call (lua_State *L, StkId func, int nResults)
 
void luaD_callnoyield (lua_State *L, StkId func, int nResults)
 
static int finishpcallk (lua_State *L, CallInfo *ci)
 
static void finishCcall (lua_State *L, CallInfo *ci)
 
static void unroll (lua_State *L, void *ud)
 
static CallInfofindpcall (lua_State *L)
 
static int resume_error (lua_State *L, const char *msg, int narg)
 
static void resume (lua_State *L, void *ud)
 
static int precover (lua_State *L, int status)
 
LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, int *nresults)
 
LUA_API int lua_isyieldable (lua_State *L)
 
LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, lua_KFunction k)
 
static void closepaux (lua_State *L, void *ud)
 
int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status)
 
int luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
 
static void checkmode (lua_State *L, const char *mode, const char *x)
 
static void f_parser (lua_State *L, void *ud)
 
int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, const char *mode)
 

Macro Definition Documentation

◆ ERRORSTACKSIZE

#define ERRORSTACKSIZE   (LUAI_MAXSTACK + 200)

Definition at line 177 of file lua-5.4.3/src/ldo.c.

Referenced by luaD_growstack(), and luaD_reallocstack().

◆ errorstatus

#define errorstatus ( s)    ((s) > LUA_YIELD)

Definition at line 38 of file lua-5.4.3/src/ldo.c.

Referenced by lua_resume(), luaD_seterrorobj(), and precover().

◆ ldo_c

#define ldo_c

Definition at line 7 of file lua-5.4.3/src/ldo.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.4.3/src/ldo.c.

◆ luai_jmpbuf

#define luai_jmpbuf   jmp_buf

Definition at line 75 of file lua-5.4.3/src/ldo.c.

◆ LUAI_THROW

#define LUAI_THROW ( L,
c )   longjmp((c)->b, 1)

Definition at line 73 of file lua-5.4.3/src/ldo.c.

Referenced by luaD_throw().

◆ LUAI_TRY

#define LUAI_TRY ( L,
c,
a )   if (setjmp((c)->b) == 0) { a }

Definition at line 74 of file lua-5.4.3/src/ldo.c.

Referenced by luaD_rawrunprotected().

◆ next_ci

#define next_ci ( L)    (L->ci->next ? L->ci->next : luaE_extendCI(L))

Definition at line 473 of file lua-5.4.3/src/ldo.c.

Referenced by luaD_precall().

Function Documentation

◆ ccall()

static void ccall ( lua_State * L,
StkId func,
int nResults,
int inc )
static

Definition at line 570 of file lua-5.4.3/src/ldo.c.

570 {
571 CallInfo *ci;
572 L->nCcalls += inc;
573 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
575 if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */
576 ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */
577 luaV_execute(L, ci); /* call it */
578 }
579 L->nCcalls -= inc;
580}
#define NULL
Definition gmacros.h:924
#define LUAI_MAXCCALLS
void luaV_execute(lua_State *L, int nexeccalls)
#define CIST_FRESH
CallInfo * luaD_precall(lua_State *L, StkId func, int nresults)
void luaE_checkcstack(lua_State *L)
#define getCcalls(L)
unsigned short nCcalls

References CallInfo::callstatus, CIST_FRESH, getCcalls, luaD_precall(), luaE_checkcstack(), LUAI_MAXCCALLS, luaV_execute(), lua_State::nCcalls, and NULL.

Referenced by luaD_call(), luaD_callnoyield(), and resume().

◆ checkmode()

static void checkmode ( lua_State * L,
const char * mode,
const char * x )
static

Definition at line 918 of file lua-5.4.3/src/ldo.c.

918 {
919 if (mode && strchr(mode, x[0]) == NULL) {
921 "attempt to load a %s chunk (mode is '%s')", x, mode);
923 }
924}
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define LUA_ERRSYNTAX
l_noret luaD_throw(lua_State *L, int errcode)

References LUA_ERRSYNTAX, luaD_throw(), luaO_pushfstring(), and NULL.

Referenced by f_parser().

◆ closepaux()

static void closepaux ( lua_State * L,
void * ud )
static

Definition at line 853 of file lua-5.4.3/src/ldo.c.

853 {
854 struct CloseP *pcl = cast(struct CloseP *, ud);
855 luaF_close(L, pcl->level, pcl->status, 0);
856}
void luaF_close(lua_State *L, StkId level)
#define cast(t, exp)

References cast, CloseP::level, luaF_close(), and CloseP::status.

Referenced by luaD_closeprotected().

◆ correctstack()

static void correctstack ( lua_State * L,
StkId oldstack,
StkId newstack )
static

Definition at line 160 of file lua-5.4.3/src/ldo.c.

160 {
161 CallInfo *ci;
162 UpVal *up;
163 L->top = (L->top - oldstack) + newstack;
164 L->tbclist = (L->tbclist - oldstack) + newstack;
165 for (up = L->openupval; up != NULL; up = up->u.open.next)
166 up->v = s2v((uplevel(up) - oldstack) + newstack);
167 for (ci = L->ci; ci != NULL; ci = ci->previous) {
168 ci->top = (ci->top - oldstack) + newstack;
169 ci->func = (ci->func - oldstack) + newstack;
170 if (isLua(ci))
171 ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */
172 }
173}
#define isLua(ci)
#define uplevel(up)
#define s2v(o)
volatile l_signalT trap
struct CallInfo * previous
struct CallInfo::@64::@65 l
union CallInfo::@64 u
struct UpVal::@68::@69 open
union UpVal::@48 u
struct UpVal * next
GCObject * openupval

References lua_State::ci, CallInfo::func, isLua, CallInfo::l, UpVal::next, NULL, UpVal::open, lua_State::openupval, CallInfo::previous, s2v, lua_State::tbclist, CallInfo::top, lua_State::top, CallInfo::trap, UpVal::u, CallInfo::u, uplevel, and UpVal::v.

Referenced by luaD_reallocstack().

◆ f_parser()

static void f_parser ( lua_State * L,
void * ud )
static

Definition at line 927 of file lua-5.4.3/src/ldo.c.

927 {
928 LClosure *cl;
929 struct SParser *p = cast(struct SParser *, ud);
930 int c = zgetc(p->z); /* read first character */
931 if (c == LUA_SIGNATURE[0]) {
932 checkmode(L, p->mode, "binary");
933 cl = luaU_undump(L, p->z, p->name);
934 }
935 else {
936 checkmode(L, p->mode, "text");
937 cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
938 }
939 lua_assert(cl->nupvalues == cl->p->sizeupvalues);
940 luaF_initupvals(L, cl);
941}
#define lua_assert(c)
#define LUA_SIGNATURE
Proto * luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff, const char *name)
#define zgetc(z)
void luaF_initupvals(lua_State *L, LClosure *cl)
static void checkmode(lua_State *L, const char *mode, const char *x)
LUAI_FUNC Proto * luaY_parser(lua_State *L, ZIO *z, Mbuffer *buff, const char *name)
Definition noparser.c:25
struct Proto * p
const char * mode
const char * name

References SParser::buff, cast, checkmode(), SParser::dyd, lua_assert, LUA_SIGNATURE, luaF_initupvals(), luaU_undump(), luaY_parser(), SParser::mode, SParser::name, LClosure::p, Proto::sizeupvalues, SParser::z, and zgetc.

Referenced by luaD_protectedparser().

◆ findpcall()

static CallInfo * findpcall ( lua_State * L)
static

Definition at line 695 of file lua-5.4.3/src/ldo.c.

695 {
696 CallInfo *ci;
697 for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */
698 if (ci->callstatus & CIST_YPCALL)
699 return ci;
700 }
701 return NULL; /* no pending pcall */
702}
#define CIST_YPCALL

References CallInfo::callstatus, lua_State::ci, CIST_YPCALL, NULL, and CallInfo::previous.

Referenced by precover().

◆ finishCcall()

static void finishCcall ( lua_State * L,
CallInfo * ci )
static

Definition at line 649 of file lua-5.4.3/src/ldo.c.

649 {
650 int n; /* actual number of results from C function */
651 if (ci->callstatus & CIST_CLSRET) { /* was returning? */
653 n = ci->u2.nres; /* just redo 'luaD_poscall' */
654 /* don't need to reset CIST_CLSRET, as it will be set again anyway */
655 }
656 else {
657 int status = LUA_YIELD; /* default if there were no errors */
658 /* must have a continuation and must be able to call it */
659 lua_assert(ci->u.c.k != NULL && yieldable(L));
660 if (ci->callstatus & CIST_YPCALL) /* was inside a 'lua_pcallk'? */
661 status = finishpcallk(L, ci); /* finish it */
662 adjustresults(L, LUA_MULTRET); /* finish 'lua_callk' */
663 lua_unlock(L);
664 n = (*ci->u.c.k)(L, status, ci->u.c.ctx); /* call continuation */
665 lua_lock(L);
666 api_checknelems(L, n);
667 }
668 luaD_poscall(L, ci, n); /* finish 'luaD_call' */
669}
#define api_checknelems(L, n)
#define adjustresults(L, nres)
#define lua_unlock(L)
#define lua_lock(L)
#define LUA_YIELD
#define LUA_MULTRET
#define hastocloseCfunc(n)
void luaD_poscall(lua_State *L, CallInfo *ci, int nres)
static int finishpcallk(lua_State *L, CallInfo *ci)
#define yieldable(L)
#define CIST_CLSRET
lua_CFunction k
union CallInfo::@95 u2
struct CallInfo::@64::@66 c

References adjustresults, api_checknelems, CallInfo::c, CallInfo::callstatus, CIST_CLSRET, CIST_YPCALL, CallInfo::ctx, finishpcallk(), hastocloseCfunc, CallInfo::k, lua_assert, lua_lock, LUA_MULTRET, lua_unlock, LUA_YIELD, luaD_poscall(), CallInfo::nres, CallInfo::nresults, NULL, lua_longjmp::status, CallInfo::u, CallInfo::u2, and yieldable.

Referenced by unroll().

◆ finishpcallk()

static int finishpcallk ( lua_State * L,
CallInfo * ci )
static

Definition at line 615 of file lua-5.4.3/src/ldo.c.

615 {
616 int status = getcistrecst(ci); /* get original status */
617 if (l_likely(status == LUA_OK)) /* no error? */
618 status = LUA_YIELD; /* was interrupted by an yield */
619 else { /* error */
620 StkId func = restorestack(L, ci->u2.funcidx);
621 L->allowhook = getoah(ci->callstatus); /* restore 'allowhook' */
622 luaF_close(L, func, status, 1); /* can yield or raise an error */
623 func = restorestack(L, ci->u2.funcidx); /* stack may be moved */
624 luaD_seterrorobj(L, status, func);
625 luaD_shrinkstack(L); /* restore stack size in case of overflow */
626 setcistrecst(ci, LUA_OK); /* clear original status */
627 }
628 ci->callstatus &= ~CIST_YPCALL;
629 L->errfunc = ci->u.c.old_errfunc;
630 /* if it is here, there were errors or yields; unlike 'lua_pcallk',
631 do not change status */
632 return status;
633}
#define restorestack(L, n)
#define LUA_OK
#define getoah(st)
void luaD_shrinkstack(lua_State *L)
void luaD_seterrorobj(lua_State *L, int errcode, StkId oldtop)
#define setcistrecst(ci, st)
#define getcistrecst(ci)
ptrdiff_t old_errfunc

References lua_State::allowhook, CallInfo::c, CallInfo::callstatus, lua_State::errfunc, CallInfo::funcidx, getcistrecst, getoah, LUA_OK, LUA_YIELD, luaD_seterrorobj(), luaD_shrinkstack(), luaF_close(), CallInfo::old_errfunc, restorestack, setcistrecst, lua_longjmp::status, CallInfo::u, and CallInfo::u2.

Referenced by finishCcall().

◆ lua_isyieldable()

LUA_API int lua_isyieldable ( lua_State * L)

Definition at line 805 of file lua-5.4.3/src/ldo.c.

805 {
806 return yieldable(L);
807}

References yieldable.

◆ lua_resume()

LUA_API int lua_resume ( lua_State * L,
lua_State * from,
int nargs,
int * nresults )

Definition at line 773 of file lua-5.4.3/src/ldo.c.

774 {
775 int status;
776 lua_lock(L);
777 if (L->status == LUA_OK) { /* may be starting a coroutine */
778 if (L->ci != &L->base_ci) /* not in base level? */
779 return resume_error(L, "cannot resume non-suspended coroutine", nargs);
780 else if (L->top - (L->ci->func + 1) == nargs) /* no function? */
781 return resume_error(L, "cannot resume dead coroutine", nargs);
782 }
783 else if (L->status != LUA_YIELD) /* ended with errors? */
784 return resume_error(L, "cannot resume dead coroutine", nargs);
785 L->nCcalls = (from) ? getCcalls(from) : 0;
786 luai_userstateresume(L, nargs);
787 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
788 status = luaD_rawrunprotected(L, resume, &nargs);
789 /* continue running after recoverable errors */
790 status = precover(L, status);
791 if (l_likely(!errorstatus(status)))
792 lua_assert(status == L->status); /* normal end or yield */
793 else { /* unrecoverable error */
794 L->status = cast_byte(status); /* mark thread as 'dead' */
795 luaD_seterrorobj(L, status, L->top); /* push error message */
796 L->ci->top = L->top;
797 }
798 *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield
799 : cast_int(L->top - (L->ci->func + 1));
800 lua_unlock(L);
801 return status;
802}
#define cast_int(i)
#define cast_byte(i)
#define luai_userstateresume(L, n)
static int resume_error(lua_State *L, const char *msg, int narg)
static int precover(lua_State *L, int status)
#define errorstatus(s)
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
static void resume(lua_State *L, void *ud)

References api_checknelems, lua_State::base_ci, cast_byte, cast_int, lua_State::ci, errorstatus, CallInfo::func, getCcalls, lua_assert, lua_lock, LUA_OK, lua_unlock, LUA_YIELD, luaD_rawrunprotected(), luaD_seterrorobj(), luai_userstateresume, lua_State::nCcalls, CallInfo::nyield, precover(), resume(), resume_error(), lua_longjmp::status, lua_State::status, CallInfo::top, lua_State::top, and CallInfo::u2.

◆ lua_yieldk()

LUA_API int lua_yieldk ( lua_State * L,
int nresults,
lua_KContext ctx,
lua_KFunction k )

Definition at line 810 of file lua-5.4.3/src/ldo.c.

811 {
812 CallInfo *ci;
813 luai_userstateyield(L, nresults);
814 lua_lock(L);
815 ci = L->ci;
816 api_checknelems(L, nresults);
817 if (l_unlikely(!yieldable(L))) {
818 if (L != G(L)->mainthread)
819 luaG_runerror(L, "attempt to yield across a C-call boundary");
820 else
821 luaG_runerror(L, "attempt to yield from outside a coroutine");
822 }
823 L->status = LUA_YIELD;
824 ci->u2.nyield = nresults; /* save number of results */
825 if (isLua(ci)) { /* inside a hook? */
826 lua_assert(!isLuacode(ci));
827 api_check(L, nresults == 0, "hooks cannot yield values");
828 api_check(L, k == NULL, "hooks cannot continue after yielding");
829 }
830 else {
831 if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
832 ci->u.c.ctx = ctx; /* save context */
834 }
835 lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */
836 lua_unlock(L);
837 return 0; /* return to 'luaD_hook' */
838}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define api_check
#define G(L)
#define luai_userstateyield(L, n)
#define CIST_HOOKED
#define isLuacode(ci)

References api_check, api_checknelems, CallInfo::c, CallInfo::callstatus, lua_State::ci, CIST_HOOKED, CallInfo::ctx, G, isLua, isLuacode, CallInfo::k, lua_assert, lua_lock, lua_unlock, LUA_YIELD, luaD_throw(), luaG_runerror(), luai_userstateyield, NULL, CallInfo::nyield, lua_State::status, CallInfo::u, CallInfo::u2, and yieldable.

◆ luaD_call()

void luaD_call ( lua_State * L,
StkId func,
int nResults )

Definition at line 586 of file lua-5.4.3/src/ldo.c.

586 {
587 ccall(L, func, nResults, 1);
588}
static void ccall(lua_State *L, StkId func, int nResults, int inc)

References ccall().

◆ luaD_callnoyield()

void luaD_callnoyield ( lua_State * L,
StkId func,
int nResults )

Definition at line 594 of file lua-5.4.3/src/ldo.c.

594 {
595 ccall(L, func, nResults, nyci);
596}
#define nyci

References ccall(), and nyci.

◆ luaD_closeprotected()

int luaD_closeprotected ( lua_State * L,
ptrdiff_t level,
int status )

Definition at line 863 of file lua-5.4.3/src/ldo.c.

863 {
864 CallInfo *old_ci = L->ci;
865 lu_byte old_allowhooks = L->allowhook;
866 for (;;) { /* keep closing upvalues until no more errors */
867 struct CloseP pcl;
868 pcl.level = restorestack(L, level); pcl.status = status;
870 if (l_likely(status == LUA_OK)) /* no more errors? */
871 return pcl.status;
872 else { /* an error occurred; restore saved state and repeat */
873 L->ci = old_ci;
874 L->allowhook = old_allowhooks;
875 }
876 }
877}
unsigned char lu_byte
static void closepaux(lua_State *L, void *ud)

References lua_State::allowhook, lua_State::ci, closepaux(), CloseP::level, LUA_OK, luaD_rawrunprotected(), restorestack, and CloseP::status.

Referenced by close_state(), luaD_pcall(), and luaE_resetthread().

◆ luaD_growstack()

int luaD_growstack ( lua_State * L,
int n,
int raiseerror )

Definition at line 219 of file lua-5.4.3/src/ldo.c.

219 {
220 int size = stacksize(L);
221 if (l_unlikely(size > LUAI_MAXSTACK)) {
222 /* if stack is larger than maximum, thread is already using the
223 extra space reserved for errors, that is, thread is handling
224 a stack error; cannot grow further than that. */
226 if (raiseerror)
227 luaD_throw(L, LUA_ERRERR); /* error inside message handler */
228 return 0; /* if not 'raiseerror', just signal it */
229 }
230 else {
231 int newsize = 2 * size; /* tentative new size */
232 int needed = cast_int(L->top - L->stack) + n;
233 if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */
234 newsize = LUAI_MAXSTACK;
235 if (newsize < needed) /* but must respect what was asked for */
236 newsize = needed;
237 if (l_likely(newsize <= LUAI_MAXSTACK))
238 return luaD_reallocstack(L, newsize, raiseerror);
239 else { /* stack overflow */
240 /* add extra size to be able to handle the error message */
241 luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
242 if (raiseerror)
243 luaG_runerror(L, "stack overflow");
244 return 0;
245 }
246 }
247}
#define LUA_ERRERR
#define LUAI_MAXSTACK
#define ERRORSTACKSIZE
int luaD_reallocstack(lua_State *L, int newsize, int raiseerror)
#define stacksize(th)

References cast_int, ERRORSTACKSIZE, lua_assert, LUA_ERRERR, luaD_reallocstack(), luaD_throw(), luaG_runerror(), LUAI_MAXSTACK, lua_State::stack, stacksize, and lua_State::top.

◆ luaD_hook()

void luaD_hook ( lua_State * L,
int event,
int line,
int ftransfer,
int ntransfer )

Definition at line 306 of file lua-5.4.3/src/ldo.c.

307 {
308 lua_Hook hook = L->hook;
309 if (hook && L->allowhook) { /* make sure there is a hook */
310 int mask = CIST_HOOKED;
311 CallInfo *ci = L->ci;
312 ptrdiff_t top = savestack(L, L->top); /* preserve original 'top' */
313 ptrdiff_t ci_top = savestack(L, ci->top); /* idem for 'ci->top' */
314 lua_Debug ar;
315 ar.event = event;
316 ar.currentline = line;
317 ar.i_ci = ci;
318 if (ntransfer != 0) {
319 mask |= CIST_TRAN; /* 'ci' has transfer information */
320 ci->u2.transferinfo.ftransfer = ftransfer;
321 ci->u2.transferinfo.ntransfer = ntransfer;
322 }
323 if (isLua(ci) && L->top < ci->top)
324 L->top = ci->top; /* protect entire activation register */
325 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
326 if (ci->top < L->top + LUA_MINSTACK)
327 ci->top = L->top + LUA_MINSTACK;
328 L->allowhook = 0; /* cannot call hooks inside a hook */
329 ci->callstatus |= mask;
330 lua_unlock(L);
331 (*hook)(L, &ar);
332 lua_lock(L);
333 lua_assert(!L->allowhook);
334 L->allowhook = 1;
335 ci->top = restorestack(L, ci_top);
336 L->top = restorestack(L, top);
337 ci->callstatus &= ~mask;
338 }
339}
#define savestack(L, p)
#define luaD_checkstack(L, n)
void(* lua_Hook)(lua_State *L, lua_Debug *ar)
#define LUA_MINSTACK
#define mask(n)
#define CIST_TRAN
struct CallInfo::@95::@98 transferinfo
unsigned short ntransfer
unsigned short ftransfer

References lua_State::allowhook, CallInfo::callstatus, lua_State::ci, CIST_HOOKED, CIST_TRAN, lua_Debug::currentline, lua_Debug::event, CallInfo::ftransfer, lua_State::hook, lua_Debug::i_ci, isLua, lua_assert, lua_lock, LUA_MINSTACK, lua_unlock, luaD_checkstack, mask, CallInfo::ntransfer, restorestack, savestack, CallInfo::top, lua_State::top, CallInfo::transferinfo, and CallInfo::u2.

Referenced by luaD_hookcall(), luaD_precall(), and rethook().

◆ luaD_hookcall()

void luaD_hookcall ( lua_State * L,
CallInfo * ci )

Definition at line 347 of file lua-5.4.3/src/ldo.c.

347 {
348 L->oldpc = 0; /* set 'oldpc' for new function */
349 if (L->hookmask & LUA_MASKCALL) { /* is call hook on? */
350 int event = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL
351 : LUA_HOOKCALL;
352 Proto *p = ci_func(ci)->p;
353 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */
354 luaD_hook(L, event, -1, 1, p->numparams);
355 ci->u.l.savedpc--; /* correct 'pc' */
356 }
357}
#define ci_func(ci)
#define LUA_MASKCALL
#define LUA_HOOKCALL
#define CIST_TAIL
#define LUA_HOOKTAILCALL
void luaD_hook(lua_State *L, int event, int line, int ftransfer, int ntransfer)
const Instruction * savedpc
struct Proto ** p
const Instruction * oldpc

References CallInfo::callstatus, ci_func, CIST_TAIL, lua_State::hookmask, CallInfo::l, LUA_HOOKCALL, LUA_HOOKTAILCALL, LUA_MASKCALL, luaD_hook(), Proto::numparams, lua_State::oldpc, Proto::p, CallInfo::savedpc, and CallInfo::u.

Referenced by luaV_execute().

◆ luaD_inctop()

void luaD_inctop ( lua_State * L)

Definition at line 293 of file lua-5.4.3/src/ldo.c.

293 {
294 luaD_checkstack(L, 1);
295 L->top++;
296}

References luaD_checkstack, and lua_State::top.

◆ luaD_pcall()

int luaD_pcall ( lua_State * L,
Pfunc func,
void * u,
ptrdiff_t old_top,
ptrdiff_t ef )

Definition at line 885 of file lua-5.4.3/src/ldo.c.

886 {
887 int status;
888 CallInfo *old_ci = L->ci;
889 lu_byte old_allowhooks = L->allowhook;
890 ptrdiff_t old_errfunc = L->errfunc;
891 L->errfunc = ef;
892 status = luaD_rawrunprotected(L, func, u);
893 if (l_unlikely(status != LUA_OK)) { /* an error occurred? */
894 L->ci = old_ci;
895 L->allowhook = old_allowhooks;
896 status = luaD_closeprotected(L, old_top, status);
897 luaD_seterrorobj(L, status, restorestack(L, old_top));
898 luaD_shrinkstack(L); /* restore stack size in case of overflow */
899 }
900 L->errfunc = old_errfunc;
901 return status;
902}
int luaD_closeprotected(lua_State *L, ptrdiff_t level, int status)

References lua_State::allowhook, lua_State::ci, lua_State::errfunc, LUA_OK, luaD_closeprotected(), luaD_rawrunprotected(), luaD_seterrorobj(), luaD_shrinkstack(), restorestack, and CloseP::status.

Referenced by luaD_protectedparser().

◆ luaD_poscall()

void luaD_poscall ( lua_State * L,
CallInfo * ci,
int nres )

Definition at line 459 of file lua-5.4.3/src/ldo.c.

459 {
460 int wanted = ci->nresults;
461 if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted)))
462 rethook(L, ci, nres);
463 /* move results to proper place */
464 moveresults(L, ci->func, nres, wanted);
465 /* function cannot be in any of these cases when returning */
466 lua_assert(!(ci->callstatus &
468 L->ci = ci->previous; /* back to caller (after closing variables) */
469}
#define CIST_FIN
static void rethook(lua_State *L, CallInfo *ci, int nres)
static void moveresults(lua_State *L, StkId res, int nres, int wanted)

References CallInfo::callstatus, lua_State::ci, CIST_CLSRET, CIST_FIN, CIST_HOOKED, CIST_TRAN, CIST_YPCALL, CallInfo::func, hastocloseCfunc, lua_State::hookmask, lua_assert, moveresults(), CallInfo::nresults, CallInfo::previous, and rethook().

Referenced by finishCcall(), luaD_precall(), and resume().

◆ luaD_precall()

CallInfo * luaD_precall ( lua_State * L,
StkId func,
int nresults )

Definition at line 508 of file lua-5.4.3/src/ldo.c.

508 {
510 retry:
511 switch (ttypetag(s2v(func))) {
512 case LUA_VCCL: /* C closure */
513 f = clCvalue(s2v(func))->f;
514 goto Cfunc;
515 case LUA_VLCF: /* light C function */
516 f = fvalue(s2v(func));
517 Cfunc: {
518 int n; /* number of returns */
519 CallInfo *ci;
520 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
521 L->ci = ci = next_ci(L);
522 ci->nresults = nresults;
523 ci->callstatus = CIST_C;
524 ci->top = L->top + LUA_MINSTACK;
525 ci->func = func;
526 lua_assert(ci->top <= L->stack_last);
527 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
528 int narg = cast_int(L->top - func) - 1;
529 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
530 }
531 lua_unlock(L);
532 n = (*f)(L); /* do the actual call */
533 lua_lock(L);
534 api_checknelems(L, n);
535 luaD_poscall(L, ci, n);
536 return NULL;
537 }
538 case LUA_VLCL: { /* Lua function */
539 CallInfo *ci;
540 Proto *p = clLvalue(s2v(func))->p;
541 int narg = cast_int(L->top - func) - 1; /* number of real arguments */
542 int nfixparams = p->numparams;
543 int fsize = p->maxstacksize; /* frame size */
544 checkstackGCp(L, fsize, func);
545 L->ci = ci = next_ci(L);
546 ci->nresults = nresults;
547 ci->u.l.savedpc = p->code; /* starting point */
548 ci->top = func + 1 + fsize;
549 ci->func = func;
550 L->ci = ci;
551 for (; narg < nfixparams; narg++)
552 setnilvalue(s2v(L->top++)); /* complete missing arguments */
553 lua_assert(ci->top <= L->stack_last);
554 return ci;
555 }
556 default: { /* not a function */
557 checkstackGCp(L, 1, func); /* space for metamethod */
558 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
559 goto retry; /* try again with metamethod */
560 }
561 }
562}
#define setnilvalue(obj)
int(* lua_CFunction)(lua_State *L)
#define fvalue(o)
#define clCvalue(o)
#define clLvalue(o)
#define next_ci(L)
void luaD_tryfuncTM(lua_State *L, StkId func)
#define checkstackGCp(L, n, p)
#define ttypetag(o)
#define LUA_VCCL
#define LUA_VLCL
#define LUA_VLCF
#define CIST_C
Instruction * code
lu_byte maxstacksize

References api_checknelems, CallInfo::callstatus, cast_int, checkstackGCp, lua_State::ci, CIST_C, clCvalue, clLvalue, Proto::code, CallInfo::func, fvalue, lua_State::hookmask, CallInfo::l, lua_assert, LUA_HOOKCALL, lua_lock, LUA_MASKCALL, LUA_MINSTACK, lua_unlock, LUA_VCCL, LUA_VLCF, LUA_VLCL, luaD_hook(), luaD_poscall(), luaD_tryfuncTM(), Proto::maxstacksize, next_ci, CallInfo::nresults, NULL, Proto::numparams, Proto::p, s2v, CallInfo::savedpc, setnilvalue, lua_State::stack_last, CallInfo::top, lua_State::top, ttypetag, and CallInfo::u.

Referenced by ccall().

◆ luaD_pretailcall()

void luaD_pretailcall ( lua_State * L,
CallInfo * ci,
StkId func,
int narg1 )

Definition at line 481 of file lua-5.4.3/src/ldo.c.

481 {
482 Proto *p = clLvalue(s2v(func))->p;
483 int fsize = p->maxstacksize; /* frame size */
484 int nfixparams = p->numparams;
485 int i;
486 for (i = 0; i < narg1; i++) /* move down function and arguments */
487 setobjs2s(L, ci->func + i, func + i);
488 checkstackGC(L, fsize);
489 func = ci->func; /* moved-down function */
490 for (; narg1 <= nfixparams; narg1++)
491 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
492 ci->top = func + 1 + fsize; /* top for new function */
493 lua_assert(ci->top <= L->stack_last);
494 ci->u.l.savedpc = p->code; /* starting point */
495 ci->callstatus |= CIST_TAIL;
496 L->top = func + narg1; /* set top */
497}
#define setobjs2s
#define checkstackGC(L, fsize)

References CallInfo::callstatus, checkstackGC, CIST_TAIL, clLvalue, Proto::code, CallInfo::func, CallInfo::l, lua_assert, Proto::maxstacksize, Proto::numparams, Proto::p, s2v, CallInfo::savedpc, setnilvalue, setobjs2s, lua_State::stack_last, CallInfo::top, lua_State::top, and CallInfo::u.

Referenced by luaV_execute().

◆ luaD_protectedparser()

int luaD_protectedparser ( lua_State * L,
ZIO * z,
const char * name,
const char * mode )

Definition at line 944 of file lua-5.4.3/src/ldo.c.

945 {
946 struct SParser p;
947 int status;
948 incnny(L); /* cannot yield during parsing */
949 p.z = z; p.name = name; p.mode = mode;
950 p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;
951 p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
952 p.dyd.label.arr = NULL; p.dyd.label.size = 0;
953 luaZ_initbuffer(L, &p.buff);
954 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
955 luaZ_freebuffer(L, &p.buff);
956 luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);
957 luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);
958 luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);
959 decnny(L);
960 return status;
961}
const char * name
Definition lsqlite3.c:2154
#define luaM_freearray(L, b, n, t)
#define luaZ_initbuffer(L, buff)
#define luaZ_freebuffer(L, buff)
static void f_parser(lua_State *L, void *ud)
int luaD_pcall(lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
#define decnny(L)
#define incnny(L)

References Dyndata::actvar, Labellist::arr, Dyndata::arr, SParser::buff, decnny, SParser::dyd, lua_State::errfunc, f_parser(), Dyndata::gt, incnny, Dyndata::label, luaD_pcall(), luaM_freearray, luaZ_freebuffer, luaZ_initbuffer, SParser::mode, name, SParser::name, NULL, savestack, Labellist::size, Dyndata::size, lua_State::top, and SParser::z.

◆ luaD_rawrunprotected()

int luaD_rawrunprotected ( lua_State * L,
Pfunc f,
void * ud )

Definition at line 138 of file lua-5.4.3/src/ldo.c.

138 {
139 l_uint32 oldnCcalls = L->nCcalls;
140 struct lua_longjmp lj;
141 lj.status = LUA_OK;
142 lj.previous = L->errorJmp; /* chain new error handler */
143 L->errorJmp = &lj;
144 LUAI_TRY(L, &lj,
145 (*f)(L, ud);
146 );
147 L->errorJmp = lj.previous; /* restore old error handler */
148 L->nCcalls = oldnCcalls;
149 return lj.status;
150}
#define LUAI_TRY(L, c, a)
unsigned long l_uint32
struct lua_longjmp * errorJmp
struct lua_longjmp * previous
volatile int status

References lua_State::errorJmp, LUA_OK, LUAI_TRY, lua_State::nCcalls, lua_longjmp::previous, and lua_longjmp::status.

Referenced by lua_resume(), luaD_closeprotected(), luaD_pcall(), and precover().

◆ luaD_reallocstack()

int luaD_reallocstack ( lua_State * L,
int newsize,
int raiseerror )

Definition at line 191 of file lua-5.4.3/src/ldo.c.

191 {
192 int oldsize = stacksize(L);
193 int i;
194 StkId newstack = luaM_reallocvector(L, NULL, 0,
195 newsize + EXTRA_STACK, StackValue);
196 lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
197 if (l_unlikely(newstack == NULL)) { /* reallocation failed? */
198 if (raiseerror)
199 luaM_error(L);
200 else return 0; /* do not raise an error */
201 }
202 /* number of elements to be copied to the new stack */
203 i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK;
204 memcpy(newstack, L->stack, i * sizeof(StackValue));
205 for (; i < newsize + EXTRA_STACK; i++)
206 setnilvalue(s2v(newstack + i)); /* erase new segment */
207 correctstack(L, L->stack, newstack);
208 luaM_freearray(L, L->stack, oldsize + EXTRA_STACK);
209 L->stack = newstack;
210 L->stack_last = L->stack + newsize;
211 return 1;
212}
#define luaM_reallocvector(L, v, oldn, n, t)
#define EXTRA_STACK
static void correctstack(lua_State *L, StkId oldstack, StkId newstack)
#define luaM_error(L)

References correctstack(), ERRORSTACKSIZE, EXTRA_STACK, lua_assert, LUAI_MAXSTACK, luaM_error, luaM_freearray, luaM_reallocvector, NULL, s2v, setnilvalue, lua_State::stack, lua_State::stack_last, and stacksize.

Referenced by luaD_growstack(), and luaD_shrinkstack().

◆ luaD_seterrorobj()

void luaD_seterrorobj ( lua_State * L,
int errcode,
StkId oldtop )

Definition at line 91 of file lua-5.4.3/src/ldo.c.

91 {
92 switch (errcode) {
93 case LUA_ERRMEM: { /* memory error? */
94 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
95 break;
96 }
97 case LUA_ERRERR: {
98 setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
99 break;
100 }
101 case LUA_OK: { /* special case only for closing upvalues */
102 setnilvalue(s2v(oldtop)); /* no error message */
103 break;
104 }
105 default: {
106 lua_assert(errorstatus(errcode)); /* real error */
107 setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
108 break;
109 }
110 }
111 L->top = oldtop + 1;
112}
#define setsvalue2s
#define luaS_newliteral(L, s)
#define LUA_ERRMEM

References errorstatus, G, lua_assert, LUA_ERRERR, LUA_ERRMEM, LUA_OK, luaS_newliteral, s2v, setnilvalue, setobjs2s, setsvalue2s, and lua_State::top.

Referenced by finishpcallk(), lua_resume(), and luaD_pcall().

◆ luaD_shrinkstack()

void luaD_shrinkstack ( lua_State * L)

Definition at line 274 of file lua-5.4.3/src/ldo.c.

274 {
275 int inuse = stackinuse(L);
276 int nsize = inuse * 2; /* proposed new size */
277 int max = inuse * 3; /* maximum "reasonable" size */
278 if (max > LUAI_MAXSTACK) {
279 max = LUAI_MAXSTACK; /* respect stack limit */
280 if (nsize > LUAI_MAXSTACK)
281 nsize = LUAI_MAXSTACK;
282 }
283 /* if thread is currently not handling a stack overflow and its
284 size is larger than maximum "reasonable" size, shrink it */
285 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max)
286 luaD_reallocstack(L, nsize, 0); /* ok if that fails */
287 else /* don't change stack */
288 condmovestack(L,{},{}); /* (change only for debugging) */
289 luaE_shrinkCI(L); /* shrink CI list */
290}
#define condmovestack(L)
void luaE_shrinkCI(lua_State *L)
static int stackinuse(lua_State *L)

References condmovestack, luaD_reallocstack(), luaE_shrinkCI(), LUAI_MAXSTACK, stackinuse(), and stacksize.

Referenced by finishpcallk(), and luaD_pcall().

◆ luaD_throw()

l_noret luaD_throw ( lua_State * L,
int errcode )

Definition at line 115 of file lua-5.4.3/src/ldo.c.

115 {
116 if (L->errorJmp) { /* thread has an error handler? */
117 L->errorJmp->status = errcode; /* set status */
118 LUAI_THROW(L, L->errorJmp); /* jump to it */
119 }
120 else { /* thread has no error handler */
121 global_State *g = G(L);
122 errcode = luaE_resetthread(L, errcode); /* close all upvalues */
123 if (g->mainthread->errorJmp) { /* main thread has a handler? */
124 setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */
125 luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
126 }
127 else { /* no handler at all; abort */
128 if (g->panic) { /* panic function? */
129 lua_unlock(L);
130 g->panic(L); /* call panic function (last chance to jump out) */
131 }
132 abort();
133 }
134 }
135}
#define LUAI_THROW(L, c)
int luaE_resetthread(lua_State *L, int status)
struct lua_State * mainthread
lua_CFunction panic

References lua_State::errorJmp, G, lua_unlock, luaD_throw(), luaE_resetthread(), LUAI_THROW, global_State::mainthread, global_State::panic, setobjs2s, lua_longjmp::status, and lua_State::top.

Referenced by checkmode(), lua_yieldk(), luaD_growstack(), and luaD_throw().

◆ luaD_tryfuncTM()

void luaD_tryfuncTM ( lua_State * L,
StkId func )

Definition at line 390 of file lua-5.4.3/src/ldo.c.

390 {
391 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);
392 StkId p;
393 if (l_unlikely(ttisnil(tm)))
394 luaG_callerror(L, s2v(func)); /* nothing to call */
395 for (p = L->top; p > func; p--) /* open space for metamethod */
396 setobjs2s(L, p, p-1);
397 L->top++; /* stack space pre-allocated by the caller */
398 setobj2s(L, func, tm); /* metamethod is the new function to be called */
399}
#define setobj2s
#define ttisnil(o)
const TValue * luaT_gettmbyobj(lua_State *L, const TValue *o, TMS event)
@ TM_CALL
l_noret luaG_callerror(lua_State *L, const TValue *o)

References luaG_callerror(), luaT_gettmbyobj(), s2v, setobj2s, setobjs2s, TM_CALL, lua_State::top, and ttisnil.

Referenced by luaD_precall(), and luaV_execute().

◆ moveresults()

static void moveresults ( lua_State * L,
StkId res,
int nres,
int wanted )
static

Definition at line 408 of file lua-5.4.3/src/ldo.c.

408 {
409 StkId firstresult;
410 int i;
411 switch (wanted) { /* handle typical cases separately */
412 case 0: /* no values needed */
413 L->top = res;
414 return;
415 case 1: /* one value needed */
416 if (nres == 0) /* no results? */
417 setnilvalue(s2v(res)); /* adjust with nil */
418 else /* at least one result */
419 setobjs2s(L, res, L->top - nres); /* move it to proper place */
420 L->top = res + 1;
421 return;
422 case LUA_MULTRET:
423 wanted = nres; /* we want all results */
424 break;
425 default: /* two/more results and/or to-be-closed variables */
426 if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */
427 ptrdiff_t savedres = savestack(L, res);
428 L->ci->callstatus |= CIST_CLSRET; /* in case of yields */
429 L->ci->u2.nres = nres;
430 luaF_close(L, res, CLOSEKTOP, 1);
431 L->ci->callstatus &= ~CIST_CLSRET;
432 if (L->hookmask) /* if needed, call hook after '__close's */
433 rethook(L, L->ci, nres);
434 res = restorestack(L, savedres); /* close and hook can move stack */
435 wanted = decodeNresults(wanted);
436 if (wanted == LUA_MULTRET)
437 wanted = nres; /* we want all results */
438 }
439 break;
440 }
441 /* generic case */
442 firstresult = L->top - nres; /* index of first result */
443 if (nres > wanted) /* extra results? */
444 nres = wanted; /* don't need them */
445 for (i = 0; i < nres; i++) /* move all results to correct place */
446 setobjs2s(L, res + i, firstresult + i);
447 for (; i < wanted; i++) /* complete wanted number of results */
448 setnilvalue(s2v(res + i));
449 L->top = res + wanted; /* top points after the last result */
450}
#define decodeNresults(n)
#define CLOSEKTOP

References CallInfo::callstatus, lua_State::ci, CIST_CLSRET, CLOSEKTOP, decodeNresults, hastocloseCfunc, lua_State::hookmask, LUA_MULTRET, luaF_close(), CallInfo::nres, restorestack, rethook(), s2v, savestack, setnilvalue, setobjs2s, lua_State::top, and CallInfo::u2.

Referenced by luaD_poscall().

◆ precover()

static int precover ( lua_State * L,
int status )
static

Definition at line 762 of file lua-5.4.3/src/ldo.c.

762 {
763 CallInfo *ci;
764 while (errorstatus(status) && (ci = findpcall(L)) != NULL) {
765 L->ci = ci; /* go down to recovery functions */
766 setcistrecst(ci, status); /* status to finish 'pcall' */
767 status = luaD_rawrunprotected(L, unroll, NULL);
768 }
769 return status;
770}
static CallInfo * findpcall(lua_State *L)
static void unroll(lua_State *L, void *ud)

References lua_State::ci, errorstatus, findpcall(), luaD_rawrunprotected(), NULL, setcistrecst, lua_longjmp::status, and unroll().

Referenced by lua_resume().

◆ resume()

static void resume ( lua_State * L,
void * ud )
static

Definition at line 726 of file lua-5.4.3/src/ldo.c.

726 {
727 int n = *(cast(int*, ud)); /* number of arguments */
728 StkId firstArg = L->top - n; /* first argument */
729 CallInfo *ci = L->ci;
730 if (L->status == LUA_OK) /* starting a coroutine? */
731 ccall(L, firstArg - 1, LUA_MULTRET, 1); /* just call its body */
732 else { /* resuming from previous yield */
734 L->status = LUA_OK; /* mark that it is running (again) */
735 luaE_incCstack(L); /* control the C stack */
736 if (isLua(ci)) { /* yielded inside a hook? */
737 L->top = firstArg; /* discard arguments */
738 luaV_execute(L, ci); /* just continue running Lua code */
739 }
740 else { /* 'common' yield */
741 if (ci->u.c.k != NULL) { /* does it have a continuation function? */
742 lua_unlock(L);
743 n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */
744 lua_lock(L);
745 api_checknelems(L, n);
746 }
747 luaD_poscall(L, ci, n); /* finish 'luaD_call' */
748 }
749 unroll(L, NULL); /* run continuation */
750 }
751}
LUAI_FUNC void luaE_incCstack(lua_State *L)

References api_checknelems, CallInfo::c, cast, ccall(), lua_State::ci, CallInfo::ctx, isLua, CallInfo::k, lua_assert, lua_lock, LUA_MULTRET, LUA_OK, lua_unlock, LUA_YIELD, luaD_poscall(), luaE_incCstack(), luaV_execute(), NULL, lua_State::status, lua_State::top, CallInfo::u, and unroll().

Referenced by lua_resume().

◆ resume_error()

static int resume_error ( lua_State * L,
const char * msg,
int narg )
static

Definition at line 710 of file lua-5.4.3/src/ldo.c.

710 {
711 L->top -= narg; /* remove args from the stack */
712 setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */
713 api_incr_top(L);
714 lua_unlock(L);
715 return LUA_ERRRUN;
716}
#define api_incr_top(L)
#define luaS_new(L, s)
#define LUA_ERRRUN

References api_incr_top, LUA_ERRRUN, lua_unlock, luaS_new, setsvalue2s, and lua_State::top.

Referenced by lua_resume().

◆ rethook()

static void rethook ( lua_State * L,
CallInfo * ci,
int nres )
static

Definition at line 365 of file lua-5.4.3/src/ldo.c.

365 {
366 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */
367 StkId firstres = L->top - nres; /* index of first result */
368 int delta = 0; /* correction for vararg functions */
369 int ftransfer;
370 if (isLua(ci)) {
371 Proto *p = ci_func(ci)->p;
372 if (p->is_vararg)
373 delta = ci->u.l.nextraargs + p->numparams + 1;
374 }
375 ci->func += delta; /* if vararg, back to virtual 'func' */
376 ftransfer = cast(unsigned short, firstres - ci->func);
377 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */
378 ci->func -= delta;
379 }
380 if (isLua(ci = ci->previous))
381 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */
382}
#define pcRel(pc, p)
#define LUA_HOOKRET
#define LUA_MASKRET

References cast, ci_func, CallInfo::func, lua_State::hookmask, Proto::is_vararg, isLua, CallInfo::l, LUA_HOOKRET, LUA_MASKRET, luaD_hook(), CallInfo::nextraargs, Proto::numparams, lua_State::oldpc, Proto::p, pcRel, CallInfo::previous, CallInfo::savedpc, lua_State::top, and CallInfo::u.

Referenced by luaD_poscall(), and moveresults().

◆ stackinuse()

static int stackinuse ( lua_State * L)
static

Definition at line 250 of file lua-5.4.3/src/ldo.c.

250 {
251 CallInfo *ci;
252 int res;
253 StkId lim = L->top;
254 for (ci = L->ci; ci != NULL; ci = ci->previous) {
255 if (lim < ci->top) lim = ci->top;
256 }
257 lua_assert(lim <= L->stack_last);
258 res = cast_int(lim - L->stack) + 1; /* part of stack in use */
259 if (res < LUA_MINSTACK)
260 res = LUA_MINSTACK; /* ensure a minimum size */
261 return res;
262}

References cast_int, lua_State::ci, lua_assert, LUA_MINSTACK, NULL, CallInfo::previous, lua_State::stack, CallInfo::top, and lua_State::top.

Referenced by luaD_shrinkstack().

◆ unroll()

static void unroll ( lua_State * L,
void * ud )
static

Definition at line 677 of file lua-5.4.3/src/ldo.c.

677 {
678 CallInfo *ci;
679 UNUSED(ud);
680 while ((ci = L->ci) != &L->base_ci) { /* something in the stack */
681 if (!isLua(ci)) /* C function? */
682 finishCcall(L, ci); /* complete its execution */
683 else { /* Lua function */
684 luaV_finishOp(L); /* finish interrupted instruction */
685 luaV_execute(L, ci); /* execute down to higher C 'boundary' */
686 }
687 }
688}
#define UNUSED(x)
void luaV_finishOp(lua_State *L)
static void finishCcall(lua_State *L, CallInfo *ci)

References lua_State::base_ci, lua_State::ci, finishCcall(), isLua, luaV_execute(), luaV_finishOp(), and UNUSED.

Referenced by precover(), and resume().