Skip to content

Commit

Permalink
Updated Lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Jan 4, 2025
1 parent a7480d9 commit 5d33c98
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 462 deletions.
3 changes: 0 additions & 3 deletions Source/3rdParty/Lua/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,6 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {
*/


#define MAXRESULTS 250


#define checkresults(L,na,nr) \
(api_check(L, (nr) == LUA_MULTRET \
|| (L->ci->top.p - L->top.p >= (nr) - (na)), \
Expand Down
24 changes: 16 additions & 8 deletions Source/3rdParty/Lua/lauxlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,27 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,

LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {
lua_Debug ar;
const char *argword;
if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
return luaL_error(L, "bad argument #%d (%s)", arg, extramsg);
lua_getinfo(L, "n", &ar);
if (strcmp(ar.namewhat, "method") == 0) {
arg--; /* do not count 'self' */
if (arg == 0) /* error is in the self argument itself? */
return luaL_error(L, "calling '%s' on bad self (%s)",
ar.name, extramsg);
lua_getinfo(L, "nt", &ar);
if (arg <= ar.extraargs) /* error in an extra argument? */
argword = "extra argument";
else {
arg -= ar.extraargs; /* do not count extra arguments */
if (strcmp(ar.namewhat, "method") == 0) { /* colon syntax? */
arg--; /* do not count (extra) self argument */
if (arg == 0) /* error in self argument? */
return luaL_error(L, "calling '%s' on bad self (%s)",
ar.name, extramsg);
/* else go through; error in a regular argument */
}
argword = "argument";
}
if (ar.name == NULL)
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
return luaL_error(L, "bad argument #%d to '%s' (%s)",
arg, ar.name, extramsg);
return luaL_error(L, "bad %s #%d to '%s' (%s)",
argword, arg, ar.name, extramsg);
}


Expand Down
4 changes: 3 additions & 1 deletion Source/3rdParty/Lua/ldblib.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ static int db_getinfo (lua_State *L) {
settabsi(L, "ftransfer", ar.ftransfer);
settabsi(L, "ntransfer", ar.ntransfer);
}
if (strchr(options, 't'))
if (strchr(options, 't')) {
settabsb(L, "istailcall", ar.istailcall);
settabsi(L, "extraargs", ar.extraargs);
}
if (strchr(options, 'L'))
treatstackoption(L, L1, "activelines");
if (strchr(options, 'f'))
Expand Down
10 changes: 9 additions & 1 deletion Source/3rdParty/Lua/ldebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,15 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
break;
}
case 't': {
ar->istailcall = (ci != NULL && (ci->callstatus & CIST_TAIL));
if (ci != NULL) {
ar->istailcall = !!(ci->callstatus & CIST_TAIL);
ar->extraargs =
cast_uchar((ci->callstatus & MAX_CCMT) >> CIST_CCMT);
}
else {
ar->istailcall = 0;
ar->extraargs = 0;
}
break;
}
case 'n': {
Expand Down
74 changes: 43 additions & 31 deletions Source/3rdParty/Lua/ldo.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@

/* C++ exceptions */
#define LUAI_THROW(L,c) throw(c)
#define LUAI_TRY(L,c,a) \
try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
#define luai_jmpbuf int /* dummy variable */
#define LUAI_TRY(L,c,f,ud) \
try { (f)(L, ud); } catch(...) { if ((c)->status == 0) (c)->status = -1; }
#define luai_jmpbuf int /* dummy field */

#elif defined(LUA_USE_POSIX) /* }{ */

/* in POSIX, try _longjmp/_setjmp (more efficient) */
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
#define LUAI_TRY(L,c,f,ud) if (_setjmp((c)->b) == 0) ((f)(L, ud))
#define luai_jmpbuf jmp_buf

#else /* }{ */

/* ISO C handling with long jumps */
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
#define LUAI_TRY(L,c,f,ud) if (setjmp((c)->b) == 0) ((f)(L, ud))
#define luai_jmpbuf jmp_buf

#endif /* } */
Expand Down Expand Up @@ -154,9 +154,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
lj.status = LUA_OK;
lj.previous = L->errorJmp; /* chain new error handler */
L->errorJmp = &lj;
LUAI_TRY(L, &lj,
(*f)(L, ud);
);
LUAI_TRY(L, &lj, f, ud); /* call 'f' catching errors */
L->errorJmp = lj.previous; /* restore old error handler */
L->nCcalls = oldnCcalls;
return lj.status;
Expand Down Expand Up @@ -464,21 +462,26 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {

/*
** Check whether 'func' has a '__call' metafield. If so, put it in the
** stack, below original 'func', so that 'luaD_precall' can call it. Raise
** an error if there is no '__call' metafield.
** stack, below original 'func', so that 'luaD_precall' can call it.
** Raise an error if there is no '__call' metafield.
** Bits CIST_CCMT in status count how many _call metamethods were
** invoked and how many corresponding extra arguments were pushed.
** (This count will be saved in the 'callstatus' of the call).
** Raise an error if this counter overflows.
*/
static StkId tryfuncTM (lua_State *L, StkId func) {
static unsigned tryfuncTM (lua_State *L, StkId func, unsigned status) {
const TValue *tm;
StkId p;
checkstackp(L, 1, func); /* space for metamethod */
tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */
if (l_unlikely(ttisnil(tm)))
luaG_callerror(L, s2v(func)); /* nothing to call */
tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);
if (l_unlikely(ttisnil(tm))) /* no metamethod? */
luaG_callerror(L, s2v(func));
for (p = L->top.p; p > func; p--) /* open space for metamethod */
setobjs2s(L, p, p-1);
L->top.p++; /* stack space pre-allocated by the caller */
setobj2s(L, func, tm); /* metamethod is the new function to be called */
return func;
if ((status & MAX_CCMT) == MAX_CCMT) /* is counter full? */
luaG_runerror(L, "'__call' chain too long");
return status + (1u << CIST_CCMT); /* increment counter */
}


Expand Down Expand Up @@ -564,12 +567,18 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L))


l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults,
l_uint32 mask, StkId top) {
/*
** Allocate and initialize CallInfo structure. At this point, the
** only valid fields in the call status are number of results,
** CIST_C (if it's a C function), and number of extra arguments.
** (All these bit-fields fit in 16-bit values.)
*/
l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, unsigned status,
StkId top) {
CallInfo *ci = L->ci = next_ci(L); /* new frame */
ci->func.p = func;
lua_assert(((nresults + 1) & ~CIST_NRESULTS) == 0);
ci->callstatus = mask | cast(l_uint32, nresults + 1);
lua_assert((status & ~(CIST_NRESULTS | CIST_C | MAX_CCMT)) == 0);
ci->callstatus = status;
ci->top.p = top;
return ci;
}
Expand All @@ -578,12 +587,12 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nresults,
/*
** precall for C functions
*/
l_sinline int precallC (lua_State *L, StkId func, int nresults,
l_sinline int precallC (lua_State *L, StkId func, unsigned status,
lua_CFunction f) {
int n; /* number of returns */
CallInfo *ci;
checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
L->ci = ci = prepCallInfo(L, func, status | CIST_C,
L->top.p + LUA_MINSTACK);
lua_assert(ci->top.p <= L->stack_last.p);
if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
Expand All @@ -607,12 +616,13 @@ l_sinline int precallC (lua_State *L, StkId func, int nresults,
*/
int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
int narg1, int delta) {
unsigned status = LUA_MULTRET + 1;
retry:
switch (ttypetag(s2v(func))) {
case LUA_VCCL: /* C closure */
return precallC(L, func, LUA_MULTRET, clCvalue(s2v(func))->f);
return precallC(L, func, status, clCvalue(s2v(func))->f);
case LUA_VLCF: /* light C function */
return precallC(L, func, LUA_MULTRET, fvalue(s2v(func)));
return precallC(L, func, status, fvalue(s2v(func)));
case LUA_VLCL: { /* Lua function */
Proto *p = clLvalue(s2v(func))->p;
int fsize = p->maxstacksize; /* frame size */
Expand All @@ -633,8 +643,8 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
return -1;
}
default: { /* not a function */
func = tryfuncTM(L, func); /* try to get '__call' metamethod */
/* return luaD_pretailcall(L, ci, func, narg1 + 1, delta); */
checkstackp(L, 1, func); /* space for metamethod */
status = tryfuncTM(L, func, status); /* try '__call' metamethod */
narg1++;
goto retry; /* try again */
}
Expand All @@ -651,13 +661,15 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
** original function position.
*/
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
unsigned status = cast_uint(nresults + 1);
lua_assert(status <= MAXRESULTS + 1);
retry:
switch (ttypetag(s2v(func))) {
case LUA_VCCL: /* C closure */
precallC(L, func, nresults, clCvalue(s2v(func))->f);
precallC(L, func, status, clCvalue(s2v(func))->f);
return NULL;
case LUA_VLCF: /* light C function */
precallC(L, func, nresults, fvalue(s2v(func)));
precallC(L, func, status, fvalue(s2v(func)));
return NULL;
case LUA_VLCL: { /* Lua function */
CallInfo *ci;
Expand All @@ -666,16 +678,16 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
int nfixparams = p->numparams;
int fsize = p->maxstacksize; /* frame size */
checkstackp(L, fsize, func);
L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize);
L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize);
ci->u.l.savedpc = p->code; /* starting point */
for (; narg < nfixparams; narg++)
setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
lua_assert(ci->top.p <= L->stack_last.p);
return ci;
}
default: { /* not a function */
func = tryfuncTM(L, func); /* try to get '__call' metamethod */
/* return luaD_precall(L, func, nresults); */
checkstackp(L, 1, func); /* space for metamethod */
status = tryfuncTM(L, func, status); /* try '__call' metamethod */
goto retry; /* try again with metamethod */
}
}
Expand Down
10 changes: 5 additions & 5 deletions Source/3rdParty/Lua/lfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ Proto *luaF_newproto (lua_State *L) {
}


size_t luaF_protosize (Proto *p) {
size_t sz = sizeof(Proto)
lu_mem luaF_protosize (Proto *p) {
lu_mem sz = cast(lu_mem, sizeof(Proto))
+ cast_uint(p->sizep) * sizeof(Proto*)
+ cast_uint(p->sizek) * sizeof(TValue)
+ cast_uint(p->sizelocvars) * sizeof(LocVar)
+ cast_uint(p->sizeupvalues) * sizeof(Upvaldesc);
if (!(p->flag & PF_FIXED)) {
sz += cast_uint(p->sizecode) * sizeof(Instruction)
+ cast_uint(p->sizelineinfo) * sizeof(lu_byte)
+ cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo);
sz += cast_uint(p->sizecode) * sizeof(Instruction);
sz += cast_uint(p->sizelineinfo) * sizeof(lu_byte);
sz += cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo);
}
return sz;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/3rdParty/Lua/lfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(offsetof(CClosure, upvalue) + sizeof(TValue) * cast_uint(n))

#define sizeLclosure(n) \
(offsetof(LClosure, upvals) + sizeof(TValue *) * cast_uint(n))
(offsetof(LClosure, upvals) + sizeof(UpVal *) * cast_uint(n))


/* test whether thread is in 'twups' list */
Expand Down Expand Up @@ -56,7 +56,7 @@ LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
LUAI_FUNC size_t luaF_protosize (Proto *p);
LUAI_FUNC lu_mem luaF_protosize (Proto *p);
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
int pc);
Expand Down
Loading

0 comments on commit 5d33c98

Please sign in to comment.