Skip to content

Commit 8fa6f7a

Browse files
committed
Update Lua to 5.3.4
1 parent 0df4813 commit 8fa6f7a

28 files changed

+423
-337
lines changed

src/lua/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TO_MAN= lua.1 luac.1
4646

4747
# Lua version and release.
4848
V= 5.3
49-
R= $V.3
49+
R= $V.4
5050

5151
# Targets start here.
5252
all: $(PLAT)

src/lua/README

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
This is Lua 5.3.3, released on 30 May 2016.
2+
This is Lua 5.3.4, released on 12 Jan 2017.
33

44
For installation instructions, license details, and
55
further information about Lua, see doc/readme.html.

src/lua/src/lauxlib.c

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lauxlib.c,v 1.286 2016/01/08 15:33:09 roberto Exp $
2+
** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp $
33
** Auxiliary functions for building Lua libraries
44
** See Copyright Notice in lua.h
55
*/
@@ -69,12 +69,11 @@ static int findfield (lua_State *L, int objidx, int level) {
6969

7070
/*
7171
** Search for a name for a function in all loaded modules
72-
** (registry._LOADED).
7372
*/
7473
static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
7574
int top = lua_gettop(L);
7675
lua_getinfo(L, "f", ar); /* push function */
77-
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
76+
lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
7877
if (findfield(L, top + 1, 2)) {
7978
const char *name = lua_tostring(L, -1);
8079
if (strncmp(name, "_G.", 3) == 0) { /* name start with '_G.'? */
@@ -809,13 +808,17 @@ LUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {
809808

810809

811810
LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
812-
if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
811+
if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
812+
if (!lua_isstring(L, -1))
813+
luaL_error(L, "'__tostring' must return a string");
814+
}
815+
else {
813816
switch (lua_type(L, idx)) {
814817
case LUA_TNUMBER: {
815818
if (lua_isinteger(L, idx))
816-
lua_pushfstring(L, "%I", lua_tointeger(L, idx));
819+
lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
817820
else
818-
lua_pushfstring(L, "%f", lua_tonumber(L, idx));
821+
lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
819822
break;
820823
}
821824
case LUA_TSTRING:
@@ -827,10 +830,15 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
827830
case LUA_TNIL:
828831
lua_pushliteral(L, "nil");
829832
break;
830-
default:
831-
lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
832-
lua_topointer(L, idx));
833+
default: {
834+
int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
835+
const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
836+
luaL_typename(L, idx);
837+
lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
838+
if (tt != LUA_TNIL)
839+
lua_remove(L, -2); /* remove '__name' */
833840
break;
841+
}
834842
}
835843
}
836844
return lua_tolstring(L, -1, len);
@@ -882,23 +890,23 @@ static int libsize (const luaL_Reg *l) {
882890

883891
/*
884892
** Find or create a module table with a given name. The function
885-
** first looks at the _LOADED table and, if that fails, try a
893+
** first looks at the LOADED table and, if that fails, try a
886894
** global variable with that name. In any case, leaves on the stack
887895
** the module table.
888896
*/
889897
LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
890898
int sizehint) {
891-
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
892-
if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no _LOADED[modname]? */
899+
luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);
900+
if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no LOADED[modname]? */
893901
lua_pop(L, 1); /* remove previous result */
894902
/* try global variable (and create one if it does not exist) */
895903
lua_pushglobaltable(L);
896904
if (luaL_findtable(L, 0, modname, sizehint) != NULL)
897905
luaL_error(L, "name conflict for module '%s'", modname);
898906
lua_pushvalue(L, -1);
899-
lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
907+
lua_setfield(L, -3, modname); /* LOADED[modname] = new table */
900908
}
901-
lua_remove(L, -2); /* remove _LOADED table */
909+
lua_remove(L, -2); /* remove LOADED table */
902910
}
903911

904912

@@ -962,17 +970,17 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
962970
*/
963971
LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
964972
lua_CFunction openf, int glb) {
965-
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
966-
lua_getfield(L, -1, modname); /* _LOADED[modname] */
973+
luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
974+
lua_getfield(L, -1, modname); /* LOADED[modname] */
967975
if (!lua_toboolean(L, -1)) { /* package not already loaded? */
968976
lua_pop(L, 1); /* remove field */
969977
lua_pushcfunction(L, openf);
970978
lua_pushstring(L, modname); /* argument to open function */
971979
lua_call(L, 1, 1); /* call 'openf' to open module */
972980
lua_pushvalue(L, -1); /* make copy of module (call result) */
973-
lua_setfield(L, -3, modname); /* _LOADED[modname] = module */
981+
lua_setfield(L, -3, modname); /* LOADED[modname] = module */
974982
}
975-
lua_remove(L, -2); /* remove _LOADED table */
983+
lua_remove(L, -2); /* remove LOADED table */
976984
if (glb) {
977985
lua_pushvalue(L, -1); /* copy of module */
978986
lua_setglobal(L, modname); /* _G[modname] = module */
@@ -1030,6 +1038,6 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {
10301038
luaL_error(L, "multiple Lua VMs detected");
10311039
else if (*v != ver)
10321040
luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
1033-
ver, *v);
1041+
(LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);
10341042
}
10351043

src/lua/src/lauxlib.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $
2+
** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp $
33
** Auxiliary functions for building Lua libraries
44
** See Copyright Notice in lua.h
55
*/
@@ -16,10 +16,18 @@
1616

1717

1818

19-
/* extra error code for 'luaL_load' */
19+
/* extra error code for 'luaL_loadfilex' */
2020
#define LUA_ERRFILE (LUA_ERRERR+1)
2121

2222

23+
/* key, in the registry, for table of loaded modules */
24+
#define LUA_LOADED_TABLE "_LOADED"
25+
26+
27+
/* key, in the registry, for table of preloaded loaders */
28+
#define LUA_PRELOAD_TABLE "_PRELOAD"
29+
30+
2331
typedef struct luaL_Reg {
2432
const char *name;
2533
lua_CFunction func;

src/lua/src/lbaselib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lbaselib.c,v 1.313 2016/04/11 19:18:40 roberto Exp $
2+
** $Id: lbaselib.c,v 1.314 2016/09/05 19:06:34 roberto Exp $
33
** Basic library
44
** See Copyright Notice in lua.h
55
*/
@@ -208,8 +208,8 @@ static int luaB_type (lua_State *L) {
208208

209209
static int pairsmeta (lua_State *L, const char *method, int iszero,
210210
lua_CFunction iter) {
211+
luaL_checkany(L, 1);
211212
if (luaL_getmetafield(L, 1, method) == LUA_TNIL) { /* no metamethod? */
212-
luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */
213213
lua_pushcfunction(L, iter); /* will return generator, */
214214
lua_pushvalue(L, 1); /* state, */
215215
if (iszero) lua_pushinteger(L, 0); /* and initial value */

src/lua/src/lcode.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lcode.c,v 2.109 2016/05/13 19:09:21 roberto Exp $
2+
** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp $
33
** Code generator for Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -40,7 +40,7 @@
4040
** If expression is a numeric constant, fills 'v' with its value
4141
** and returns 1. Otherwise, returns 0.
4242
*/
43-
static int tonumeral(expdesc *e, TValue *v) {
43+
static int tonumeral(const expdesc *e, TValue *v) {
4444
if (hasjumps(e))
4545
return 0; /* not a numeral */
4646
switch (e->k) {
@@ -86,7 +86,7 @@ void luaK_nil (FuncState *fs, int from, int n) {
8686
/*
8787
** Gets the destination address of a jump instruction. Used to traverse
8888
** a list of jumps.
89-
*/
89+
*/
9090
static int getjump (FuncState *fs, int pc) {
9191
int offset = GETARG_sBx(fs->f->code[pc]);
9292
if (offset == NO_JUMP) /* point to itself represents end of list */
@@ -754,7 +754,7 @@ void luaK_exp2val (FuncState *fs, expdesc *e) {
754754
** (that is, it is either in a register or in 'k' with an index
755755
** in the range of R/K indices).
756756
** Returns R/K index.
757-
*/
757+
*/
758758
int luaK_exp2RK (FuncState *fs, expdesc *e) {
759759
luaK_exp2val(fs, e);
760760
switch (e->k) { /* move constants to 'k' */
@@ -975,7 +975,8 @@ static int validop (int op, TValue *v1, TValue *v2) {
975975
** Try to "constant-fold" an operation; return 1 iff successful.
976976
** (In this case, 'e1' has the final result.)
977977
*/
978-
static int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) {
978+
static int constfolding (FuncState *fs, int op, expdesc *e1,
979+
const expdesc *e2) {
979980
TValue v1, v2, res;
980981
if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
981982
return 0; /* non-numeric operands or not safe to fold */
@@ -1014,11 +1015,14 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {
10141015
** (everything but logical operators 'and'/'or' and comparison
10151016
** operators).
10161017
** Expression to produce final result will be encoded in 'e1'.
1018+
** Because 'luaK_exp2RK' can free registers, its calls must be
1019+
** in "stack order" (that is, first on 'e2', which may have more
1020+
** recent registers to be released).
10171021
*/
10181022
static void codebinexpval (FuncState *fs, OpCode op,
10191023
expdesc *e1, expdesc *e2, int line) {
1020-
int rk1 = luaK_exp2RK(fs, e1); /* both operands are "RK" */
1021-
int rk2 = luaK_exp2RK(fs, e2);
1024+
int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */
1025+
int rk1 = luaK_exp2RK(fs, e1);
10221026
freeexps(fs, e1, e2);
10231027
e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */
10241028
e1->k = VRELOCABLE; /* all those operations are relocatable */
@@ -1060,9 +1064,9 @@ static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
10601064
** Aplly prefix operation 'op' to expression 'e'.
10611065
*/
10621066
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
1063-
static expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP}; /* fake 2nd operand */
1067+
static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
10641068
switch (op) {
1065-
case OPR_MINUS: case OPR_BNOT:
1069+
case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
10661070
if (constfolding(fs, op + LUA_OPUNM, e, &ef))
10671071
break;
10681072
/* FALLTHROUGH */

src/lua/src/ldebug.c

+32-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ldebug.c,v 2.120 2016/03/31 19:01:21 roberto Exp $
2+
** $Id: ldebug.c,v 2.121 2016/10/19 12:32:10 roberto Exp $
33
** Debug Interface
44
** See Copyright Notice in lua.h
55
*/
@@ -38,7 +38,8 @@
3838
#define ci_func(ci) (clLvalue((ci)->func))
3939

4040

41-
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
41+
static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
42+
const char **name);
4243

4344

4445
static int currentpc (CallInfo *ci) {
@@ -244,6 +245,20 @@ static void collectvalidlines (lua_State *L, Closure *f) {
244245
}
245246

246247

248+
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
249+
if (ci == NULL) /* no 'ci'? */
250+
return NULL; /* no info */
251+
else if (ci->callstatus & CIST_FIN) { /* is this a finalizer? */
252+
*name = "__gc";
253+
return "metamethod"; /* report it as such */
254+
}
255+
/* calling function is a known Lua function? */
256+
else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
257+
return funcnamefromcode(L, ci->previous, name);
258+
else return NULL; /* no way to find a name */
259+
}
260+
261+
247262
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
248263
Closure *f, CallInfo *ci) {
249264
int status = 1;
@@ -274,11 +289,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
274289
break;
275290
}
276291
case 'n': {
277-
/* calling function is a known Lua function? */
278-
if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
279-
ar->namewhat = getfuncname(L, ci->previous, &ar->name);
280-
else
281-
ar->namewhat = NULL;
292+
ar->namewhat = getfuncname(L, ci, &ar->name);
282293
if (ar->namewhat == NULL) {
283294
ar->namewhat = ""; /* not found */
284295
ar->name = NULL;
@@ -471,8 +482,15 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
471482
}
472483

473484

474-
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
475-
TMS tm = (TMS)0; /* to avoid warnings */
485+
/*
486+
** Try to find a name for a function based on the code that called it.
487+
** (Only works when function was called by a Lua function.)
488+
** Returns what the name is (e.g., "for iterator", "method",
489+
** "metamethod") and sets '*name' to point to the name.
490+
*/
491+
static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
492+
const char **name) {
493+
TMS tm = (TMS)0; /* (initial value avoids warnings) */
476494
Proto *p = ci_func(ci)->p; /* calling function */
477495
int pc = currentpc(ci); /* calling instruction index */
478496
Instruction i = p->code[pc]; /* calling instruction */
@@ -482,13 +500,13 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
482500
}
483501
switch (GET_OPCODE(i)) {
484502
case OP_CALL:
485-
case OP_TAILCALL: /* get function name */
486-
return getobjname(p, pc, GETARG_A(i), name);
503+
case OP_TAILCALL:
504+
return getobjname(p, pc, GETARG_A(i), name); /* get function name */
487505
case OP_TFORCALL: { /* for iterator */
488506
*name = "for iterator";
489507
return "for iterator";
490508
}
491-
/* all other instructions can call only through metamethods */
509+
/* other instructions can do calls through metamethods */
492510
case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
493511
tm = TM_INDEX;
494512
break;
@@ -509,7 +527,8 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
509527
case OP_EQ: tm = TM_EQ; break;
510528
case OP_LT: tm = TM_LT; break;
511529
case OP_LE: tm = TM_LE; break;
512-
default: lua_assert(0); /* other instructions cannot call a function */
530+
default:
531+
return NULL; /* cannot find a reasonable name */
513532
}
514533
*name = getstr(G(L)->tmname[tm]);
515534
return "metamethod";

0 commit comments

Comments
 (0)