History

Lua 5.1-rc1

Lua Team committed 20 years ago

Commit 53d3c321 parent 27f2ec746 files · +1822 −1531Browse files

Showing the changes to src (34 of 46 files). Show all

Unified · Split

34 files
  1. src/Makefile +42 −9
  2. src/lapi.c +13 −14
  3. src/lauxlib.c +13 −5
  4. src/lauxlib.h +2 −2
  5. src/lbaselib.c +3 −3
  6. src/lcode.c +6 −6
  7. src/ldblib.c +3 −3
  8. src/ldebug.c +4 −4
  9. src/ldo.c +8 −9
  10. src/lfunc.c +3 −3
  11. src/lgc.c +8 −9
  12. src/linit.c +2 −2
  13. src/liolib.c +4 −4
  14. src/llex.c +46 −6
  15. src/llex.h +4 −2
  16. src/llimits.h +18 −5
  17. src/lmem.c +1 −17
  18. src/loadlib.c +38 −27
  19. src/lobject.c +6 −6
  20. src/lobject.h +9 −5
  21. src/lopcodes.h +2 −2
  22. src/loslib.c +24 −24
  23. src/lparser.c +31 −49
  24. src/lstring.c +2 −2
  25. src/lstrlib.c +38 −21
  26. src/ltable.c +53 −39
  27. src/ltable.h +8 −7
  28. src/ltm.c +3 −3
  29. src/lua.c +9 −5
  30. src/lua.h +4 −4
  31. src/luaconf.h +31 −13
  32. src/lualib.h +7 −1
  33. src/lvm.c +7 −7
  34. src/print.c +5 −2
src/Makefile+42−9
@@ -4,6 +4,9 @@ · 3 unmodified lines
44
55 # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
66
7+# Your platform. See PLATS for possible values.
8+PLAT= none
9+
710 CC= gcc
811 CFLAGS= -O2 -Wall $(MYCFLAGS)
912 AR= ar rcu
@@ -14,12 +17,11 @@ LIBS= -lm $(MYLIBS) · 4 unmodified lines
1417 MYCFLAGS=
1518 MYLDFLAGS=
1619 MYLIBS=
17−# enable dynamic loading and line editing in Linux
18−# MYCFLAGS= -DLUA_USE_DLOPEN -DLUA_USE_READLINE
19−# MYLIBS= -Wl,-E -ldl -lreadline -lhistory -lncurses
2020
2121 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
2222
23+PLATS= ansi bsd generic linux macosx mingw posix
24+
2325 LUA_A= liblua.a
2426 CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
2527 lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
@@ -37,6 +39,8 @@ ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) · 11 unmodified lines
3739 ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
3840 ALL_A= $(LUA_A)
3941
42+default: $(PLAT)
43+
4044 all: $(ALL_T)
4145
4246 o: $(ALL_O)
@@ -60,6 +64,7 @@ depend: · 17 unmodified lines
6064 @$(CC) $(CFLAGS) -MM l*.c print.c
6165
6266 echo:
67+ @echo "PLAT = $(PLAT)"
6368 @echo "CC = $(CC)"
6469 @echo "CFLAGS = $(CFLAGS)"
6570 @echo "AR = $(AR)"
@@ -69,6 +74,34 @@ echo: · 3 unmodified lines
6974 @echo "MYLDFLAGS = $(MYLDFLAGS)"
7075 @echo "MYLIBS = $(MYLIBS)"
7176
77+# convenience targets for usual platforms
78+
79+none:
80+ @echo "Please choose a platform: $(PLATS)"
81+
82+ansi:
83+ $(MAKE) all MYCFLAGS=-DLUA_ANSI
84+
85+bsd:
86+ $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
87+
88+generic:
89+ $(MAKE) all MYCFLAGS=
90+
91+linux:
92+ $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
93+
94+macosx:
95+ $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
96+
97+mingw:
98+ $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
99+ "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \
100+ "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
101+
102+posix:
103+ $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
104+
72105 # DO NOT DELETE
73106
74107 lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
@@ -86,8 +119,8 @@ ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ · 11 unmodified lines
86119 ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
87120 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
88121 lstring.h lundump.h lvm.h
89−ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \
90− ltm.h lzio.h lmem.h lundump.h
122+ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
123+ lzio.h lmem.h lundump.h
91124 lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
92125 lstate.h ltm.h lzio.h
93126 lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
@@ -99,10 +132,11 @@ llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ · 5 unmodified lines
99132 lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
100133 lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
101134 ltm.h lzio.h lmem.h ldo.h
102−loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
135+loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \
136+ lualib.h
103137 lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
104138 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
105−lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h
139+lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
106140 loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
107141 lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
108142 lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
@@ -122,8 +156,7 @@ luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \ · 13 unmodified lines
122156 lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
123157 lundump.h
124158 lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
125− llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \
126− lundump.h
159+ llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
127160 lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
128161 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
129162 lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
src/lapi.c+13−14
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.51 2005/10/20 11:35:50 roberto Exp $
2+** $Id: lapi.c,v 2.53 2006/01/10 12:50:00 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -40,7 +40,7 @@ const char lua_ident[] = · 34 unmodified lines
4040
4141 #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
4242
43−#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject)
43+#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
4444
4545 #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
4646
@@ -50,7 +50,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 3 unmodified lines
5050 if (idx > 0) {
5151 TValue *o = L->base + (idx - 1);
5252 api_check(L, idx <= L->ci->top - L->base);
53− if (o >= L->top) return cast(TValue *, &luaO_nilobject);
53+ if (o >= L->top) return cast(TValue *, luaO_nilobject);
5454 else return o;
5555 }
5656 else if (idx > LUA_REGISTRYINDEX) {
@@ -70,7 +70,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 13 unmodified lines
7070 idx = LUA_GLOBALSINDEX - idx;
7171 return (idx <= func->c.nupvalues)
7272 ? &func->c.upvalue[idx-1]
73− : cast(TValue *, &luaO_nilobject);
73+ : cast(TValue *, luaO_nilobject);
7474 }
7575 }
7676 }
@@ -153,7 +153,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 76 unmodified lines
153153
154154
155155 LUA_API int lua_gettop (lua_State *L) {
156− return cast(int, L->top - L->base);
156+ return cast_int(L->top - L->base);
157157 }
158158
159159
@@ -234,7 +234,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 74 unmodified lines
234234
235235 LUA_API int lua_type (lua_State *L, int idx) {
236236 StkId o = index2adr(L, idx);
237− return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o);
237+ return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
238238 }
239239
240240
@@ -272,7 +272,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { · 31 unmodified lines
272272 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
273273 StkId o1 = index2adr(L, index1);
274274 StkId o2 = index2adr(L, index2);
275− return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
275+ return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
276276 : luaO_rawequalObj(o1, o2);
277277 }
278278
@@ -283,8 +283,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { · 4 unmodified lines
283283 lua_lock(L); /* may call tag method */
284284 o1 = index2adr(L, index1);
285285 o2 = index2adr(L, index2);
286− i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
287− : equalobj(L, o1, o2);
286+ i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
288287 lua_unlock(L);
289288 return i;
290289 }
@@ -296,7 +295,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 5 unmodified lines
296295 lua_lock(L); /* may call tag method */
297296 o1 = index2adr(L, index1);
298297 o2 = index2adr(L, index2);
299− i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
298+ i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
300299 : luaV_lessthan(L, o1, o2);
301300 lua_unlock(L);
302301 return i;
@@ -430,7 +429,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { · 127 unmodified lines
430429
431430 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
432431 lua_lock(L);
433− setnvalue(L->top, cast(lua_Number, n));
432+ setnvalue(L->top, cast_num(n));
434433 api_incr_top(L);
435434 lua_unlock(L);
436435 }
@@ -910,11 +909,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 473 unmodified lines
910909 }
911910 case LUA_GCCOUNT: {
912911 /* GC values are expressed in Kbytes: #bytes/2^10 */
913− res = cast(int, g->totalbytes >> 10);
912+ res = cast_int(g->totalbytes >> 10);
914913 break;
915914 }
916915 case LUA_GCCOUNTB: {
917− res = cast(int, g->totalbytes & 0x3ff);
916+ res = cast_int(g->totalbytes & 0x3ff);
918917 break;
919918 }
920919 case LUA_GCSTEP: {
@@ -983,7 +982,7 @@ LUA_API void lua_concat (lua_State *L, int n) { · 62 unmodified lines
983982 api_checknelems(L, n);
984983 if (n >= 2) {
985984 luaC_checkGC(L);
986− luaV_concat(L, n, cast(int, L->top - L->base) - 1);
985+ luaV_concat(L, n, cast_int(L->top - L->base) - 1);
987986 L->top -= (n-1);
988987 }
989988 else if (n == 0) { /* push empty string */
src/lauxlib.c+13−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp $
2+** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -226,16 +226,24 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname, · 220 unmodified lines
226226 }
227227
228228
229+static int libsize (const luaL_Reg *l) {
230+ int size = 0;
231+ for (; l->name; l++) size++;
232+ return size;
233+}
234+
235+
229236 LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
230237 const luaL_Reg *l, int nup) {
231238 if (libname) {
239+ int size = libsize(l);
232240 /* check whether lib already exists */
233− luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
241+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size);
234242 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
235243 if (!lua_istable(L, -1)) { /* not found? */
236244 lua_pop(L, 1); /* remove previous result */
237245 /* try global variable (and create one if it does not exist) */
238− if (luaL_findtable(L, LUA_GLOBALSINDEX, libname) != NULL)
246+ if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
239247 luaL_error(L, "name conflict for module " LUA_QS, libname);
240248 lua_pushvalue(L, -1);
241249 lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
@@ -331,7 +339,7 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, · 89 unmodified lines
331339
332340
333341 LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
334− const char *fname) {
342+ const char *fname, int szhint) {
335343 const char *e;
336344 lua_pushvalue(L, idx);
337345 do {
@@ -341,7 +349,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, · 3 unmodified lines
341349 lua_rawget(L, -2);
342350 if (lua_isnil(L, -1)) { /* no such field? */
343351 lua_pop(L, 1); /* remove this nil */
344− lua_newtable(L); /* create a new table for field */
352+ lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
345353 lua_pushlstring(L, fname, e - fname);
346354 lua_pushvalue(L, -2);
347355 lua_settable(L, -4); /* set new table into field */
src/lauxlib.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.86 2005/10/21 13:47:42 roberto Exp $
2+** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -86,7 +86,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, · 80 unmodified lines
8686 const char *r);
8787
8888 LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
89− const char *fname);
89+ const char *fname, int szhint);
9090
9191
9292
src/lbaselib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.186 2005/10/21 13:47:42 roberto Exp $
2+** $Id: lbaselib.c,v 1.188 2005/12/29 15:32:11 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -201,7 +201,7 @@ static int luaB_collectgarbage (lua_State *L) { · 195 unmodified lines
201201 switch (optsnum[o]) {
202202 case LUA_GCCOUNT: {
203203 int b = lua_gc(L, LUA_GCCOUNTB, 0);
204− lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000);
204+ lua_pushnumber(L, ((lua_Number)res*1024 + b)/1024);
205205 return 1;
206206 }
207207 case LUA_GCSTEP: {
@@ -625,7 +625,7 @@ static void base_open (lua_State *L) { · 417 unmodified lines
625625 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
626626 auxopen(L, "pairs", luaB_pairs, luaB_next);
627627 /* `newproxy' needs a weaktable as upvalue */
628− lua_newtable(L); /* new table `w' */
628+ lua_createtable(L, 0, 1); /* new table `w' */
629629 lua_pushvalue(L, -1); /* `w' will be its own metatable */
630630 lua_setmetatable(L, -2);
631631 lua_pushliteral(L, "kv");
src/lcode.c+6−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.22 2005/11/16 11:55:27 roberto Exp $
2+** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -196,7 +196,7 @@ void luaK_checkstack (FuncState *fs, int n) { · 190 unmodified lines
196196 if (newstack > fs->f->maxstacksize) {
197197 if (newstack >= MAXSTACK)
198198 luaX_syntaxerror(fs->ls, "function or expression too complex");
199− fs->f->maxstacksize = cast(lu_byte, newstack);
199+ fs->f->maxstacksize = cast_byte(newstack);
200200 }
201201 }
202202
@@ -227,11 +227,11 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { · 24 unmodified lines
227227 Proto *f = fs->f;
228228 int oldsize = f->sizek;
229229 if (ttisnumber(idx)) {
230− lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v));
231− return cast(int, nvalue(idx));
230+ lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
231+ return cast_int(nvalue(idx));
232232 }
233233 else { /* constant not found; create a new entry */
234− setnvalue(idx, cast(lua_Number, fs->nk));
234+ setnvalue(idx, cast_num(fs->nk));
235235 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
236236 MAXARG_Bx, "constant table overflow");
237237 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
@@ -647,7 +647,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { · 409 unmodified lines
647647 case OP_LEN: return 0; /* no constant folding for 'len' */
648648 default: lua_assert(0); r = 0; break;
649649 }
650− if (r != r) return 0; /* do not attempt to produce NaN */
650+ if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
651651 e1->u.nval = r;
652652 return 1;
653653 }
src/ldblib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.103 2005/11/01 16:08:32 roberto Exp $
2+** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -116,7 +116,7 @@ static int db_getinfo (lua_State *L) { · 110 unmodified lines
116116 return luaL_argerror(L, arg+1, "function or level expected");
117117 if (!lua_getinfo(L1, options, &ar))
118118 return luaL_argerror(L, arg+2, "invalid option");
119− lua_newtable(L);
119+ lua_createtable(L, 0, 2);
120120 if (strchr(options, 'S')) {
121121 settabss(L, "source", ar.source);
122122 settabss(L, "short_src", ar.short_src);
@@ -246,7 +246,7 @@ static void gethooktable (lua_State *L) { · 123 unmodified lines
246246 lua_rawget(L, LUA_REGISTRYINDEX);
247247 if (!lua_istable(L, -1)) {
248248 lua_pop(L, 1);
249− lua_newtable(L);
249+ lua_createtable(L, 0, 1);
250250 lua_pushlightuserdata(L, (void *)&KEY_HOOK);
251251 lua_pushvalue(L, -2);
252252 lua_rawset(L, LUA_REGISTRYINDEX);
src/ldebug.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp $
2+** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -61,7 +61,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { · 55 unmodified lines
6161 L->hook = func;
6262 L->basehookcount = count;
6363 resethookcount(L);
64− L->hookmask = cast(lu_byte, mask);
64+ L->hookmask = cast_byte(mask);
6565 return 1;
6666 }
6767
@@ -92,7 +92,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 24 unmodified lines
9292 }
9393 if (level == 0 && ci > L->base_ci) { /* level found? */
9494 status = 1;
95− ar->i_ci = cast(int, ci - L->base_ci);
95+ ar->i_ci = cast_int(ci - L->base_ci);
9696 }
9797 else if (level < 0) { /* level is of a lost tail call? */
9898 status = 1;
@@ -550,7 +550,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 451 unmodified lines
550550 const char *name = NULL;
551551 const char *t = luaT_typenames[ttype(o)];
552552 const char *kind = (isinstack(L->ci, o)) ?
553− getobjname(L, L->ci, cast(int, o - L->base), &name) :
553+ getobjname(L, L->ci, cast_int(o - L->base), &name) :
554554 NULL;
555555 if (kind)
556556 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
src/ldo.c+8−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp $
2+** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -71,7 +71,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 65 unmodified lines
7171 static void restore_stack_limit (lua_State *L) {
7272 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
7373 if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */
74− int inuse = cast(int, L->ci - L->base_ci);
74+ int inuse = cast_int(L->ci - L->base_ci);
7575 if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
7676 luaD_reallocCI(L, LUAI_MAXCALLS);
7777 }
@@ -97,7 +97,7 @@ void luaD_throw (lua_State *L, int errcode) { · 19 unmodified lines
9797 LUAI_THROW(L, L->errorJmp);
9898 }
9999 else {
100− L->status = cast(lu_byte, errcode);
100+ L->status = cast_byte(errcode);
101101 if (G(L)->panic) {
102102 resetstack(L, errcode);
103103 lua_unlock(L);
@@ -189,7 +189,7 @@ void luaD_callhook (lua_State *L, int event, int line) { · 85 unmodified lines
189189 if (event == LUA_HOOKTAILRET)
190190 ar.i_ci = 0; /* tail call; no debug information about it */
191191 else
192− ar.i_ci = cast(int, L->ci - L->base_ci);
192+ ar.i_ci = cast_int(L->ci - L->base_ci);
193193 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
194194 L->ci->top = L->top + LUA_MINSTACK;
195195 lua_assert(L->ci->top <= L->stack_last);
@@ -221,8 +221,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { · 25 unmodified lines
221221 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
222222 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
223223 /* store counter in field `n' */
224− setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),
225− cast(lua_Number, nvar));
224+ setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
226225 }
227226 #endif
228227 /* move fixed parameters to final position */
@@ -282,7 +281,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 53 unmodified lines
282281 L->top = base + p->numparams;
283282 }
284283 else { /* vararg function */
285− int nargs = cast(int, L->top - func) - 1;
284+ int nargs = cast_int(L->top - func) - 1;
286285 base = adjust_varargs(L, p, nargs);
287286 func = restorestack(L, funcr); /* previous call may change the stack */
288287 }
@@ -401,7 +400,7 @@ static void resume (lua_State *L, void *ud) { · 112 unmodified lines
401400 L->base = L->ci->base;
402401 }
403402 L->status = 0;
404− luaV_execute(L, cast(int, L->ci - L->base_ci));
403+ luaV_execute(L, cast_int(L->ci - L->base_ci));
405404 }
406405
407406
@@ -427,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 19 unmodified lines
427426 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
428427 status = luaD_rawrunprotected(L, resume, L->top - nargs);
429428 if (status != 0) { /* error? */
430− L->status = cast(lu_byte, status); /* mark thread as `dead' */
429+ L->status = cast_byte(status); /* mark thread as `dead' */
431430 luaD_seterrorobj(L, status, L->top);
432431 L->ci->top = L->top;
433432 }
src/lfunc.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp $
2+** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
@@ -25,7 +25,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { · 19 unmodified lines
2525 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
2626 c->c.isC = 1;
2727 c->c.env = e;
28− c->c.nupvalues = cast(lu_byte, nelems);
28+ c->c.nupvalues = cast_byte(nelems);
2929 return c;
3030 }
3131
@@ -35,7 +35,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { · 3 unmodified lines
3535 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
3636 c->l.isC = 0;
3737 c->l.env = e;
38− c->l.nupvalues = cast(lu_byte, nelems);
38+ c->l.nupvalues = cast_byte(nelems);
3939 while (nelems--) c->l.upvals[nelems] = NULL;
4040 return c;
4141 }
src/lgc.c+8−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.36 2005/08/24 17:06:36 roberto Exp $
2+** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -29,11 +29,10 @@ · 23 unmodified lines
2929 #define GCFINALIZECOST 100
3030
3131
32−#define maskmarks \
33− cast(lu_byte, ~(bitmask(BLACKBIT)|WHITEBITS))
32+#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
3433
3534 #define makewhite(g,x) \
36− ((x)->gch.marked = ((x)->gch.marked & maskmarks) | luaC_white(g))
35+ ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
3736
3837 #define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
3938 #define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
@@ -169,8 +168,8 @@ static int traversetable (global_State *g, Table *h) { · 129 unmodified lines
169168 weakvalue = (strchr(svalue(mode), 'v') != NULL);
170169 if (weakkey || weakvalue) { /* is really weak? */
171170 h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
172− h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) |
173− (weakvalue << VALUEWEAKBIT));
171+ h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
172+ (weakvalue << VALUEWEAKBIT));
174173 h->gclist = g->weak; /* must be cleared after GC, ... */
175174 g->weak = obj2gco(h); /* ... so put in the appropriate list */
176175 }
@@ -240,8 +239,8 @@ static void traverseclosure (global_State *g, Closure *cl) { · 63 unmodified lines
240239
241240
242241 static void checkstacksizes (lua_State *L, StkId max) {
243− int ci_used = cast(int, L->ci - L->base_ci); /* number of `ci' in use */
244− int s_used = cast(int, max - L->stack); /* part of stack in use */
242+ int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
243+ int s_used = cast_int(max - L->stack); /* part of stack in use */
245244 if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
246245 return; /* do not touch the stacks */
247246 if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
@@ -544,7 +543,7 @@ static void atomic (lua_State *L) { · 296 unmodified lines
544543 propagateall(g); /* remark, to propagate `preserveness' */
545544 cleartable(g->weak); /* remove collected objects from weak tables */
546545 /* flip current white */
547− g->currentwhite = cast(lu_byte, otherwhite(g));
546+ g->currentwhite = cast_byte(otherwhite(g));
548547 g->sweepstrgc = 0;
549548 g->sweepgc = &g->rootgc;
550549 g->gcstate = GCSsweepstring;
src/linit.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: linit.c,v 1.13 2005/08/26 17:36:32 roberto Exp $
2+** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $
33 ** Initialization of libraries for lua.c
44 ** See Copyright Notice in lua.h
55 */
@@ -16,13 +16,13 @@ · 10 unmodified lines
1616
1717 static const luaL_Reg lualibs[] = {
1818 {"", luaopen_base},
19+ {LUA_LOADLIBNAME, luaopen_package},
1920 {LUA_TABLIBNAME, luaopen_table},
2021 {LUA_IOLIBNAME, luaopen_io},
2122 {LUA_OSLIBNAME, luaopen_os},
2223 {LUA_STRLIBNAME, luaopen_string},
2324 {LUA_MATHLIBNAME, luaopen_math},
2425 {LUA_DBLIBNAME, luaopen_debug},
25− {LUA_LOADLIBNAME, luaopen_package},
2626 {NULL, NULL}
2727 };
2828
src/liolib.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.69 2005/10/19 13:05:11 roberto Exp $
2+** $Id: liolib.c,v 2.70 2005/12/29 15:32:11 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -507,8 +507,8 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { · 501 unmodified lines
507507
508508 LUALIB_API int luaopen_io (lua_State *L) {
509509 createmeta(L);
510− /* create new (private) environment */
511− lua_newtable(L);
510+ /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
511+ lua_createtable(L, 2, 1);
512512 lua_replace(L, LUA_ENVIRONINDEX);
513513 /* open library */
514514 luaL_register(L, LUA_IOLIBNAME, iolib);
@@ -518,7 +518,7 @@ LUALIB_API int luaopen_io (lua_State *L) { · 3 unmodified lines
518518 createstdfile(L, stderr, 0, "stderr");
519519 /* create environment for 'popen' */
520520 lua_getfield(L, -1, "popen");
521− lua_newtable(L);
521+ lua_createtable(L, 0, 1);
522522 lua_pushcfunction(L, io_pclose);
523523 lua_setfield(L, -2, "__close");
524524 lua_setfenv(L, -2);
src/llex.c+46−6
@@ -1,11 +1,12 @@
11 /*
2−** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp $
2+** $Id: llex.c,v 2.17 2005/12/22 16:19:56 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
66
77
88 #include <ctype.h>
9+#include <locale.h>
910 #include <string.h>
1011
1112 #define llex_c
@@ -65,7 +66,7 @@ void luaX_init (lua_State *L) { · 53 unmodified lines
6566 TString *ts = luaS_new(L, luaX_tokens[i]);
6667 luaS_fix(ts); /* reserved words are never collected */
6768 lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
68− ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */
69+ ts->tsv.reserved = cast_byte(i+1); /* reserved word */
6970 }
7071 }
7172
@@ -134,6 +135,7 @@ static void inclinenumber (LexState *ls) { · 62 unmodified lines
134135
135136
136137 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
138+ ls->decpoint = '.';
137139 ls->L = L;
138140 ls->lookahead.token = TK_EOS; /* no look-ahead token */
139141 ls->z = z;
@@ -163,6 +165,27 @@ static int check_next (LexState *ls, const char *set) { · 23 unmodified lines
163165 }
164166
165167
168+static void buffreplace (LexState *ls, char from, char to) {
169+ int n = luaZ_bufflen(ls->buff);
170+ char *p = luaZ_buffer(ls->buff);
171+ while (n--)
172+ if (p[n] == from) p[n] = to;
173+}
174+
175+
176+static void trydecpoint (LexState *ls, SemInfo *seminfo) {
177+ /* format error: try to update decimal point separator */
178+ struct lconv *cv = localeconv();
179+ char old = ls->decpoint;
180+ ls->decpoint = (cv ? cv->decimal_point[0] : '.');
181+ buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
182+ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
183+ /* format error with correct decimal point: no more options */
184+ buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
185+ luaX_lexerror(ls, "malformed number", TK_NUMBER);
186+ }
187+}
188+
166189
167190 /* LUA_NUMBER */
168191 static void read_numeral (LexState *ls, SemInfo *seminfo) {
@@ -177,8 +200,9 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 8 unmodified lines
177200 }
178201 }
179202 save(ls, '\0');
180− if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))
181− luaX_lexerror(ls, "malformed number", TK_NUMBER);
203+ buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
204+ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
205+ trydecpoint(ls, seminfo); /* try to update decimal point separator */
182206 }
183207
184208
@@ -306,7 +330,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 121 unmodified lines
306330 }
307331
308332
309−int luaX_lex (LexState *ls, SemInfo *seminfo) {
333+static int llex (LexState *ls, SemInfo *seminfo) {
310334 luaZ_resetbuffer(ls->buff);
311335 for (;;) {
312336 switch (ls->current) {
@@ -419,4 +443,20 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 106 unmodified lines
419443 }
420444 }
421445
422−#undef next
446+
447+void luaX_next (LexState *ls) {
448+ ls->lastline = ls->linenumber;
449+ if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
450+ ls->t = ls->lookahead; /* use this one */
451+ ls->lookahead.token = TK_EOS; /* and discharge it */
452+ }
453+ else
454+ ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
455+}
456+
457+
458+void luaX_lookahead (LexState *ls) {
459+ lua_assert(ls->lookahead.token == TK_EOS);
460+ ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
461+}
462+
src/llex.h+4−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.h,v 1.55 2005/06/06 13:30:25 roberto Exp $
2+** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -63,6 +63,7 @@ typedef struct LexState { · 57 unmodified lines
6363 ZIO *z; /* input stream */
6464 Mbuffer *buff; /* buffer for tokens */
6565 TString *source; /* current source name */
66+ char decpoint; /* locale decimal point */
6667 } LexState;
6768
6869
@@ -70,7 +71,8 @@ LUAI_FUNC void luaX_init (lua_State *L); · 1 unmodified line
7071 LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,
7172 TString *source);
7273 LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);
73−LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo);
74+LUAI_FUNC void luaX_next (LexState *ls);
75+LUAI_FUNC void luaX_lookahead (LexState *ls);
7476 LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
7577 LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
7678 LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
src/llimits.h+18−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.67 2005/08/24 16:15:49 roberto Exp $
2+** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -15,9 +15,6 @@ · 9 unmodified lines
1515 #include "lua.h"
1616
1717
18−#define api_check luai_apicheck
19−
20−
2118 typedef LUAI_UINT32 lu_int32;
2219
2320 typedef LUAI_UMEM lu_mem;
@@ -54,7 +51,19 @@ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; · 30 unmodified lines
5451 typedef LUAI_UACNUMBER l_uacNumber;
5552
5653
57−#define check_exp(c,e) (lua_assert(c), (e))
54+/* internal assertions for in-house debugging */
55+#ifdef lua_assert
56+
57+#define check_exp(c,e) (lua_assert(c), (e))
58+#define api_check(l,e) lua_assert(e)
59+
60+#else
61+
62+#define lua_assert(c) ((void)0)
63+#define check_exp(c,e) (e)
64+#define api_check luai_apicheck
65+
66+#endif
5867
5968
6069 #ifndef UNUSED
@@ -66,6 +75,10 @@ typedef LUAI_UACNUMBER l_uacNumber; · 5 unmodified lines
6675 #define cast(t, exp) ((t)(exp))
6776 #endif
6877
78+#define cast_byte(i) cast(lu_byte, (i))
79+#define cast_num(i) cast(lua_Number, (i))
80+#define cast_int(i) cast(int, (i))
81+
6982
7083
7184 /*
src/lmem.c+1−17
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.c,v 1.69 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
@@ -81,22 +81,6 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 75 unmodified lines
8181 luaD_throw(L, LUA_ERRMEM);
8282 lua_assert((nsize == 0) == (block == NULL));
8383 g->totalbytes = (g->totalbytes - osize) + nsize;
84−#if 0
85− { /* auxiliar patch to monitor garbage collection */
86− static unsigned long total = 0; /* our "time" */
87− static lu_mem last = 0; /* last totalmem that generated an output */
88− static FILE *f = NULL; /* output file */
89− if (nsize <= osize) total += 1; /* "time" always grow */
90− else total += (nsize - osize);
91− if ((int)g->totalbytes - (int)last > 1000 ||
92− (int)g->totalbytes - (int)last < -1000) {
93− last = g->totalbytes;
94− if (f == NULL) f = fopen("trace", "w");
95− fprintf(f, "%lu %u %u %u %d\n", total, g->totalbytes, g->GCthreshold,
96− g->estimate, g->gcstate);
97− }
98− }
99−#endif
10084 return block;
10185 }
10286
src/loadlib.c+38−27
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.48 2005/10/17 18:01:51 roberto Exp $
2+** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -16,8 +16,9 @@ · 10 unmodified lines
1616 #define loadlib_c
1717 #define LUA_LIB
1818
19−#include "lua.h"
2019 #include "lauxlib.h"
20+#include "lobject.h"
21+#include "lua.h"
2122 #include "lualib.h"
2223
2324
@@ -236,11 +237,8 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 212 unmodified lines
236237 #define LIB_FAIL "absent"
237238
238239
239−#if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux)
240−#define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation"
241−#else
242−#define DLMSG LUA_QL("loadlib") " not supported"
243−#endif
240+#define DLMSG "dynamic libraries not enabled; check your Lua installation"
241+
244242
245243 static void ll_unloadlib (void *lib) {
246244 (void)lib; /* to avoid warnings */
@@ -362,20 +360,23 @@ static const char *findfile (lua_State *L, const char *name, · 115 unmodified lines
362360 path = lua_tostring(L, -1);
363361 if (path == NULL)
364362 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
363+ lua_pushstring(L, ""); /* error accumulator */
365364 while ((path = pushnexttemplate(L, path)) != NULL) {
366365 const char *filename;
367366 filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
368367 if (readable(filename)) /* does file exist and is readable? */
369368 return filename; /* return that file name */
370369 lua_pop(L, 2); /* remove path template and file name */
370+ luaO_pushfstring(L, "\n\tno file " LUA_QS, filename);
371+ lua_concat(L, 2);
371372 }
372373 return NULL; /* not found */
373374 }
374375
375376
376−static void loaderror (lua_State *L) {
377− luaL_error(L, "error loading module " LUA_QS " (%s)",
378− lua_tostring(L, 1), lua_tostring(L, -1));
377+static void loaderror (lua_State *L, const char *filename) {
378+ luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
379+ lua_tostring(L, 1), filename, lua_tostring(L, -1));
379380 }
380381
381382
@@ -383,9 +384,9 @@ static int loader_Lua (lua_State *L) { · 1 unmodified line
383384 const char *filename;
384385 const char *name = luaL_checkstring(L, 1);
385386 filename = findfile(L, name, "path");
386− if (filename == NULL) return 0; /* library not found in this path */
387+ if (filename == NULL) return 1; /* library not found in this path */
387388 if (luaL_loadfile(L, filename) != 0)
388− loaderror(L);
389+ loaderror(L, filename);
389390 return 1; /* library loaded successfully */
390391 }
391392
@@ -405,10 +406,10 @@ static int loader_C (lua_State *L) { · 13 unmodified lines
405406 const char *funcname;
406407 const char *name = luaL_checkstring(L, 1);
407408 const char *filename = findfile(L, name, "cpath");
408− if (filename == NULL) return 0; /* library not found in this path */
409+ if (filename == NULL) return 1; /* library not found in this path */
409410 funcname = mkfuncname(L, name);
410411 if (ll_loadfunc(L, filename, funcname) != 0)
411− loaderror(L);
412+ loaderror(L, filename);
412413 return 1; /* library loaded successfully */
413414 }
414415
@@ -422,22 +423,26 @@ static int loader_Croot (lua_State *L) { · 7 unmodified lines
422423 if (p == NULL) return 0; /* is root */
423424 lua_pushlstring(L, name, p - name);
424425 filename = findfile(L, lua_tostring(L, -1), "cpath");
425− if (filename == NULL) return 0; /* root not found */
426+ if (filename == NULL) return 1; /* root not found */
426427 funcname = mkfuncname(L, name);
427428 if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
428− if (stat == ERRFUNC) return 0; /* function not found */
429− else
430− loaderror(L); /* real error */
429+ if (stat != ERRFUNC) loaderror(L, filename); /* real error */
430+ luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
431+ name, filename);
432+ return 1; /* function not found */
431433 }
432434 return 1;
433435 }
434436
435437
436438 static int loader_preload (lua_State *L) {
439+ const char *name = luaL_checkstring(L, 1);
437440 lua_getfield(L, LUA_ENVIRONINDEX, "preload");
438441 if (!lua_istable(L, -1))
439442 luaL_error(L, LUA_QL("package.preload") " must be a table");
440− lua_getfield(L, -1, luaL_checkstring(L, 1));
443+ lua_getfield(L, -1, name);
444+ if (lua_isnil(L, -1)) /* not found? */
445+ luaO_pushfstring(L, "\n\tno field package.preload['%s']", name);
441446 return 1;
442447 }
443448
@@ -461,14 +466,20 @@ static int ll_require (lua_State *L) { · 17 unmodified lines
461466 lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
462467 if (!lua_istable(L, -1))
463468 luaL_error(L, LUA_QL("package.loaders") " must be a table");
469+ lua_pushstring(L, ""); /* error message accumulator */
464470 for (i=1; ; i++) {
465− lua_rawgeti(L, -1, i); /* get a loader */
471+ lua_rawgeti(L, -2, i); /* get a loader */
466472 if (lua_isnil(L, -1))
467− luaL_error(L, "module " LUA_QS " not found", name);
473+ luaL_error(L, "module " LUA_QS " not found:%s",
474+ name, lua_tostring(L, -2));
468475 lua_pushstring(L, name);
469476 lua_call(L, 1, 1); /* call it */
470− if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */
471− else break; /* module loaded successfully */
477+ if (lua_isfunction(L, -1)) /* did it find module? */
478+ break; /* module loaded successfully */
479+ else if (lua_isstring(L, -1)) /* loader returned error message? */
480+ lua_concat(L, 2); /* accumulate it */
481+ else
482+ lua_pop(L, 1);
472483 }
473484 lua_pushlightuserdata(L, sentinel);
474485 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
@@ -539,7 +550,7 @@ static int ll_module (lua_State *L) { · 64 unmodified lines
539550 if (!lua_istable(L, -1)) { /* not found? */
540551 lua_pop(L, 1); /* remove previous result */
541552 /* try global variable (and create one if it does not exist) */
542− if (luaL_findtable(L, LUA_GLOBALSINDEX, modname) != NULL)
553+ if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
543554 return luaL_error(L, "name conflict for module " LUA_QS, modname);
544555 lua_pushvalue(L, -1);
545556 lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
@@ -562,7 +573,7 @@ static int ll_module (lua_State *L) { · 16 unmodified lines
562573 static int ll_seeall (lua_State *L) {
563574 luaL_checktype(L, 1, LUA_TTABLE);
564575 if (!lua_getmetatable(L, 1)) {
565− lua_newtable(L); /* create new metatable */
576+ lua_createtable(L, 0, 1); /* create new metatable */
566577 lua_pushvalue(L, -1);
567578 lua_setmetatable(L, 1);
568579 }
@@ -629,7 +640,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 60 unmodified lines
629640 lua_pushvalue(L, -1);
630641 lua_replace(L, LUA_ENVIRONINDEX);
631642 /* create `loaders' table */
632− lua_newtable(L);
643+ lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
633644 /* fill it with pre-defined loaders */
634645 for (i=0; loaders[i] != NULL; i++) {
635646 lua_pushcfunction(L, loaders[i]);
@@ -643,7 +654,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 7 unmodified lines
643654 LUA_EXECDIR "\n" LUA_IGMARK);
644655 lua_setfield(L, -2, "config");
645656 /* set field `loaded' */
646− luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
657+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
647658 lua_setfield(L, -2, "loaded");
648659 /* set field `preload' */
649660 lua_newtable(L);
src/lobject.c+6−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.19 2005/10/24 17:37:52 roberto Exp $
2+** $Id: lobject.c,v 2.21 2006/01/10 12:50:00 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -24,7 +24,7 @@ · 18 unmodified lines
2424
2525
2626
27−const TValue luaO_nilobject = {{NULL}, LUA_TNIL};
27+const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
2828
2929
3030 /*
@@ -39,7 +39,7 @@ int luaO_int2fb (unsigned int x) { · 8 unmodified lines
3939 e++;
4040 }
4141 if (x < 8) return x;
42− else return ((e+1) << 3) | (cast(int, x) - 8);
42+ else return ((e+1) << 3) | (cast_int(x) - 8);
4343 }
4444
4545
@@ -129,12 +129,12 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 83 unmodified lines
129129 break;
130130 }
131131 case 'd': {
132− setnvalue(L->top, cast(lua_Number, va_arg(argp, int)));
132+ setnvalue(L->top, cast_num(va_arg(argp, int)));
133133 incr_top(L);
134134 break;
135135 }
136136 case 'f': {
137− setnvalue(L->top, cast(lua_Number, va_arg(argp, l_uacNumber)));
137+ setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
138138 incr_top(L);
139139 break;
140140 }
@@ -161,7 +161,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 20 unmodified lines
161161 fmt = e+2;
162162 }
163163 pushstr(L, fmt);
164− luaV_concat(L, n+1, cast(int, L->top - L->base) - 1);
164+ luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
165165 L->top -= n;
166166 return svalue(L->top - 1);
167167 }
src/lobject.h+9−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.18 2005/10/24 17:37:33 roberto Exp $
2+** $Id: lobject.h,v 2.19 2006/01/10 12:51:53 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -323,9 +323,12 @@ typedef union Closure { · 317 unmodified lines
323323 ** Tables
324324 */
325325
326−typedef struct TKey {
327− TValuefields;
328− struct Node *next; /* for chaining */
326+typedef union TKey {
327+ struct {
328+ TValuefields;
329+ struct Node *next; /* for chaining */
330+ } nk;
331+ TValue tvk;
329332 } TKey;
330333
331334
@@ -360,8 +363,9 @@ typedef struct Table { · 28 unmodified lines
360363 #define sizenode(t) (twoto((t)->lsizenode))
361364
362365
366+#define luaO_nilobject (&luaO_nilobject_)
363367
364−LUAI_DATA const TValue luaO_nilobject;
368+LUAI_DATA const TValue luaO_nilobject_;
365369
366370 #define ceillog2(x) (luaO_log2((x)-1) + 1)
367371
src/lopcodes.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.123 2005/10/23 17:37:55 roberto Exp $
2+** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -208,7 +208,7 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ · 202 unmodified lines
208208 } OpCode;
209209
210210
211−#define NUM_OPCODES (cast(int, OP_VARARG+1))
211+#define NUM_OPCODES (cast(int, OP_VARARG) + 1)
212212
213213
214214
src/loslib.c+24−24
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 roberto Exp $
2+** $Id: loslib.c,v 1.16 2005/12/22 16:19:56 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -37,26 +37,26 @@ static int os_pushresult (lua_State *L, int i, const char *filename) { · 31 unmodified lines
3737 }
3838
3939
40−static int io_execute (lua_State *L) {
40+static int os_execute (lua_State *L) {
4141 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
4242 return 1;
4343 }
4444
4545
46−static int io_remove (lua_State *L) {
46+static int os_remove (lua_State *L) {
4747 const char *filename = luaL_checkstring(L, 1);
4848 return os_pushresult(L, remove(filename) == 0, filename);
4949 }
5050
5151
52−static int io_rename (lua_State *L) {
52+static int os_rename (lua_State *L) {
5353 const char *fromname = luaL_checkstring(L, 1);
5454 const char *toname = luaL_checkstring(L, 2);
5555 return os_pushresult(L, rename(fromname, toname) == 0, fromname);
5656 }
5757
5858
59−static int io_tmpname (lua_State *L) {
59+static int os_tmpname (lua_State *L) {
6060 char buff[LUA_TMPNAMBUFSIZE];
6161 int err;
6262 lua_tmpnam(buff, err);
@@ -67,13 +67,13 @@ static int io_tmpname (lua_State *L) { · 4 unmodified lines
6767 }
6868
6969
70−static int io_getenv (lua_State *L) {
70+static int os_getenv (lua_State *L) {
7171 lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
7272 return 1;
7373 }
7474
7575
76−static int io_clock (lua_State *L) {
76+static int os_clock (lua_State *L) {
7777 lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
7878 return 1;
7979 }
@@ -123,7 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { · 43 unmodified lines
123123 }
124124
125125
126−static int io_date (lua_State *L) {
126+static int os_date (lua_State *L) {
127127 const char *s = luaL_optstring(L, 1, "%c");
128128 time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
129129 (time_t)luaL_checknumber(L, 2);
@@ -159,7 +159,7 @@ static int io_date (lua_State *L) { · 29 unmodified lines
159159 }
160160
161161
162−static int io_time (lua_State *L) {
162+static int os_time (lua_State *L) {
163163 time_t t;
164164 if (lua_isnoneornil(L, 1)) /* called without args? */
165165 t = time(NULL); /* get current time */
@@ -179,12 +179,12 @@ static int io_time (lua_State *L) { · 13 unmodified lines
179179 if (t == (time_t)(-1))
180180 lua_pushnil(L);
181181 else
182− lua_pushnumber(L, t);
182+ lua_pushnumber(L, (lua_Number)t);
183183 return 1;
184184 }
185185
186186
187−static int io_difftime (lua_State *L) {
187+static int os_difftime (lua_State *L) {
188188 lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
189189 (time_t)(luaL_optnumber(L, 2, 0))));
190190 return 1;
@@ -193,7 +193,7 @@ static int io_difftime (lua_State *L) { · 2 unmodified lines
193193 /* }====================================================== */
194194
195195
196−static int io_setloc (lua_State *L) {
196+static int os_setlocale (lua_State *L) {
197197 static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
198198 LC_NUMERIC, LC_TIME};
199199 static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
@@ -206,23 +206,23 @@ static int io_setloc (lua_State *L) { · 6 unmodified lines
206206 }
207207
208208
209−static int io_exit (lua_State *L) {
209+static int os_exit (lua_State *L) {
210210 exit(luaL_optint(L, 1, EXIT_SUCCESS));
211211 return 0; /* to avoid warnings */
212212 }
213213
214214 static const luaL_Reg syslib[] = {
215− {"clock", io_clock},
216− {"date", io_date},
217− {"difftime", io_difftime},
218− {"execute", io_execute},
219− {"exit", io_exit},
220− {"getenv", io_getenv},
221− {"remove", io_remove},
222− {"rename", io_rename},
223− {"setlocale", io_setloc},
224− {"time", io_time},
225− {"tmpname", io_tmpname},
215+ {"clock", os_clock},
216+ {"date", os_date},
217+ {"difftime", os_difftime},
218+ {"execute", os_execute},
219+ {"exit", os_exit},
220+ {"getenv", os_getenv},
221+ {"remove", os_remove},
222+ {"rename", os_rename},
223+ {"setlocale", os_setlocale},
224+ {"time", os_time},
225+ {"tmpname", os_tmpname},
226226 {NULL, NULL}
227227 };
228228
src/lparser.c+31−49
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.38 2005/10/24 17:38:47 roberto Exp $
2+** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -54,24 +54,6 @@ static void chunk (LexState *ls); · 48 unmodified lines
5454 static void expr (LexState *ls, expdesc *v);
5555
5656
57−
58−static void next (LexState *ls) {
59− ls->lastline = ls->linenumber;
60− if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
61− ls->t = ls->lookahead; /* use this one */
62− ls->lookahead.token = TK_EOS; /* and discharge it */
63− }
64− else
65− ls->t.token = luaX_lex(ls, &ls->t.seminfo); /* read next token */
66−}
67−
68−
69−static void lookahead (LexState *ls) {
70− lua_assert(ls->lookahead.token == TK_EOS);
71− ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo);
72−}
73−
74−
7557 static void anchor_token (LexState *ls) {
7658 if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
7759 TString *ts = ls->t.seminfo.ts;
@@ -97,7 +79,7 @@ static void errorlimit (FuncState *fs, int limit, const char *what) { · 19 unmodified lines
9779
9880 static int testnext (LexState *ls, int c) {
9981 if (ls->t.token == c) {
100− next(ls);
82+ luaX_next(ls);
10183 return 1;
10284 }
10385 else return 0;
@@ -111,7 +93,7 @@ static void check (LexState *ls, int c) { · 7 unmodified lines
11193
11294 static void checknext (LexState *ls, int c) {
11395 check(ls, c);
114− next(ls);
96+ luaX_next(ls);
11597 }
11698
11799
@@ -136,7 +118,7 @@ static TString *str_checkname (LexState *ls) { · 18 unmodified lines
136118 TString *ts;
137119 check(ls, TK_NAME);
138120 ts = ls->t.seminfo.ts;
139− next(ls);
121+ luaX_next(ls);
140122 return ts;
141123 }
142124
@@ -184,7 +166,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { · 41 unmodified lines
184166
185167 static void adjustlocalvars (LexState *ls, int nvars) {
186168 FuncState *fs = ls->fs;
187− fs->nactvar = cast(lu_byte, fs->nactvar + nvars);
169+ fs->nactvar = cast_byte(fs->nactvar + nvars);
188170 for (; nvars; nvars--) {
189171 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
190172 }
@@ -216,8 +198,8 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 25 unmodified lines
216198 f->upvalues[f->nups] = name;
217199 luaC_objbarrier(fs->L, f, name);
218200 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
219− fs->upvalues[f->nups].k = cast(lu_byte, v->k);
220− fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);
201+ fs->upvalues[f->nups].k = cast_byte(v->k);
202+ fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
221203 return f->nups++;
222204 }
223205
@@ -404,7 +386,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 180 unmodified lines
404386 luaX_setinput(L, &lexstate, z, luaS_new(L, name));
405387 open_func(&lexstate, &funcstate);
406388 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
407− next(&lexstate); /* read first token */
389+ luaX_next(&lexstate); /* read first token */
408390 chunk(&lexstate);
409391 check(&lexstate, TK_EOS);
410392 close_func(&lexstate);
@@ -426,7 +408,7 @@ static void field (LexState *ls, expdesc *v) { · 15 unmodified lines
426408 FuncState *fs = ls->fs;
427409 expdesc key;
428410 luaK_exp2anyreg(fs, v);
429− next(ls); /* skip the dot or colon */
411+ luaX_next(ls); /* skip the dot or colon */
430412 checkname(ls, &key);
431413 luaK_indexed(fs, v, &key);
432414 }
@@ -434,7 +416,7 @@ static void field (LexState *ls, expdesc *v) { · 1 unmodified line
434416
435417 static void yindex (LexState *ls, expdesc *v) {
436418 /* index -> '[' expr ']' */
437− next(ls); /* skip the '[' */
419+ luaX_next(ls); /* skip the '[' */
438420 expr(ls, v);
439421 luaK_exp2val(ls->fs, v);
440422 checknext(ls, ']');
@@ -530,7 +512,7 @@ static void constructor (LexState *ls, expdesc *t) { · 89 unmodified lines
530512 closelistfield(fs, &cc);
531513 switch(ls->t.token) {
532514 case TK_NAME: { /* may be listfields or recfields */
533− lookahead(ls);
515+ luaX_lookahead(ls);
534516 if (ls->lookahead.token != '=') /* expression? */
535517 listfield(ls, &cc);
536518 else
@@ -571,7 +553,7 @@ static void parlist (LexState *ls) { · 34 unmodified lines
571553 break;
572554 }
573555 case TK_DOTS: { /* param -> `...' */
574− next(ls);
556+ luaX_next(ls);
575557 #if defined(LUA_COMPAT_VARARG)
576558 /* use `arg' as default name */
577559 new_localvarliteral(ls, "arg", nparams++);
@@ -585,7 +567,7 @@ static void parlist (LexState *ls) { · 7 unmodified lines
585567 } while (!f->is_vararg && testnext(ls, ','));
586568 }
587569 adjustlocalvars(ls, nparams);
588− f->numparams = fs->nactvar - (f->is_vararg & VARARG_HASARG);
570+ f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
589571 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
590572 }
591573
@@ -632,7 +614,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 40 unmodified lines
632614 case '(': { /* funcargs -> `(' [ explist1 ] `)' */
633615 if (line != ls->lastline)
634616 luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
635− next(ls);
617+ luaX_next(ls);
636618 if (ls->t.token == ')') /* arg list is empty? */
637619 args.k = VVOID;
638620 else {
@@ -648,7 +630,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 9 unmodified lines
648630 }
649631 case TK_STRING: { /* funcargs -> STRING */
650632 codestring(ls, &args, ls->t.seminfo.ts);
651− next(ls); /* must use `seminfo' before `next' */
633+ luaX_next(ls); /* must use `seminfo' before `next' */
652634 break;
653635 }
654636 default: {
@@ -686,7 +668,7 @@ static void prefixexp (LexState *ls, expdesc *v) { · 31 unmodified lines
686668 switch (ls->t.token) {
687669 case '(': {
688670 int line = ls->linenumber;
689− next(ls);
671+ luaX_next(ls);
690672 expr(ls, v);
691673 check_match(ls, ')', '(', line);
692674 luaK_dischargevars(ls->fs, v);
@@ -724,7 +706,7 @@ static void primaryexp (LexState *ls, expdesc *v) { · 31 unmodified lines
724706 }
725707 case ':': { /* `:' NAME funcargs */
726708 expdesc key;
727− next(ls);
709+ luaX_next(ls);
728710 checkname(ls, &key);
729711 luaK_self(fs, v, &key);
730712 funcargs(ls, v);
@@ -779,7 +761,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 48 unmodified lines
779761 return;
780762 }
781763 case TK_FUNCTION: {
782− next(ls);
764+ luaX_next(ls);
783765 body(ls, v, 0, ls->linenumber);
784766 return;
785767 }
@@ -788,7 +770,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 2 unmodified lines
788770 return;
789771 }
790772 }
791− next(ls);
773+ luaX_next(ls);
792774 }
793775
794776
@@ -848,7 +830,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 53 unmodified lines
848830 enterlevel(ls);
849831 uop = getunopr(ls->t.token);
850832 if (uop != OPR_NOUNOPR) {
851− next(ls);
833+ luaX_next(ls);
852834 subexpr(ls, v, UNARY_PRIORITY);
853835 luaK_prefix(ls->fs, uop, v);
854836 }
@@ -858,7 +840,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 3 unmodified lines
858840 while (op != OPR_NOBINOPR && priority[op].left > limit) {
859841 expdesc v2;
860842 BinOpr nextop;
861− next(ls);
843+ luaX_next(ls);
862844 luaK_infix(ls->fs, op, v);
863845 /* read sub-expression with higher priority */
864846 nextop = subexpr(ls, &v2, priority[op].right);
@@ -1009,7 +991,7 @@ static void whilestat (LexState *ls, int line) { · 144 unmodified lines
1009991 int whileinit;
1010992 int condexit;
1011993 BlockCnt bl;
1012− next(ls); /* skip WHILE */
994+ luaX_next(ls); /* skip WHILE */
1013995 whileinit = luaK_getlabel(fs);
1014996 condexit = cond(ls);
1015997 enterblock(fs, &bl, 1);
@@ -1030,7 +1012,7 @@ static void repeatstat (LexState *ls, int line) { · 14 unmodified lines
10301012 BlockCnt bl1, bl2;
10311013 enterblock(fs, &bl1, 1); /* loop block */
10321014 enterblock(fs, &bl2, 0); /* scope block */
1033− next(ls); /* skip REPEAT */
1015+ luaX_next(ls); /* skip REPEAT */
10341016 chunk(ls);
10351017 check_match(ls, TK_UNTIL, TK_REPEAT, line);
10361018 condexit = cond(ls); /* read condition (inside scope block) */
@@ -1130,7 +1112,7 @@ static void forstat (LexState *ls, int line) { · 93 unmodified lines
11301112 TString *varname;
11311113 BlockCnt bl;
11321114 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1133− next(ls); /* skip `for' */
1115+ luaX_next(ls); /* skip `for' */
11341116 varname = str_checkname(ls); /* first variable name */
11351117 switch (ls->t.token) {
11361118 case '=': fornum(ls, varname, line); break;
@@ -1145,7 +1127,7 @@ static void forstat (LexState *ls, int line) { · 8 unmodified lines
11451127 static int test_then_block (LexState *ls) {
11461128 /* test_then_block -> [IF | ELSEIF] cond THEN block */
11471129 int condexit;
1148− next(ls); /* skip IF or ELSEIF */
1130+ luaX_next(ls); /* skip IF or ELSEIF */
11491131 condexit = cond(ls);
11501132 checknext(ls, TK_THEN);
11511133 block(ls); /* `then' part */
@@ -1167,7 +1149,7 @@ static void ifstat (LexState *ls, int line) { · 15 unmodified lines
11671149 if (ls->t.token == TK_ELSE) {
11681150 luaK_concat(fs, &escapelist, luaK_jump(fs));
11691151 luaK_patchtohere(fs, flist);
1170− next(ls); /* skip ELSE (after patch, for correct line info) */
1152+ luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
11711153 block(ls); /* `else' part */
11721154 }
11731155 else
@@ -1228,7 +1210,7 @@ static void funcstat (LexState *ls, int line) { · 54 unmodified lines
12281210 /* funcstat -> FUNCTION funcname body */
12291211 int needself;
12301212 expdesc v, b;
1231− next(ls); /* skip FUNCTION */
1213+ luaX_next(ls); /* skip FUNCTION */
12321214 needself = funcname(ls, &v);
12331215 body(ls, &b, needself, line);
12341216 luaK_storevar(ls->fs, &v, &b);
@@ -1255,7 +1237,7 @@ static void retstat (LexState *ls) { · 20 unmodified lines
12551237 FuncState *fs = ls->fs;
12561238 expdesc e;
12571239 int first, nret; /* registers with returned values */
1258− next(ls); /* skip RETURN */
1240+ luaX_next(ls); /* skip RETURN */
12591241 if (block_follow(ls->t.token) || ls->t.token == ';')
12601242 first = nret = 0; /* return no values */
12611243 else {
@@ -1295,7 +1277,7 @@ static int statement (LexState *ls) { · 33 unmodified lines
12951277 return 0;
12961278 }
12971279 case TK_DO: { /* stat -> DO block END */
1298− next(ls); /* skip DO */
1280+ luaX_next(ls); /* skip DO */
12991281 block(ls);
13001282 check_match(ls, TK_END, TK_DO, line);
13011283 return 0;
@@ -1313,7 +1295,7 @@ static int statement (LexState *ls) { · 11 unmodified lines
13131295 return 0;
13141296 }
13151297 case TK_LOCAL: { /* stat -> localstat */
1316− next(ls); /* skip LOCAL */
1298+ luaX_next(ls); /* skip LOCAL */
13171299 if (testnext(ls, TK_FUNCTION)) /* local function? */
13181300 localfunc(ls);
13191301 else
@@ -1325,7 +1307,7 @@ static int statement (LexState *ls) { · 5 unmodified lines
13251307 return 1; /* must be last statement */
13261308 }
13271309 case TK_BREAK: { /* stat -> breakstat */
1328− next(ls); /* skip BREAK */
1310+ luaX_next(ls); /* skip BREAK */
13291311 breakstat(ls);
13301312 return 1; /* must be last statement */
13311313 }
src/lstring.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp $
2+** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $
33 ** String table (keeps all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
@@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) { · 29 unmodified lines
3535 GCObject *next = p->gch.next; /* save next */
3636 unsigned int h = gco2ts(p)->hash;
3737 int h1 = lmod(h, newsize); /* new position */
38− lua_assert(cast(int, h%newsize) == lmod(h, newsize));
38+ lua_assert(cast_int(h%newsize) == lmod(h, newsize));
3939 p->gch.next = newhash[h1]; /* chain it */
4040 newhash[h1] = p;
4141 p = next;
src/lstrlib.c+38−21
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.127 2005/10/26 13:28:19 roberto Exp $
2+** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -683,8 +683,13 @@ static int str_gsub (lua_State *L) { · 677 unmodified lines
683683
684684 /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
685685 #define MAX_ITEM 512
686−/* maximum size of each format specification (such as '%-099.99d') */
687−#define MAX_FORMAT 20
686+/* valid flags in a format specification */
687+#define FLAGS "-+ #0"
688+/*
689+** maximum size of each format specification (such as '%-099.99d')
690+** (+10 accounts for %99.99x plus margin of error)
691+*/
692+#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
688693
689694
690695 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
@@ -712,30 +717,37 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 21 unmodified lines
712717 luaL_addchar(b, '"');
713718 }
714719
715−
716−static const char *scanformat (lua_State *L, const char *strfrmt,
717− char *form, int *hasprecision) {
720+static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
718721 const char *p = strfrmt;
719− while (strchr("-+ #0", *p)) p++; /* skip flags */
722+ while (strchr(FLAGS, *p)) p++; /* skip flags */
723+ if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
724+ luaL_error(L, "invalid format (repeated flags)");
720725 if (isdigit(uchar(*p))) p++; /* skip width */
721726 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
722727 if (*p == '.') {
723728 p++;
724− *hasprecision = 1;
725729 if (isdigit(uchar(*p))) p++; /* skip precision */
726730 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
727731 }
728732 if (isdigit(uchar(*p)))
729733 luaL_error(L, "invalid format (width or precision too long)");
730− if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
731− luaL_error(L, "invalid format (too long)");
732− form[0] = L_ESC;
733− strncpy(form+1, strfrmt, p-strfrmt+1);
734− form[p-strfrmt+2] = 0;
734+ *(form++) = '%';
735+ strncpy(form, strfrmt, p - strfrmt + 1);
736+ form += p - strfrmt + 1;
737+ *form = '\0';
735738 return p;
736739 }
737740
738741
742+static void addintlen (char *form) {
743+ size_t l = strlen(form);
744+ char spec = form[l - 1];
745+ strcpy(form + l - 1, LUA_INTFRMLEN);
746+ form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
747+ form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
748+}
749+
750+
739751 static int str_format (lua_State *L) {
740752 int arg = 1;
741753 size_t sfl;
@@ -751,21 +763,26 @@ static int str_format (lua_State *L) { · 9 unmodified lines
751763 else { /* format item */
752764 char form[MAX_FORMAT]; /* to store the format (`%...') */
753765 char buff[MAX_ITEM]; /* to store the formatted item */
754− int hasprecision = 0;
755766 arg++;
756− strfrmt = scanformat(L, strfrmt, form, &hasprecision);
767+ strfrmt = scanformat(L, strfrmt, form);
757768 switch (*strfrmt++) {
758− case 'c': case 'd': case 'i': {
759− sprintf(buff, form, luaL_checkint(L, arg));
769+ case 'c': {
770+ sprintf(buff, form, (int)luaL_checknumber(L, arg));
771+ break;
772+ }
773+ case 'd': case 'i': {
774+ addintlen(form);
775+ sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
760776 break;
761777 }
762778 case 'o': case 'u': case 'x': case 'X': {
763− sprintf(buff, form, (unsigned int)(luaL_checknumber(L, arg)));
779+ addintlen(form);
780+ sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
764781 break;
765782 }
766783 case 'e': case 'E': case 'f':
767784 case 'g': case 'G': {
768− sprintf(buff, form, luaL_checknumber(L, arg));
785+ sprintf(buff, form, (double)luaL_checknumber(L, arg));
769786 break;
770787 }
771788 case 'q': {
@@ -775,7 +792,7 @@ static int str_format (lua_State *L) { · 3 unmodified lines
775792 case 's': {
776793 size_t l;
777794 const char *s = luaL_checklstring(L, arg, &l);
778− if (!hasprecision && l >= 100) {
795+ if (!strchr(form, '.') && l >= 100) {
779796 /* no precision and string is too long to be formatted;
780797 keep original string */
781798 lua_pushvalue(L, arg);
@@ -820,7 +837,7 @@ static const luaL_Reg strlib[] = { · 38 unmodified lines
820837
821838
822839 static void createmetatable (lua_State *L) {
823− lua_newtable(L); /* create metatable for strings */
840+ lua_createtable(L, 0, 1); /* create metatable for strings */
824841 lua_pushliteral(L, ""); /* dummy string */
825842 lua_pushvalue(L, -2);
826843 lua_setmetatable(L, -2); /* set string metatable */
src/ltable.c+53−39
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.27 2005/10/24 17:37:52 roberto Exp $
2+** $Id: ltable.c,v 2.31 2006/01/10 13:13:06 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -66,13 +66,15 @@ · 60 unmodified lines
6666 /*
6767 ** number of ints inside a lua_Number
6868 */
69−#define numints cast(int, sizeof(lua_Number)/sizeof(int))
69+#define numints cast_int(sizeof(lua_Number)/sizeof(int))
7070
7171
7272
73−const Node luaH_dummynode = {
73+#define dummynode (&dummynode_)
74+
75+static const Node dummynode_ = {
7476 {{NULL}, LUA_TNIL}, /* value */
75− {{NULL}, LUA_TNIL, NULL} /* key */
77+ {{{NULL}, LUA_TNIL, NULL}} /* key */
7678 };
7779
7880
@@ -95,7 +97,7 @@ static Node *hashnum (const Table *t, lua_Number n) { · 16 unmodified lines
9597 ** returns the `main' position of an element in a table (that is, the index
9698 ** of its hash value)
9799 */
98−Node *luaH_mainposition (const Table *t, const TValue *key) {
100+static Node *mainposition (const Table *t, const TValue *key) {
99101 switch (ttype(key)) {
100102 case LUA_TNUMBER:
101103 return hashnum(t, nvalue(key));
@@ -120,7 +122,7 @@ static int arrayindex (const TValue *key) { · 18 unmodified lines
120122 lua_Number n = nvalue(key);
121123 int k;
122124 lua_number2int(k, n);
123− if (luai_numeq(cast(lua_Number, k), nvalue(key)))
125+ if (luai_numeq(cast_num(k), nvalue(key)))
124126 return k;
125127 }
126128 return -1; /* `key' did not match some condition */
@@ -139,13 +141,13 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 12 unmodified lines
139141 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
140142 return i-1; /* yes; that's the index (corrected to C) */
141143 else {
142− Node *n = luaH_mainposition(t, key);
144+ Node *n = mainposition(t, key);
143145 do { /* check whether `key' is somewhere in the chain */
144146 /* key may be dead already, but it is ok to use it in `next' */
145147 if (luaO_rawequalObj(key2tval(n), key) ||
146148 (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
147149 gcvalue(gkey(n)) == gcvalue(key))) {
148− i = cast(int, n - gnode(t, 0)); /* key index in hash table */
150+ i = cast_int(n - gnode(t, 0)); /* key index in hash table */
149151 /* hash elements are numbered after array ones */
150152 return i + t->sizearray;
151153 }
@@ -161,7 +163,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { · 9 unmodified lines
161163 int i = findindex(L, t, key); /* find original element */
162164 for (i++; i < t->sizearray; i++) { /* try first array part */
163165 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
164− setnvalue(key, cast(lua_Number, i+1));
166+ setnvalue(key, cast_num(i+1));
165167 setobj2s(L, key+1, &t->array[i]);
166168 return 1;
167169 }
@@ -270,7 +272,7 @@ static void setarrayvector (lua_State *L, Table *t, int size) { · 102 unmodified lines
270272 static void setnodevector (lua_State *L, Table *t, int size) {
271273 int lsize;
272274 if (size == 0) { /* no elements to hash part? */
273− t->node = cast(Node *, &luaH_dummynode); /* use common `dummynode' */
275+ t->node = cast(Node *, dummynode); /* use common `dummynode' */
274276 lsize = 0;
275277 }
276278 else {
@@ -281,12 +283,13 @@ static void setnodevector (lua_State *L, Table *t, int size) { · 4 unmodified lines
281283 size = twoto(lsize);
282284 t->node = luaM_newvector(L, size, Node);
283285 for (i=0; i<size; i++) {
284− gnext(&t->node[i]) = NULL;
285− setnilvalue(gkey(gnode(t, i)));
286− setnilvalue(gval(gnode(t, i)));
286+ Node *n = gnode(t, i);
287+ gnext(n) = NULL;
288+ setnilvalue(gkey(n));
289+ setnilvalue(gval(n));
287290 }
288291 }
289− t->lsizenode = cast(lu_byte, lsize);
292+ t->lsizenode = cast_byte(lsize);
290293 t->lastfree = gnode(t, size); /* all positions are free */
291294 }
292295
@@ -316,13 +319,13 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) { · 23 unmodified lines
316319 if (!ttisnil(gval(old)))
317320 setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
318321 }
319− if (nold != &luaH_dummynode)
322+ if (nold != dummynode)
320323 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
321324 }
322325
323326
324327 void luaH_resizearray (lua_State *L, Table *t, int nasize) {
325− int nsize = (t->node == &luaH_dummynode) ? 0 : sizenode(t);
328+ int nsize = (t->node == dummynode) ? 0 : sizenode(t);
326329 resize(L, t, nasize, nsize);
327330 }
328331
@@ -356,12 +359,12 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 27 unmodified lines
356359 Table *t = luaM_new(L, Table);
357360 luaC_link(L, obj2gco(t), LUA_TTABLE);
358361 t->metatable = NULL;
359− t->flags = cast(lu_byte, ~0);
362+ t->flags = cast_byte(~0);
360363 /* temporary values (kept only if some malloc fails) */
361364 t->array = NULL;
362365 t->sizearray = 0;
363366 t->lsizenode = 0;
364− t->node = cast(Node *, &luaH_dummynode);
367+ t->node = cast(Node *, dummynode);
365368 setarrayvector(L, t, narray);
366369 setnodevector(L, t, nhash);
367370 return t;
@@ -369,7 +372,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 1 unmodified line
369372
370373
371374 void luaH_free (lua_State *L, Table *t) {
372− if (t->node != &luaH_dummynode)
375+ if (t->node != dummynode)
373376 luaM_freearray(L, t->node, sizenode(t), Node);
374377 luaM_freearray(L, t->array, t->sizearray, TValue);
375378 luaM_free(L, t);
@@ -394,16 +397,16 @@ static Node *getfreepos (Table *t) { · 18 unmodified lines
394397 ** position), new key goes to an empty position.
395398 */
396399 static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
397− Node *mp = luaH_mainposition(t, key);
398− if (!ttisnil(gval(mp)) || mp == &luaH_dummynode) {
400+ Node *mp = mainposition(t, key);
401+ if (!ttisnil(gval(mp)) || mp == dummynode) {
399402 Node *othern;
400403 Node *n = getfreepos(t); /* get a free place */
401404 if (n == NULL) { /* cannot find a free place? */
402405 rehash(L, t, key); /* grow table */
403406 return luaH_set(L, t, key); /* re-insert key into grown table */
404407 }
405− lua_assert(n != &luaH_dummynode);
406− othern = luaH_mainposition(t, key2tval(mp));
408+ lua_assert(n != dummynode);
409+ othern = mainposition(t, key2tval(mp));
407410 if (othern != mp) { /* is colliding node out of its main position? */
408411 /* yes; move colliding node into free position */
409412 while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
@@ -434,14 +437,14 @@ const TValue *luaH_getnum (Table *t, int key) { · 24 unmodified lines
434437 if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
435438 return &t->array[key-1];
436439 else {
437− lua_Number nk = cast(lua_Number, key);
440+ lua_Number nk = cast_num(key);
438441 Node *n = hashnum(t, nk);
439442 do { /* check whether `key' is somewhere in the chain */
440443 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
441444 return gval(n); /* that's it */
442445 else n = gnext(n);
443446 } while (n);
444− return &luaO_nilobject;
447+ return luaO_nilobject;
445448 }
446449 }
447450
@@ -456,7 +459,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 8 unmodified lines
456459 return gval(n); /* that's it */
457460 else n = gnext(n);
458461 } while (n);
459− return &luaO_nilobject;
462+ return luaO_nilobject;
460463 }
461464
462465
@@ -465,24 +468,24 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 2 unmodified lines
465468 */
466469 const TValue *luaH_get (Table *t, const TValue *key) {
467470 switch (ttype(key)) {
468− case LUA_TNIL: return &luaO_nilobject;
471+ case LUA_TNIL: return luaO_nilobject;
469472 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
470473 case LUA_TNUMBER: {
471474 int k;
472475 lua_Number n = nvalue(key);
473476 lua_number2int(k, n);
474− if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */
477+ if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
475478 return luaH_getnum(t, k); /* use specialized version */
476479 /* else go through */
477480 }
478481 default: {
479− Node *n = luaH_mainposition(t, key);
482+ Node *n = mainposition(t, key);
480483 do { /* check whether `key' is somewhere in the chain */
481484 if (luaO_rawequalObj(key2tval(n), key))
482485 return gval(n); /* that's it */
483486 else n = gnext(n);
484487 } while (n);
485− return &luaO_nilobject;
488+ return luaO_nilobject;
486489 }
487490 }
488491 }
@@ -491,11 +494,11 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 2 unmodified lines
491494 TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
492495 const TValue *p = luaH_get(t, key);
493496 t->flags = 0;
494− if (p != &luaO_nilobject)
497+ if (p != luaO_nilobject)
495498 return cast(TValue *, p);
496499 else {
497500 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
498− else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key)))
501+ else if (ttisnumber(key) && luai_numisnan(nvalue(key)))
499502 luaG_runerror(L, "table index is NaN");
500503 return newkey(L, t, key);
501504 }
@@ -504,11 +507,11 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 2 unmodified lines
504507
505508 TValue *luaH_setnum (lua_State *L, Table *t, int key) {
506509 const TValue *p = luaH_getnum(t, key);
507− if (p != &luaO_nilobject)
510+ if (p != luaO_nilobject)
508511 return cast(TValue *, p);
509512 else {
510513 TValue k;
511− setnvalue(&k, cast(lua_Number, key));
514+ setnvalue(&k, cast_num(key));
512515 return newkey(L, t, &k);
513516 }
514517 }
@@ -516,7 +519,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) { · 1 unmodified line
516519
517520 TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
518521 const TValue *p = luaH_getstr(t, key);
519− if (p != &luaO_nilobject)
522+ if (p != luaO_nilobject)
520523 return cast(TValue *, p);
521524 else {
522525 TValue k;
@@ -528,11 +531,11 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { · 5 unmodified lines
528531
529532 static int unbound_search (Table *t, unsigned int j) {
530533 unsigned int i = j; /* i is zero or a present index */
531− j = j+1;
534+ j++;
532535 /* find `i' and `j' such that i is present and j is not */
533536 while (!ttisnil(luaH_getnum(t, j))) {
534537 i = j;
535− j = i*2;
538+ j *= 2;
536539 if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
537540 /* table was built with bad purposes: resort to linear search */
538541 i = 1;
@@ -541,7 +544,7 @@ static int unbound_search (Table *t, unsigned int j) { · 2 unmodified lines
541544 }
542545 }
543546 /* now do a binary search between them */
544− while (i < j-1) {
547+ while (j - i > 1) {
545548 unsigned int m = (i+j)/2;
546549 if (ttisnil(luaH_getnum(t, m))) j = m;
547550 else i = m;
@@ -567,8 +570,19 @@ int luaH_getn (Table *t) { · 19 unmodified lines
567570 return i;
568571 }
569572 /* else must find a boundary in hash part */
570− else if (t->node == &luaH_dummynode) /* hash part is empty? */
573+ else if (t->node == dummynode) /* hash part is empty? */
571574 return j; /* that is easy... */
572575 else return unbound_search(t, j);
573576 }
574577
578+
579+
580+#if defined(LUA_DEBUG)
581+
582+Node *luaH_mainposition (const Table *t, const TValue *key) {
583+ return mainposition(t, key);
584+}
585+
586+int luaH_isdummy (Node *n) { return n == dummynode; }
587+
588+#endif
src/ltable.h+8−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.h,v 2.8 2005/06/06 13:30:25 roberto Exp $
2+** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -11,15 +11,13 @@ · 5 unmodified lines
1111
1212
1313 #define gnode(t,i) (&(t)->node[i])
14−#define gkey(n) (&(n)->i_key)
14+#define gkey(n) (&(n)->i_key.nk)
1515 #define gval(n) (&(n)->i_val)
16−#define gnext(n) ((n)->i_key.next)
16+#define gnext(n) ((n)->i_key.nk.next)
1717
18−#define key2tval(n) (cast(const TValue *, gkey(n)))
18+#define key2tval(n) (&(n)->i_key.tvk)
1919
2020
21−LUAI_DATA const Node luaH_dummynode;
22−
2321 LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
2422 LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
2523 LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
@@ -32,8 +30,11 @@ LUAI_FUNC void luaH_free (lua_State *L, Table *t); · 6 unmodified lines
3230 LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
3331 LUAI_FUNC int luaH_getn (Table *t);
3432
35−/* exported only for debugging */
33+
34+#if defined(LUA_DEBUG)
3635 LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
36+LUAI_FUNC int luaH_isdummy (Node *n);
37+#endif
3738
3839
3940 #endif
src/ltm.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltm.c,v 2.6 2005/05/20 15:53:42 roberto Exp $
2+** $Id: ltm.c,v 2.8 2006/01/10 12:50:00 roberto Exp $
33 ** Tag methods
44 ** See Copyright Notice in lua.h
55 */
@@ -51,7 +51,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { · 45 unmodified lines
5151 const TValue *tm = luaH_getstr(events, ename);
5252 lua_assert(event <= TM_EQ);
5353 if (ttisnil(tm)) { /* no tag method? */
54− events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */
54+ events->flags |= cast_byte(1u<<event); /* cache this fact */
5555 return NULL;
5656 }
5757 else return tm;
@@ -70,6 +70,6 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { · 12 unmodified lines
7070 default:
7171 mt = G(L)->mt[ttype(o)];
7272 }
73− return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);
73+ return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
7474 }
7575
src/lua.c+9−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.154 2005/10/24 17:38:47 roberto Exp $
2+** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -120,7 +120,7 @@ static int getargs (lua_State *L, char **argv, int n) { · 114 unmodified lines
120120 luaL_checkstack(L, narg + 3, "too many arguments to script");
121121 for (i=n+1; i < argc; i++)
122122 lua_pushstring(L, argv[i]);
123− lua_newtable(L);
123+ lua_createtable(L, narg, n + 1);
124124 for (i=0; i < argc; i++) {
125125 lua_pushstring(L, argv[i]);
126126 lua_rawseti(L, -2, i - n);
@@ -215,7 +215,6 @@ static void dotty (lua_State *L) { · 88 unmodified lines
215215 int status;
216216 const char *oldprogname = progname;
217217 progname = NULL;
218− print_version();
219218 while ((status = loadline(L)) != -1) {
220219 if (status == 0) status = docall(L, 0, 0);
221220 report(L, status);
@@ -261,7 +260,7 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 39 unmodified lines
261260 switch (argv[i][1]) { /* option */
262261 case '-': return (argv[i+1] != NULL ? i+1 : 0);
263262 case '\0': return i;
264− case 'i': *pi = 1; break;
263+ case 'i': *pi = 1; /* go through */
265264 case 'v': *pv = 1; break;
266265 case 'e': *pe = 1; /* go through */
267266 case 'l':
@@ -330,7 +329,9 @@ static int pmain (lua_State *L) { · 62 unmodified lines
330329 int has_i = 0, has_v = 0, has_e = 0;
331330 globalL = L;
332331 if (argv[0] && argv[0][0]) progname = argv[0];
332+ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
333333 luaL_openlibs(L); /* open libraries */
334+ lua_gc(L, LUA_GCRESTART, 0);
334335 s->status = handle_luainit(L);
335336 if (s->status != 0) return 0;
336337 script = collectargs(argv, &has_i, &has_v, &has_e);
@@ -348,7 +349,10 @@ static int pmain (lua_State *L) { · 11 unmodified lines
348349 if (has_i)
349350 dotty(L);
350351 else if (script == 0 && !has_e && !has_v) {
351− if (lua_stdin_is_tty()) dotty(L);
352+ if (lua_stdin_is_tty()) {
353+ print_version();
354+ dotty(L);
355+ }
352356 else dofile(L, NULL); /* executes stdin as a file */
353357 }
354358 return 0;
src/lua.h+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.214 2005/10/20 11:35:50 roberto Exp $
2+** $Id: lua.h,v 1.216 2006/01/10 12:50:13 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -16,9 +16,9 @@ · 10 unmodified lines
1616 #include "luaconf.h"
1717
1818
19−#define LUA_VERSION "Lua 5.1 (beta)"
19+#define LUA_VERSION "Lua 5.1"
2020 #define LUA_VERSION_NUM 501
21−#define LUA_COPYRIGHT "Copyright (C) 1994-2005 Lua.org, PUC-Rio"
21+#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
2222 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2323
2424
@@ -358,7 +358,7 @@ struct lua_Debug { · 333 unmodified lines
358358
359359
360360 /******************************************************************************
361−* Copyright (C) 1994-2005 Lua.org, PUC-Rio. All rights reserved.
361+* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.
362362 *
363363 * Permission is hereby granted, free of charge, to any person obtaining
364364 * a copy of this software and associated documentation files (the
src/luaconf.h+31−13
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.74 2005/11/16 16:24:28 roberto Exp $
2+** $Id: luaconf.h,v 1.77 2005/12/27 17:12:00 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -28,6 +28,11 @@ · 22 unmodified lines
2828 #define LUA_ANSI
2929 #endif
3030
31+
32+#if !defined(LUA_ANSI) && defined(_WIN32)
33+#define LUA_WIN
34+#endif
35+
3136 #if defined(LUA_USE_LINUX)
3237 #define LUA_USE_POSIX
3338 #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
@@ -177,13 +182,6 @@ · 143 unmodified lines
177182
178183
179184
180−/*
181−@@ lua_assert describes the internal assertions in Lua.
182−** CHANGE that only if you need to debug Lua.
183−*/
184−#define lua_assert(c) ((void)0)
185−
186−
187185 /*
188186 @@ LUA_QL describes how error messages quote program elements.
189187 ** CHANGE it if you want a different appearance.
@@ -217,7 +215,7 @@ · 27 unmodified lines
217215 #if defined(LUA_USE_ISATTY)
218216 #include <unistd.h>
219217 #define lua_stdin_is_tty() isatty(0)
220−#elif !defined(LUA_ANSI) && defined(_WIN32)
218+#elif defined(LUA_WIN)
221219 #include <io.h>
222220 #include <stdio.h>
223221 #define lua_stdin_is_tty() _isatty(_fileno(stdin))
@@ -368,8 +366,7 @@ · 144 unmodified lines
368366 #include <assert.h>
369367 #define luai_apicheck(L,o) { (void)L; assert(o); }
370368 #else
371−/* (By default lua_assert is empty, so luai_apicheck is also empty.) */
372−#define luai_apicheck(L,o) { (void)L; lua_assert(o); }
369+#define luai_apicheck(L,o) { (void)L; }
373370 #endif
374371
375372
@@ -529,6 +526,7 @@ · 153 unmodified lines
529526 #define luai_numeq(a,b) ((a)==(b))
530527 #define luai_numlt(a,b) ((a)<(b))
531528 #define luai_numle(a,b) ((a)<=(b))
529+#define luai_numisnan(a) (!luai_numeq((a), (a)))
532530 #endif
533531
534532
@@ -644,7 +642,7 @@ union luai_Cast { double l_d; long l_l; }; · 109 unmodified lines
644642 #define lua_popen(L,c,m) ((void)L, popen(c,m))
645643 #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
646644
647−#elif !defined(LUA_ANSI) && defined(_WIN32)
645+#elif defined(LUA_WIN)
648646
649647 #define lua_popen(L,c,m) ((void)L, _popen(c,m))
650648 #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
@@ -675,7 +673,7 @@ union luai_Cast { double l_d; long l_l; }; · 24 unmodified lines
675673 #define LUA_DL_DLOPEN
676674 #endif
677675
678−#if !defined(LUA_ANSI) && defined(_WIN32)
676+#if defined(LUA_WIN)
679677 #define LUA_DL_DLL
680678 #endif
681679
@@ -702,6 +700,26 @@ union luai_Cast { double l_d; long l_l; }; · 20 unmodified lines
702700 #define luai_userstateyield(L,n) ((void)L)
703701
704702
703+/*
704+@@ LUA_INTFRMLEN is the length modifier for integer conversions
705+@* in 'string.fomat'.
706+@@ LUA_INTFRM_T is the integer type correspoding to the previous length
707+@* modifier.
708+** CHANGE them if your system supports long long or does not support long.
709+*/
710+
711+#if defined(LUA_USELONGLONG)
712+
713+#define LUA_INTFRMLEN "ll"
714+#define LUA_INTFRM_T long long
715+
716+#else
717+
718+#define LUA_INTFRMLEN "l"
719+#define LUA_INTFRM_T long
720+
721+#endif
722+
705723
706724
707725 /* =================================================================== */
src/lualib.h+7−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lualib.h,v 1.35 2005/08/10 18:06:58 roberto Exp $
2+** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $
33 ** Lua standard libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -44,4 +44,10 @@ LUALIB_API int (luaopen_package) (lua_State *L); · 38 unmodified lines
4444 LUALIB_API void (luaL_openlibs) (lua_State *L);
4545
4646
47+
48+#ifndef lua_assert
49+#define lua_assert(x) ((void)0)
50+#endif
51+
52+
4753 #endif
src/lvm.c+7−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 2.59 2005/11/01 16:08:45 roberto Exp $
2+** $Id: lvm.c,v 2.61 2006/01/10 12:50:00 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -509,16 +509,16 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 503 unmodified lines
509509 const TValue *rb = RB(i);
510510 switch (ttype(rb)) {
511511 case LUA_TTABLE: {
512− setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb))));
512+ setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
513513 break;
514514 }
515515 case LUA_TSTRING: {
516− setnvalue(ra, cast(lua_Number, tsvalue(rb)->len));
516+ setnvalue(ra, cast_num(tsvalue(rb)->len));
517517 break;
518518 }
519519 default: { /* try metamethod */
520520 Protect(
521− if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN))
521+ if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
522522 luaG_typeerror(L, rb, "get length of");
523523 )
524524 }
@@ -693,10 +693,10 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 168 unmodified lines
693693 int last;
694694 Table *h;
695695 if (n == 0) {
696− n = cast(int, L->top - ra) - 1;
696+ n = cast_int(L->top - ra) - 1;
697697 L->top = L->ci->top;
698698 }
699− if (c == 0) c = cast(int, *pc++);
699+ if (c == 0) c = cast_int(*pc++);
700700 runtime_check(L, ttistable(ra));
701701 h = hvalue(ra);
702702 last = ((c-1)*LFIELDS_PER_FLUSH) + n;
@@ -737,7 +737,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 34 unmodified lines
737737 int b = GETARG_B(i) - 1;
738738 int j;
739739 CallInfo *ci = L->ci;
740− int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1;
740+ int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
741741 if (b == LUA_MULTRET) {
742742 Protect(luaD_checkstack(L, n));
743743 ra = RA(i); /* previous call may change the stack */
src/print.c+5−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.53 2005/11/11 14:03:13 lhf Exp $
2+** $Id: print.c,v 1.54 2006/01/11 22:49:27 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -36,7 +36,10 @@ static void PrintString(const Proto* f, int n) · 30 unmodified lines
3636 case '\r': printf("\\r"); break;
3737 case '\t': printf("\\t"); break;
3838 case '\v': printf("\\v"); break;
39− default: printf(isprint((unsigned char)*s) ? "%c" : "\\%03d",*s);
39+ default: if (isprint((unsigned char)*s))
40+ printf("%c",*s);
41+ else
42+ printf("\\%03u",(unsigned char)*s);
4043 }
4144 }
4245 putchar('"');