mirror of
https://github.com/lua/lua.git
synced 2026-07-30 01:49:06 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
934fdd481c | ||
|
|
9ac9d23f41 | ||
|
|
1b0f943da7 | ||
|
|
6e22fedb74 | ||
|
|
267ef461d0 | ||
|
|
d1ee2a4deb | ||
|
|
3fe7be956f | ||
|
|
983bc433e6 | ||
|
|
25da574fcb | ||
|
|
f5e55be2a0 | ||
|
|
9f0c0fe0de | ||
|
|
782ef85b22 | ||
|
|
30982bec96 |
2
lapi.c
2
lapi.c
@@ -1343,7 +1343,7 @@ void lua_warning (lua_State *L, const char *msg, int tocont) {
|
|||||||
LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
|
LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
|
||||||
Udata *u;
|
Udata *u;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value");
|
api_check(L, 0 <= nuvalue && nuvalue < SHRT_MAX, "invalid value");
|
||||||
u = luaS_newudata(L, size, nuvalue);
|
u = luaS_newudata(L, size, nuvalue);
|
||||||
setuvalue(L, s2v(L->top.p), u);
|
setuvalue(L, s2v(L->top.p), u);
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
|
|||||||
3
lcode.c
3
lcode.c
@@ -35,6 +35,7 @@
|
|||||||
#define MAXREGS 255
|
#define MAXREGS 255
|
||||||
|
|
||||||
|
|
||||||
|
/* (note that expressions VJMP also have jumps.) */
|
||||||
#define hasjumps(e) ((e)->t != (e)->f)
|
#define hasjumps(e) ((e)->t != (e)->f)
|
||||||
|
|
||||||
|
|
||||||
@@ -985,7 +986,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
|
|||||||
** or it is a constant.
|
** or it is a constant.
|
||||||
*/
|
*/
|
||||||
void luaK_exp2val (FuncState *fs, expdesc *e) {
|
void luaK_exp2val (FuncState *fs, expdesc *e) {
|
||||||
if (hasjumps(e))
|
if (e->k == VJMP || hasjumps(e))
|
||||||
luaK_exp2anyreg(fs, e);
|
luaK_exp2anyreg(fs, e);
|
||||||
else
|
else
|
||||||
luaK_dischargevars(fs, e);
|
luaK_dischargevars(fs, e);
|
||||||
|
|||||||
21
ldebug.c
21
ldebug.c
@@ -37,6 +37,9 @@
|
|||||||
static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
|
static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
|
||||||
const char **name);
|
const char **name);
|
||||||
|
|
||||||
|
static const char strlocal[] = "local";
|
||||||
|
static const char strupval[] = "upvalue";
|
||||||
|
|
||||||
|
|
||||||
static int currentpc (CallInfo *ci) {
|
static int currentpc (CallInfo *ci) {
|
||||||
lua_assert(isLua(ci));
|
lua_assert(isLua(ci));
|
||||||
@@ -497,7 +500,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
|
|||||||
int pc = *ppc;
|
int pc = *ppc;
|
||||||
*name = luaF_getlocalname(p, reg + 1, pc);
|
*name = luaF_getlocalname(p, reg + 1, pc);
|
||||||
if (*name) /* is a local? */
|
if (*name) /* is a local? */
|
||||||
return "local";
|
return strlocal;
|
||||||
/* else try symbolic execution */
|
/* else try symbolic execution */
|
||||||
*ppc = pc = findsetreg(p, pc, reg);
|
*ppc = pc = findsetreg(p, pc, reg);
|
||||||
if (pc != -1) { /* could find instruction? */
|
if (pc != -1) { /* could find instruction? */
|
||||||
@@ -512,7 +515,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
|
|||||||
}
|
}
|
||||||
case OP_GETUPVAL: {
|
case OP_GETUPVAL: {
|
||||||
*name = upvalname(p, GETARG_B(i));
|
*name = upvalname(p, GETARG_B(i));
|
||||||
return "upvalue";
|
return strupval;
|
||||||
}
|
}
|
||||||
case OP_LOADK: return kname(p, GETARG_Bx(i), name);
|
case OP_LOADK: return kname(p, GETARG_Bx(i), name);
|
||||||
case OP_LOADKX: return kname(p, GETARG_Ax(p->code[pc + 1]), name);
|
case OP_LOADKX: return kname(p, GETARG_Ax(p->code[pc + 1]), name);
|
||||||
@@ -547,15 +550,21 @@ static void rkname (const Proto *p, int pc, Instruction i, const char **name) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
** Check whether table being indexed by instruction 'i' is the
|
** Check whether table being indexed by instruction 'i' is the
|
||||||
** environment '_ENV'
|
** environment '_ENV'. If the table is an upvalue, get its name;
|
||||||
|
** otherwise, find some "name" for the table and check whether
|
||||||
|
** that name is the name of a local variable (and not, for instance,
|
||||||
|
** a string). Then check that, if there is a name, it is '_ENV'.
|
||||||
*/
|
*/
|
||||||
static const char *isEnv (const Proto *p, int pc, Instruction i, int isup) {
|
static const char *isEnv (const Proto *p, int pc, Instruction i, int isup) {
|
||||||
int t = GETARG_B(i); /* table index */
|
int t = GETARG_B(i); /* table index */
|
||||||
const char *name; /* name of indexed variable */
|
const char *name; /* name of indexed variable */
|
||||||
if (isup) /* is 't' an upvalue? */
|
if (isup) /* is 't' an upvalue? */
|
||||||
name = upvalname(p, t);
|
name = upvalname(p, t);
|
||||||
else /* 't' is a register */
|
else { /* 't' is a register */
|
||||||
basicgetobjname(p, &pc, t, &name);
|
const char *what = basicgetobjname(p, &pc, t, &name);
|
||||||
|
if (what != strlocal && what != strupval)
|
||||||
|
name = NULL; /* cannot be the variable _ENV */
|
||||||
|
}
|
||||||
return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field";
|
return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -701,7 +710,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o,
|
|||||||
for (i = 0; i < c->nupvalues; i++) {
|
for (i = 0; i < c->nupvalues; i++) {
|
||||||
if (c->upvals[i]->v.p == o) {
|
if (c->upvals[i]->v.p == o) {
|
||||||
*name = upvalname(c->p, i);
|
*name = upvalname(c->p, i);
|
||||||
return "upvalue";
|
return strupval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
17
ldo.c
17
ldo.c
@@ -94,10 +94,6 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
|
|||||||
setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
|
setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LUA_ERRERR: {
|
|
||||||
setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LUA_OK: { /* special case only for closing upvalues */
|
case LUA_OK: { /* special case only for closing upvalues */
|
||||||
setnilvalue(s2v(oldtop)); /* no error message */
|
setnilvalue(s2v(oldtop)); /* no error message */
|
||||||
break;
|
break;
|
||||||
@@ -120,6 +116,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
|
|||||||
else { /* thread has no error handler */
|
else { /* thread has no error handler */
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
errcode = luaE_resetthread(L, errcode); /* close all upvalues */
|
errcode = luaE_resetthread(L, errcode); /* close all upvalues */
|
||||||
|
L->status = errcode;
|
||||||
if (g->mainthread->errorJmp) { /* main thread has a handler? */
|
if (g->mainthread->errorJmp) { /* main thread has a handler? */
|
||||||
setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
|
setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
|
||||||
luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
|
luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
|
||||||
@@ -198,6 +195,16 @@ static void correctstack (lua_State *L) {
|
|||||||
/* some space for error handling */
|
/* some space for error handling */
|
||||||
#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
|
#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
|
||||||
|
|
||||||
|
|
||||||
|
/* raise an error while running the message handler */
|
||||||
|
l_noret luaD_errerr (lua_State *L) {
|
||||||
|
TString *msg = luaS_newliteral(L, "error in error handling");
|
||||||
|
setsvalue2s(L, L->top.p, msg);
|
||||||
|
L->top.p++; /* assume EXTRA_STACK */
|
||||||
|
luaD_throw(L, LUA_ERRERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Reallocate the stack to a new size, correcting all pointers into it.
|
** Reallocate the stack to a new size, correcting all pointers into it.
|
||||||
** In ISO C, any pointer use after the pointer has been deallocated is
|
** In ISO C, any pointer use after the pointer has been deallocated is
|
||||||
@@ -247,7 +254,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
|
|||||||
a stack error; cannot grow further than that. */
|
a stack error; cannot grow further than that. */
|
||||||
lua_assert(stacksize(L) == ERRORSTACKSIZE);
|
lua_assert(stacksize(L) == ERRORSTACKSIZE);
|
||||||
if (raiseerror)
|
if (raiseerror)
|
||||||
luaD_throw(L, LUA_ERRERR); /* error inside message handler */
|
luaD_errerr(L); /* error inside message handler */
|
||||||
return 0; /* if not 'raiseerror', just signal it */
|
return 0; /* if not 'raiseerror', just signal it */
|
||||||
}
|
}
|
||||||
else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
|
else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
|
||||||
|
|||||||
1
ldo.h
1
ldo.h
@@ -60,6 +60,7 @@
|
|||||||
/* type of protected functions, to be ran by 'runprotected' */
|
/* type of protected functions, to be ran by 'runprotected' */
|
||||||
typedef void (*Pfunc) (lua_State *L, void *ud);
|
typedef void (*Pfunc) (lua_State *L, void *ud);
|
||||||
|
|
||||||
|
LUAI_FUNC l_noret luaD_errerr (lua_State *L);
|
||||||
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
|
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
|
||||||
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
|
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
|
||||||
const char *mode);
|
const char *mode);
|
||||||
|
|||||||
8
lgc.c
8
lgc.c
@@ -553,8 +553,12 @@ static lu_mem traversetable (global_State *g, Table *h) {
|
|||||||
traverseweakvalue(g, h);
|
traverseweakvalue(g, h);
|
||||||
else if (!weakvalue) /* strong values? */
|
else if (!weakvalue) /* strong values? */
|
||||||
traverseephemeron(g, h, 0);
|
traverseephemeron(g, h, 0);
|
||||||
else /* all weak */
|
else { /* all weak */
|
||||||
linkgclist(h, g->allweak); /* nothing to traverse now */
|
if (g->gcstate == GCSpropagate)
|
||||||
|
linkgclist(h, g->grayagain); /* must visit again its metatable */
|
||||||
|
else
|
||||||
|
linkgclist(h, g->allweak); /* must clear collected entries */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else /* not weak */
|
else /* not weak */
|
||||||
traversestrongtable(g, h);
|
traversestrongtable(g, h);
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ static int new_localvar (LexState *ls, TString *name) {
|
|||||||
checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
|
checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
|
||||||
MAXVARS, "local variables");
|
MAXVARS, "local variables");
|
||||||
luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1,
|
luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1,
|
||||||
dyd->actvar.size, Vardesc, USHRT_MAX, "local variables");
|
dyd->actvar.size, Vardesc, SHRT_MAX, "local variables");
|
||||||
var = &dyd->actvar.arr[dyd->actvar.n++];
|
var = &dyd->actvar.arr[dyd->actvar.n++];
|
||||||
var->vd.kind = VDKREG; /* default */
|
var->vd.kind = VDKREG; /* default */
|
||||||
var->vd.name = name;
|
var->vd.name = name;
|
||||||
@@ -849,12 +849,11 @@ static void recfield (LexState *ls, ConsControl *cc) {
|
|||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
int reg = ls->fs->freereg;
|
int reg = ls->fs->freereg;
|
||||||
expdesc tab, key, val;
|
expdesc tab, key, val;
|
||||||
if (ls->t.token == TK_NAME) {
|
if (ls->t.token == TK_NAME)
|
||||||
checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
|
|
||||||
codename(ls, &key);
|
codename(ls, &key);
|
||||||
}
|
|
||||||
else /* ls->t.token == '[' */
|
else /* ls->t.token == '[' */
|
||||||
yindex(ls, &key);
|
yindex(ls, &key);
|
||||||
|
checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
|
||||||
cc->nh++;
|
cc->nh++;
|
||||||
checknext(ls, '=');
|
checknext(ls, '=');
|
||||||
tab = *cc->t;
|
tab = *cc->t;
|
||||||
@@ -941,6 +940,8 @@ static void constructor (LexState *ls, expdesc *t) {
|
|||||||
if (ls->t.token == '}') break;
|
if (ls->t.token == '}') break;
|
||||||
closelistfield(fs, &cc);
|
closelistfield(fs, &cc);
|
||||||
field(ls, &cc);
|
field(ls, &cc);
|
||||||
|
checklimit(fs, cc.tostore + cc.na + cc.nh, INT_MAX/2,
|
||||||
|
"items in a constructor");
|
||||||
} while (testnext(ls, ',') || testnext(ls, ';'));
|
} while (testnext(ls, ',') || testnext(ls, ';'));
|
||||||
check_match(ls, '}', '{', line);
|
check_match(ls, '}', '{', line);
|
||||||
lastlistfield(fs, &cc);
|
lastlistfield(fs, &cc);
|
||||||
|
|||||||
5
lstate.c
5
lstate.c
@@ -166,7 +166,7 @@ void luaE_checkcstack (lua_State *L) {
|
|||||||
if (getCcalls(L) == LUAI_MAXCCALLS)
|
if (getCcalls(L) == LUAI_MAXCCALLS)
|
||||||
luaG_runerror(L, "C stack overflow");
|
luaG_runerror(L, "C stack overflow");
|
||||||
else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11))
|
else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11))
|
||||||
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
|
luaD_errerr(L); /* error while handling stack error */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -272,7 +272,9 @@ static void close_state (lua_State *L) {
|
|||||||
luaC_freeallobjects(L); /* just collect its objects */
|
luaC_freeallobjects(L); /* just collect its objects */
|
||||||
else { /* closing a fully built state */
|
else { /* closing a fully built state */
|
||||||
L->ci = &L->base_ci; /* unwind CallInfo list */
|
L->ci = &L->base_ci; /* unwind CallInfo list */
|
||||||
|
L->errfunc = 0; /* stack unwind can "throw away" the error function */
|
||||||
luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */
|
luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */
|
||||||
|
L->top.p = L->stack.p + 1; /* empty the stack to run finalizers */
|
||||||
luaC_freeallobjects(L); /* collect all objects */
|
luaC_freeallobjects(L); /* collect all objects */
|
||||||
luai_userstateclose(L);
|
luai_userstateclose(L);
|
||||||
}
|
}
|
||||||
@@ -328,6 +330,7 @@ int luaE_resetthread (lua_State *L, int status) {
|
|||||||
if (status == LUA_YIELD)
|
if (status == LUA_YIELD)
|
||||||
status = LUA_OK;
|
status = LUA_OK;
|
||||||
L->status = LUA_OK; /* so it can run __close metamethods */
|
L->status = LUA_OK; /* so it can run __close metamethods */
|
||||||
|
L->errfunc = 0; /* stack unwind can "throw away" the error function */
|
||||||
status = luaD_closeprotected(L, 1, status);
|
status = luaD_closeprotected(L, 1, status);
|
||||||
if (status != LUA_OK) /* errors? */
|
if (status != LUA_OK) /* errors? */
|
||||||
luaD_seterrorobj(L, status, L->stack.p + 1);
|
luaD_seterrorobj(L, status, L->stack.p + 1);
|
||||||
|
|||||||
3
ltests.c
3
ltests.c
@@ -1655,6 +1655,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
|
|||||||
int level = getnum;
|
int level = getnum;
|
||||||
luaL_traceback(L1, L1, msg, level);
|
luaL_traceback(L1, L1, msg, level);
|
||||||
}
|
}
|
||||||
|
else if EQ("threadstatus") {
|
||||||
|
lua_pushstring(L1, statcodes[lua_status(L1)]);
|
||||||
|
}
|
||||||
else if EQ("return") {
|
else if EQ("return") {
|
||||||
int n = getnum;
|
int n = getnum;
|
||||||
if (L1 != L) {
|
if (L1 != L) {
|
||||||
|
|||||||
14
lua.c
14
lua.c
@@ -302,7 +302,8 @@ static int collectargs (char **argv, int *first) {
|
|||||||
case '-': /* '--' */
|
case '-': /* '--' */
|
||||||
if (argv[i][2] != '\0') /* extra characters after '--'? */
|
if (argv[i][2] != '\0') /* extra characters after '--'? */
|
||||||
return has_error; /* invalid option */
|
return has_error; /* invalid option */
|
||||||
*first = i + 1;
|
/* if there is a script name, it comes after '--' */
|
||||||
|
*first = (argv[i + 1] != NULL) ? i + 1 : 0;
|
||||||
return args;
|
return args;
|
||||||
case '\0': /* '-' */
|
case '\0': /* '-' */
|
||||||
return args; /* script "name" is '-' */
|
return args; /* script "name" is '-' */
|
||||||
@@ -490,10 +491,8 @@ static int incomplete (lua_State *L, int status) {
|
|||||||
if (status == LUA_ERRSYNTAX) {
|
if (status == LUA_ERRSYNTAX) {
|
||||||
size_t lmsg;
|
size_t lmsg;
|
||||||
const char *msg = lua_tolstring(L, -1, &lmsg);
|
const char *msg = lua_tolstring(L, -1, &lmsg);
|
||||||
if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
|
if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0)
|
||||||
lua_pop(L, 1);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0; /* else... */
|
return 0; /* else... */
|
||||||
}
|
}
|
||||||
@@ -508,9 +507,9 @@ static int pushline (lua_State *L, int firstline) {
|
|||||||
size_t l;
|
size_t l;
|
||||||
const char *prmt = get_prompt(L, firstline);
|
const char *prmt = get_prompt(L, firstline);
|
||||||
int readstatus = lua_readline(L, b, prmt);
|
int readstatus = lua_readline(L, b, prmt);
|
||||||
if (readstatus == 0)
|
|
||||||
return 0; /* no input (prompt will be popped by caller) */
|
|
||||||
lua_pop(L, 1); /* remove prompt */
|
lua_pop(L, 1); /* remove prompt */
|
||||||
|
if (readstatus == 0)
|
||||||
|
return 0; /* no input */
|
||||||
l = strlen(b);
|
l = strlen(b);
|
||||||
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
||||||
b[--l] = '\0'; /* remove it */
|
b[--l] = '\0'; /* remove it */
|
||||||
@@ -552,8 +551,9 @@ static int multiline (lua_State *L) {
|
|||||||
int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */
|
int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */
|
||||||
if (!incomplete(L, status) || !pushline(L, 0)) {
|
if (!incomplete(L, status) || !pushline(L, 0)) {
|
||||||
lua_saveline(L, line); /* keep history */
|
lua_saveline(L, line); /* keep history */
|
||||||
return status; /* cannot or should not try to add continuation line */
|
return status; /* should not or cannot try to add continuation line */
|
||||||
}
|
}
|
||||||
|
lua_remove(L, -2); /* remove error message (from incomplete line) */
|
||||||
lua_pushliteral(L, "\n"); /* add newline... */
|
lua_pushliteral(L, "\n"); /* add newline... */
|
||||||
lua_insert(L, -2); /* ...between the two lines */
|
lua_insert(L, -2); /* ...between the two lines */
|
||||||
lua_concat(L, 3); /* join them */
|
lua_concat(L, 3); /* join them */
|
||||||
|
|||||||
8
lua.h
8
lua.h
@@ -18,14 +18,14 @@
|
|||||||
|
|
||||||
#define LUA_VERSION_MAJOR "5"
|
#define LUA_VERSION_MAJOR "5"
|
||||||
#define LUA_VERSION_MINOR "4"
|
#define LUA_VERSION_MINOR "4"
|
||||||
#define LUA_VERSION_RELEASE "7"
|
#define LUA_VERSION_RELEASE "8"
|
||||||
|
|
||||||
#define LUA_VERSION_NUM 504
|
#define LUA_VERSION_NUM 504
|
||||||
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 7)
|
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 8)
|
||||||
|
|
||||||
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||||
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
|
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
|
||||||
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2024 Lua.org, PUC-Rio"
|
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2025 Lua.org, PUC-Rio"
|
||||||
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
|
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
|
||||||
|
|
||||||
|
|
||||||
@@ -497,7 +497,7 @@ struct lua_Debug {
|
|||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Copyright (C) 1994-2024 Lua.org, PUC-Rio.
|
* Copyright (C) 1994-2025 Lua.org, PUC-Rio.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
|
|||||||
3
lvm.c
3
lvm.c
@@ -339,7 +339,10 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
|
|||||||
lua_assert(isempty(slot)); /* slot must be empty */
|
lua_assert(isempty(slot)); /* slot must be empty */
|
||||||
tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
|
tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
|
||||||
if (tm == NULL) { /* no metamethod? */
|
if (tm == NULL) { /* no metamethod? */
|
||||||
|
sethvalue2s(L, L->top.p, h); /* anchor 't' */
|
||||||
|
L->top.p++; /* assume EXTRA_STACK */
|
||||||
luaH_finishset(L, h, key, slot, val); /* set new value */
|
luaH_finishset(L, h, key, slot, val); /* set new value */
|
||||||
|
L->top.p--;
|
||||||
invalidateTMcache(h);
|
invalidateTMcache(h);
|
||||||
luaC_barrierback(L, obj2gco(h), val);
|
luaC_barrierback(L, obj2gco(h), val);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
|
|||||||
<p>
|
<p>
|
||||||
<small>
|
<small>
|
||||||
<a href="http://www.lua.org/copyright.html">Copyright</a>
|
<a href="http://www.lua.org/copyright.html">Copyright</a>
|
||||||
© 2024 Lua.org, PUC-Rio. All rights reserved.
|
© 2025 Lua.org, PUC-Rio. All rights reserved.
|
||||||
</small>
|
</small>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ print("final OK !!!")
|
|||||||
|
|
||||||
--[[
|
--[[
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
* Copyright (C) 1994-2016 Lua.org, PUC-Rio.
|
* Copyright (C) 1994-2025 Lua.org, PUC-Rio.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
|
|||||||
@@ -399,6 +399,10 @@ do
|
|||||||
-- trivial error
|
-- trivial error
|
||||||
assert(T.checkpanic("pushstring hi; error") == "hi")
|
assert(T.checkpanic("pushstring hi; error") == "hi")
|
||||||
|
|
||||||
|
-- thread status inside panic (bug in 5.4.4)
|
||||||
|
assert(T.checkpanic("pushstring hi; error", "threadstatus; return 2") ==
|
||||||
|
"ERRRUN")
|
||||||
|
|
||||||
-- using the stack inside panic
|
-- using the stack inside panic
|
||||||
assert(T.checkpanic("pushstring hi; error;",
|
assert(T.checkpanic("pushstring hi; error;",
|
||||||
[[checkstack 5 XX
|
[[checkstack 5 XX
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
print "testing closures"
|
print "testing closures"
|
||||||
|
|
||||||
|
do -- bug in 5.4.7
|
||||||
|
_ENV[true] = 10
|
||||||
|
local function aux () return _ENV[1 < 2] end
|
||||||
|
assert(aux() == 10)
|
||||||
|
_ENV[true] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local A,B = 0,{g=10}
|
local A,B = 0,{g=10}
|
||||||
local function f(x)
|
local function f(x)
|
||||||
local a = {}
|
local a = {}
|
||||||
|
|||||||
@@ -493,6 +493,25 @@ assert(not pcall(a, a))
|
|||||||
a = nil
|
a = nil
|
||||||
|
|
||||||
|
|
||||||
|
do
|
||||||
|
-- bug in 5.4: thread can use message handler higher in the stack
|
||||||
|
-- than the variable being closed
|
||||||
|
local c = coroutine.create(function()
|
||||||
|
local clo <close> = setmetatable({}, {__close=function()
|
||||||
|
local x = 134 -- will overwrite message handler
|
||||||
|
error(x)
|
||||||
|
end})
|
||||||
|
-- yields coroutine but leaves a new message handler for it,
|
||||||
|
-- that would be used when closing the coroutine (except that it
|
||||||
|
-- will be overwritten)
|
||||||
|
xpcall(coroutine.yield, function() return "XXX" end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert(coroutine.resume(c)) -- start coroutine
|
||||||
|
local st, msg = coroutine.close(c)
|
||||||
|
assert(not st and msg == 134)
|
||||||
|
end
|
||||||
|
|
||||||
-- access to locals of erroneous coroutines
|
-- access to locals of erroneous coroutines
|
||||||
local x = coroutine.create (function ()
|
local x = coroutine.create (function ()
|
||||||
local a = 10
|
local a = 10
|
||||||
|
|||||||
@@ -137,6 +137,10 @@ checkmessage("aaa=(1)..{}", "a table value")
|
|||||||
-- bug in 5.4.6
|
-- bug in 5.4.6
|
||||||
checkmessage("a = {_ENV = {}}; print(a._ENV.x + 1)", "field 'x'")
|
checkmessage("a = {_ENV = {}}; print(a._ENV.x + 1)", "field 'x'")
|
||||||
|
|
||||||
|
-- a similar bug in 5.4.7, since 5.4.0
|
||||||
|
checkmessage("print(('_ENV').x + 1)", "field 'x'")
|
||||||
|
|
||||||
|
|
||||||
_G.aaa, _G.bbbb = nil
|
_G.aaa, _G.bbbb = nil
|
||||||
|
|
||||||
-- calls
|
-- calls
|
||||||
|
|||||||
@@ -370,6 +370,19 @@ x = 0 .."a".."b"..c..d.."e".."f".."g"
|
|||||||
assert(x.val == "0abcdefg")
|
assert(x.val == "0abcdefg")
|
||||||
|
|
||||||
|
|
||||||
|
do
|
||||||
|
-- bug since 5.4.1
|
||||||
|
local mt = setmetatable({__newindex={}}, {__mode='v'})
|
||||||
|
local t = setmetatable({}, mt)
|
||||||
|
|
||||||
|
if T then T.allocfailnext() end
|
||||||
|
|
||||||
|
-- seg. fault
|
||||||
|
for i=1, 10 do t[i] = 1 end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- concat metamethod x numbers (bug in 5.1.1)
|
-- concat metamethod x numbers (bug in 5.1.1)
|
||||||
c = {}
|
c = {}
|
||||||
local x
|
local x
|
||||||
|
|||||||
@@ -301,6 +301,16 @@ collectgarbage()
|
|||||||
assert(next(a) == string.rep('$', 11))
|
assert(next(a) == string.rep('$', 11))
|
||||||
|
|
||||||
|
|
||||||
|
if T then -- bug since 5.3: all-weak tables are not being revisited
|
||||||
|
T.gcstate("propagate")
|
||||||
|
local t = setmetatable({}, {__mode = "kv"})
|
||||||
|
T.gcstate("atomic") -- 't' was visited
|
||||||
|
setmetatable(t, {__mode = "kv"})
|
||||||
|
T.gcstate("pause") -- its new metatable is not being visited
|
||||||
|
assert(getmetatable(t).__mode == "kv")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- 'bug' in 5.1
|
-- 'bug' in 5.1
|
||||||
a = {}
|
a = {}
|
||||||
local t = {x = 10}
|
local t = {x = 10}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ prepfile[[
|
|||||||
1, a
|
1, a
|
||||||
)
|
)
|
||||||
]]
|
]]
|
||||||
RUN('lua - < %s > %s', prog, out)
|
RUN('lua - -- < %s > %s', prog, out)
|
||||||
checkout("1\tnil\n")
|
checkout("1\tnil\n")
|
||||||
|
|
||||||
RUN('echo "print(10)\nprint(2)\n" | lua > %s', out)
|
RUN('echo "print(10)\nprint(2)\n" | lua > %s', out)
|
||||||
@@ -133,7 +133,7 @@ checkout("-h\n")
|
|||||||
prepfile("print(package.path)")
|
prepfile("print(package.path)")
|
||||||
|
|
||||||
-- test LUA_PATH
|
-- test LUA_PATH
|
||||||
RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out)
|
RUN('env LUA_INIT= LUA_PATH=x lua -- %s > %s', prog, out)
|
||||||
checkout("x\n")
|
checkout("x\n")
|
||||||
|
|
||||||
-- test LUA_PATH_version
|
-- test LUA_PATH_version
|
||||||
@@ -346,9 +346,14 @@ RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out)
|
|||||||
checkprogout("6\n10\n10\n\n")
|
checkprogout("6\n10\n10\n\n")
|
||||||
|
|
||||||
prepfile("a = [[b\nc\nd\ne]]\n=a")
|
prepfile("a = [[b\nc\nd\ne]]\n=a")
|
||||||
RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out)
|
RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i -- < %s > %s]], prog, out)
|
||||||
checkprogout("b\nc\nd\ne\n\n")
|
checkprogout("b\nc\nd\ne\n\n")
|
||||||
|
|
||||||
|
-- input interrupted in continuation line
|
||||||
|
prepfile("a.\n")
|
||||||
|
RUN([[lua -i < %s > /dev/null 2> %s]], prog, out)
|
||||||
|
checkprogout("near <eof>\n")
|
||||||
|
|
||||||
local prompt = "alo"
|
local prompt = "alo"
|
||||||
prepfile[[ --
|
prepfile[[ --
|
||||||
a = 2
|
a = 2
|
||||||
@@ -473,12 +478,14 @@ assert(not os.remove(out))
|
|||||||
-- invalid options
|
-- invalid options
|
||||||
NoRun("unrecognized option '-h'", "lua -h")
|
NoRun("unrecognized option '-h'", "lua -h")
|
||||||
NoRun("unrecognized option '---'", "lua ---")
|
NoRun("unrecognized option '---'", "lua ---")
|
||||||
NoRun("unrecognized option '-Ex'", "lua -Ex")
|
NoRun("unrecognized option '-Ex'", "lua -Ex --")
|
||||||
NoRun("unrecognized option '-vv'", "lua -vv")
|
NoRun("unrecognized option '-vv'", "lua -vv")
|
||||||
NoRun("unrecognized option '-iv'", "lua -iv")
|
NoRun("unrecognized option '-iv'", "lua -iv")
|
||||||
NoRun("'-e' needs argument", "lua -e")
|
NoRun("'-e' needs argument", "lua -e")
|
||||||
NoRun("syntax error", "lua -e a")
|
NoRun("syntax error", "lua -e a")
|
||||||
NoRun("'-l' needs argument", "lua -l")
|
NoRun("'-l' needs argument", "lua -l")
|
||||||
|
NoRun("-i", "lua -- -i") -- handles -i as a script name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if T then -- test library?
|
if T then -- test library?
|
||||||
|
|||||||
Reference in New Issue
Block a user