History

Lua 5.1-work3

Lua Team committed 21 years ago

Commit ec3e02b1 parent cdf85b646 files · +1107 −738Browse files

Unified · Split

46 files
  1. INSTALL +1 −1
  2. MANIFEST +114 −113
  3. Makefile +2 −25
  4. README +3 −2
  5. config +3 −3
  6. etc/all.c +0 −1
  7. etc/lua.hpp +8 −0
  8. etc/min.c +1 −0
  9. include/lauxlib.h +14 −8
  10. include/lua.h +26 −20
  11. include/luaconf.h +77 −33
  12. src/lapi.c +52 −42
  13. src/lcode.c +50 −27
  14. src/lcode.h +2 −1
  15. src/ldebug.c +15 −8
  16. src/ldo.c +5 −7
  17. src/ldump.c +6 −3
  18. src/lfunc.c +4 −4
  19. src/lgc.c +25 −25
  20. src/lib/lauxlib.c +68 −10
  21. src/lib/lbaselib.c +13 −63
  22. src/lib/ldblib.c +5 −4
  23. src/lib/loadlib.c +319 −78
  24. src/lib/loslib.c +4 −4
  25. src/lib/lstrlib.c +24 −26
  26. src/llex.c +41 −35
  27. src/llex.h +7 −3
  28. src/llimits.h +6 −17
  29. src/lmem.c +14 −11
  30. src/lmem.h +22 −16
  31. src/lobject.c +16 −7
  32. src/lobject.h +15 −7
  33. src/lopcodes.c +5 −6
  34. src/lopcodes.h +10 −8
  35. src/lparser.c +16 −19
  36. src/lstate.c +6 −4
  37. src/lstate.h +3 −1
  38. src/lstring.c +9 −4
  39. src/lstring.h +3 −4
  40. src/ltable.c +45 −40
  41. src/ltable.h +4 −1
  42. src/lua/lua.c +4 −4
  43. src/luac/print.c +8 −5
  44. src/lundump.c +10 −11
  45. src/lundump.h +5 −7
  46. src/lvm.c +17 −20
INSTALL+1−1
@@ -32,7 +32,7 @@ This is Lua 5.1 (work). · 31 unmodified lines
3232
3333 * If you have problems (and solutions!)
3434 -------------------------------------
35− If "make" fails, please let us know (lua@tecgraf.puc-rio.br).
35+ If "make" fails, please let us know.
3636 If you make changes to "config" or to the Makefiles, please send them to us.
3737
3838 * Shared libraries
MANIFEST+114−113
@@ -1,114 +1,115 @@
1−MANIFEST contents of Lua 5.1 (work2) distribution on Mon Sep 20 21:28:06 BRT 2004
2−lua-5.1-work2
3−lua-5.1-work2/COPYRIGHT
4−lua-5.1-work2/HISTORY
5−lua-5.1-work2/INSTALL
6−lua-5.1-work2/MANIFEST
7−lua-5.1-work2/Makefile
8−lua-5.1-work2/README
9−lua-5.1-work2/bin
10−lua-5.1-work2/build
11−lua-5.1-work2/config
12−lua-5.1-work2/etc
13−lua-5.1-work2/etc/Makefile
14−lua-5.1-work2/etc/README
15−lua-5.1-work2/etc/all.c
16−lua-5.1-work2/etc/lua.ico
17−lua-5.1-work2/etc/min.c
18−lua-5.1-work2/etc/noparser.c
19−lua-5.1-work2/etc/saconfig.c
20−lua-5.1-work2/include
21−lua-5.1-work2/include/Makefile
22−lua-5.1-work2/include/lauxlib.h
23−lua-5.1-work2/include/lua.h
24−lua-5.1-work2/include/luaconf.h
25−lua-5.1-work2/include/lualib.h
26−lua-5.1-work2/lib
27−lua-5.1-work2/src
28−lua-5.1-work2/src/Makefile
29−lua-5.1-work2/src/README
30−lua-5.1-work2/src/lapi.c
31−lua-5.1-work2/src/lapi.h
32−lua-5.1-work2/src/lcode.c
33−lua-5.1-work2/src/lcode.h
34−lua-5.1-work2/src/ldebug.c
35−lua-5.1-work2/src/ldebug.h
36−lua-5.1-work2/src/ldo.c
37−lua-5.1-work2/src/ldo.h
38−lua-5.1-work2/src/ldump.c
39−lua-5.1-work2/src/lfunc.c
40−lua-5.1-work2/src/lfunc.h
41−lua-5.1-work2/src/lgc.c
42−lua-5.1-work2/src/lgc.h
43−lua-5.1-work2/src/lib
44−lua-5.1-work2/src/lib/Makefile
45−lua-5.1-work2/src/lib/README
46−lua-5.1-work2/src/lib/lauxlib.c
47−lua-5.1-work2/src/lib/lbaselib.c
48−lua-5.1-work2/src/lib/ldblib.c
49−lua-5.1-work2/src/lib/linit.c
50−lua-5.1-work2/src/lib/liolib.c
51−lua-5.1-work2/src/lib/lmathlib.c
52−lua-5.1-work2/src/lib/loadlib.c
53−lua-5.1-work2/src/lib/loslib.c
54−lua-5.1-work2/src/lib/lstrlib.c
55−lua-5.1-work2/src/lib/ltablib.c
56−lua-5.1-work2/src/llex.c
57−lua-5.1-work2/src/llex.h
58−lua-5.1-work2/src/llimits.h
59−lua-5.1-work2/src/lmem.c
60−lua-5.1-work2/src/lmem.h
61−lua-5.1-work2/src/lobject.c
62−lua-5.1-work2/src/lobject.h
63−lua-5.1-work2/src/lopcodes.c
64−lua-5.1-work2/src/lopcodes.h
65−lua-5.1-work2/src/lparser.c
66−lua-5.1-work2/src/lparser.h
67−lua-5.1-work2/src/lstate.c
68−lua-5.1-work2/src/lstate.h
69−lua-5.1-work2/src/lstring.c
70−lua-5.1-work2/src/lstring.h
71−lua-5.1-work2/src/ltable.c
72−lua-5.1-work2/src/ltable.h
73−lua-5.1-work2/src/ltm.c
74−lua-5.1-work2/src/ltm.h
75−lua-5.1-work2/src/lua
76−lua-5.1-work2/src/lua/Makefile
77−lua-5.1-work2/src/lua/README
78−lua-5.1-work2/src/lua/lua.c
79−lua-5.1-work2/src/luac
80−lua-5.1-work2/src/luac/Makefile
81−lua-5.1-work2/src/luac/README
82−lua-5.1-work2/src/luac/luac.c
83−lua-5.1-work2/src/luac/print.c
84−lua-5.1-work2/src/lundump.c
85−lua-5.1-work2/src/lundump.h
86−lua-5.1-work2/src/lvm.c
87−lua-5.1-work2/src/lvm.h
88−lua-5.1-work2/src/lzio.c
89−lua-5.1-work2/src/lzio.h
90−lua-5.1-work2/test
91−lua-5.1-work2/test/README
92−lua-5.1-work2/test/bisect.lua
93−lua-5.1-work2/test/cf.lua
94−lua-5.1-work2/test/echo.lua
95−lua-5.1-work2/test/env.lua
96−lua-5.1-work2/test/factorial.lua
97−lua-5.1-work2/test/fib.lua
98−lua-5.1-work2/test/fibfor.lua
99−lua-5.1-work2/test/globals.lua
100−lua-5.1-work2/test/hello.lua
101−lua-5.1-work2/test/life.lua
102−lua-5.1-work2/test/lua
103−lua-5.1-work2/test/luac
104−lua-5.1-work2/test/luac.lua
105−lua-5.1-work2/test/printf.lua
106−lua-5.1-work2/test/readonly.lua
107−lua-5.1-work2/test/sieve.lua
108−lua-5.1-work2/test/sort.lua
109−lua-5.1-work2/test/table.lua
110−lua-5.1-work2/test/trace-calls.lua
111−lua-5.1-work2/test/trace-globals.lua
112−lua-5.1-work2/test/undefined.lua
113−lua-5.1-work2/test/xd.lua
1+MANIFEST contents of Lua 5.1 (work3) distribution on Mon Dec 6 23:00:22 BRST 2004
2+lua-5.1-work3
3+lua-5.1-work3/COPYRIGHT
4+lua-5.1-work3/HISTORY
5+lua-5.1-work3/INSTALL
6+lua-5.1-work3/MANIFEST
7+lua-5.1-work3/Makefile
8+lua-5.1-work3/README
9+lua-5.1-work3/bin
10+lua-5.1-work3/build
11+lua-5.1-work3/config
12+lua-5.1-work3/etc
13+lua-5.1-work3/etc/Makefile
14+lua-5.1-work3/etc/README
15+lua-5.1-work3/etc/all.c
16+lua-5.1-work3/etc/lua.hpp
17+lua-5.1-work3/etc/lua.ico
18+lua-5.1-work3/etc/min.c
19+lua-5.1-work3/etc/noparser.c
20+lua-5.1-work3/etc/saconfig.c
21+lua-5.1-work3/include
22+lua-5.1-work3/include/Makefile
23+lua-5.1-work3/include/lauxlib.h
24+lua-5.1-work3/include/lua.h
25+lua-5.1-work3/include/luaconf.h
26+lua-5.1-work3/include/lualib.h
27+lua-5.1-work3/lib
28+lua-5.1-work3/src
29+lua-5.1-work3/src/Makefile
30+lua-5.1-work3/src/README
31+lua-5.1-work3/src/lapi.c
32+lua-5.1-work3/src/lapi.h
33+lua-5.1-work3/src/lcode.c
34+lua-5.1-work3/src/lcode.h
35+lua-5.1-work3/src/ldebug.c
36+lua-5.1-work3/src/ldebug.h
37+lua-5.1-work3/src/ldo.c
38+lua-5.1-work3/src/ldo.h
39+lua-5.1-work3/src/ldump.c
40+lua-5.1-work3/src/lfunc.c
41+lua-5.1-work3/src/lfunc.h
42+lua-5.1-work3/src/lgc.c
43+lua-5.1-work3/src/lgc.h
44+lua-5.1-work3/src/lib
45+lua-5.1-work3/src/lib/Makefile
46+lua-5.1-work3/src/lib/README
47+lua-5.1-work3/src/lib/lauxlib.c
48+lua-5.1-work3/src/lib/lbaselib.c
49+lua-5.1-work3/src/lib/ldblib.c
50+lua-5.1-work3/src/lib/linit.c
51+lua-5.1-work3/src/lib/liolib.c
52+lua-5.1-work3/src/lib/lmathlib.c
53+lua-5.1-work3/src/lib/loadlib.c
54+lua-5.1-work3/src/lib/loslib.c
55+lua-5.1-work3/src/lib/lstrlib.c
56+lua-5.1-work3/src/lib/ltablib.c
57+lua-5.1-work3/src/llex.c
58+lua-5.1-work3/src/llex.h
59+lua-5.1-work3/src/llimits.h
60+lua-5.1-work3/src/lmem.c
61+lua-5.1-work3/src/lmem.h
62+lua-5.1-work3/src/lobject.c
63+lua-5.1-work3/src/lobject.h
64+lua-5.1-work3/src/lopcodes.c
65+lua-5.1-work3/src/lopcodes.h
66+lua-5.1-work3/src/lparser.c
67+lua-5.1-work3/src/lparser.h
68+lua-5.1-work3/src/lstate.c
69+lua-5.1-work3/src/lstate.h
70+lua-5.1-work3/src/lstring.c
71+lua-5.1-work3/src/lstring.h
72+lua-5.1-work3/src/ltable.c
73+lua-5.1-work3/src/ltable.h
74+lua-5.1-work3/src/ltm.c
75+lua-5.1-work3/src/ltm.h
76+lua-5.1-work3/src/lua
77+lua-5.1-work3/src/lua/Makefile
78+lua-5.1-work3/src/lua/README
79+lua-5.1-work3/src/lua/lua.c
80+lua-5.1-work3/src/luac
81+lua-5.1-work3/src/luac/Makefile
82+lua-5.1-work3/src/luac/README
83+lua-5.1-work3/src/luac/luac.c
84+lua-5.1-work3/src/luac/print.c
85+lua-5.1-work3/src/lundump.c
86+lua-5.1-work3/src/lundump.h
87+lua-5.1-work3/src/lvm.c
88+lua-5.1-work3/src/lvm.h
89+lua-5.1-work3/src/lzio.c
90+lua-5.1-work3/src/lzio.h
91+lua-5.1-work3/test
92+lua-5.1-work3/test/README
93+lua-5.1-work3/test/bisect.lua
94+lua-5.1-work3/test/cf.lua
95+lua-5.1-work3/test/echo.lua
96+lua-5.1-work3/test/env.lua
97+lua-5.1-work3/test/factorial.lua
98+lua-5.1-work3/test/fib.lua
99+lua-5.1-work3/test/fibfor.lua
100+lua-5.1-work3/test/globals.lua
101+lua-5.1-work3/test/hello.lua
102+lua-5.1-work3/test/life.lua
103+lua-5.1-work3/test/lua
104+lua-5.1-work3/test/luac
105+lua-5.1-work3/test/luac.lua
106+lua-5.1-work3/test/printf.lua
107+lua-5.1-work3/test/readonly.lua
108+lua-5.1-work3/test/sieve.lua
109+lua-5.1-work3/test/sort.lua
110+lua-5.1-work3/test/table.lua
111+lua-5.1-work3/test/trace-calls.lua
112+lua-5.1-work3/test/trace-globals.lua
113+lua-5.1-work3/test/undefined.lua
114+lua-5.1-work3/test/xd.lua
114115 END OF MANIFEST
Makefile+2−25
@@ -14,8 +14,6 @@ all clean co klean: · 13 unmodified lines
1414 cd src/luac; $(MAKE) $@
1515 cd src/lua; $(MAKE) $@
1616
17−clean klean: soclean
18−
1917 # in case they were not created during unpacking
2018 all: bin lib
2119
@@ -38,27 +36,6 @@ install: all strip · 16 unmodified lines
3836 $(INSTALL_DATA) lib/*.a $(INSTALL_LIB)
3937 $(INSTALL_DATA) doc/*.1 $(INSTALL_MAN)
4038
41−# shared libraries (for Linux)
42−so:
43− ld -o lib/liblua.so.$V -shared src/*.o
44− ld -o lib/liblualib.so.$V -shared src/lib/*.o
45− cd lib; ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so
46−
47−# binaries using shared libraries
48−sobin:
49− rm -f bin/lua*
50− cd src/lua; $(MAKE)
51− cd src/luac; $(MAKE)
52−
53−# install shared libraries
54−soinstall:
55− $(INSTALL_EXEC) lib/*.so.* $(INSTALL_LIB)
56− cd $(INSTALL_LIB); ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so
57−
58−# clean shared libraries
59−soclean:
60− rm -f lib/*.so* bin/lua*
61−
6239 # echo config parameters
6340 echo:
6441 @echo ""
@@ -98,7 +75,7 @@ lecho: · 33 unmodified lines
9875 @make echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/'
9976 @echo "-- EOF"
10077
101−# (end of Makefile)
102−
10378 newer:
10479 @find . -newer MANIFEST -type f
80+
81+# (end of Makefile)
README+3−2
@@ -29,9 +29,10 @@ See HISTORY for a summary of changes since the last released version. · 28 unmodified lines
2929
3030 * Contacting the authors
3131 ----------------------
32− Send your comments, questions, and bug reports to lua@tecgraf.puc-rio.br.
32+ Send your comments, questions, and bug reports to
33+ lua-team AT tecgraf.puc-rio.br.
3334 For more information about the authors, see http://www.lua.org/authors.html .
34− For reporting bugs, try also the mailing list: lua-l@tecgraf.puc-rio.br.
35+ For reporting bugs, try also the mailing list: lua@bazar2.conectiva.com.br .
3536 For more information about this list, including instructions on how to
3637 subscribe and access the archives, see http://www.lua.org/lua-l.html .
3738
config+3−3
@@ -21,15 +21,15 @@ USERCONF= · 20 unmodified lines
2121 # interface (e.g., Linux, Solaris, IRIX, BSD, AIX, HPUX, and probably others),
2222 # uncomment the next two lines. Also read the next paragraph.
2323 #
24−#LOADLIB= -DUSE_DLOPEN=1
25−#DLLIB= -ldl
24+LOADLIB= -DUSE_DLOPEN=1
25+DLLIB= -ldl
2626 #
2727 # In Linux with gcc, you should also uncomment the next definition for
2828 # MYLDFLAGS, which passes -E (= -export-dynamic) to the linker. This option
2929 # allows dynamic libraries to link back to the `lua' program, so that they do
3030 # not need the Lua libraries. (Other systems may have an equivalent facility.)
3131 #
32−#MYLDFLAGS= -Wl,-E
32+MYLDFLAGS= -Wl,-E
3333 #
3434 # On Windows systems. support for dynamic loading is enabled by default.
3535 # To disable this support, uncomment the next line.
etc/all.c+0−1
@@ -33,7 +33,6 @@ · 32 unmodified lines
3333 #include "linit.c"
3434 #include "lmathlib.c"
3535 #include "loadlib.c"
36−#define pushresult pushresult2
3736 #include "loslib.c"
3837 #include "lstrlib.c"
3938 #include "ltablib.c"
etc/lua.hpp+8−0
@@ -0,0 +1,8 @@
1+// lua.hpp
2+// Lua header files for C++
3+
4+extern "C" {
5+#include "lua.h"
6+#include "lualib.h"
7+#include "lauxlib.h"
8+}
etc/min.c+1−0
@@ -43,5 +43,6 @@ int main(void) · 42 unmodified lines
4343 lua_register(L,"print",print);
4444 if (lua_load(L,getF,stdin,"=stdin") || lua_pcall(L,0,0,0))
4545 fprintf(stderr,"%s\n",lua_tostring(L,-1));
46+ lua_close(L);
4647 return 0;
4748 }
include/lauxlib.h+14−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.70 2004/07/09 18:23:17 roberto Exp $
2+** $Id: lauxlib.h,v 1.73 2004/10/18 12:51:44 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -70,6 +70,12 @@ LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t sz, · 64 unmodified lines
7070 LUALIB_API lua_State *(luaL_newstate) (void);
7171
7272
73+LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
74+ const char *r);
75+LUALIB_API const char *luaL_getfield (lua_State *L, int idx, const char *fname);
76+LUALIB_API const char *luaL_setfield (lua_State *L, int idx, const char *fname);
77+
78+
7379
7480 /*
7581 ** ===============================================================
@@ -78,15 +84,15 @@ LUALIB_API lua_State *(luaL_newstate) (void); · 2 unmodified lines
7884 */
7985
8086 #define luaL_argcheck(L, cond,numarg,extramsg) \
81− ((void)((cond) || luaL_argerror(L, numarg,extramsg)))
87+ ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
8288 #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
8389 #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
84−#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, n))
85−#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, n,d))
86−#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, n))
87−#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, n,d))
90+#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
91+#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
92+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
93+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
8894
89−#define luaL_typename(L,i) lua_typename(L,lua_type(L,(i)))
95+#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
9096
9197 /*
9298 ** {======================================================
@@ -131,7 +137,7 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B); · 38 unmodified lines
131137
132138 #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
133139
134−#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, ref)
140+#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
135141
136142
137143 #endif
include/lua.h+26−20
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.193 2004/09/15 20:39:42 roberto Exp $
2+** $Id: lua.h,v 1.196 2004/12/06 17:53:42 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
55 ** http://www.lua.org mailto:info@lua.org
@@ -17,7 +17,7 @@ · 11 unmodified lines
1717 #include "luaconf.h"
1818
1919
20−#define LUA_VERSION "Lua 5.1 (work2)"
20+#define LUA_VERSION "Lua 5.1 (work3)"
2121 #define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
2222 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2323
@@ -81,6 +81,10 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); · 57 unmodified lines
8181 #define LUA_TTHREAD 8
8282
8383
84+/* first index for arrays */
85+#define LUA_FIRSTINDEX 1
86+
87+
8488 /* minimum Lua stack available to a C function */
8589 #define LUA_MINSTACK 20
8690
@@ -216,11 +220,13 @@ LUA_API int lua_threadstatus (lua_State *L); · 129 unmodified lines
216220 ** garbage-collection function and options
217221 */
218222
219−#define LUA_GCSTOP 0
220−#define LUA_GCRESTART 1
221−#define LUA_GCCOLLECT 2
222−#define LUA_GCCOUNT 3
223−#define LUA_GCSTEP 4
223+#define LUA_GCSTOP 0
224+#define LUA_GCRESTART 1
225+#define LUA_GCCOLLECT 2
226+#define LUA_GCCOUNT 3
227+#define LUA_GCSTEP 4
228+#define LUA_GCSETSTEPMUL 5
229+#define LUA_GCSETINCMODE 6
224230
225231 LUA_API int lua_gc (lua_State *L, int what, int data);
226232
@@ -251,26 +257,26 @@ LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud); · 24 unmodified lines
251257
252258 #define lua_newtable(L) lua_createtable(L, 0, 0)
253259
254−#define lua_register(L,n,f) (lua_pushcfunction(L,f), lua_setglobal(L,n))
260+#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
255261
256−#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
262+#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
257263
258−#define lua_strlen(L,i) lua_objsize(L,i)
264+#define lua_strlen(L,i) lua_objsize(L, (i))
259265
260−#define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION)
261−#define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE)
262−#define lua_islightuserdata(L,n) (lua_type(L,n) == LUA_TLIGHTUSERDATA)
263−#define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL)
264−#define lua_isboolean(L,n) (lua_type(L,n) == LUA_TBOOLEAN)
265−#define lua_isthread(L,n) (lua_type(L,n) == LUA_TTHREAD)
266−#define lua_isnone(L,n) (lua_type(L,n) == LUA_TNONE)
267−#define lua_isnoneornil(L, n) (lua_type(L,n) <= 0)
266+#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
267+#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
268+#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
269+#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
270+#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
271+#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
272+#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
273+#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
268274
269275 #define lua_pushliteral(L, s) \
270276 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
271277
272−#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, s)
273−#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, s)
278+#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
279+#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
274280
275281
276282
include/luaconf.h+77−33
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.12 2004/09/10 17:30:46 roberto Exp $
2+** $Id: luaconf.h,v 1.20 2004/12/06 17:53:42 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -31,7 +31,11 @@ · 25 unmodified lines
3131 */
3232
3333 /* default path */
34−#define LUA_PATH_DEFAULT "?;?.lua"
34+#define LUA_PATH_DEFAULT \
35+ "./?.lua;/usr/local/share/lua/5.0/?.lua;/usr/local/share/lua/5.0/?/init.lua"
36+#define LUA_CPATH_DEFAULT \
37+ "./?.so;/usr/local/lib/lua/5.0/?.so;/usr/local/lib/lua/5.0/lib?.so"
38+
3539
3640
3741 /* type of numbers in Lua */
@@ -42,8 +46,11 @@ · 4 unmodified lines
4246 #define LUA_NUMBER_FMT "%.14g"
4347
4448
45−/* type for integer functions */
46−#define LUA_INTEGER long
49+/*
50+** type for integer functions
51+** on most machines, `ptrdiff_t' gives a reasonable size for integers
52+*/
53+#define LUA_INTEGER ptrdiff_t
4754
4855
4956 /* mark for all API functions */
@@ -56,9 +63,6 @@ · 6 unmodified lines
5663 #define LUAL_BUFFERSIZE BUFSIZ
5764
5865
59−/* first index for arrays */
60−#define LUA_FIRSTINDEX 1
61−
6266 /* assertions in Lua (mainly for internal debugging) */
6367 #define lua_assert(c) ((void)0)
6468
@@ -123,19 +127,45 @@ · 58 unmodified lines
123127 #ifdef LUA_CORE
124128
125129 /* LUA-C API assertions */
126−#define api_check(L, o) lua_assert(o)
130+#define api_check(L,o) lua_assert(o)
127131
128132
129−/* an unsigned integer with at least 32 bits */
130−#define LUA_UINT32 unsigned long
133+/* number of bits in an `int' */
134+/* avoid overflows in comparison */
135+#if INT_MAX-20 < 32760
136+#define LUA_BITSINT 16
137+#elif INT_MAX > 2147483640L
138+/* `int' has at least 32 bits */
139+#define LUA_BITSINT 32
140+#else
141+#error "you must define LUA_BITSINT with number of bits in an integer"
142+#endif
143+
131144
132−/* a signed integer with at least 32 bits */
145+/*
146+** L_UINT32: unsigned integer with at least 32 bits
147+** L_INT32: signed integer with at least 32 bits
148+** LU_MEM: an unsigned integer big enough to count the total memory used by Lua
149+** L_MEM: a signed integer big enough to count the total memory used by Lua
150+*/
151+#if LUA_BITSINT >= 32
152+#define LUA_UINT32 unsigned int
153+#define LUA_INT32 int
154+#define LUA_MAXINT32 INT_MAX
155+#define LU_MEM size_t
156+#define L_MEM ptrdiff_t
157+#else
158+/* 16-bit ints */
159+#define LUA_UINT32 unsigned long
133160 #define LUA_INT32 long
134161 #define LUA_MAXINT32 LONG_MAX
162+#define LU_MEM LUA_UINT32
163+#define L_MEM ptrdiff_t
164+#endif
135165
136166
137167 /* maximum depth for calls (unsigned short) */
138−#define LUA_MAXCALLS 4096
168+#define LUA_MAXCALLS 10000
139169
140170 /*
141171 ** maximum depth for C calls (unsigned short): Not too big, or may
@@ -160,7 +190,7 @@ · 18 unmodified lines
160190
161191
162192 /* maximum number of upvalues per function */
163−#define MAXUPVALUES 32 /* <MAXSTACK */
193+#define MAXUPVALUES 60 /* <MAXSTACK */
164194
165195
166196 /* maximum size of expressions for optimizing `while' code */
@@ -170,7 +200,7 @@ · 3 unmodified lines
170200 /* function to convert a lua_Number to int (with any rounding method) */
171201 #if defined(__GNUC__) && defined(__i386)
172202 #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st")
173−#elif 0
203+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L)
174204 /* on machines compliant with C99, you can try `lrint' */
175205 #include <math.h>
176206 #define lua_number2int(i,d) ((i)=lrint(d))
@@ -179,7 +209,7 @@ · 2 unmodified lines
179209 #endif
180210
181211 /* function to convert a lua_Number to lua_Integer (with any rounding method) */
182−#define lua_number2integer(i,n) lua_number2int(i,n)
212+#define lua_number2integer(i,n) lua_number2int((i), (n))
183213
184214
185215 /* function to convert a lua_Number to a string */
@@ -195,17 +225,6 @@ · 9 unmodified lines
195225 #define LUA_UACNUMBER double
196226
197227
198−/* number of bits in an `int' */
199−/* avoid overflows in comparison */
200−#if INT_MAX-20 < 32760
201−#define LUA_BITSINT 16
202−#elif INT_MAX > 2147483640L
203−/* machine has at least 32 bits */
204−#define LUA_BITSINT 32
205−#else
206−#error "you must define LUA_BITSINT with number of bits in an integer"
207−#endif
208−
209228
210229 /* type to ensure maximum alignment */
211230 #define LUSER_ALIGNMENT_T union { double u; void *s; long l; }
@@ -215,14 +234,14 @@ · 3 unmodified lines
215234 #ifndef __cplusplus
216235 /* default handling with long jumps */
217236 #include <setjmp.h>
218−#define L_THROW(c) longjmp((c)->b, 1)
219−#define L_TRY(c,a) if (setjmp((c)->b) == 0) { a }
237+#define L_THROW(L,c) longjmp((c)->b, 1)
238+#define L_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
220239 #define l_jmpbuf jmp_buf
221240
222241 #else
223242 /* C++ exceptions */
224−#define L_THROW(c) throw(c)
225−#define L_TRY(c,a) try { a } catch(...) \
243+#define L_THROW(L,c) throw(c)
244+#define L_TRY(L,c,a) try { a } catch(...) \
226245 { if ((c)->status == 0) (c)->status = -1; }
227246 #define l_jmpbuf int /* dummy variable */
228247 #endif
@@ -251,9 +270,12 @@ · 22 unmodified lines
251270
252271
253272 /* allows user-specific initialization on new threads */
254−#define lua_userstateopen(l) /* empty */
273+#define lua_userstateopen(L) /* empty */
255274
256275
276+/* initial GC parameters */
277+#define STEPMUL 4
278+
257279 #endif
258280
259281 /* }====================================================== */
@@ -272,8 +294,19 @@ · 12 unmodified lines
272294
273295 /* `assert' options */
274296
275−/* environment variable that holds the search path for packages */
297+/* environment variables that hold the search path for packages */
276298 #define LUA_PATH "LUA_PATH"
299+#define LUA_CPATH "LUA_CPATH"
300+
301+/* prefix for open functions in C libraries */
302+#if defined(__APPLE__) && defined(__MACH__)
303+#define LUA_POF "_luaopen_"
304+#else
305+#define LUA_POF "luaopen_"
306+#endif
307+
308+/* directory separator (for submodules) */
309+#define LUA_DIRSEP "/"
277310
278311 /* separator of templates in a path */
279312 #define LUA_PATH_SEP ';'
@@ -288,7 +321,7 @@ · 8 unmodified lines
288321
289322 /*
290323 ** by default, gcc does not get `tmpname'
291−*/
324+*/
292325 #ifdef __GNUC__
293326 #define USE_TMPNAME 0
294327 #else
@@ -296,6 +329,17 @@ · 1 unmodified line
296329 #endif
297330
298331
332+/*
333+** Configuration for loadlib
334+*/
335+#if defined(__linux) || defined(sun) || defined(sgi) || defined(BSD)
336+#define USE_DLOPEN
337+#elif defined(_WIN32)
338+#define USE_DLL
339+#elif defined(__APPLE__) && defined(__MACH__)
340+#define USE_DYLD
341+#endif
342+
299343
300344 #endif
301345
src/lapi.c+52−42
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.19 2004/09/15 20:39:42 roberto Exp $
2+** $Id: lapi.c,v 2.22 2004/12/06 17:53:42 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -45,7 +45,7 @@ const char lua_ident[] = · 39 unmodified lines
4545
4646
4747
48−static TValue *luaA_index (lua_State *L, int idx) {
48+static TValue *index2adr (lua_State *L, int idx) {
4949 if (idx > 0) {
5050 TValue *o = L->base + (idx - 1);
5151 api_check(L, idx <= L->ci->top - L->base);
@@ -160,7 +160,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { · 108 unmodified lines
160160 LUA_API void lua_remove (lua_State *L, int idx) {
161161 StkId p;
162162 lua_lock(L);
163− p = luaA_index(L, idx);
163+ p = index2adr(L, idx);
164164 api_checkvalidindex(L, p);
165165 while (++p < L->top) setobjs2s(L, p-1, p);
166166 L->top--;
@@ -172,7 +172,7 @@ LUA_API void lua_insert (lua_State *L, int idx) { · 5 unmodified lines
172172 StkId p;
173173 StkId q;
174174 lua_lock(L);
175− p = luaA_index(L, idx);
175+ p = index2adr(L, idx);
176176 api_checkvalidindex(L, p);
177177 for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
178178 setobjs2s(L, p, L->top);
@@ -184,7 +184,7 @@ LUA_API void lua_replace (lua_State *L, int idx) { · 5 unmodified lines
184184 StkId o;
185185 lua_lock(L);
186186 api_checknelems(L, 1);
187− o = luaA_index(L, idx);
187+ o = index2adr(L, idx);
188188 api_checkvalidindex(L, o);
189189 setobj(L, o, L->top - 1);
190190 if (idx < LUA_GLOBALSINDEX) /* function upvalue? */
@@ -196,7 +196,7 @@ LUA_API void lua_replace (lua_State *L, int idx) { · 5 unmodified lines
196196
197197 LUA_API void lua_pushvalue (lua_State *L, int idx) {
198198 lua_lock(L);
199− setobj2s(L, L->top, luaA_index(L, idx));
199+ setobj2s(L, L->top, index2adr(L, idx));
200200 api_incr_top(L);
201201 lua_unlock(L);
202202 }
@@ -209,7 +209,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 6 unmodified lines
209209
210210
211211 LUA_API int lua_type (lua_State *L, int idx) {
212− StkId o = luaA_index(L, idx);
212+ StkId o = index2adr(L, idx);
213213 return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o);
214214 }
215215
@@ -221,14 +221,14 @@ LUA_API const char *lua_typename (lua_State *L, int t) { · 5 unmodified lines
221221
222222
223223 LUA_API int lua_iscfunction (lua_State *L, int idx) {
224− StkId o = luaA_index(L, idx);
224+ StkId o = index2adr(L, idx);
225225 return iscfunction(o);
226226 }
227227
228228
229229 LUA_API int lua_isnumber (lua_State *L, int idx) {
230230 TValue n;
231− const TValue *o = luaA_index(L, idx);
231+ const TValue *o = index2adr(L, idx);
232232 return tonumber(o, &n);
233233 }
234234
@@ -240,14 +240,14 @@ LUA_API int lua_isstring (lua_State *L, int idx) { · 5 unmodified lines
240240
241241
242242 LUA_API int lua_isuserdata (lua_State *L, int idx) {
243− const TValue *o = luaA_index(L, idx);
243+ const TValue *o = index2adr(L, idx);
244244 return (ttisuserdata(o) || ttislightuserdata(o));
245245 }
246246
247247
248248 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
249− StkId o1 = luaA_index(L, index1);
250− StkId o2 = luaA_index(L, index2);
249+ StkId o1 = index2adr(L, index1);
250+ StkId o2 = index2adr(L, index2);
251251 return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
252252 : luaO_rawequalObj(o1, o2);
253253 }
@@ -257,8 +257,8 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { · 3 unmodified lines
257257 StkId o1, o2;
258258 int i;
259259 lua_lock(L); /* may call tag method */
260− o1 = luaA_index(L, index1);
261− o2 = luaA_index(L, index2);
260+ o1 = index2adr(L, index1);
261+ o2 = index2adr(L, index2);
262262 i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
263263 : equalobj(L, o1, o2);
264264 lua_unlock(L);
@@ -270,8 +270,8 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 5 unmodified lines
270270 StkId o1, o2;
271271 int i;
272272 lua_lock(L); /* may call tag method */
273− o1 = luaA_index(L, index1);
274− o2 = luaA_index(L, index2);
273+ o1 = index2adr(L, index1);
274+ o2 = index2adr(L, index2);
275275 i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
276276 : luaV_lessthan(L, o1, o2);
277277 lua_unlock(L);
@@ -282,7 +282,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 4 unmodified lines
282282
283283 LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
284284 TValue n;
285− const TValue *o = luaA_index(L, idx);
285+ const TValue *o = index2adr(L, idx);
286286 if (tonumber(o, &n))
287287 return nvalue(o);
288288 else
@@ -292,7 +292,7 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { · 3 unmodified lines
292292
293293 LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
294294 TValue n;
295− const TValue *o = luaA_index(L, idx);
295+ const TValue *o = index2adr(L, idx);
296296 if (tonumber(o, &n)) {
297297 lua_Integer res;
298298 lua_number2integer(res, nvalue(o));
@@ -304,13 +304,13 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { · 5 unmodified lines
304304
305305
306306 LUA_API int lua_toboolean (lua_State *L, int idx) {
307− const TValue *o = luaA_index(L, idx);
307+ const TValue *o = index2adr(L, idx);
308308 return !l_isfalse(o);
309309 }
310310
311311
312312 LUA_API const char *lua_tostring (lua_State *L, int idx) {
313− StkId o = luaA_index(L, idx);
313+ StkId o = index2adr(L, idx);
314314 if (ttisstring(o))
315315 return svalue(o);
316316 else {
@@ -325,7 +325,7 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) { · 8 unmodified lines
325325
326326
327327 LUA_API size_t lua_objsize (lua_State *L, int idx) {
328− StkId o = luaA_index(L, idx);
328+ StkId o = index2adr(L, idx);
329329 if (ttisstring(o))
330330 return tsvalue(o)->len;
331331 else if (ttisuserdata(o))
@@ -341,13 +341,13 @@ LUA_API size_t lua_objsize (lua_State *L, int idx) { · 9 unmodified lines
341341
342342
343343 LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
344− StkId o = luaA_index(L, idx);
344+ StkId o = index2adr(L, idx);
345345 return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;
346346 }
347347
348348
349349 LUA_API void *lua_touserdata (lua_State *L, int idx) {
350− StkId o = luaA_index(L, idx);
350+ StkId o = index2adr(L, idx);
351351 switch (ttype(o)) {
352352 case LUA_TUSERDATA: return (rawuvalue(o) + 1);
353353 case LUA_TLIGHTUSERDATA: return pvalue(o);
@@ -357,13 +357,13 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { · 3 unmodified lines
357357
358358
359359 LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
360− StkId o = luaA_index(L, idx);
360+ StkId o = index2adr(L, idx);
361361 return (!ttisthread(o)) ? NULL : thvalue(o);
362362 }
363363
364364
365365 LUA_API const void *lua_topointer (lua_State *L, int idx) {
366− StkId o = luaA_index(L, idx);
366+ StkId o = index2adr(L, idx);
367367 switch (ttype(o)) {
368368 case LUA_TTABLE: return hvalue(o);
369369 case LUA_TFUNCTION: return clvalue(o);
@@ -498,7 +498,7 @@ LUA_API int lua_pushthread (lua_State *L) { · 128 unmodified lines
498498 LUA_API void lua_gettable (lua_State *L, int idx) {
499499 StkId t;
500500 lua_lock(L);
501− t = luaA_index(L, idx);
501+ t = index2adr(L, idx);
502502 api_checkvalidindex(L, t);
503503 luaV_gettable(L, t, L->top - 1, L->top - 1, NULL);
504504 lua_unlock(L);
@@ -509,7 +509,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { · 4 unmodified lines
509509 StkId t;
510510 TValue key;
511511 lua_lock(L);
512− t = luaA_index(L, idx);
512+ t = index2adr(L, idx);
513513 api_checkvalidindex(L, t);
514514 setsvalue(L, &key, luaS_new(L, k));
515515 luaV_gettable(L, t, &key, L->top, NULL);
@@ -521,7 +521,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { · 5 unmodified lines
521521 LUA_API void lua_rawget (lua_State *L, int idx) {
522522 StkId t;
523523 lua_lock(L);
524− t = luaA_index(L, idx);
524+ t = index2adr(L, idx);
525525 api_check(L, ttistable(t));
526526 setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
527527 lua_unlock(L);
@@ -531,7 +531,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) { · 3 unmodified lines
531531 LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
532532 StkId o;
533533 lua_lock(L);
534− o = luaA_index(L, idx);
534+ o = index2adr(L, idx);
535535 api_check(L, ttistable(o));
536536 setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
537537 api_incr_top(L);
@@ -553,7 +553,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { · 15 unmodified lines
553553 Table *mt = NULL;
554554 int res;
555555 lua_lock(L);
556− obj = luaA_index(L, objindex);
556+ obj = index2adr(L, objindex);
557557 switch (ttype(obj)) {
558558 case LUA_TTABLE:
559559 mt = hvalue(obj)->metatable;
@@ -577,7 +577,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { · 17 unmodified lines
577577 LUA_API void lua_getfenv (lua_State *L, int idx) {
578578 StkId o;
579579 lua_lock(L);
580− o = luaA_index(L, idx);
580+ o = index2adr(L, idx);
581581 api_checkvalidindex(L, o);
582582 setobj2s(L, L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L));
583583 api_incr_top(L);
@@ -594,7 +594,7 @@ LUA_API void lua_settable (lua_State *L, int idx) { · 10 unmodified lines
594594 StkId t;
595595 lua_lock(L);
596596 api_checknelems(L, 2);
597− t = luaA_index(L, idx);
597+ t = index2adr(L, idx);
598598 api_checkvalidindex(L, t);
599599 luaV_settable(L, t, L->top - 2, L->top - 1, NULL);
600600 L->top -= 2; /* pop index and value */
@@ -607,7 +607,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { · 6 unmodified lines
607607 TValue key;
608608 lua_lock(L);
609609 api_checknelems(L, 1);
610− t = luaA_index(L, idx);
610+ t = index2adr(L, idx);
611611 api_checkvalidindex(L, t);
612612 setsvalue(L, &key, luaS_new(L, k));
613613 luaV_settable(L, t, &key, L->top - 1, NULL);
@@ -620,7 +620,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { · 6 unmodified lines
620620 StkId t;
621621 lua_lock(L);
622622 api_checknelems(L, 2);
623− t = luaA_index(L, idx);
623+ t = index2adr(L, idx);
624624 api_check(L, ttistable(t));
625625 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
626626 luaC_barriert(L, hvalue(t), L->top-1);
@@ -633,7 +633,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { · 6 unmodified lines
633633 StkId o;
634634 lua_lock(L);
635635 api_checknelems(L, 1);
636− o = luaA_index(L, idx);
636+ o = index2adr(L, idx);
637637 api_check(L, ttistable(o));
638638 setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
639639 luaC_barriert(L, hvalue(o), L->top-1);
@@ -648,7 +648,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { · 8 unmodified lines
648648 int res = 1;
649649 lua_lock(L);
650650 api_checknelems(L, 1);
651− obj = luaA_index(L, objindex);
651+ obj = index2adr(L, objindex);
652652 api_checkvalidindex(L, obj);
653653 if (ttisnil(L->top - 1))
654654 mt = NULL;
@@ -685,7 +685,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { · 30 unmodified lines
685685 int res = 0;
686686 lua_lock(L);
687687 api_checknelems(L, 1);
688− o = luaA_index(L, idx);
688+ o = index2adr(L, idx);
689689 api_checkvalidindex(L, o);
690690 api_check(L, ttistable(L->top - 1));
691691 if (isLfunction(o)) {
@@ -751,7 +751,7 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { · 59 unmodified lines
751751 if (errfunc == 0)
752752 func = 0;
753753 else {
754− StkId o = luaA_index(L, errfunc);
754+ StkId o = index2adr(L, errfunc);
755755 api_checkvalidindex(L, o);
756756 func = savestack(L, o);
757757 }
@@ -842,7 +842,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 84 unmodified lines
842842 g = G(L);
843843 switch (what) {
844844 case LUA_GCSTOP: {
845− g->GCthreshold = MAXLMEM;
845+ g->GCthreshold = MAX_LUMEM;
846846 break;
847847 }
848848 case LUA_GCRESTART: {
@@ -867,6 +867,16 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 18 unmodified lines
867867 luaC_step(L);
868868 break;
869869 }
870+ case LUA_GCSETSTEPMUL: {
871+ res = g->stepmul;
872+ g->stepmul = data;
873+ break;
874+ }
875+ case LUA_GCSETINCMODE: {
876+ res = g->incgc;
877+ g->incgc = data;
878+ break;
879+ }
870880 default: res = -1; /* invalid option */
871881 }
872882 lua_unlock(L);
@@ -898,7 +908,7 @@ LUA_API int lua_next (lua_State *L, int idx) { · 25 unmodified lines
898908 StkId t;
899909 int more;
900910 lua_lock(L);
901− t = luaA_index(L, idx);
911+ t = index2adr(L, idx);
902912 api_check(L, ttistable(t));
903913 more = luaH_next(L, hvalue(t), L->top - 1);
904914 if (more) {
@@ -970,7 +980,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { · 65 unmodified lines
970980 const char *name;
971981 TValue *val;
972982 lua_lock(L);
973− name = aux_upvalue(L, luaA_index(L, funcindex), n, &val);
983+ name = aux_upvalue(L, index2adr(L, funcindex), n, &val);
974984 if (name) {
975985 setobj2s(L, L->top, val);
976986 api_incr_top(L);
@@ -985,7 +995,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { · 8 unmodified lines
985995 TValue *val;
986996 StkId fi;
987997 lua_lock(L);
988− fi = luaA_index(L, funcindex);
998+ fi = index2adr(L, funcindex);
989999 api_checknelems(L, 1);
9901000 name = aux_upvalue(L, fi, n, &val);
9911001 if (name) {
src/lcode.c+50−27
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.6 2004/08/24 20:09:11 roberto Exp $
2+** $Id: lcode.c,v 2.8 2004/12/03 20:35:33 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -53,13 +53,13 @@ int luaK_jump (FuncState *fs) { · 47 unmodified lines
5353 }
5454
5555
56−static int luaK_condjump (FuncState *fs, OpCode op, int A, int B, int C) {
56+static int condjump (FuncState *fs, OpCode op, int A, int B, int C) {
5757 luaK_codeABC(fs, op, A, B, C);
5858 return luaK_jump(fs);
5959 }
6060
6161
62−static void luaK_fixjump (FuncState *fs, int pc, int dest) {
62+static void fixjump (FuncState *fs, int pc, int dest) {
6363 Instruction *jmp = &fs->f->code[pc];
6464 int offset = dest-(pc+1);
6565 lua_assert(dest != NO_JUMP);
@@ -79,7 +79,7 @@ int luaK_getlabel (FuncState *fs) { · 13 unmodified lines
7979 }
8080
8181
82−static int luaK_getjump (FuncState *fs, int pc) {
82+static int getjump (FuncState *fs, int pc) {
8383 int offset = GETARG_sBx(fs->f->code[pc]);
8484 if (offset == NO_JUMP) /* point to itself represents end of list */
8585 return NO_JUMP; /* end of list */
@@ -102,7 +102,7 @@ static Instruction *getjumpcontrol (FuncState *fs, int pc) { · 16 unmodified lines
102102 ** (or produce an inverted value)
103103 */
104104 static int need_value (FuncState *fs, int list, int cond) {
105− for (; list != NO_JUMP; list = luaK_getjump(fs, list)) {
105+ for (; list != NO_JUMP; list = getjump(fs, list)) {
106106 Instruction i = *getjumpcontrol(fs, list);
107107 if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1;
108108 }
@@ -116,25 +116,25 @@ static void patchtestreg (Instruction *i, int reg) { · 7 unmodified lines
116116 }
117117
118118
119−static void luaK_patchlistaux (FuncState *fs, int list,
119+static void patchlistaux (FuncState *fs, int list,
120120 int ttarget, int treg, int ftarget, int freg, int dtarget) {
121121 while (list != NO_JUMP) {
122− int next = luaK_getjump(fs, list);
122+ int next = getjump(fs, list);
123123 Instruction *i = getjumpcontrol(fs, list);
124124 if (GET_OPCODE(*i) != OP_TEST) {
125125 lua_assert(dtarget != NO_JUMP);
126− luaK_fixjump(fs, list, dtarget); /* jump to default target */
126+ fixjump(fs, list, dtarget); /* jump to default target */
127127 }
128128 else {
129129 if (GETARG_C(*i)) {
130130 lua_assert(ttarget != NO_JUMP);
131131 patchtestreg(i, treg);
132− luaK_fixjump(fs, list, ttarget);
132+ fixjump(fs, list, ttarget);
133133 }
134134 else {
135135 lua_assert(ftarget != NO_JUMP);
136136 patchtestreg(i, freg);
137− luaK_fixjump(fs, list, ftarget);
137+ fixjump(fs, list, ftarget);
138138 }
139139 }
140140 list = next;
@@ -142,8 +142,8 @@ static void luaK_patchlistaux (FuncState *fs, int list, · 1 unmodified line
142142 }
143143
144144
145−static void luaK_dischargejpc (FuncState *fs) {
146− luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
145+static void dischargejpc (FuncState *fs) {
146+ patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
147147 fs->jpc = NO_JUMP;
148148 }
149149
@@ -153,7 +153,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) { · 3 unmodified lines
153153 luaK_patchtohere(fs, list);
154154 else {
155155 lua_assert(target < fs->pc);
156− luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
156+ patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
157157 }
158158 }
159159
@@ -171,9 +171,9 @@ void luaK_concat (FuncState *fs, int *l1, int l2) { · 11 unmodified lines
171171 else {
172172 int list = *l1;
173173 int next;
174− while ((next = luaK_getjump(fs, list)) != NO_JUMP) /* find last element */
174+ while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
175175 list = next;
176− luaK_fixjump(fs, list, l2);
176+ fixjump(fs, list, l2);
177177 }
178178 }
179179
@@ -243,7 +243,14 @@ int luaK_numberK (FuncState *fs, lua_Number r) { · 63 unmodified lines
243243 }
244244
245245
246−static int nil_constant (FuncState *fs) {
246+static int boolK (FuncState *fs, int b) {
247+ TValue o;
248+ setbvalue(&o, b);
249+ return addk(fs, &o, &o);
250+}
251+
252+
253+static int nilK (FuncState *fs) {
247254 TValue k, v;
248255 setnilvalue(&v);
249256 /* cannot use nil as key; instead use table itself to represent nil */
@@ -358,7 +365,7 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { · 108 unmodified lines
358365 }
359366
360367
361−static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) {
368+static void exp2reg (FuncState *fs, expdesc *e, int reg) {
362369 discharge2reg(fs, e, reg);
363370 if (e->k == VJMP)
364371 luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */
@@ -375,8 +382,8 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { · 10 unmodified lines
375382 luaK_patchtohere(fs, fj);
376383 }
377384 final = luaK_getlabel(fs);
378− luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
379− luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t);
385+ patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
386+ patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t);
380387 }
381388 e->f = e->t = NO_JUMP;
382389 e->info = reg;
@@ -388,7 +395,7 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { · 5 unmodified lines
388395 luaK_dischargevars(fs, e);
389396 freeexp(fs, e);
390397 luaK_reserveregs(fs, 1);
391− luaK_exp2reg(fs, e, fs->freereg - 1);
398+ exp2reg(fs, e, fs->freereg - 1);
392399 }
393400
394401
@@ -397,7 +404,7 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) { · 2 unmodified lines
397404 if (e->k == VNONRELOC) {
398405 if (!hasjumps(e)) return e->info; /* exp is already in a register */
399406 if (e->info >= fs->nactvar) { /* reg. is not a local? */
400− luaK_exp2reg(fs, e, e->info); /* put value on it */
407+ exp2reg(fs, e, e->info); /* put value on it */
401408 return e->info;
402409 }
403410 }
@@ -417,9 +424,11 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { · 13 unmodified lines
417424 int luaK_exp2RK (FuncState *fs, expdesc *e) {
418425 luaK_exp2val(fs, e);
419426 switch (e->k) {
427+ case VTRUE:
428+ case VFALSE:
420429 case VNIL: {
421430 if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
422− e->info = nil_constant(fs);
431+ e->info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
423432 e->k = VK;
424433 return RKASK(e->info);
425434 }
@@ -441,7 +450,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { · 15 unmodified lines
441450 switch (var->k) {
442451 case VLOCAL: {
443452 freeexp(fs, ex);
444− luaK_exp2reg(fs, ex, var->info);
453+ exp2reg(fs, ex, var->info);
445454 return;
446455 }
447456 case VUPVAL: {
@@ -493,13 +502,13 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) { · 45 unmodified lines
493502 Instruction ie = getcode(fs, e);
494503 if (GET_OPCODE(ie) == OP_NOT) {
495504 fs->pc--; /* remove previous OP_NOT */
496− return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond);
505+ return condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond);
497506 }
498507 /* else go through */
499508 }
500509 discharge2anyreg(fs, e);
501510 freeexp(fs, e);
502− return luaK_condjump(fs, OP_TEST, NO_REG, e->info, cond);
511+ return condjump(fs, OP_TEST, NO_REG, e->info, cond);
503512 }
504513
505514
@@ -651,7 +660,7 @@ static void codebinop (FuncState *fs, expdesc *res, BinOpr op, · 145 unmodified lines
651660 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
652661 }
653662 else if (op == OPR_NE) cond = 0;
654− res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2);
663+ res->info = condjump(fs, ops[op - OPR_NE], cond, o1, o2);
655664 res->k = VJMP;
656665 }
657666 }
@@ -708,7 +717,7 @@ void luaK_fixline (FuncState *fs, int line) { · 50 unmodified lines
708717
709718 int luaK_code (FuncState *fs, Instruction i, int line) {
710719 Proto *f = fs->f;
711− luaK_dischargejpc(fs); /* `pc' will change */
720+ dischargejpc(fs); /* `pc' will change */
712721 /* put new instruction in code array */
713722 luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
714723 MAX_INT, "code size overflow");
@@ -735,3 +744,17 @@ int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { · 20 unmodified lines
735744 return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);
736745 }
737746
747+
748+void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
749+ int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
750+ int b = (tostore == LUA_MULTRET) ? 0 : tostore;
751+ lua_assert(tostore != 0);
752+ if (c <= MAXARG_C)
753+ luaK_codeABC(fs, OP_SETLIST, base, b, c);
754+ else {
755+ luaK_codeABC(fs, OP_SETLIST, base, b, 0);
756+ luaK_code(fs, cast(Instruction, c), fs->ls->lastline);
757+ }
758+ fs->freereg = base + 1; /* free registers with list values */
759+}
760+
src/lcode.h+2−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.h,v 1.39 2004/05/31 18:51:50 roberto Exp $
2+** $Id: lcode.h,v 1.40 2004/10/04 19:01:53 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -72,6 +72,7 @@ int luaK_getlabel (FuncState *fs); · 66 unmodified lines
7272 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
7373 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
7474 void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);
75+void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
7576
7677
7778 #endif
src/ldebug.c+15−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.8 2004/09/01 13:47:31 roberto Exp $
2+** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -261,11 +261,11 @@ int luaG_checkopenop (Instruction i) { · 255 unmodified lines
261261 switch (GET_OPCODE(i)) {
262262 case OP_CALL:
263263 case OP_TAILCALL:
264− case OP_RETURN: {
264+ case OP_RETURN:
265+ case OP_SETLIST: {
265266 check(GETARG_B(i) == 0);
266267 return 1;
267268 }
268− case OP_SETLISTO: return 1;
269269 default: return 0; /* invalid instruction after an open call */
270270 }
271271 }
@@ -284,7 +284,7 @@ static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { · 12 unmodified lines
284284 }
285285
286286
287−static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
287+static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
288288 int pc;
289289 int last; /* stores position of last instruction that changed `reg' */
290290 last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */
@@ -315,6 +315,11 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 24 unmodified lines
315315 if (getBMode(op) == OpArgR) {
316316 int dest = pc+1+b;
317317 check(0 <= dest && dest < pt->sizecode);
318+ if (dest > 0) {
319+ /* cannot jump to a setlist count */
320+ const Instruction d = pt->code[dest-1];
321+ check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
322+ }
318323 }
319324 break;
320325 }
@@ -356,7 +361,8 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 35 unmodified lines
356361 break;
357362 }
358363 case OP_TFORLOOP: {
359− checkreg(pt, a+5); /* space for control variables */
364+ check(c >= 1); /* at least one result (control variable) */
365+ checkreg(pt, a+3+c); /* space for results */
360366 if (reg >= a+3) last = pc; /* affect all regs above its call base */
361367 break;
362368 }
@@ -392,7 +398,8 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 29 unmodified lines
392398 break;
393399 }
394400 case OP_SETLIST: {
395− checkreg(pt, a + (b&(LFIELDS_PER_FLUSH-1)) + 1);
401+ if (b > 0) checkreg(pt, a + b);
402+ if (c == 0) pc++;
396403 break;
397404 }
398405 case OP_CLOSURE: {
@@ -427,7 +434,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { · 28 unmodified lines
427434
428435
429436 int luaG_checkcode (const Proto *pt) {
430− return (luaG_symbexec(pt, pt->sizecode, NO_REG) != 0);
437+ return (symbexec(pt, pt->sizecode, NO_REG) != 0);
431438 }
432439
433440
@@ -447,7 +454,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { · 13 unmodified lines
447454 *name = luaF_getlocalname(p, stackpos+1, pc);
448455 if (*name) /* is a local? */
449456 return "local";
450− i = luaG_symbexec(p, pc, stackpos); /* try symbolic execution */
457+ i = symbexec(p, pc, stackpos); /* try symbolic execution */
451458 lua_assert(pc != -1);
452459 switch (GET_OPCODE(i)) {
453460 case OP_GETGLOBAL: {
src/ldo.c+5−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.10 2004/09/15 20:39:42 roberto Exp $
2+** $Id: ldo.c,v 2.13 2004/12/03 20:35:33 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -70,7 +70,7 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 64 unmodified lines
7070 void luaD_throw (lua_State *L, int errcode) {
7171 if (L->errorJmp) {
7272 L->errorJmp->status = errcode;
73− L_THROW(L->errorJmp);
73+ L_THROW(L, L->errorJmp);
7474 }
7575 else {
7676 if (G(L)->panic) G(L)->panic(L);
@@ -84,7 +84,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 7 unmodified lines
8484 lj.status = 0;
8585 lj.previous = L->errorJmp; /* chain new error handler */
8686 L->errorJmp = &lj;
87− L_TRY(&lj,
87+ L_TRY(L, &lj,
8888 (*f)(L, ud);
8989 );
9090 L->errorJmp = lj.previous; /* restore old error handler */
@@ -147,7 +147,7 @@ void luaD_growstack (lua_State *L, int n) { · 56 unmodified lines
147147 }
148148
149149
150−static CallInfo *luaD_growCI (lua_State *L) {
150+static CallInfo *growCI (lua_State *L) {
151151 if (L->size_ci > LUA_MAXCALLS) /* overflow while handling overflow? */
152152 luaD_throw(L, LUA_ERRERR);
153153 else {
@@ -238,7 +238,7 @@ static StkId tryfuncTM (lua_State *L, StkId func) { · 84 unmodified lines
238238
239239
240240 #define inc_ci(L) \
241− ((L->ci == L->end_ci) ? luaD_growCI(L) : \
241+ ((L->ci == L->end_ci) ? growCI(L) : \
242242 (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))
243243
244244
@@ -391,7 +391,6 @@ static int resume_error (lua_State *L, const char *msg) { · 146 unmodified lines
391391
392392 LUA_API int lua_resume (lua_State *L, int nargs) {
393393 int status;
394− lu_byte old_allowhooks;
395394 lua_lock(L);
396395 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
397396 if (L->status != LUA_YIELD) {
@@ -400,7 +399,6 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 2 unmodified lines
400399 else if (L->ci != L->base_ci)
401400 return resume_error(L, "cannot resume non-suspended coroutine");
402401 }
403− old_allowhooks = L->allowhook;
404402 status = luaD_rawrunprotected(L, resume, &nargs);
405403 if (status != 0) { /* error? */
406404 L->status = status; /* mark thread as `dead' */
src/ldump.c+6−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldump.c,v 1.8 2004/09/01 21:22:34 lhf Exp $
2+** $Id: ldump.c,v 1.9 2004/11/25 09:31:41 lhf Exp $
33 ** save pre-compiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -113,14 +113,17 @@ static void DumpConstants(const Proto* f, DumpState* D) · 107 unmodified lines
113113 DumpByte(ttype(o),D);
114114 switch (ttype(o))
115115 {
116+ case LUA_TNIL:
117+ break;
118+ case LUA_TBOOLEAN:
119+ DumpByte(bvalue(o),D);
120+ break;
116121 case LUA_TNUMBER:
117122 DumpNumber(nvalue(o),D);
118123 break;
119124 case LUA_TSTRING:
120125 DumpString(rawtsvalue(o),D);
121126 break;
122− case LUA_TNIL:
123− break;
124127 default:
125128 lua_assert(0); /* cannot happen */
126129 break;
src/lfunc.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.c,v 2.4 2004/04/30 20:13:38 roberto Exp $
2+** $Id: lfunc.c,v 2.5 2004/11/24 19:20:21 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
@@ -75,7 +75,7 @@ void luaF_close (lua_State *L, StkId level) { · 69 unmodified lines
7575 lua_assert(!isblack(o));
7676 L->openupval = uv->next; /* remove from `open' list */
7777 if (isdead(g, o))
78− luaM_freelem(L, uv); /* free upvalue */
78+ luaM_free(L, uv); /* free upvalue */
7979 else {
8080 setobj(L, &uv->value, uv->v);
8181 uv->v = &uv->value; /* now current value lives here */
@@ -117,14 +117,14 @@ void luaF_freeproto (lua_State *L, Proto *f) { · 35 unmodified lines
117117 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
118118 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
119119 luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
120− luaM_freelem(L, f);
120+ luaM_free(L, f);
121121 }
122122
123123
124124 void luaF_freeclosure (lua_State *L, Closure *c) {
125125 int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
126126 sizeLclosure(c->l.nupvalues);
127− luaM_free(L, c, size);
127+ luaM_freemem(L, c, size);
128128 }
129129
130130
src/lgc.c+25−25
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.12 2004/09/15 20:38:15 roberto Exp $
2+** $Id: lgc.c,v 2.18 2004/12/06 17:53:42 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -24,7 +24,6 @@ · 18 unmodified lines
2424
2525
2626 #define GCSTEPSIZE 1000
27−#define STEPMUL 2
2827 #define GCSWEEPMAX 10
2928 #define GCSWEEPCOST 30
3029 #define GCFINALIZECOST 100
@@ -65,7 +64,7 @@ · 34 unmodified lines
6564 static void removeentry (Node *n) {
6665 setnilvalue(gval(n)); /* remove corresponding value ... */
6766 if (iscollectable(gkey(n)))
68− setttype(gkey(n), LUA_TNONE); /* dead key; remove it */
67+ setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */
6968 }
7069
7170
@@ -139,7 +138,7 @@ size_t luaC_separateudata (lua_State *L, int all) { · 67 unmodified lines
139138 p = &curr->gch.next;
140139 }
141140 else { /* must call its gc method */
142− deadmem += sizeudata(gco2u(curr)->len);
141+ deadmem += sizeudata(gco2u(curr));
143142 markfinalized(gco2u(curr));
144143 *p = curr->gch.next;
145144 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
@@ -184,6 +183,7 @@ static int traversetable (global_State *g, Table *h) { · 38 unmodified lines
184183 i = sizenode(h);
185184 while (i--) {
186185 Node *n = gnode(h, i);
186+ lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n)));
187187 if (ttisnil(gval(n)))
188188 removeentry(n); /* remove empty entries */
189189 else {
@@ -367,7 +367,7 @@ static void cleartable (GCObject *l) { · 177 unmodified lines
367367 while (i--) {
368368 Node *n = gnode(h, i);
369369 if (!ttisnil(gval(n)) && /* non-empty entry? */
370− (iscleared(gkey(n), 1) || iscleared(gval(n), 0)))
370+ (iscleared(key2tval(n), 1) || iscleared(gval(n), 0)))
371371 removeentry(n); /* remove entry from table */
372372 }
373373 l = h->gclist;
@@ -379,7 +379,7 @@ static void freeobj (lua_State *L, GCObject *o) { · 5 unmodified lines
379379 switch (o->gch.tt) {
380380 case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
381381 case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
382− case LUA_TUPVAL: luaM_freelem(L, gco2uv(o)); break;
382+ case LUA_TUPVAL: luaM_free(L, gco2uv(o)); break;
383383 case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
384384 case LUA_TTHREAD: {
385385 lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);
@@ -388,11 +388,11 @@ static void freeobj (lua_State *L, GCObject *o) { · 2 unmodified lines
388388 }
389389 case LUA_TSTRING: {
390390 G(L)->strt.nuse--;
391− luaM_free(L, o, sizestring(gco2ts(o)->len));
391+ luaM_freemem(L, o, sizestring(gco2ts(o)));
392392 break;
393393 }
394394 case LUA_TUSERDATA: {
395− luaM_free(L, o, sizeudata(gco2u(o)->len));
395+ luaM_freemem(L, o, sizeudata(gco2u(o)));
396396 break;
397397 }
398398 default: lua_assert(0);
@@ -529,6 +529,7 @@ static void remarkupvals (global_State *g) { · 130 unmodified lines
529529
530530 static void atomic (lua_State *L) {
531531 global_State *g = G(L);
532+ size_t udsize; /* total size of userdata to be finalized */
532533 int aux;
533534 /* remark objects cautch by write barrier */
534535 propagateall(g);
@@ -544,7 +545,7 @@ static void atomic (lua_State *L) { · 9 unmodified lines
544545 g->gray = g->grayagain;
545546 g->grayagain = NULL;
546547 propagateall(g);
547− luaC_separateudata(L, 0); /* separate userdata to be preserved */
548+ udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
548549 marktmu(g); /* mark `preserved' userdata */
549550 propagateall(g); /* remark, to propagate `preserveness' */
550551 cleartable(g->weak); /* remove collected objects from weak tables */
@@ -554,10 +555,10 @@ static void atomic (lua_State *L) { · 3 unmodified lines
554555 g->sweepgc = &g->rootgc;
555556 g->gcstate = GCSsweepstring;
556557 aux = g->gcgenerational;
557− g->gcgenerational = (g->estimate <= 4*g->prevestimate/2);
558+ g->gcgenerational = g->incgc && (g->estimate/2 <= g->prevestimate);
558559 if (!aux) /* last collection was full? */
559560 g->prevestimate = g->estimate; /* keep estimate of last full collection */
560− g->estimate = g->totalbytes; /* first estimate */
561+ g->estimate = g->totalbytes - udsize; /* first estimate */
561562 }
562563
563564
@@ -586,6 +587,7 @@ static l_mem singlestep (lua_State *L) { · 22 unmodified lines
586587 sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
587588 if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */
588589 g->gcstate = GCSsweep; /* end sweep-string phase */
590+ lua_assert(old >= g->totalbytes);
589591 g->estimate -= old - g->totalbytes;
590592 return GCSWEEPCOST;
591593 }
@@ -596,12 +598,15 @@ static l_mem singlestep (lua_State *L) { · 4 unmodified lines
596598 checkSizes(L);
597599 g->gcstate = GCSfinalize; /* end sweep phase */
598600 }
601+ lua_assert(old >= g->totalbytes);
599602 g->estimate -= old - g->totalbytes;
600603 return GCSWEEPMAX*GCSWEEPCOST;
601604 }
602605 case GCSfinalize: {
603606 if (g->tmudata) {
607+ g->GCthreshold += GCFINALIZECOST; /* avoid GC steps inside method */
604608 GCTM(L);
609+ g->GCthreshold -= GCFINALIZECOST; /* correct threshold */
605610 return GCFINALIZECOST;
606611 }
607612 else {
@@ -616,23 +621,18 @@ static l_mem singlestep (lua_State *L) { · 8 unmodified lines
616621
617622 void luaC_step (lua_State *L) {
618623 global_State *g = G(L);
619− l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * STEPMUL;
620−/*printf("step(%c): ", g->gcgenerational?'g':' ');*/
624+ l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * g->stepmul;
621625 do {
622− /*printf("%c", "_pswf"[g->gcstate]);*/
623626 lim -= singlestep(L);
624627 if (g->gcstate == GCSpause)
625628 break;
626− } while (lim > 0);
627−/*printf("\n");*/
628− if (g->gcstate != GCSpause)
629+ } while (lim > 0 || !g->incgc);
630+ if (g->incgc)
629631 g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */
630632 else {
631−/*printf("---\n");*/
632633 lua_assert(g->totalbytes >= g->estimate);
634+ lua_assert(g->gcstate == GCSpause);
633635 g->GCthreshold = 2*g->estimate;
634− if (g->GCthreshold < g->totalbytes + GCSTEPSIZE)
635− g->GCthreshold = g->totalbytes + GCSTEPSIZE;
636636 }
637637 }
638638
@@ -657,20 +657,19 @@ void luaC_fullgc (lua_State *L) { · 18 unmodified lines
657657 }
658658 markroot(L);
659659 lua_assert(!g->gcgenerational);
660− while (g->gcstate != GCSfinalize) {
660+ while (g->gcstate != GCSpause) {
661661 singlestep(L);
662662 g->gcgenerational = 0; /* keep it in this mode */
663663 }
664− lua_assert(g->estimate == g->totalbytes);
665664 g->GCthreshold = 2*g->estimate;
666− luaC_callGCTM(L); /* call finalizers */
667665 }
668666
669667
670668 void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
671669 global_State *g = G(L);
672670 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
673− lua_assert(g->gcgenerational || g->gcstate != GCSfinalize);
671+ lua_assert(g->gcgenerational ||
672+ (g->gcstate != GCSfinalize && g->gcstate != GCSpause));
674673 lua_assert(ttype(&o->gch) != LUA_TTABLE);
675674 /* must keep invariant? */
676675 if (g->gcstate == GCSpropagate || g->gcgenerational)
@@ -683,7 +682,8 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { · 6 unmodified lines
683682 void luaC_barrierback (lua_State *L, GCObject *o, GCObject *v) {
684683 global_State *g = G(L);
685684 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
686− lua_assert(g->gcgenerational || g->gcstate != GCSfinalize);
685+ lua_assert(g->gcgenerational ||
686+ (g->gcstate != GCSfinalize && g->gcstate != GCSpause));
687687 black2gray(o); /* make table gray (again) */
688688 gco2h(o)->gclist = g->grayagain;
689689 g->grayagain = o;
src/lib/lauxlib.c+68−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.124 2004/09/03 13:17:14 roberto Exp $
2+** $Id: lauxlib.c,v 1.126 2004/09/29 21:03:14 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -239,16 +239,22 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, · 233 unmodified lines
239239 const luaL_reg *l, int nup) {
240240 if (libname) {
241241 /* check whether lib already exists */
242− lua_getglobal(L, libname);
243− if (lua_isnil(L, -1)) { /* no? */
244− lua_pop(L, 1);
242+ luaL_getfield(L, LUA_GLOBALSINDEX, libname);
243+ if (lua_isnil(L, -1)) { /* not found? */
244+ lua_pop(L, 1); /* remove previous result */
245245 lua_newtable(L); /* create it */
246246 if (lua_getmetatable(L, LUA_GLOBALSINDEX))
247247 lua_setmetatable(L, -2); /* share metatable with global table */
248− lua_pushvalue(L, -1);
249248 /* register it with given name */
250− lua_setglobal(L, libname);
249+ lua_pushvalue(L, -1);
250+ luaL_setfield(L, LUA_GLOBALSINDEX, libname);
251251 }
252+ else if (!lua_istable(L, -1))
253+ luaL_error(L, "name conflict for library `%s'", libname);
254+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
255+ lua_pushvalue(L, -2);
256+ lua_setfield(L, -2, libname); /* _LOADED[modname] = new table */
257+ lua_pop(L, 1); /* remove _LOADED table */
252258 lua_insert(L, -(nup+1)); /* move library table to below upvalues */
253259 }
254260 for (; l->name; l++) {
@@ -352,8 +358,8 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { · 97 unmodified lines
352358 }
353359
354360
355−static const char *luaL_gsub (lua_State *L, const char *s,
356− const char *p, const char *r) {
361+LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
362+ const char *r) {
357363 const char *wild;
358364 int l = strlen(p);
359365 luaL_Buffer b;
@@ -381,16 +387,68 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, · 21 unmodified lines
381387 }
382388 fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
383389 lua_remove(L, -2); /* remove path template */
384− f = fopen(fname, "r"); /* try to read it */
390+ f = fopen(fname, "r"); /* try to open it */
385391 if (f) {
392+ int err;
393+ getc(f); /* try to read file */
394+ err = ferror(f);
386395 fclose(f);
387− return fname;
396+ if (err == 0) /* open and read sucessful? */
397+ return fname; /* return that file name */
388398 }
389399 lua_pop(L, 1); /* remove file name */
390400 }
391401 }
392402
393403
404+LUALIB_API const char *luaL_getfield (lua_State *L, int idx,
405+ const char *fname) {
406+ const char *e;
407+ lua_pushvalue(L, idx);
408+ while ((e = strchr(fname, '.')) != NULL) {
409+ lua_pushlstring(L, fname, e - fname);
410+ lua_rawget(L, -2);
411+ lua_remove(L, -2); /* remove previous table */
412+ fname = e + 1;
413+ if (!lua_istable(L, -1)) return fname;
414+ }
415+ lua_pushstring(L, fname);
416+ lua_rawget(L, -2); /* get last field */
417+ lua_remove(L, -2); /* remove previous table */
418+ return NULL;
419+}
420+
421+
422+LUALIB_API const char *luaL_setfield (lua_State *L, int idx,
423+ const char *fname) {
424+ const char *e;
425+ lua_pushvalue(L, idx);
426+ while ((e = strchr(fname, '.')) != NULL) {
427+ lua_pushlstring(L, fname, e - fname);
428+ lua_rawget(L, -2);
429+ if (lua_isnil(L, -1)) { /* no such field? */
430+ lua_pop(L, 1); /* remove this nil */
431+ lua_newtable(L); /* create a new table for field */
432+ lua_pushlstring(L, fname, e - fname);
433+ lua_pushvalue(L, -2);
434+ lua_settable(L, -4); /* set new table into field */
435+ }
436+ lua_remove(L, -2); /* remove previous table */
437+ fname = e + 1;
438+ if (!lua_istable(L, -1)) {
439+ lua_pop(L, 2); /* remove table and value */
440+ return fname;
441+ }
442+ }
443+ lua_pushstring(L, fname);
444+ lua_pushvalue(L, -3); /* move value to the top */
445+ lua_rawset(L, -3); /* set last field */
446+ lua_pop(L, 2); /* remove value and table */
447+ return NULL;
448+}
449+
450+
451+
394452 /*
395453 ** {======================================================
396454 ** Generic Buffer manipulation
src/lib/lbaselib.c+13−63
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.158 2004/09/15 20:39:42 roberto Exp $
2+** $Id: lbaselib.c,v 1.161 2004/12/06 17:53:42 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -181,10 +181,10 @@ static int luaB_gcinfo (lua_State *L) { · 175 unmodified lines
181181
182182
183183 static int luaB_collectgarbage (lua_State *L) {
184− static const char *const opts[] = {"stop", "restart", "collect", "count",
185− "step", NULL};
186− static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART,
187− LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCSTEP};
184+ static const char *const opts[] = {"stop", "restart", "collect",
185+ "count", "step", "setstepmul", "setincmode", NULL};
186+ static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
187+ LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETSTEPMUL, LUA_GCSETINCMODE};
188188 int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
189189 int ex = luaL_optint(L, 2, 0);
190190 luaL_argcheck(L, o >= 0, 1, "invalid option");
@@ -440,50 +440,6 @@ static int luaB_newproxy (lua_State *L) { · 249 unmodified lines
440440 }
441441
442442
443−/*
444−** {======================================================
445−** `require' function
446−** =======================================================
447−*/
448−
449−
450−static const char *getpath (lua_State *L) {
451− /* try first `LUA_PATH' for compatibility */
452− lua_getfield(L, LUA_GLOBALSINDEX, "LUA_PATH");
453− if (!lua_isstring(L, -1)) {
454− lua_pop(L, 1);
455− lua_getfield(L, LUA_GLOBALSINDEX, "_PATH");
456− }
457− if (!lua_isstring(L, -1))
458− luaL_error(L, "global _PATH must be a string");
459− return lua_tostring(L, -1);
460−}
461−
462−
463−static int luaB_require (lua_State *L) {
464− const char *name = luaL_checkstring(L, 1);
465− const char *fname;
466− lua_getfield(L, lua_upvalueindex(1), name);
467− if (lua_toboolean(L, -1)) /* is it there? */
468− return 1; /* package is already loaded; return its result */
469− /* else must load it; first mark it as loaded */
470− lua_pushboolean(L, 1);
471− lua_setfield(L, lua_upvalueindex(1), name); /* _LOADED[name] = true */
472− fname = luaL_searchpath(L, name, getpath(L));
473− if (fname == NULL || luaL_loadfile(L, fname) != 0)
474− return luaL_error(L, "error loading package `%s' (%s)", name,
475− lua_tostring(L, -1));
476− lua_pushvalue(L, 1); /* pass name as argument to module */
477− lua_call(L, 1, 1); /* run loaded module */
478− if (!lua_isnil(L, -1)) /* nil return? */
479− lua_setfield(L, lua_upvalueindex(1), name);
480− lua_getfield(L, lua_upvalueindex(1), name); /* return _LOADED[name] */
481− return 1;
482−}
483−
484−/* }====================================================== */
485−
486−
487443 static const luaL_reg base_funcs[] = {
488444 {"error", luaB_error},
489445 {"getmetatable", luaB_getmetatable},
@@ -656,11 +612,10 @@ static void auxopen (lua_State *L, const char *name, · 166 unmodified lines
656612
657613
658614 static void base_open (lua_State *L) {
659− const char *path;
660615 lua_pushvalue(L, LUA_GLOBALSINDEX);
661616 luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */
662617 lua_pushliteral(L, LUA_VERSION);
663− lua_setfield(L, LUA_GLOBALSINDEX, "_VERSION"); /* set global _VERSION */
618+ lua_setglobal(L, "_VERSION"); /* set global _VERSION */
664619 /* `ipairs' and `pairs' need auxliliary functions as upvalues */
665620 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
666621 auxopen(L, "pairs", luaB_pairs, luaB_next);
@@ -671,21 +626,16 @@ static void base_open (lua_State *L) { · 4 unmodified lines
671626 lua_pushliteral(L, "kv");
672627 lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
673628 lua_pushcclosure(L, luaB_newproxy, 1);
674− lua_setfield(L, LUA_GLOBALSINDEX, "newproxy"); /* set global `newproxy' */
675− /* `require' needs a table to keep loaded chunks */
629+ lua_setglobal(L, "newproxy"); /* set global `newproxy' */
630+ /* create register._LOADED to track loaded modules */
631+ lua_newtable(L);
632+ lua_setfield(L, LUA_REGISTRYINDEX, "_LOADED");
633+ /* create register._PRELOAD to allow pre-loaded modules */
676634 lua_newtable(L);
677− lua_pushvalue(L, -1);
678− lua_setglobal(L, "_LOADED");
679− lua_pushcclosure(L, luaB_require, 1);
680− lua_setfield(L, LUA_GLOBALSINDEX, "require");
635+ lua_setfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
681636 /* set global _G */
682637 lua_pushvalue(L, LUA_GLOBALSINDEX);
683− lua_setfield(L, LUA_GLOBALSINDEX, "_G");
684− /* set global _PATH */
685− path = getenv(LUA_PATH);
686− if (path == NULL) path = LUA_PATH_DEFAULT;
687− lua_pushstring(L, path);
688− lua_setfield(L, LUA_GLOBALSINDEX, "_PATH");
638+ lua_setglobal(L, "_G");
689639 }
690640
691641
src/lib/ldblib.c+5−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.87 2004/08/13 18:02:36 roberto Exp $
2+** $Id: ldblib.c,v 1.89 2004/11/17 12:02:41 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -261,7 +261,7 @@ static int debug (lua_State *L) { · 255 unmodified lines
261261 if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
262262 strcmp(buffer, "cont\n") == 0)
263263 return 0;
264− if (luaL_loadbuffer(L, buffer, strlen(buffer), "=debug command") ||
264+ if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
265265 lua_pcall(L, 0, 0, 0)) {
266266 fputs(lua_tostring(L, -1), stderr);
267267 fputs("\n", stderr);
@@ -275,14 +275,15 @@ static int debug (lua_State *L) { · 7 unmodified lines
275275 #define LEVELS2 10 /* size of the second part of the stack */
276276
277277 static int errorfb (lua_State *L) {
278− int level = 1; /* skip level 0 (it's this function) */
278+ int level = 0;
279279 int firstpart = 1; /* still before eventual `...' */
280280 int arg;
281281 lua_State *L1 = getthread(L, &arg);
282282 lua_Debug ar;
283+ if (L == L1) level++; /* skip level 0 (it's this function) */
283284 if (lua_gettop(L) == arg)
284285 lua_pushliteral(L, "");
285− else if (!lua_isstring(L, arg+1)) return 1; /* no string message */
286+ else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */
286287 else lua_pushliteral(L, "\n");
287288 lua_pushliteral(L, "stack traceback:");
288289 while (lua_getstack(L1, level++, &ar)) {
src/lib/loadlib.c+319−78
@@ -1,31 +1,35 @@
11 /*
2−** $Id: loadlib.c,v 1.6 2004/04/30 20:13:38 roberto Exp $
2+** $Id: loadlib.c,v 1.11 2004/11/19 15:52:12 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 *
6−* This Lua library exports a single function, called loadlib, which is
7−* called from Lua as loadlib(lib,init), where lib is the full name of the
8−* library to be loaded (including the complete path) and init is the name
9−* of a function to be called after the library is loaded. Typically, this
10−* function will register other functions, thus making the complete library
11−* available to Lua. The init function is *not* automatically called by
12−* loadlib. Instead, loadlib returns the init function as a Lua function
13−* that the client can call when it thinks is appropriate. In the case of
14−* errors, loadlib returns nil and two strings describing the error.
15−* The first string is supplied by the operating system; it should be
16−* informative and useful for error messages. The second string is "open",
17−* "init", or "absent" to identify the error and is meant to be used for
18−* making decisions without having to look into the first string (whose
19−* format is system-dependent).
20−*
21−* This module contains an implementation of loadlib for Unix systems that
22−* have dlfcn, an implementation for Windows, and a stub for other systems.
23−* See the list at the end of this file for some links to available
24−* implementations of dlfcn and interfaces to other native dynamic loaders
25−* on top of which loadlib could be implemented.
26−*
6+* This Lua library exports a single function, called loadlib, which
7+* is called from Lua as loadlib(lib,init), where lib is the full
8+* name of the library to be loaded (including the complete path) and
9+* init is the name of a function to be called after the library is
10+* loaded. Typically, this function will register other functions, thus
11+* making the complete library available to Lua. The init function is
12+* *not* automatically called by loadlib. Instead, loadlib returns the
13+* init function as a Lua function that the client can call when it
14+* thinks is appropriate. In the case of errors, loadlib returns nil and
15+* two strings describing the error. The first string is supplied by
16+* the operating system; it should be informative and useful for error
17+* messages. The second string is "open", "init", or "absent" to identify
18+* the error and is meant to be used for making decisions without having
19+* to look into the first string (whose format is system-dependent).
20+* This module contains an implementation of loadlib for Unix systems
21+* that have dlfcn, an implementation for Darwin (Mac OS X), an
22+* implementation for Windows, and a stub for other systems. See
23+* the list at the end of this file for some links to available
24+* implementations of dlfcn and interfaces to other native dynamic
25+* loaders on top of which loadlib could be implemented.
2726 */
2827
28+
29+#include <stdlib.h>
30+#include <string.h>
31+
32+
2933 #define loadlib_c
3034 #define LUA_LIB
3135
@@ -34,11 +38,14 @@ · 2 unmodified lines
3438 #include "lualib.h"
3539
3640
37−#undef LOADLIB
41+#define ERR_OPEN 1
42+#define ERR_FUNCTION 2
43+
44+
45+static void registerlib (lua_State *L, const void *lib);
3846
3947
40−#ifdef USE_DLOPEN
41−#define LOADLIB
48+#if defined(USE_DLOPEN)
4249 /*
4350 * This is an implementation of loadlib based on the dlfcn interface.
4451 * The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
@@ -48,53 +55,41 @@ · 3 unmodified lines
4855
4956 #include <dlfcn.h>
5057
51−static int loadlib(lua_State *L)
58+#define freelib dlclose
59+
60+static int loadlib(lua_State *L, const char *path, const char *init)
5261 {
53− const char *path=luaL_checkstring(L,1);
54− const char *init=luaL_checkstring(L,2);
5562 void *lib=dlopen(path,RTLD_NOW);
5663 if (lib!=NULL)
5764 {
5865 lua_CFunction f=(lua_CFunction) dlsym(lib,init);
5966 if (f!=NULL)
6067 {
61− lua_pushlightuserdata(L,lib);
62− lua_pushcclosure(L,f,1);
63− return 1;
68+ registerlib(L, lib);
69+ lua_pushcfunction(L,f);
70+ return 0;
6471 }
6572 }
66− /* else return appropriate error messages */
67− lua_pushnil(L);
73+ /* else return appropriate error message */
6874 lua_pushstring(L,dlerror());
69− lua_pushstring(L,(lib!=NULL) ? "init" : "open");
70− if (lib!=NULL) dlclose(lib);
71− return 3;
75+ if (lib!=NULL) {
76+ dlclose(lib);
77+ return ERR_FUNCTION; /* error loading function */
78+ }
79+ else return ERR_OPEN; /* error loading library */
7280 }
7381
74−#endif
75−
76−
77−
78−/*
79−** In Windows, default is to use dll; otherwise, default is not to use dll
80−*/
81−#ifndef USE_DLL
82−#ifdef _WIN32
83−#define USE_DLL 1
84−#else
85−#define USE_DLL 0
86−#endif
87−#endif
8882
8983
90−#if USE_DLL
91−#define LOADLIB
84+#elif defined(USE_DLL)
9285 /*
9386 * This is an implementation of loadlib for Windows using native functions.
9487 */
9588
9689 #include <windows.h>
9790
91+#define freelib(lib) FreeLibrary((HINSTANCE)lib)
92+
9893 static void pusherror(lua_State *L)
9994 {
10095 int error=GetLastError();
@@ -106,61 +101,310 @@ static void pusherror(lua_State *L) · 5 unmodified lines
106101 lua_pushfstring(L,"system error %d\n",error);
107102 }
108103
109−static int loadlib(lua_State *L)
104+static int loadlib(lua_State *L, const char *path, const char *init)
110105 {
111− const char *path=luaL_checkstring(L,1);
112− const char *init=luaL_checkstring(L,2);
113106 HINSTANCE lib=LoadLibrary(path);
114107 if (lib!=NULL)
115108 {
116109 lua_CFunction f=(lua_CFunction) GetProcAddress(lib,init);
117110 if (f!=NULL)
118111 {
119− lua_pushlightuserdata(L,lib);
120− lua_pushcclosure(L,f,1);
112+ registerlib(L, lib);
113+ lua_pushcfunction(L,f);
121114 return 1;
122115 }
123116 }
124− lua_pushnil(L);
125117 pusherror(L);
126− lua_pushstring(L,(lib!=NULL) ? "init" : "open");
127− if (lib!=NULL) FreeLibrary(lib);
128− return 3;
118+ if (lib!=NULL) {
119+ FreeLibrary(lib);
120+ return ERR_OPEN;
121+ }
122+ else return ERR_FUNCTION;
129123 }
130124
131−#endif
132125
133126
127+/* Native Mac OS X / Darwin Implementation */
128+#elif defined(USE_DYLD)
129+
130+#include <mach-o/dyld.h>
131+
132+
133+/* Mach cannot unload images (?) */
134+#define freelib(lib) ((void)lib)
135+
136+static void pusherror (lua_State *L)
137+{
138+ const char *err_str;
139+ const char *err_file;
140+ NSLinkEditErrors err;
141+ int err_num;
142+ NSLinkEditError(&err, &err_num, &err_file, &err_str);
143+ lua_pushstring(L, err_str);
144+}
145+
146+static int loadlib (lua_State *L, const char *path, const char *init) {
147+ const struct mach_header *lib;
148+ /* this would be a rare case, but prevents crashing if it happens */
149+ if(!_dyld_present()) {
150+ lua_pushstring(L,"dyld not present.");
151+ return ERR_OPEN;
152+ }
153+ lib = NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
154+ if(lib != NULL) {
155+ NSSymbol init_sym = NSLookupSymbolInImage(lib, init,
156+ NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
157+ NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
158+ if(init_sym != NULL) {
159+ lua_CFunction f = (lua_CFunction)NSAddressOfSymbol(init_sym);
160+ registerlib(L, lib);
161+ lua_pushcfunction(L,f);
162+ return 0;
163+ }
164+ }
165+ /* else an error ocurred */
166+ pusherror(L);
167+ /* Can't unload image */
168+ return (lib != NULL) ? ERR_FUNCTION : ERR_OPEN;
169+}
170+
134171
135−#ifndef LOADLIB
136−/* Fallback for other systems */
137172
138−/*
139−** Those systems support dlopen, so they should have defined USE_DLOPEN.
140−** The default (no)implementation gives them a special error message.
141−*/
142−#if defined(linux) || defined(sun) || defined(sgi) || defined(BSD) || defined(_WIN32)
143−#define LOADLIB "`loadlib' not installed (check your Lua configuration)"
144173 #else
145−#define LOADLIB "`loadlib' not supported"
146−#endif
174+/* Fallback for other systems */
175+
147176
177+#define freelib(lib) ((void)lib)
148178
149179 static int loadlib(lua_State *L)
150180 {
181+ registerlib(L, NULL); /* to avoid warnings */
151182 lua_pushnil(L);
152− lua_pushliteral(L,LOADLIB);
183+ lua_pushliteral(L,"`loadlib' not supported");
153184 lua_pushliteral(L,"absent");
154185 return 3;
155186 }
187+
156188 #endif
157189
158−LUALIB_API int luaopen_loadlib (lua_State *L)
190+
191+/*
192+** common code for all implementations: put a library into the registry
193+** so that, when Lua closes its state, the library's __gc metamethod
194+** will be called to unload the library.
195+*/
196+static void registerlib (lua_State *L, const void *lib)
197+{
198+ const void **plib = (const void **)lua_newuserdata(L, sizeof(const void *));
199+ *plib = lib;
200+ luaL_getmetatable(L, "_LOADLIB");
201+ lua_setmetatable(L, -2);
202+ lua_pushboolean(L, 1);
203+ lua_settable(L, LUA_REGISTRYINDEX); /* registry[lib] = true */
204+}
205+
206+/*
207+** __gc tag method: calls library's `freelib' function with the lib
208+** handle
209+*/
210+static int gctm (lua_State *L)
159211 {
160− lua_register(L,"loadlib",loadlib);
212+ void *lib = *(void **)luaL_checkudata(L, 1, "_LOADLIB");
213+ freelib(lib);
161214 return 0;
162215 }
163216
217+
218+static int loadlib1 (lua_State *L) {
219+ const char *path=luaL_checkstring(L,1);
220+ const char *init=luaL_checkstring(L,2);
221+ int res = loadlib(L,path,init);
222+ if (res == 0) /* no error? */
223+ return 1; /* function is at stack top */
224+ else { /* error */
225+ lua_pushnil(L);
226+ lua_insert(L,-2); /* insert nil before error message */
227+ lua_pushstring(L, (res==ERR_OPEN)?"open":"init");
228+ return 3;
229+ }
230+}
231+
232+
233+
234+/*
235+** {======================================================
236+** `require' and `module' functions
237+** =======================================================
238+*/
239+
240+
241+static const char *loadLua (lua_State *L, const char *fname, const char *name) {
242+ const char *path;
243+ /* try first `LUA_PATH' for compatibility */
244+ lua_getglobal(L, "LUA_PATH");
245+ path = lua_tostring(L, -1);
246+ if (!path) {
247+ lua_pop(L, 1);
248+ luaL_getfield(L, LUA_GLOBALSINDEX, "package.path");
249+ path = lua_tostring(L, -1);
250+ }
251+ if (path == NULL)
252+ luaL_error(L, "`package.path' must be a string");
253+ fname = luaL_searchpath(L, fname, path);
254+ if (fname == NULL) return path; /* library not found in this path */
255+ if (luaL_loadfile(L, fname) != 0)
256+ luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1));
257+ return NULL; /* library loaded successfully */
258+}
259+
260+
261+static const char *loadC (lua_State *L, const char *fname, const char *name) {
262+ const char *path;
263+ const char *funcname;
264+ luaL_getfield(L, LUA_GLOBALSINDEX, "package.cpath");
265+ path = lua_tostring(L, -1);
266+ if (path == NULL)
267+ luaL_error(L, "global _CPATH must be a string");
268+ fname = luaL_searchpath(L, fname, path);
269+ if (fname == NULL) return path; /* library not found in this path */
270+ funcname = luaL_gsub(L, name, ".", "");
271+ funcname = lua_pushfstring(L, "%s%s", LUA_POF, funcname);
272+ if (loadlib(L, fname, funcname) != 0)
273+ luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1));
274+ return NULL; /* library loaded successfully */
275+}
276+
277+
278+static int ll_require (lua_State *L) {
279+ const char *name = luaL_checkstring(L, 1);
280+ lua_settop(L, 1);
281+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
282+ lua_getfield(L, 2, name);
283+ if (lua_toboolean(L, -1)) /* is it there? */
284+ return 1; /* package is already loaded; return its result */
285+ /* else must load it; first mark it as loaded */
286+ lua_pushboolean(L, 1);
287+ lua_setfield(L, 2, name); /* _LOADED[name] = true */
288+ /* check whether it is preloaded */
289+ lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
290+ lua_getfield(L, -1, name);
291+ if (lua_isnil(L, -1)) { /* no preload function for that module? */
292+ const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP);
293+ const char *cpath = loadC(L, fname, name); /* try a C module */
294+ if (cpath) { /* not found? */
295+ const char *path = loadLua(L, fname, name); /* try a Lua module */
296+ if (path) { /* yet not found? */
297+ lua_pushnil(L);
298+ lua_setfield(L, 2, name); /* unmark _LOADED[name] */
299+ return luaL_error(L, "package `%s' not found\n"
300+ " cpath: %s\n path: %s",
301+ name, cpath, path);
302+ }
303+ }
304+ }
305+ lua_pushvalue(L, 1); /* pass name as argument to module */
306+ lua_call(L, 1, 1); /* run loaded module */
307+ if (!lua_isnil(L, -1)) /* non-nil return? */
308+ lua_setfield(L, 2, name); /* update _LOADED[name] with returned value */
309+ lua_getfield(L, 2, name); /* return _LOADED[name] */
310+ return 1;
311+}
312+
313+
314+static void setfenv (lua_State *L) {
315+ lua_Debug ar;
316+ lua_getstack(L, 1, &ar);
317+ lua_getinfo(L, "f", &ar);
318+ lua_pushvalue(L, -2);
319+ lua_setfenv(L, -2);
320+}
321+
322+
323+static int ll_module (lua_State *L) {
324+ const char *modname = luaL_checkstring(L, 1);
325+ const char *dot;
326+ lua_settop(L, 1);
327+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
328+ /* try to find given table */
329+ luaL_getfield(L, LUA_GLOBALSINDEX, modname);
330+ if (lua_isnil(L, -1)) { /* not found? */
331+ lua_pop(L, 1); /* remove previous result */
332+ lua_newtable(L); /* create it */
333+ /* register it with given name */
334+ lua_pushvalue(L, -1);
335+ luaL_setfield(L, LUA_GLOBALSINDEX, modname);
336+ }
337+ else if (!lua_istable(L, -1))
338+ return luaL_error(L, "name conflict for module `%s'", modname);
339+ /* check whether table already has a _NAME field */
340+ lua_getfield(L, -1, "_NAME");
341+ if (!lua_isnil(L, -1)) /* is table an initialized module? */
342+ lua_pop(L, 1);
343+ else { /* no; initialize it */
344+ lua_pop(L, 1);
345+ lua_newtable(L); /* create new metatable */
346+ lua_pushvalue(L, LUA_GLOBALSINDEX);
347+ lua_setfield(L, -2, "__index"); /* mt.__index = _G */
348+ lua_setmetatable(L, -2);
349+ lua_pushstring(L, modname);
350+ lua_setfield(L, -2, "_NAME");
351+ dot = strrchr(modname, '.'); /* look for last dot in module name */
352+ if (dot == NULL) dot = modname;
353+ else dot++;
354+ /* set _PACKAGE as package name (full module name minus last part) */
355+ lua_pushlstring(L, modname, dot - modname);
356+ lua_setfield(L, -2, "_PACKAGE");
357+ }
358+ lua_pushvalue(L, -1);
359+ lua_setfield(L, 2, modname); /* _LOADED[modname] = new table */
360+ setfenv(L);
361+ return 0;
362+}
363+
364+
365+/* }====================================================== */
366+
367+
368+static const luaL_reg ll_funcs[] = {
369+ {"loadlib", loadlib1},
370+ {"require", ll_require},
371+ {"module", ll_module},
372+ {NULL, NULL}
373+};
374+
375+
376+
377+LUALIB_API int luaopen_loadlib (lua_State *L) {
378+ const char *path;
379+ /* create new type _LOADLIB */
380+ luaL_newmetatable(L, "_LOADLIB");
381+ lua_pushcfunction(L, gctm);
382+ lua_setfield(L, -2, "__gc");
383+ /* create `package' table */
384+ lua_newtable(L);
385+ lua_pushvalue(L, -1);
386+ lua_setglobal(L, "package");
387+ /* set field `path' */
388+ path = getenv(LUA_PATH);
389+ if (path == NULL) path = LUA_PATH_DEFAULT;
390+ lua_pushstring(L, path);
391+ lua_setfield(L, -2, "path");
392+ /* set field `cpath' */
393+ path = getenv(LUA_CPATH);
394+ if (path == NULL) path = LUA_CPATH_DEFAULT;
395+ lua_pushstring(L, path);
396+ lua_setfield(L, -2, "cpath");
397+ /* set field `loaded' */
398+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
399+ lua_setfield(L, -2, "loaded");
400+ /* set field `preload' */
401+ lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
402+ lua_setfield(L, -2, "preload");
403+ lua_pushvalue(L, LUA_GLOBALSINDEX);
404+ luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */
405+ return 1;
406+}
407+
164408 /*
165409 * Here are some links to available implementations of dlfcn and
166410 * interfaces to other native dynamic loaders on top of which loadlib
@@ -179,9 +423,6 @@ LUALIB_API int luaopen_loadlib (lua_State *L) · 12 unmodified lines
179423 * Macintosh, Windows
180424 * http://www.stat.umn.edu/~luke/xls/projects/dlbasics/dlbasics.html
181425 *
182−* Mac OS X/Darwin
183−* http://www.opendarwin.org/projects/dlcompat/
184−*
185426 * GLIB has wrapper code for BeOS, OS2, Unix and Windows
186427 * http://cvs.gnome.org/lxr/source/glib/gmodule/
187428 *
src/lib/loslib.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.2 2004/08/05 19:30:37 roberto Exp $
2+** $Id: loslib.c,v 1.3 2004/10/08 18:57:16 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -20,7 +20,7 @@ · 14 unmodified lines
2020 #include "lualib.h"
2121
2222
23−static int pushresult (lua_State *L, int i, const char *filename) {
23+static int os_pushresult (lua_State *L, int i, const char *filename) {
2424 if (i) {
2525 lua_pushboolean(L, 1);
2626 return 1;
@@ -45,14 +45,14 @@ static int io_execute (lua_State *L) { · 18 unmodified lines
4545
4646 static int io_remove (lua_State *L) {
4747 const char *filename = luaL_checkstring(L, 1);
48− return pushresult(L, remove(filename) == 0, filename);
48+ return os_pushresult(L, remove(filename) == 0, filename);
4949 }
5050
5151
5252 static int io_rename (lua_State *L) {
5353 const char *fromname = luaL_checkstring(L, 1);
5454 const char *toname = luaL_checkstring(L, 2);
55− return pushresult(L, rename(fromname, toname) == 0, fromname);
55+ return os_pushresult(L, rename(fromname, toname) == 0, fromname);
5656 }
5757
5858
src/lib/lstrlib.c+24−26
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.106 2004/08/09 13:30:33 roberto Exp $
2+** $Id: lstrlib.c,v 1.109 2004/12/01 15:46:06 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -24,8 +24,6 @@ · 18 unmodified lines
2424 #define uchar(c) ((unsigned char)(c))
2525
2626
27−typedef lua_Integer sint32; /* a signed version for size_t */
28−
2927
3028 static int str_len (lua_State *L) {
3129 size_t l;
@@ -35,19 +33,19 @@ static int str_len (lua_State *L) { · 3 unmodified lines
3533 }
3634
3735
38−static sint32 posrelat (sint32 pos, size_t len) {
36+static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {
3937 /* relative string position: negative means back from end */
40− return (pos>=0) ? pos : (sint32)len+pos+1;
38+ return (pos>=0) ? pos : (ptrdiff_t)len+pos+1;
4139 }
4240
4341
4442 static int str_sub (lua_State *L) {
4543 size_t l;
4644 const char *s = luaL_checklstring(L, 1, &l);
47− sint32 start = posrelat(luaL_checkinteger(L, 2), l);
48− sint32 end = posrelat(luaL_optinteger(L, 3, -1), l);
45+ ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l);
46+ ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l);
4947 if (start < 1) start = 1;
50− if (end > (sint32)l) end = (sint32)l;
48+ if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;
5149 if (start <= end)
5250 lua_pushlstring(L, s+start-1, end-start+1);
5351 else lua_pushliteral(L, "");
@@ -107,8 +105,8 @@ static int str_rep (lua_State *L) { · 53 unmodified lines
107105 static int str_byte (lua_State *L) {
108106 size_t l;
109107 const char *s = luaL_checklstring(L, 1, &l);
110− sint32 posi = posrelat(luaL_optinteger(L, 2, 1), l);
111− sint32 pose = posrelat(luaL_optinteger(L, 3, posi), l);
108+ ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
109+ ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
112110 int n, i;
113111 if (posi <= 0) posi = 1;
114112 if ((size_t)pose > l) pose = l;
@@ -173,7 +171,7 @@ typedef struct MatchState { · 58 unmodified lines
173171 int level; /* total number of captures (finished or unfinished) */
174172 struct {
175173 const char *init;
176− sint32 len;
174+ ptrdiff_t len;
177175 } capture[MAX_CAPTURES];
178176 } MatchState;
179177
@@ -198,7 +196,7 @@ static int capture_to_close (MatchState *ms) { · 18 unmodified lines
198196 }
199197
200198
201−static const char *luaI_classend (MatchState *ms, const char *p) {
199+static const char *classend (MatchState *ms, const char *p) {
202200 switch (*p++) {
203201 case ESC: {
204202 if (*p == '\0')
@@ -250,7 +248,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 45 unmodified lines
250248 while (++p < ec) {
251249 if (*p == ESC) {
252250 p++;
253− if (match_class(c, *p))
251+ if (match_class(c, uchar(*p)))
254252 return sig;
255253 }
256254 else if ((*(p+1) == '-') && (p+2 < ec)) {
@@ -264,10 +262,10 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 7 unmodified lines
264262 }
265263
266264
267−static int luaI_singlematch (int c, const char *p, const char *ep) {
265+static int singlematch (int c, const char *p, const char *ep) {
268266 switch (*p) {
269267 case '.': return 1; /* matches any char */
270− case ESC: return match_class(c, *(p+1));
268+ case ESC: return match_class(c, uchar(*(p+1)));
271269 case '[': return matchbracketclass(c, p, ep-1);
272270 default: return (uchar(*p) == c);
273271 }
@@ -299,8 +297,8 @@ static const char *matchbalance (MatchState *ms, const char *s, · 25 unmodified lines
299297
300298 static const char *max_expand (MatchState *ms, const char *s,
301299 const char *p, const char *ep) {
302− sint32 i = 0; /* counts maximum expand for item */
303− while ((s+i)<ms->src_end && luaI_singlematch(uchar(*(s+i)), p, ep))
300+ ptrdiff_t i = 0; /* counts maximum expand for item */
301+ while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))
304302 i++;
305303 /* keeps trying to match with the maximum repetitions */
306304 while (i>=0) {
@@ -318,7 +316,7 @@ static const char *min_expand (MatchState *ms, const char *s, · 11 unmodified lines
318316 const char *res = match(ms, s, ep+1);
319317 if (res != NULL)
320318 return res;
321− else if (s<ms->src_end && luaI_singlematch(uchar(*s), p, ep))
319+ else if (s<ms->src_end && singlematch(uchar(*s), p, ep))
322320 s++; /* try with one more repetition */
323321 else return NULL;
324322 }
@@ -385,7 +383,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 60 unmodified lines
385383 p += 2;
386384 if (*p != '[')
387385 luaL_error(ms->L, "missing `[' after `%%f' in pattern");
388− ep = luaI_classend(ms, p); /* points to what is next */
386+ ep = classend(ms, p); /* points to what is next */
389387 previous = (s == ms->src_init) ? '\0' : *(s-1);
390388 if (matchbracketclass(uchar(previous), p, ep-1) ||
391389 !matchbracketclass(uchar(*s), p, ep-1)) return NULL;
@@ -393,7 +391,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 1 unmodified line
393391 }
394392 default: {
395393 if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
396− s = match_capture(ms, s, *(p+1));
394+ s = match_capture(ms, s, uchar(*(p+1)));
397395 if (s == NULL) return NULL;
398396 p+=2; goto init; /* else return match(ms, s, p+2) */
399397 }
@@ -410,8 +408,8 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 10 unmodified lines
410408 else goto dflt;
411409 }
412410 default: dflt: { /* it is a pattern item */
413− const char *ep = luaI_classend(ms, p); /* points to what is next */
414− int m = s<ms->src_end && luaI_singlematch(uchar(*s), p, ep);
411+ const char *ep = classend(ms, p); /* points to what is next */
412+ int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
415413 switch (*ep) {
416414 case '?': { /* optional */
417415 const char *res;
@@ -490,9 +488,9 @@ static int str_find (lua_State *L) { · 72 unmodified lines
490488 size_t l1, l2;
491489 const char *s = luaL_checklstring(L, 1, &l1);
492490 const char *p = luaL_checklstring(L, 2, &l2);
493− sint32 init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
491+ ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
494492 if (init < 0) init = 0;
495− else if ((size_t)(init) > l1) init = (sint32)l1;
493+ else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
496494 if (lua_toboolean(L, 4) || /* explicit request? */
497495 strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
498496 /* do a plain search */
@@ -642,7 +640,7 @@ static int str_gsub (lua_State *L) { · 143 unmodified lines
642640 #define MAX_FORMAT 20
643641
644642
645−static void luaI_addquoted (lua_State *L, luaL_Buffer *b, int arg) {
643+static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
646644 size_t l;
647645 const char *s = luaL_checklstring(L, arg, &l);
648646 luaL_putchar(b, '"');
@@ -726,7 +724,7 @@ static int str_format (lua_State *L) { · 77 unmodified lines
726724 break;
727725 }
728726 case 'q': {
729− luaI_addquoted(L, &b, arg);
727+ addquoted(L, &b, arg);
730728 continue; /* skip the `addsize' at the end */
731729 }
732730 case 's': {
src/llex.c+41−35
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.3 2004/04/30 20:13:38 roberto Exp $
2+** $Id: llex.c,v 2.9 2004/12/03 20:54:12 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -26,34 +26,45 @@ · 20 unmodified lines
2626 #define next(ls) (ls->current = zgetc(ls->z))
2727
2828
29−#define save(ls,c) { \
30− Mbuffer *b = ls->buff; \
31− if (b->n + 1 > b->buffsize) \
32− luaZ_resizebuffer(ls->L, b, ((b->buffsize*2) + LUA_MINBUFFER)); \
33− b->buffer[b->n++] = cast(char, c); }
34−
3529
3630
3731 #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
3832
3933
4034 /* ORDER RESERVED */
41−static const char *const token2string [] = {
35+const char *const luaX_tokens [] = {
4236 "and", "break", "do", "else", "elseif",
4337 "end", "false", "for", "function", "if",
4438 "in", "local", "nil", "not", "or", "repeat",
45− "return", "then", "true", "until", "while", "*name",
39+ "return", "then", "true", "until", "while",
4640 "..", "...", "==", ">=", "<=", "~=",
47− "*number", "*string", "<eof>"
41+ "<number>", "<name>", "<string>", "<eof>",
42+ NULL
4843 };
4944
5045
46+#define save_and_next(ls) (save(ls, ls->current), next(ls))
47+
48+
49+static void save (LexState *ls, int c) {
50+ Mbuffer *b = ls->buff;
51+ if (b->n + 1 > b->buffsize) {
52+ size_t newsize;
53+ if (b->buffsize >= MAX_SIZET/2)
54+ luaX_lexerror(ls, "lexical element too long", 0);
55+ newsize = b->buffsize * 2;
56+ luaZ_resizebuffer(ls->L, b, newsize);
57+ }
58+ b->buffer[b->n++] = cast(char, c);
59+}
60+
61+
5162 void luaX_init (lua_State *L) {
5263 int i;
5364 for (i=0; i<NUM_RESERVED; i++) {
54− TString *ts = luaS_new(L, token2string[i]);
65+ TString *ts = luaS_new(L, luaX_tokens[i]);
5566 luaS_fix(ts); /* reserved words are never collected */
56− lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN);
67+ lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
5768 ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */
5869 }
5970 }
@@ -64,12 +75,12 @@ void luaX_init (lua_State *L) { · 4 unmodified lines
6475
6576 const char *luaX_token2str (LexState *ls, int token) {
6677 if (token < FIRST_RESERVED) {
67− lua_assert(token == (unsigned char)token);
78+ lua_assert(token == cast(unsigned char, token));
6879 return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
6980 luaO_pushfstring(ls->L, "%c", token);
7081 }
7182 else
72− return token2string[token-FIRST_RESERVED];
83+ return luaX_tokens[token-FIRST_RESERVED];
7384 }
7485
7586
@@ -130,6 +141,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 54 unmodified lines
130141 ls->linenumber = 1;
131142 ls->lastline = 1;
132143 ls->source = source;
144+ luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
133145 next(ls); /* read first char */
134146 }
135147
@@ -143,12 +155,6 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 7 unmodified lines
143155
144156
145157
146−static void save_and_next (LexState *ls) {
147− save(ls, ls->current);
148− next(ls);
149−}
150−
151−
152158
153159 /* LUA_NUMBER */
154160 static void read_numeral (LexState *ls, SemInfo *seminfo) {
@@ -181,12 +187,12 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 26 unmodified lines
181187 }
182188
183189
184−static int skip_ast (LexState *ls) {
190+static int skip_sep (LexState *ls) {
185191 int count = 0;
186192 int s = ls->current;
187193 lua_assert(s == '[' || s == ']');
188194 save_and_next(ls);
189− while (ls->current == '*') {
195+ while (ls->current == '=') {
190196 save_and_next(ls);
191197 count++;
192198 }
@@ -194,7 +200,7 @@ static int skip_ast (LexState *ls) { · 1 unmodified line
194200 }
195201
196202
197−static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) {
203+static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
198204 int cont = 0;
199205 save_and_next(ls); /* skip 2nd `[' */
200206 if (currIsNewline(ls)) /* string starts with a newline? */
@@ -206,13 +212,13 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) { · 5 unmodified lines
206212 "unfinished long comment", TK_EOS);
207213 break; /* to avoid warnings */
208214 case '[':
209− if (skip_ast(ls) == ast) {
215+ if (skip_sep(ls) == sep) {
210216 save_and_next(ls); /* skip 2nd `[' */
211217 cont++;
212218 }
213219 continue;
214220 case ']':
215− if (skip_ast(ls) == ast) {
221+ if (skip_sep(ls) == sep) {
216222 save_and_next(ls); /* skip 2nd `]' */
217223 if (cont-- == 0) goto endloop;
218224 }
@@ -229,8 +235,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int ast) { · 10 unmodified lines
229235 }
230236 } endloop:
231237 if (seminfo)
232− seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + ast),
233− luaZ_bufflen(ls->buff) - 2*(2 + ast));
238+ seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
239+ luaZ_bufflen(ls->buff) - 2*(2 + sep));
234240 }
235241
236242
@@ -305,10 +311,10 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 68 unmodified lines
305311 /* else is a comment */
306312 next(ls);
307313 if (ls->current == '[') {
308− int ast = skip_ast(ls);
309− luaZ_resetbuffer(ls->buff); /* `skip_ast' may dirty the buffer */
310− if (ast >= 0) {
311− read_long_string(ls, NULL, ast); /* long comment */
314+ int sep = skip_sep(ls);
315+ luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
316+ if (sep >= 0) {
317+ read_long_string(ls, NULL, sep); /* long comment */
312318 luaZ_resetbuffer(ls->buff);
313319 continue;
314320 }
@@ -319,12 +325,12 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 4 unmodified lines
319325 continue;
320326 }
321327 case '[': {
322− int ast = skip_ast(ls);
323− if (ast >= 0) {
324− read_long_string(ls, seminfo, ast);
328+ int sep = skip_sep(ls);
329+ if (sep >= 0) {
330+ read_long_string(ls, seminfo, sep);
325331 return TK_STRING;
326332 }
327− else if (ast == -1) return '[';
333+ else if (sep == -1) return '[';
328334 else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
329335 }
330336 case '=': {
src/llex.h+7−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.h,v 1.50 2004/03/12 19:53:56 roberto Exp $
2+** $Id: llex.h,v 1.52 2004/12/03 20:54:12 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -28,14 +28,18 @@ enum RESERVED { · 22 unmodified lines
2828 TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
2929 TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
3030 /* other terminal symbols */
31− TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
32− TK_STRING, TK_EOS
31+ TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
32+ TK_NAME, TK_STRING, TK_EOS
3333 };
3434
3535 /* number of reserved words */
3636 #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
3737
3838
39+/* array with token `names' */
40+extern const char *const luaX_tokens [];
41+
42+
3943 typedef union {
4044 lua_Number r;
4145 TString *ts;
src/llimits.h+6−17
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.60 2004/09/10 17:30:46 roberto Exp $
2+** $Id: llimits.h,v 1.61 2004/11/24 18:55:56 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -18,22 +18,9 @@ · 12 unmodified lines
1818
1919 typedef LUA_UINT32 lu_int32;
2020
21−typedef LUA_INT32 l_int32;
21+typedef LU_MEM lu_mem;
2222
23−
24−/*
25−** an unsigned integer big enough to count the total memory used by Lua;
26−** it should be at least as large as `size_t'
27−*/
28−typedef lu_int32 lu_mem;
29−
30−
31−/*
32−** a signed integer big enough to count the total memory used by Lua;
33−** it should be at least as large as `size_t'
34−*/
35−typedef l_int32 l_mem;
36−#define MAXLMEM LUA_MAXINT32
23+typedef L_MEM l_mem;
3724
3825
3926
@@ -43,6 +30,8 @@ typedef unsigned char lu_byte; · 3 unmodified lines
4330
4431 #define MAX_SIZET ((size_t)(~(size_t)0)-2)
4532
33+#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
34+
4635
4736 #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
4837
@@ -51,7 +40,7 @@ typedef unsigned char lu_byte; · 2 unmodified lines
5140 ** this is for hashing only; there is no problem if the integer
5241 ** cannot hold the whole pointer value
5342 */
54−#define IntPoint(p) ((unsigned int)(p))
43+#define IntPoint(p) ((unsigned int)(lu_mem)(p))
5544
5645
5746
src/lmem.c+14−11
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.c,v 1.65 2004/08/30 13:44:44 roberto Exp $
2+** $Id: lmem.c,v 1.67 2004/12/01 15:46:18 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
@@ -43,36 +43,39 @@ · 37 unmodified lines
4343 #define MINSIZEARRAY 4
4444
4545
46−void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
47− int limit, const char *errormsg) {
46+void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
47+ int limit, const char *errormsg) {
4848 void *newblock;
4949 int newsize;
5050 if (*size >= limit/2) { /* cannot double it? */
51− if (*size >= limit - MINSIZEARRAY) /* try something smaller... */
51+ if (*size >= limit) /* cannot grow even a little? */
5252 luaG_runerror(L, errormsg);
53− newsize = limit; /* still have at least MINSIZEARRAY free places */
53+ newsize = limit; /* still have at least one free place */
5454 }
5555 else {
5656 newsize = (*size)*2;
5757 if (newsize < MINSIZEARRAY)
5858 newsize = MINSIZEARRAY; /* minimum size */
5959 }
60− newblock = luaM_realloc(L, block,
61− cast(lu_mem, *size)*cast(lu_mem, size_elems),
62− cast(lu_mem, newsize)*cast(lu_mem, size_elems));
60+ newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
6361 *size = newsize; /* update only when everything else is OK */
6462 return newblock;
6563 }
6664
6765
66+void *luaM_toobig (lua_State *L) {
67+ luaG_runerror(L, "memory allocation error: block too big");
68+ return NULL; /* to avoid warnings */
69+}
70+
71+
72+
6873 /*
6974 ** generic allocation routine.
7075 */
71−void *luaM_realloc (lua_State *L, void *block, lu_mem osize, lu_mem nsize) {
76+void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
7277 global_State *g = G(L);
7378 lua_assert((osize == 0) == (block == NULL));
74− if (nsize >= MAX_SIZET)
75− luaG_runerror(L, "memory allocation error: block too big");
7679 block = (*g->realloc)(g->ud, block, osize, nsize);
7780 if (block == NULL && nsize > 0)
7881 luaD_throw(L, LUA_ERRMEM);
src/lmem.h+22−16
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.h,v 1.26 2002/05/01 20:40:42 roberto Exp $
2+** $Id: lmem.h,v 1.29 2004/12/01 15:46:18 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
@@ -16,28 +16,34 @@ · 10 unmodified lines
1616 #define MEMERRMSG "not enough memory"
1717
1818
19−void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size);
19+void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size);
2020
21−void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
22− int limit, const char *errormsg);
21+void *luaM_toobig (lua_State *L);
2322
24−#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
25−#define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0)
26−#define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
27− cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
23+#define luaM_reallocv(L,b,on,n,e) \
24+ ((cast(unsigned int, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
25+ luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
26+ luaM_toobig(L))
2827
29−#define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
30−#define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
31−#define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
32− cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
28+
29+void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem,
30+ int limit, const char *errormsg);
31+
32+#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
33+#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
34+#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
35+
36+#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
37+#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
38+#define luaM_newvector(L,n,t) \
39+ cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
3340
3441 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
35− if (((nelems)+1) > (size)) \
36− ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
42+ if ((nelems)+1 > (size)) \
43+ ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
3744
3845 #define luaM_reallocvector(L, v,oldn,n,t) \
39− ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
40− cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
46+ ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
4147
4248
4349 #endif
src/lobject.c+16−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.4 2004/07/09 16:01:38 roberto Exp $
2+** $Id: lobject.c,v 2.7 2004/11/24 19:16:03 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -23,7 +23,7 @@ · 17 unmodified lines
2323
2424
2525
26−const TValue luaO_nilobject = {LUA_TNIL, {NULL}};
26+const TValue luaO_nilobject = {{NULL}, LUA_TNIL};
2727
2828
2929 /*
@@ -31,12 +31,21 @@ const TValue luaO_nilobject = {LUA_TNIL, {NULL}}; · 1 unmodified line
3131 ** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm)
3232 */
3333 int luaO_int2fb (unsigned int x) {
34− int m = 0; /* mantissa */
35− while (x >= (1<<3)) {
34+ int e = 0; /* expoent */
35+ while (x >= 16) {
3636 x = (x+1) >> 1;
37− m++;
37+ e++;
3838 }
39− return (m << 3) | cast(int, x);
39+ if (x < 8) return x;
40+ else return ((e+1) << 3) | (cast(int, x) - 8);
41+}
42+
43+
44+/* converts back */
45+int luaO_fb2int (int x) {
46+ int e = (x >> 3) & 31;
47+ if (e == 0) return x;
48+ else return ((x & 7)+8) << (e - 1);
4049 }
4150
4251
@@ -80,7 +89,7 @@ int luaO_str2d (const char *s, lua_Number *result) { · 37 unmodified lines
8089 char *endptr;
8190 lua_Number res = lua_str2number(s, &endptr);
8291 if (endptr == s) return 0; /* no conversion */
83− while (isspace((unsigned char)(*endptr))) endptr++;
92+ while (isspace(cast(unsigned char, *endptr))) endptr++;
8493 if (*endptr != '\0') return 0; /* invalid trailing characters? */
8594 *result = res;
8695 return 1;
src/lobject.h+15−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.5 2004/05/31 18:51:50 roberto Exp $
2+** $Id: lobject.h,v 2.8 2004/12/04 18:10:22 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -25,6 +25,7 @@ · 19 unmodified lines
2525 */
2626 #define LUA_TPROTO (NUM_TAGS+1)
2727 #define LUA_TUPVAL (NUM_TAGS+2)
28+#define LUA_TDEADKEY (NUM_TAGS+3)
2829
2930
3031 /*
@@ -64,9 +65,11 @@ typedef union { · 33 unmodified lines
6465 /*
6566 ** Tagged Values
6667 */
68+
69+#define TValuefields Value value; int tt
70+
6771 typedef struct lua_TValue {
68− int tt;
69− Value value;
72+ TValuefields;
7073 } TValue;
7174
7275
@@ -158,7 +161,7 @@ typedef struct lua_TValue { · 85 unmodified lines
158161
159162 #define setobj(L,obj1,obj2) \
160163 { const TValue *o2=(obj2); TValue *o1=(obj1); \
161− o1->tt=o2->tt; o1->value = o2->value; \
164+ o1->value = o2->value; o1->tt=o2->tt; \
162165 checkliveness(G(L),o1); }
163166
164167
@@ -308,10 +311,15 @@ typedef union Closure { · 143 unmodified lines
308311 ** Tables
309312 */
310313
314+typedef struct TKey {
315+ TValuefields;
316+ struct Node *next; /* for chaining */
317+} TKey;
318+
319+
311320 typedef struct Node {
312− TValue i_key;
313321 TValue i_val;
314− struct Node *next; /* for chaining */
322+ TKey i_key;
315323 } Node;
316324
317325
@@ -345,7 +353,7 @@ extern const TValue luaO_nilobject; · 27 unmodified lines
345353
346354 int luaO_log2 (unsigned int x);
347355 int luaO_int2fb (unsigned int x);
348−#define fb2int(x) (((x) & 7) << ((x) >> 3))
356+int luaO_fb2int (int x);
349357
350358 int luaO_rawequalObj (const TValue *t1, const TValue *t2);
351359 int luaO_str2d (const char *s, lua_Number *result);
src/lopcodes.c+5−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.c,v 1.28 2004/07/16 13:15:32 roberto Exp $
2+** $Id: lopcodes.c,v 1.30 2004/12/02 12:59:10 roberto Exp $
33 ** See Copyright Notice in lua.h
44 */
55
@@ -15,7 +15,7 @@ · 9 unmodified lines
1515
1616 /* ORDER OP */
1717
18−const char *const luaP_opnames[NUM_OPCODES] = {
18+const char *const luaP_opnames[NUM_OPCODES+1] = {
1919 "MOVE",
2020 "LOADK",
2121 "LOADBOOL",
@@ -49,10 +49,10 @@ const char *const luaP_opnames[NUM_OPCODES] = { · 27 unmodified lines
4949 "TFORLOOP",
5050 "TFORPREP",
5151 "SETLIST",
52− "SETLISTO",
5352 "CLOSE",
5453 "CLOSURE",
55− "VARARG"
54+ "VARARG",
55+ NULL
5656 };
5757
5858
@@ -92,8 +92,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 33 unmodified lines
9292 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
9393 ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */
9494 ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_TFORPREP */
95− ,opmode(0, 0, OpArgU, OpArgN, iABx) /* OP_SETLIST */
96− ,opmode(0, 0, OpArgU, OpArgN, iABx) /* OP_SETLISTO */
95+ ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
9796 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
9897 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
9998 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
src/lopcodes.h+10−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.111 2004/08/04 20:18:13 roberto Exp $
2+** $Id: lopcodes.h,v 1.114 2004/12/02 12:59:10 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -198,8 +198,7 @@ OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); · 192 unmodified lines
198198 OP_TFORPREP,/* A sBx if type(R(A)) == table then R(A+1):=R(A), R(A):=next;
199199 pc+=sBx */
200200
201−OP_SETLIST,/* A Bx R(A)[Bx-Bx%FPF+i] := R(A+i), 1 <= i <= Bx%FPF+1 */
202−OP_SETLISTO,/* A Bx */
201+OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
203202
204203 OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
205204 OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */
@@ -219,11 +218,15 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ · 13 unmodified lines
219218 next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.
220219
221220 (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
222− set top (like in OP_CALL).
221+ set top (like in OP_CALL with C == 0).
223222
224223 (*) In OP_RETURN, if (B == 0) then return up to `top'
225224
226− (*) For comparisons, B specifies what conditions the test should accept.
225+ (*) In OP_SETLIST, if (B == 0) then B = `top';
226+ if (C == 0) then next `instruction' is real C
227+
228+ (*) For comparisons, A specifies what condition the test should accept
229+ (true or false).
227230
228231 (*) All `skips' (pc++) assume that next instruction is a jump
229232 ===========================================================================*/
@@ -254,12 +257,11 @@ extern const lu_byte luaP_opmodes[NUM_OPCODES]; · 24 unmodified lines
254257 #define testTMode(m) (luaP_opmodes[m] & (1 << 7))
255258
256259
257−extern const char *const luaP_opnames[NUM_OPCODES]; /* opcode names */
260+extern const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
258261
259262
260263 /* number of list items to accumulate before a SETLIST instruction */
261−/* (must be a power of 2) */
262−#define LFIELDS_PER_FLUSH 32
264+#define LFIELDS_PER_FLUSH 50
263265
264266
265267 #endif
src/lparser.c+16−19
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.5 2004/05/31 18:51:50 roberto Exp $
2+** $Id: lparser.c,v 2.10 2004/12/03 20:50:25 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -31,7 +31,7 @@ · 25 unmodified lines
3131
3232 #define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]])
3333
34−#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) luaY_errorlimit(fs,l,m)
34+#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
3535
3636 #define enterlevel(ls) if (++(ls)->nestlevel > LUA_MAXPARSERLEVEL) \
3737 luaX_lexerror(ls, "chunk has too many syntax levels", 0)
@@ -90,7 +90,7 @@ static void error_expected (LexState *ls, int token) { · 52 unmodified lines
9090 }
9191
9292
93−static void luaY_errorlimit (FuncState *fs, int limit, const char *what) {
93+static void errorlimit (FuncState *fs, int limit, const char *what) {
9494 const char *msg = (fs->f->lineDefined == 0) ?
9595 luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
9696 luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
@@ -133,7 +133,7 @@ static void check_match (LexState *ls, int what, int who, int where) { · 36 unmodified lines
133133
134134 static TString *str_checkname (LexState *ls) {
135135 TString *ts;
136− check_condition(ls, (ls->t.token == TK_NAME), "<name> expected");
136+ if (ls->t.token != TK_NAME) error_expected(ls, TK_NAME);
137137 ts = ls->t.seminfo.ts;
138138 next(ls);
139139 return ts;
@@ -157,7 +157,7 @@ static void checkname(LexState *ls, expdesc *e) { · 17 unmodified lines
157157 }
158158
159159
160−static int luaI_registerlocalvar (LexState *ls, TString *varname) {
160+static int registerlocalvar (LexState *ls, TString *varname) {
161161 FuncState *fs = ls->fs;
162162 Proto *f = fs->f;
163163 int oldsize = f->sizelocvars;
@@ -177,8 +177,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { · 13 unmodified lines
177177 static void new_localvar (LexState *ls, TString *name, int n) {
178178 FuncState *fs = ls->fs;
179179 luaY_checklimit(fs, fs->nactvar+n+1, MAXVARS, "local variables");
180− fs->actvar[fs->nactvar+n] = cast(unsigned short,
181− luaI_registerlocalvar(ls, name));
180+ fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));
182181 }
183182
184183
@@ -413,7 +412,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 228 unmodified lines
413412 /*============================================================*/
414413
415414
416−static void luaY_field (LexState *ls, expdesc *v) {
415+static void field (LexState *ls, expdesc *v) {
417416 /* field -> ['.' | ':'] NAME */
418417 FuncState *fs = ls->fs;
419418 expdesc key;
@@ -424,7 +423,7 @@ static void luaY_field (LexState *ls, expdesc *v) { · 4 unmodified lines
424423 }
425424
426425
427−static void luaY_index (LexState *ls, expdesc *v) {
426+static void yindex (LexState *ls, expdesc *v) {
428427 /* index -> '[' expr ']' */
429428 next(ls); /* skip the '[' */
430429 expr(ls, v);
@@ -460,7 +459,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) { · 29 unmodified lines
460459 checkname(ls, &key);
461460 }
462461 else /* ls->t.token == '[' */
463− luaY_index(ls, &key);
462+ yindex(ls, &key);
464463 check(ls, '=');
465464 luaK_exp2RK(fs, &key);
466465 expr(ls, &val);
@@ -475,9 +474,8 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) { · 8 unmodified lines
475474 luaK_exp2nextreg(fs, &cc->v);
476475 cc->v.k = VVOID;
477476 if (cc->tostore == LFIELDS_PER_FLUSH) {
478− luaK_codeABx(fs, OP_SETLIST, cc->t->info, cc->na-1); /* flush */
477+ luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); /* flush */
479478 cc->tostore = 0; /* no more items pending */
480− fs->freereg = cc->t->info + 1; /* free registers */
481479 }
482480 }
483481
@@ -486,15 +484,14 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 2 unmodified lines
486484 if (cc->tostore == 0) return;
487485 if (hasmultret(cc->v.k)) {
488486 luaK_setmultret(fs, &cc->v);
489− luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1);
487+ luaK_setlist(fs, cc->t->info, cc->na, LUA_MULTRET);
490488 cc->na--; /* do not count last expression (unknown number of elements) */
491489 }
492490 else {
493491 if (cc->v.k != VVOID)
494492 luaK_exp2nextreg(fs, &cc->v);
495− luaK_codeABx(fs, OP_SETLIST, cc->t->info, cc->na-1);
493+ luaK_setlist(fs, cc->t->info, cc->na, cc->tostore);
496494 }
497− fs->freereg = cc->t->info + 1; /* free registers */
498495 }
499496
500497
@@ -703,13 +700,13 @@ static void primaryexp (LexState *ls, expdesc *v) { · 202 unmodified lines
703700 for (;;) {
704701 switch (ls->t.token) {
705702 case '.': { /* field */
706− luaY_field(ls, v);
703+ field(ls, v);
707704 break;
708705 }
709706 case '[': { /* `[' exp1 `]' */
710707 expdesc key;
711708 luaK_exp2anyreg(fs, v);
712− luaY_index(ls, &key);
709+ yindex(ls, &key);
713710 luaK_indexed(fs, v, &key);
714711 break;
715712 }
@@ -1213,10 +1210,10 @@ static int funcname (LexState *ls, expdesc *v) { · 497 unmodified lines
12131210 int needself = 0;
12141211 singlevar(ls, v, 1);
12151212 while (ls->t.token == '.')
1216− luaY_field(ls, v);
1213+ field(ls, v);
12171214 if (ls->t.token == ':') {
12181215 needself = 1;
1219− luaY_field(ls, v);
1216+ field(ls, v);
12201217 }
12211218 return needself;
12221219 }
src/lstate.c+6−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.c,v 2.14 2004/09/15 20:39:42 roberto Exp $
2+** $Id: lstate.c,v 2.18 2004/12/06 17:53:42 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -79,7 +79,7 @@ static void f_luaopen (lua_State *L, void *ud) { · 73 unmodified lines
7979 Udata *u; /* head of udata list */
8080 global_State *g = G(L);
8181 UNUSED(ud);
82− u = cast(Udata *, luaM_malloc(L, sizeudata(0)));
82+ u = luaM_new(L, Udata);
8383 u->uv.len = 0;
8484 u->uv.metatable = NULL;
8585 g->firstudata = obj2gco(u);
@@ -155,7 +155,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) { · 69 unmodified lines
155155 luaF_close(L1, L1->stack); /* close all upvalues for this thread */
156156 lua_assert(L1->openupval == NULL);
157157 freestack(L, L1);
158− luaM_free(L, fromstate(L1), state_size(lua_State));
158+ luaM_freemem(L, fromstate(L1), state_size(lua_State));
159159 }
160160
161161
@@ -191,8 +191,10 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 29 unmodified lines
191191 g->tmudata = NULL;
192192 setnilvalue(gkey(g->dummynode));
193193 setnilvalue(gval(g->dummynode));
194− g->dummynode->next = NULL;
194+ gnext(g->dummynode) = NULL;
195195 g->totalbytes = sizeof(LG);
196+ g->stepmul = STEPMUL;
197+ g->incgc = 1;
196198 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
197199 /* memory allocation error: free partial state */
198200 close_state(L);
src/lstate.h+3−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.h,v 2.8 2004/09/15 20:39:42 roberto Exp $
2+** $Id: lstate.h,v 2.9 2004/12/06 17:53:42 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -85,6 +85,8 @@ typedef struct global_State { · 79 unmodified lines
8585 lu_mem totalbytes; /* number of bytes currently allocated */
8686 lu_mem estimate; /* an estimate of number of bytes actually in use */
8787 lu_mem prevestimate; /* previous estimate */
88+ int stepmul; /* relative `speed' of the GC */
89+ int incgc; /* 0 if GC is done non-incrementally */
8890 lua_CFunction panic; /* to be called in unprotected errors */
8991 TValue _registry;
9092 struct lua_State *mainthread;
src/lstring.c+9−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.c,v 2.3 2004/08/24 20:12:06 roberto Exp $
2+** $Id: lstring.c,v 2.5 2004/11/24 19:16:03 roberto Exp $
33 ** String table (keeps all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
@@ -49,8 +49,11 @@ void luaS_resize (lua_State *L, int newsize) { · 43 unmodified lines
4949
5050 static TString *newlstr (lua_State *L, const char *str, size_t l,
5151 unsigned int h) {
52− TString *ts = cast(TString *, luaM_malloc(L, sizestring(l)));
52+ TString *ts;
5353 stringtable *tb;
54+ if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
55+ luaM_toobig(L);
56+ ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
5457 ts->tsv.len = l;
5558 ts->tsv.hash = h;
5659 ts->tsv.marked = luaC_white(G(L));
@@ -75,7 +78,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { · 18 unmodified lines
7578 size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
7679 size_t l1;
7780 for (l1=l; l1>=step; l1-=step) /* compute hash */
78− h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1]));
81+ h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
7982 for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
8083 o != NULL;
8184 o = o->gch.next) {
@@ -92,7 +95,9 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { · 10 unmodified lines
9295
9396 Udata *luaS_newudata (lua_State *L, size_t s) {
9497 Udata *u;
95− u = cast(Udata *, luaM_malloc(L, sizeudata(s)));
98+ if (s > MAX_SIZET - sizeof(Udata))
99+ luaM_toobig(L);
100+ u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
96101 u->uv.marked = luaC_white(G(L)); /* is not finalized */
97102 u->uv.tt = LUA_TUSERDATA;
98103 u->uv.len = s;
src/lstring.h+3−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.h,v 1.39 2004/08/24 20:12:06 roberto Exp $
2+** $Id: lstring.h,v 1.40 2004/11/19 15:52:40 roberto Exp $
33 ** String table (keep all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
@@ -13,10 +13,9 @@ · 7 unmodified lines
1313 #include "lstate.h"
1414
1515
16−#define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \
17− (cast(lu_mem, l)+1)*sizeof(char))
16+#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
1817
19−#define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l))
18+#define sizeudata(u) (sizeof(union Udata)+(u)->len)
2019
2120 #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
2221 #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
src/ltable.c+45−40
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.5 2004/08/31 17:57:33 roberto Exp $
2+** $Id: ltable.c,v 2.12 2004/12/04 18:10:22 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -38,7 +38,7 @@ · 32 unmodified lines
3838 ** max size of array part is 2^MAXBITS
3939 */
4040 #if LUA_BITSINT > 26
41−#define MAXBITS 24
41+#define MAXBITS 26
4242 #else
4343 #define MAXBITS (LUA_BITSINT-2)
4444 #endif
@@ -107,11 +107,10 @@ Node *luaH_mainposition (const Table *t, const TValue *key) { · 62 unmodified lines
107107 ** returns the index for `key' if `key' is an appropriate key to live in
108108 ** the array part of the table, -1 otherwise.
109109 */
110−static int arrayindex (const TValue *key, lua_Number lim) {
110+static int arrayindex (const TValue *key) {
111111 if (ttisnumber(key)) {
112112 lua_Number n = nvalue(key);
113113 int k;
114− if (n <= 0 || n > lim) return -1; /* out of range? */
115114 lua_number2int(k, n);
116115 if (cast(lua_Number, k) == nvalue(key))
117116 return k;
@@ -123,28 +122,35 @@ static int arrayindex (const TValue *key, lua_Number lim) { · 5 unmodified lines
123122 /*
124123 ** returns the index of a `key' for table traversals. First goes all
125124 ** elements in the array part, then elements in the hash part. The
126−** beginning and end of a traversal are signalled by -1.
125+** beginning of a traversal is signalled by -1.
127126 */
128−static int luaH_index (lua_State *L, Table *t, StkId key) {
127+static int findindex (lua_State *L, Table *t, StkId key) {
129128 int i;
130129 if (ttisnil(key)) return -1; /* first iteration */
131− i = arrayindex(key, t->sizearray);
132− if (0 <= i) { /* is `key' inside array part? */
130+ i = arrayindex(key);
131+ if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
133132 return i-1; /* yes; that's the index (corrected to C) */
134− }
135133 else {
136− const TValue *v = luaH_get(t, key);
137− if (v == &luaO_nilobject)
138− luaG_runerror(L, "invalid key for `next'");
139− i = cast(int, (cast(const lu_byte *, v) -
140− cast(const lu_byte *, gval(gnode(t, 0)))) / sizeof(Node));
141− return i + t->sizearray; /* hash elements are numbered after array ones */
134+ Node *n = luaH_mainposition(t, key);
135+ do { /* check whether `key' is somewhere in the chain */
136+ /* key may be dead already, but it is ok to use it in `next' */
137+ if (luaO_rawequalObj(key2tval(n), key) ||
138+ (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
139+ gcvalue(gkey(n)) == gcvalue(key))) {
140+ i = n - gnode(t, 0); /* key index in hash table */
141+ /* hash elements are numbered after array ones */
142+ return i + t->sizearray;
143+ }
144+ else n = gnext(n);
145+ } while (n);
146+ luaG_runerror(L, "invalid key for `next'"); /* key not found */
147+ return 0; /* to avoid warnings */
142148 }
143149 }
144150
145151
146152 int luaH_next (lua_State *L, Table *t, StkId key) {
147− int i = luaH_index(L, t, key); /* find original element */
153+ int i = findindex(L, t, key); /* find original element */
148154 for (i++; i < t->sizearray; i++) { /* try first array part */
149155 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
150156 setnvalue(key, cast(lua_Number, i+1));
@@ -154,7 +160,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { · 3 unmodified lines
154160 }
155161 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
156162 if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
157− setobj2s(L, key, gkey(gnode(t, i)));
163+ setobj2s(L, key, key2tval(gnode(t, i)));
158164 setobj2s(L, key+1, gval(gnode(t, i)));
159165 return 1;
160166 }
@@ -195,7 +201,6 @@ static void numuse (const Table *t, int *narray, int *nhash) { · 34 unmodified lines
195201 int nums[MAXBITS+1];
196202 int i, lg;
197203 int totaluse = 0;
198− lua_Number sizelimit; /* an upper bound for the array size */
199204 /* count elements in array part */
200205 for (i=0, lg=0; lg<=MAXBITS; lg++) { /* for each slice [2^(lg-1) to 2^lg) */
201206 int ttlg = twoto(lg); /* 2^lg */
@@ -215,14 +220,11 @@ static void numuse (const Table *t, int *narray, int *nhash) { · 13 unmodified lines
215220 *narray = totaluse; /* all previous uses were in array part */
216221 /* count elements in hash part */
217222 i = sizenode(t);
218− /* array part cannot be larger than twice the maximum number of elements */
219− sizelimit = cast(lua_Number, totaluse + i) * 2;
220− if (sizelimit >= MAXASIZE) sizelimit = MAXASIZE;
221223 while (i--) {
222224 Node *n = &t->node[i];
223225 if (!ttisnil(gval(n))) {
224− int k = arrayindex(gkey(n), sizelimit);
225− if (k >= 0) { /* is `key' an appropriate array index? */
226+ int k = arrayindex(key2tval(n));
227+ if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
226228 nums[luaO_log2(k-1)+1]++; /* count as such */
227229 (*narray)++;
228230 }
@@ -251,12 +253,12 @@ static void setnodevector (lua_State *L, Table *t, int lsize) { · 22 unmodified lines
251253 t->node = G(L)->dummynode; /* use common `dummynode' */
252254 lua_assert(ttisnil(gkey(t->node))); /* assert invariants: */
253255 lua_assert(ttisnil(gval(t->node)));
254− lua_assert(t->node->next == NULL); /* (`dummynode' must be empty) */
256+ lua_assert(gnext(t->node) == NULL); /* (`dummynode' must be empty) */
255257 }
256258 else {
257259 t->node = luaM_newvector(L, size, Node);
258260 for (i=0; i<size; i++) {
259− t->node[i].next = NULL;
261+ gnext(&t->node[i]) = NULL;
260262 setnilvalue(gkey(gnode(t, i)));
261263 setnilvalue(gval(gnode(t, i)));
262264 }
@@ -280,7 +282,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 17 unmodified lines
280282 nold = temp;
281283 setnilvalue(gkey(G(L)->dummynode)); /* restate invariant */
282284 setnilvalue(gval(G(L)->dummynode));
283− lua_assert(G(L)->dummynode->next == NULL);
285+ lua_assert(gnext(G(L)->dummynode) == NULL);
284286 }
285287 if (nasize > oldasize) /* array part must grow? */
286288 setarrayvector(L, t, nasize);
@@ -301,7 +303,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 14 unmodified lines
301303 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
302304 Node *old = nold+i;
303305 if (!ttisnil(gval(old)))
304− setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
306+ setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
305307 }
306308 if (oldhsize)
307309 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
@@ -341,7 +343,7 @@ void luaH_free (lua_State *L, Table *t) { · 33 unmodified lines
341343 if (t->lsizenode)
342344 luaM_freearray(L, t->node, sizenode(t), Node);
343345 luaM_freearray(L, t->array, t->sizearray, TValue);
344− luaM_freelem(L, t);
346+ luaM_free(L, t);
345347 }
346348
347349
@@ -357,24 +359,25 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { · 9 unmodified lines
357359 TValue *val;
358360 Node *mp = luaH_mainposition(t, key);
359361 if (!ttisnil(gval(mp))) { /* main position is not free? */
360− Node *othern = luaH_mainposition(t, gkey(mp)); /* `mp' of colliding node */
362+ /* `mp' of colliding node */
363+ Node *othern = luaH_mainposition(t, key2tval(mp));
361364 Node *n = t->firstfree; /* get a free place */
362365 if (othern != mp) { /* is colliding node out of its main position? */
363366 /* yes; move colliding node into free position */
364− while (othern->next != mp) othern = othern->next; /* find previous */
365− othern->next = n; /* redo the chain with `n' in place of `mp' */
367+ while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
368+ gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
366369 *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
367− mp->next = NULL; /* now `mp' is free */
370+ gnext(mp) = NULL; /* now `mp' is free */
368371 setnilvalue(gval(mp));
369372 }
370373 else { /* colliding node is in its own main position */
371374 /* new node will go into free position */
372− n->next = mp->next; /* chain new position */
373− mp->next = n;
375+ gnext(n) = gnext(mp); /* chain new position */
376+ gnext(mp) = n;
374377 mp = n;
375378 }
376379 }
377− setobj2t(L, gkey(mp), key);
380+ gkey(mp)->value = key->value; gkey(mp)->tt = key->tt;
378381 luaC_barriert(L, t, key);
379382 lua_assert(ttisnil(gval(mp)));
380383 for (;;) { /* correct `firstfree' */
@@ -397,7 +400,8 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { · 16 unmodified lines
397400 ** search function for integers
398401 */
399402 const TValue *luaH_getnum (Table *t, int key) {
400− if (1 <= key && key <= t->sizearray)
403+ /* (1 <= key && key <= t->sizearray) */
404+ if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
401405 return &t->array[key-1];
402406 else {
403407 lua_Number nk = cast(lua_Number, key);
@@ -405,7 +409,7 @@ const TValue *luaH_getnum (Table *t, int key) { · 1 unmodified line
405409 do { /* check whether `key' is somewhere in the chain */
406410 if (ttisnumber(gkey(n)) && nvalue(gkey(n)) == nk)
407411 return gval(n); /* that's it */
408− else n = n->next;
412+ else n = gnext(n);
409413 } while (n);
410414 return &luaO_nilobject;
411415 }
@@ -420,7 +424,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 8 unmodified lines
420424 do { /* check whether `key' is somewhere in the chain */
421425 if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
422426 return gval(n); /* that's it */
423− else n = n->next;
427+ else n = gnext(n);
424428 } while (n);
425429 return &luaO_nilobject;
426430 }
@@ -443,8 +447,9 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 16 unmodified lines
443447 default: {
444448 Node *n = luaH_mainposition(t, key);
445449 do { /* check whether `key' is somewhere in the chain */
446− if (luaO_rawequalObj(gkey(n), key)) return gval(n); /* that's it */
447− else n = n->next;
450+ if (luaO_rawequalObj(key2tval(n), key))
451+ return gval(n); /* that's it */
452+ else n = gnext(n);
448453 } while (n);
449454 return &luaO_nilobject;
450455 }
src/ltable.h+4−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.h,v 2.2 2004/03/26 14:02:41 roberto Exp $
2+** $Id: ltable.h,v 2.3 2004/10/06 18:34:16 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -13,6 +13,9 @@ · 7 unmodified lines
1313 #define gnode(t,i) (&(t)->node[i])
1414 #define gkey(n) (&(n)->i_key)
1515 #define gval(n) (&(n)->i_val)
16+#define gnext(n) ((n)->i_key.next)
17+
18+#define key2tval(n) (cast(const TValue *, gkey(n)))
1619
1720
1821 const TValue *luaH_getnum (Table *t, int key);
src/lua/lua.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.132 2004/08/30 18:35:14 roberto Exp $
2+** $Id: lua.c,v 1.133 2004/11/18 19:53:49 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -127,9 +127,9 @@ static int dostring (lua_State *L, const char *s, const char *name) { · 121 unmodified lines
127127
128128
129129 static int dolibrary (lua_State *L, const char *name) {
130− lua_getfield(L, LUA_GLOBALSINDEX, "_PATH");
130+ luaL_getfield(L, LUA_GLOBALSINDEX, "package.path");
131131 if (!lua_isstring(L, -1)) {
132− l_message(progname, "global _PATH must be a string");
132+ l_message(progname, "`package.path' must be a string");
133133 return 1;
134134 }
135135 name = luaL_searchpath(L, name, lua_tostring(L, -1));
@@ -295,7 +295,7 @@ static int handle_argv (lua_State *L, char *argv[], int *interactive) { · 159 unmodified lines
295295 print_usage();
296296 return 1;
297297 }
298− if (dostring(L, chunk, "=<command line>") != 0)
298+ if (dostring(L, chunk, "=(command line)") != 0)
299299 return 1;
300300 break;
301301 }
src/luac/print.c+8−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.48 2004/09/01 21:22:34 lhf Exp $
2+** $Id: print.c,v 1.49 2004/11/25 09:31:41 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -33,7 +33,7 @@ static void PrintString(const Proto* f, int n) · 27 unmodified lines
3333 case '\r': printf("\\r"); break;
3434 case '\t': printf("\\t"); break;
3535 case '\v': printf("\\v"); break;
36− default: printf(isprint(*s) ? "%c" : "\\%03d",*s);
36+ default: printf(isprint((unsigned char)*s) ? "%c" : "\\%03d",*s);
3737 }
3838 }
3939 putchar('"');
@@ -44,15 +44,18 @@ static void PrintConstant(const Proto* f, int i) · 4 unmodified lines
4444 const TValue* o=&f->k[i];
4545 switch (ttype(o))
4646 {
47+ case LUA_TNIL:
48+ printf("nil");
49+ break;
50+ case LUA_TBOOLEAN:
51+ printf(bvalue(o) ? "true" : "false");
52+ break;
4753 case LUA_TNUMBER:
4854 printf(LUA_NUMBER_FMT,nvalue(o));
4955 break;
5056 case LUA_TSTRING:
5157 PrintString(f,i);
5258 break;
53− case LUA_TNIL:
54− printf("nil");
55− break;
5659 default: /* cannot happen */
5760 printf("? type=%d",ttype(o));
5861 break;
src/lundump.c+10−11
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.c,v 1.53 2004/09/01 21:22:34 lhf Exp $
2+** $Id: lundump.c,v 1.54 2004/11/25 09:31:41 lhf Exp $
33 ** load pre-compiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -177,15 +177,18 @@ static void LoadConstants (LoadState* S, Proto* f) · 171 unmodified lines
177177 int t=LoadByte(S);
178178 switch (t)
179179 {
180+ case LUA_TNIL:
181+ setnilvalue(o);
182+ break;
183+ case LUA_TBOOLEAN:
184+ setbvalue(o,LoadByte(S));
185+ break;
180186 case LUA_TNUMBER:
181187 setnvalue(o,LoadNumber(S));
182188 break;
183189 case LUA_TSTRING:
184190 setsvalue2n(S->L,o,LoadString(S));
185191 break;
186− case LUA_TNIL:
187− setnilvalue(o);
188− break;
189192 default:
190193 error(S,"bad constant type (%d)",t);
191194 break;
@@ -243,19 +246,15 @@ static void LoadHeader (LoadState* S) · 51 unmodified lines
243246 lua_Number x,tx=TEST_NUMBER;
244247 LoadSignature(S);
245248 version=LoadByte(S);
246− if (version>VERSION)
247− error(S,"bad version (read %d.%d; expected at %s %d.%d)",
248− V(version),"most",V(VERSION));
249− if (version<VERSION0) /* check last major change */
250− error(S,"bad version (read %d.%d; expected at %s %d.%d)",
251− V(version),"least",V(VERSION0));
249+ if (version!=VERSION)
250+ error(S,"bad version (read %d.%d; expected %d.%d)",V(version),V(VERSION));
252251 S->swap=(luaU_endianness()!=LoadByte(S)); /* need to swap bytes? */
253252 TestSize(S,sizeof(int),"int");
254253 TestSize(S,sizeof(size_t),"size_t");
255254 TestSize(S,sizeof(Instruction),"instruction");
256255 TestSize(S,sizeof(lua_Number),"number");
257256 x=LoadNumber(S);
258− if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
257+ if (x!=tx)
259258 error(S,"unknown number format");
260259 }
261260
src/lundump.h+5−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.h,v 1.33 2004/06/09 21:03:53 lhf Exp $
2+** $Id: lundump.h,v 1.34 2004/11/25 09:31:41 lhf Exp $
33 ** load pre-compiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -22,12 +22,10 @@ int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int · 16 unmodified lines
2222 /* print one chunk; from print.c */
2323 void luaU_print (const Proto* f, int full);
2424
25−/* definitions for headers of binary files */
26−#define VERSION 0x51 /* last format change was in 5.1 */
27−#define VERSION0 0x51 /* last major change was in 5.1 */
25+/* for header of binary files -- this is Lua 5.1 */
26+#define VERSION 0x51
2827
29−/* a multiple of PI for testing native format */
30−/* multiplying by 1E7 gives non-trivial integer values */
31−#define TEST_NUMBER ((lua_Number)3.14159265358979323846E7)
28+/* for testing native format of lua_Numbers */
29+#define TEST_NUMBER ((lua_Number)31415926.0)
3230
3331 #endif
src/lvm.c+17−20
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 2.14 2004/09/15 20:39:42 roberto Exp $
2+** $Id: lvm.c,v 2.18 2004/12/03 20:35:33 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -214,7 +214,7 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, · 208 unmodified lines
214214 }
215215
216216
217−static int luaV_strcmp (const TString *ls, const TString *rs) {
217+static int l_strcmp (const TString *ls, const TString *rs) {
218218 const char *l = getstr(ls);
219219 size_t ll = ls->tsv.len;
220220 const char *r = getstr(rs);
@@ -243,21 +243,21 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 22 unmodified lines
243243 else if (ttisnumber(l))
244244 return nvalue(l) < nvalue(r);
245245 else if (ttisstring(l))
246− return luaV_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
246+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
247247 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
248248 return res;
249249 return luaG_ordererror(L, l, r);
250250 }
251251
252252
253−static int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
253+static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
254254 int res;
255255 if (ttype(l) != ttype(r))
256256 return luaG_ordererror(L, l, r);
257257 else if (ttisnumber(l))
258258 return nvalue(l) <= nvalue(r);
259259 else if (ttisstring(l))
260− return luaV_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
260+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
261261 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
262262 return res;
263263 else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
@@ -303,15 +303,14 @@ void luaV_concat (lua_State *L, int total, int last) { · 39 unmodified lines
303303 luaG_concaterror(L, top-2, top-1);
304304 } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
305305 /* at least two string values; get as many as possible */
306− lu_mem tl = cast(lu_mem, tsvalue(top-1)->len) +
307− cast(lu_mem, tsvalue(top-2)->len);
306+ size_t tl = tsvalue(top-1)->len;
308307 char *buffer;
309308 int i;
310− while (n < total && tostring(L, top-n-1)) { /* collect total length */
309+ /* collect total length */
310+ for (n = 1; n < total && tostring(L, top-n-1); n++) {
311311 size_t l = tsvalue(top-n-1)->len;
312312 if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
313313 tl += l;
314− n++;
315314 }
316315 buffer = luaZ_openspace(L, &G(L)->buff, tl);
317316 tl = 0;
@@ -462,7 +461,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 144 unmodified lines
462461 }
463462 case OP_NEWTABLE: {
464463 int b = GETARG_B(i);
465− b = fb2int(b);
464+ b = luaO_fb2int(b);
466465 sethvalue(L, ra, luaH_new(L, b, GETARG_C(i)));
467466 L->ci->savedpc = pc;
468467 luaC_checkGC(L); /***/
@@ -569,7 +568,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 100 unmodified lines
569568 }
570569 case OP_LE: {
571570 L->ci->savedpc = pc;
572− if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
571+ if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
573572 else dojump(L, pc, GETARG_sBx(*pc) + 1);
574573 base = L->base;
575574 continue;
@@ -710,21 +709,19 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 134 unmodified lines
710709 dojump(L, pc, GETARG_sBx(i));
711710 continue;
712711 }
713− case OP_SETLIST:
714− case OP_SETLISTO: {
715− int bc = GETARG_Bx(i);
716− int n, last;
712+ case OP_SETLIST: {
713+ int n = GETARG_B(i);
714+ int c = GETARG_C(i);
715+ int last;
717716 Table *h;
718717 runtime_check(L, ttistable(ra));
719718 h = hvalue(ra);
720− if (GET_OPCODE(i) == OP_SETLIST)
721− n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
722− else {
719+ if (n == 0) {
723720 n = L->top - ra - 1;
724721 L->top = L->ci->top;
725722 }
726− bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
727− last = bc + n + LUA_FIRSTINDEX - 1;
723+ if (c == 0) c = cast(int, *pc++);
724+ last = ((c-1)*LFIELDS_PER_FLUSH) + n + LUA_FIRSTINDEX - 1;
728725 if (last > h->sizearray) /* needs more space? */
729726 luaH_resize(L, h, last, h->lsizenode); /* pre-alloc it at once */
730727 for (; n > 0; n--) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t