Skip to content

Commit 1551af1

Browse files
committed
Update Lua 5.4 to 5.4.2 and bump version to 542.0.0
1 parent d651672 commit 1551af1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+418
-429
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lua-src"
3-
version = "541.0.0"
3+
version = "542.0.0"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2018"
66
repository = "https://github.com/khvzak/lua-src-rs"

lua-5.4.1/lapi.c renamed to lua-5.4.2/lapi.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,13 +1383,16 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
13831383

13841384

13851385
static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
1386+
static const UpVal *const nullup = NULL;
13861387
LClosure *f;
13871388
TValue *fi = index2value(L, fidx);
13881389
api_check(L, ttisLclosure(fi), "Lua function expected");
13891390
f = clLvalue(fi);
1390-
api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
13911391
if (pf) *pf = f;
1392-
return &f->upvals[n - 1]; /* get its upvalue pointer */
1392+
if (1 <= n && n <= f->p->sizeupvalues)
1393+
return &f->upvals[n - 1]; /* get its upvalue pointer */
1394+
else
1395+
return (UpVal**)&nullup;
13931396
}
13941397

13951398

@@ -1401,11 +1404,14 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
14011404
}
14021405
case LUA_VCCL: { /* C closure */
14031406
CClosure *f = clCvalue(fi);
1404-
api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
1405-
return &f->upvalue[n - 1];
1406-
}
1407+
if (1 <= n && n <= f->nupvalues)
1408+
return &f->upvalue[n - 1];
1409+
/* else */
1410+
} /* FALLTHROUGH */
1411+
case LUA_VLCF:
1412+
return NULL; /* light C functions have no upvalues */
14071413
default: {
1408-
api_check(L, 0, "closure expected");
1414+
api_check(L, 0, "function expected");
14091415
return NULL;
14101416
}
14111417
}
@@ -1417,6 +1423,7 @@ LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
14171423
LClosure *f1;
14181424
UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
14191425
UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1426+
api_check(L, *up1 != NULL && *up2 != NULL, "invalid upvalue index");
14201427
*up1 = *up2;
14211428
luaC_objbarrier(L, f1, *up1);
14221429
}
File renamed without changes.

lua-5.4.1/lauxlib.c renamed to lua-5.4.2/lauxlib.c

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
283283

284284

285285
LUALIB_API int luaL_execresult (lua_State *L, int stat) {
286-
const char *what = "exit"; /* type of termination */
287286
if (stat != 0 && errno != 0) /* error with an 'errno'? */
288287
return luaL_fileresult(L, 0, NULL);
289288
else {
289+
const char *what = "exit"; /* type of termination */
290290
l_inspectstat(stat, what); /* interpret result */
291291
if (*what == 'e' && stat == 0) /* successful termination? */
292292
lua_pushboolean(L, 1);
@@ -1006,43 +1006,67 @@ static int panic (lua_State *L) {
10061006

10071007

10081008
/*
1009-
** Emit a warning. '*warnstate' means:
1010-
** 0 - warning system is off;
1011-
** 1 - ready to start a new message;
1012-
** 2 - previous message is to be continued.
1009+
** Warning functions:
1010+
** warnfoff: warning system is off
1011+
** warnfon: ready to start a new message
1012+
** warnfcont: previous message is to be continued
10131013
*/
1014-
static void warnf (void *ud, const char *message, int tocont) {
1015-
int *warnstate = (int *)ud;
1016-
if (*warnstate != 2 && !tocont && *message == '@') { /* control message? */
1017-
if (strcmp(message, "@off") == 0)
1018-
*warnstate = 0;
1019-
else if (strcmp(message, "@on") == 0)
1020-
*warnstate = 1;
1021-
return;
1014+
static void warnfoff (void *ud, const char *message, int tocont);
1015+
static void warnfon (void *ud, const char *message, int tocont);
1016+
static void warnfcont (void *ud, const char *message, int tocont);
1017+
1018+
1019+
/*
1020+
** Check whether message is a control message. If so, execute the
1021+
** control or ignore it if unknown.
1022+
*/
1023+
static int checkcontrol (lua_State *L, const char *message, int tocont) {
1024+
if (tocont || *(message++) != '@') /* not a control message? */
1025+
return 0;
1026+
else {
1027+
if (strcmp(message, "off") == 0)
1028+
lua_setwarnf(L, warnfoff, L); /* turn warnings off */
1029+
else if (strcmp(message, "on") == 0)
1030+
lua_setwarnf(L, warnfon, L); /* turn warnings on */
1031+
return 1; /* it was a control message */
10221032
}
1023-
else if (*warnstate == 0) /* warnings off? */
1024-
return;
1025-
if (*warnstate == 1) /* previous message was the last? */
1026-
lua_writestringerror("%s", "Lua warning: "); /* start a new warning */
1033+
}
1034+
1035+
1036+
static void warnfoff (void *ud, const char *message, int tocont) {
1037+
checkcontrol((lua_State *)ud, message, tocont);
1038+
}
1039+
1040+
1041+
/*
1042+
** Writes the message and handle 'tocont', finishing the message
1043+
** if needed and setting the next warn function.
1044+
*/
1045+
static void warnfcont (void *ud, const char *message, int tocont) {
1046+
lua_State *L = (lua_State *)ud;
10271047
lua_writestringerror("%s", message); /* write message */
10281048
if (tocont) /* not the last part? */
1029-
*warnstate = 2; /* to be continued */
1049+
lua_setwarnf(L, warnfcont, L); /* to be continued */
10301050
else { /* last part */
10311051
lua_writestringerror("%s", "\n"); /* finish message with end-of-line */
1032-
*warnstate = 1; /* ready to start a new message */
1052+
lua_setwarnf(L, warnfon, L); /* next call is a new message */
10331053
}
10341054
}
10351055

10361056

1057+
static void warnfon (void *ud, const char *message, int tocont) {
1058+
if (checkcontrol((lua_State *)ud, message, tocont)) /* control message? */
1059+
return; /* nothing else to be done */
1060+
lua_writestringerror("%s", "Lua warning: "); /* start a new warning */
1061+
warnfcont(ud, message, tocont); /* finish processing */
1062+
}
1063+
1064+
10371065
LUALIB_API lua_State *luaL_newstate (void) {
10381066
lua_State *L = lua_newstate(l_alloc, NULL);
10391067
if (L) {
1040-
int *warnstate; /* space for warning state */
10411068
lua_atpanic(L, &panic);
1042-
warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0);
1043-
luaL_ref(L, LUA_REGISTRYINDEX); /* make sure it won't be collected */
1044-
*warnstate = 0; /* default is warnings off */
1045-
lua_setwarnf(L, warnf, warnstate);
1069+
lua_setwarnf(L, warnfoff, L); /* default is warnings off */
10461070
}
10471071
return L;
10481072
}
File renamed without changes.
File renamed without changes.

lua-5.4.1/lcode.c renamed to lua-5.4.2/lcode.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ void luaK_setoneret (FuncState *fs, expdesc *e) {
753753

754754

755755
/*
756-
** Ensure that expression 'e' is not a variable (nor a constant).
756+
** Ensure that expression 'e' is not a variable (nor a <const>).
757757
** (Expression still may have jump lists.)
758758
*/
759759
void luaK_dischargevars (FuncState *fs, expdesc *e) {
@@ -805,8 +805,8 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
805805

806806

807807
/*
808-
** Ensures expression value is in register 'reg' (and therefore
809-
** 'e' will become a non-relocatable expression).
808+
** Ensure expression value is in register 'reg', making 'e' a
809+
** non-relocatable expression.
810810
** (Expression still may have jump lists.)
811811
*/
812812
static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
@@ -860,7 +860,8 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
860860

861861

862862
/*
863-
** Ensures expression value is in any register.
863+
** Ensure expression value is in a register, making 'e' a
864+
** non-relocatable expression.
864865
** (Expression still may have jump lists.)
865866
*/
866867
static void discharge2anyreg (FuncState *fs, expdesc *e) {
@@ -946,8 +947,11 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
946947
exp2reg(fs, e, e->u.info); /* put final result in it */
947948
return e->u.info;
948949
}
950+
/* else expression has jumps and cannot change its register
951+
to hold the jump values, because it is a local variable.
952+
Go through to the default case. */
949953
}
950-
luaK_exp2nextreg(fs, e); /* otherwise, use next available register */
954+
luaK_exp2nextreg(fs, e); /* default: use next available register */
951955
return e->u.info;
952956
}
953957

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)