History

Lua 5.1-work6

Lua Team committed 21 years ago

Commit b5301731 parent e684a4d66 files · +1742 −1346Browse files

Unified · Split

66 files
  1. HISTORY +4 −0
  2. INSTALL +13 −12
  3. MANIFEST +103 −104
  4. Makefile +16 −5
  5. etc/Makefile +2 −2
  6. etc/README +3 −3
  7. etc/all.c +1 −3
  8. etc/lua.pc +24 −0
  9. etc/saconfig.c +0 −65
  10. src/Makefile +15 −19
  11. src/lapi.c +48 −37
  12. src/lapi.h +2 −2
  13. src/lauxlib.c +20 −47
  14. src/lauxlib.h +7 −1
  15. src/lbaselib.c +21 −12
  16. src/lcode.c +22 −9
  17. src/lcode.h +33 −33
  18. src/ldblib.c +59 −55
  19. src/ldebug.c +71 −44
  20. src/ldebug.h +12 −9
  21. src/ldo.c +24 −16
  22. src/ldo.h +14 −14
  23. src/ldump.c +3 −2
  24. src/lfunc.c +3 −6
  25. src/lfunc.h +12 −12
  26. src/lgc.c +13 −4
  27. src/lgc.h +10 −10
  28. src/linit.c +6 −8
  29. src/liolib.c +3 −5
  30. src/llex.c +25 −10
  31. src/llex.h +9 −9
  32. src/llimits.h +8 −6
  33. src/lmathlib.c +30 −1
  34. src/lmem.h +11 −12
  35. src/loadlib.c +51 −23
  36. src/lobject.c +6 −4
  37. src/lobject.h +12 −12
  38. src/lopcodes.c +5 −3
  39. src/lopcodes.h +5 −5
  40. src/loslib.c +8 −11
  41. src/lparser.c +35 −29
  42. src/lparser.h +6 −5
  43. src/lstate.c +17 −22
  44. src/lstate.h +7 −5
  45. src/lstring.h +4 −4
  46. src/lstrlib.c +38 −24
  47. src/ltable.c +58 −9
  48. src/ltable.h +13 −12
  49. src/ltablib.c +21 −18
  50. src/ltm.c +5 −5
  51. src/ltm.h +8 −5
  52. src/lua.c +55 −82
  53. src/lua.h +28 −28
  54. src/luac.c +1 −3
  55. src/luaconf.h +484 −213
  56. src/lualib.h +3 −3
  57. src/lundump.c +3 −2
  58. src/lundump.h +5 −5
  59. src/lvm.c +179 −179
  60. src/lvm.h +11 −11
  61. src/lzio.c +2 −2
  62. src/lzio.h +10 −13
  63. src/print.c +13 −20
  64. test/README +0 −1
  65. test/luac.lua +2 −2
  66. test/undefined.lua +0 −9
HISTORY+4−0
@@ -8,6 +8,9 @@ This is Lua 5.1 (work). · 7 unmodified lines
88 + new semantics for setn/getn.
99 + new syntax/semantics for varargs.
1010 + new long strings.
11+ + new `mod' (`%') operator
12+ + new operation *t (for size of t)
13+ + metatables for all types
1114 API:
1215 + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer.
1316 + user supplies memory allocator (lua_open becomes lua_newstate).
@@ -18,6 +21,7 @@ This is Lua 5.1 (work). · 4 unmodified lines
1821 + fully reentrant parser (new Lua function `load')
1922 + better support for 64-bit machines (special thanks to Mike Pall).
2023 + native loadlib support for Mac OS X (thanks to Matthew Cox).
24+ + standard distribution in only one library (lualib.a merged into lua.a)
2125
2226 * Changes from version 4.0 to 5.0
2327 -------------------------------
INSTALL+13−12
@@ -5,17 +5,20 @@ This is Lua 5.1 (work). · 4 unmodified lines
55 Building Lua on a Unix system should be very easy: simply doing "make"
66 should work. This will build Lua in the src directory.
77
8+ See below for customization instructions. We strongly recommend that
9+ you enable dynamic loading.
10+
811 If you want to install Lua in an official place in your system, then
912 do "make install". The official place and the way to install files are
1013 defined in Makefile. You must have the right permissions to install files.
1114
1215 If you want to install Lua locally, then do "make local". This will
13− create directories bin, include, lib, man and install Lua there as
16+ create directories bin, include, lib, man, and install Lua there as
1417 follows:
1518
1619 bin: lua luac
1720 include: lua.h luaconf.h lualib.h lauxlib.h
18− lib: liblua.a liblualib.a
21+ lib: liblua.a
1922 man/man1: lua.1 luac.1
2023
2124 These are the only directories you need for development.
@@ -38,25 +41,23 @@ This is Lua 5.1 (work). · 16 unmodified lines
3841
3942 On the other hand, if you need to select some Lua features, you'll need
4043 to edit src/luaconf.h. The edited file will be the one installed, and
41− will be used by any Lua clients that you build, to ensure consistency.
44+ it will be used by any Lua clients that you build, to ensure consistency.
4245
4346 * Installation on Windows and other systems
4447 -----------------------------------------
4548 The instructions for building Lua on other systems depend on the compiler
4649 you use. You'll need to create projects (or whatever your compiler uses)
47− for building the core library, the standard library, the interpreter, and
48− the compiler, as follows:
50+ for building the library, the interpreter, and the compiler, as follows:
4951
50− core lib: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
51− lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
52+ library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
53+ lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
5254 ltable.c ltm.c lundump.c lvm.c lzio.c
55+ lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c
56+ ltablib.c lstrlib.c loadlib.c linit.c
5357
54− standard lib: lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c
55− ltablib.c lstrlib.c loadlib.c linit.c
56−
57− interpreter: core lib, standard lib, lua.c
58+ interpreter: library, lua.c
5859
59− compiler: core lib, lauxlib.c luac.c print.c
60+ compiler: library, luac.c print.c
6061
6162 If all you want is to build the Lua interpreter, you may put all .c files
6263 in a single project, except for luac.c and print.c.
MANIFEST+103−104
@@ -1,105 +1,104 @@
1−MANIFEST contents of Lua 5.1 (work5) distribution on Fri Mar 4 13:32:55 BRST 2005
2−lua-5.1-work5
3−lua-5.1-work5/COPYRIGHT
4−lua-5.1-work5/HISTORY
5−lua-5.1-work5/INSTALL
6−lua-5.1-work5/MANIFEST
7−lua-5.1-work5/Makefile
8−lua-5.1-work5/README
9−lua-5.1-work5/doc
10−lua-5.1-work5/doc/contents.html
11−lua-5.1-work5/doc/logo.gif
12−lua-5.1-work5/doc/lua.1
13−lua-5.1-work5/doc/lua.html
14−lua-5.1-work5/doc/luac.1
15−lua-5.1-work5/doc/luac.html
16−lua-5.1-work5/doc/readme.html
17−lua-5.1-work5/etc
18−lua-5.1-work5/etc/Makefile
19−lua-5.1-work5/etc/README
20−lua-5.1-work5/etc/all.c
21−lua-5.1-work5/etc/lua.hpp
22−lua-5.1-work5/etc/lua.ico
23−lua-5.1-work5/etc/min.c
24−lua-5.1-work5/etc/noparser.c
25−lua-5.1-work5/etc/saconfig.c
26−lua-5.1-work5/src
27−lua-5.1-work5/src/Makefile
28−lua-5.1-work5/src/lapi.c
29−lua-5.1-work5/src/lapi.h
30−lua-5.1-work5/src/lauxlib.c
31−lua-5.1-work5/src/lauxlib.h
32−lua-5.1-work5/src/lbaselib.c
33−lua-5.1-work5/src/lcode.c
34−lua-5.1-work5/src/lcode.h
35−lua-5.1-work5/src/ldblib.c
36−lua-5.1-work5/src/ldebug.c
37−lua-5.1-work5/src/ldebug.h
38−lua-5.1-work5/src/ldo.c
39−lua-5.1-work5/src/ldo.h
40−lua-5.1-work5/src/ldump.c
41−lua-5.1-work5/src/lfunc.c
42−lua-5.1-work5/src/lfunc.h
43−lua-5.1-work5/src/lgc.c
44−lua-5.1-work5/src/lgc.h
45−lua-5.1-work5/src/linit.c
46−lua-5.1-work5/src/liolib.c
47−lua-5.1-work5/src/llex.c
48−lua-5.1-work5/src/llex.h
49−lua-5.1-work5/src/llimits.h
50−lua-5.1-work5/src/lmathlib.c
51−lua-5.1-work5/src/lmem.c
52−lua-5.1-work5/src/lmem.h
53−lua-5.1-work5/src/loadlib.c
54−lua-5.1-work5/src/lobject.c
55−lua-5.1-work5/src/lobject.h
56−lua-5.1-work5/src/lopcodes.c
57−lua-5.1-work5/src/lopcodes.h
58−lua-5.1-work5/src/loslib.c
59−lua-5.1-work5/src/lparser.c
60−lua-5.1-work5/src/lparser.h
61−lua-5.1-work5/src/lstate.c
62−lua-5.1-work5/src/lstate.h
63−lua-5.1-work5/src/lstring.c
64−lua-5.1-work5/src/lstring.h
65−lua-5.1-work5/src/lstrlib.c
66−lua-5.1-work5/src/ltable.c
67−lua-5.1-work5/src/ltable.h
68−lua-5.1-work5/src/ltablib.c
69−lua-5.1-work5/src/ltm.c
70−lua-5.1-work5/src/ltm.h
71−lua-5.1-work5/src/lua.c
72−lua-5.1-work5/src/lua.h
73−lua-5.1-work5/src/luac.c
74−lua-5.1-work5/src/luaconf.h
75−lua-5.1-work5/src/lualib.h
76−lua-5.1-work5/src/lundump.c
77−lua-5.1-work5/src/lundump.h
78−lua-5.1-work5/src/lvm.c
79−lua-5.1-work5/src/lvm.h
80−lua-5.1-work5/src/lzio.c
81−lua-5.1-work5/src/lzio.h
82−lua-5.1-work5/src/print.c
83−lua-5.1-work5/test
84−lua-5.1-work5/test/README
85−lua-5.1-work5/test/bisect.lua
86−lua-5.1-work5/test/cf.lua
87−lua-5.1-work5/test/echo.lua
88−lua-5.1-work5/test/env.lua
89−lua-5.1-work5/test/factorial.lua
90−lua-5.1-work5/test/fib.lua
91−lua-5.1-work5/test/fibfor.lua
92−lua-5.1-work5/test/globals.lua
93−lua-5.1-work5/test/hello.lua
94−lua-5.1-work5/test/life.lua
95−lua-5.1-work5/test/luac.lua
96−lua-5.1-work5/test/printf.lua
97−lua-5.1-work5/test/readonly.lua
98−lua-5.1-work5/test/sieve.lua
99−lua-5.1-work5/test/sort.lua
100−lua-5.1-work5/test/table.lua
101−lua-5.1-work5/test/trace-calls.lua
102−lua-5.1-work5/test/trace-globals.lua
103−lua-5.1-work5/test/undefined.lua
104−lua-5.1-work5/test/xd.lua
1+MANIFEST contents of Lua 5.1 (work6) distribution on Wed May 18 10:13:40 BRST 2005
2+lua-5.1-work6
3+lua-5.1-work6/COPYRIGHT
4+lua-5.1-work6/HISTORY
5+lua-5.1-work6/INSTALL
6+lua-5.1-work6/MANIFEST
7+lua-5.1-work6/Makefile
8+lua-5.1-work6/README
9+lua-5.1-work6/doc
10+lua-5.1-work6/doc/contents.html
11+lua-5.1-work6/doc/logo.gif
12+lua-5.1-work6/doc/lua.1
13+lua-5.1-work6/doc/lua.html
14+lua-5.1-work6/doc/luac.1
15+lua-5.1-work6/doc/luac.html
16+lua-5.1-work6/doc/readme.html
17+lua-5.1-work6/etc
18+lua-5.1-work6/etc/Makefile
19+lua-5.1-work6/etc/README
20+lua-5.1-work6/etc/all.c
21+lua-5.1-work6/etc/lua.hpp
22+lua-5.1-work6/etc/lua.ico
23+lua-5.1-work6/etc/lua.pc
24+lua-5.1-work6/etc/min.c
25+lua-5.1-work6/etc/noparser.c
26+lua-5.1-work6/src
27+lua-5.1-work6/src/Makefile
28+lua-5.1-work6/src/lapi.c
29+lua-5.1-work6/src/lapi.h
30+lua-5.1-work6/src/lauxlib.c
31+lua-5.1-work6/src/lauxlib.h
32+lua-5.1-work6/src/lbaselib.c
33+lua-5.1-work6/src/lcode.c
34+lua-5.1-work6/src/lcode.h
35+lua-5.1-work6/src/ldblib.c
36+lua-5.1-work6/src/ldebug.c
37+lua-5.1-work6/src/ldebug.h
38+lua-5.1-work6/src/ldo.c
39+lua-5.1-work6/src/ldo.h
40+lua-5.1-work6/src/ldump.c
41+lua-5.1-work6/src/lfunc.c
42+lua-5.1-work6/src/lfunc.h
43+lua-5.1-work6/src/lgc.c
44+lua-5.1-work6/src/lgc.h
45+lua-5.1-work6/src/linit.c
46+lua-5.1-work6/src/liolib.c
47+lua-5.1-work6/src/llex.c
48+lua-5.1-work6/src/llex.h
49+lua-5.1-work6/src/llimits.h
50+lua-5.1-work6/src/lmathlib.c
51+lua-5.1-work6/src/lmem.c
52+lua-5.1-work6/src/lmem.h
53+lua-5.1-work6/src/loadlib.c
54+lua-5.1-work6/src/lobject.c
55+lua-5.1-work6/src/lobject.h
56+lua-5.1-work6/src/lopcodes.c
57+lua-5.1-work6/src/lopcodes.h
58+lua-5.1-work6/src/loslib.c
59+lua-5.1-work6/src/lparser.c
60+lua-5.1-work6/src/lparser.h
61+lua-5.1-work6/src/lstate.c
62+lua-5.1-work6/src/lstate.h
63+lua-5.1-work6/src/lstring.c
64+lua-5.1-work6/src/lstring.h
65+lua-5.1-work6/src/lstrlib.c
66+lua-5.1-work6/src/ltable.c
67+lua-5.1-work6/src/ltable.h
68+lua-5.1-work6/src/ltablib.c
69+lua-5.1-work6/src/ltm.c
70+lua-5.1-work6/src/ltm.h
71+lua-5.1-work6/src/lua.c
72+lua-5.1-work6/src/lua.h
73+lua-5.1-work6/src/luac.c
74+lua-5.1-work6/src/luaconf.h
75+lua-5.1-work6/src/lualib.h
76+lua-5.1-work6/src/lundump.c
77+lua-5.1-work6/src/lundump.h
78+lua-5.1-work6/src/lvm.c
79+lua-5.1-work6/src/lvm.h
80+lua-5.1-work6/src/lzio.c
81+lua-5.1-work6/src/lzio.h
82+lua-5.1-work6/src/print.c
83+lua-5.1-work6/test
84+lua-5.1-work6/test/README
85+lua-5.1-work6/test/bisect.lua
86+lua-5.1-work6/test/cf.lua
87+lua-5.1-work6/test/echo.lua
88+lua-5.1-work6/test/env.lua
89+lua-5.1-work6/test/factorial.lua
90+lua-5.1-work6/test/fib.lua
91+lua-5.1-work6/test/fibfor.lua
92+lua-5.1-work6/test/globals.lua
93+lua-5.1-work6/test/hello.lua
94+lua-5.1-work6/test/life.lua
95+lua-5.1-work6/test/luac.lua
96+lua-5.1-work6/test/printf.lua
97+lua-5.1-work6/test/readonly.lua
98+lua-5.1-work6/test/sieve.lua
99+lua-5.1-work6/test/sort.lua
100+lua-5.1-work6/test/table.lua
101+lua-5.1-work6/test/trace-calls.lua
102+lua-5.1-work6/test/trace-globals.lua
103+lua-5.1-work6/test/xd.lua
105104 END OF MANIFEST
Makefile+16−5
@@ -4,8 +4,9 @@ · 3 unmodified lines
44
55 # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
66
7−# Where to install. The installation starts in the src directory, so take
8−# care if INSTALL_TOP is not an absolute path.
7+# Where to install. The installation starts in the src directory, so take care
8+# if INSTALL_TOP is not an absolute path. (Man pages are installed from the
9+# doc directory.)
910 #
1011 INSTALL_TOP= /usr/local
1112 INSTALL_BIN= $(INSTALL_TOP)/bin
@@ -23,13 +24,15 @@ INSTALL_DATA= cp · 11 unmodified lines
2324
2425 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
2526
26−V= 5.1
27−
27+# What to install.
2828 TO_BIN= lua luac
2929 TO_INC= lua.h luaconf.h lualib.h lauxlib.h
30−TO_LIB= liblua.a liblualib.a
30+TO_LIB= liblua.a
3131 TO_MAN= lua.1 luac.1
3232
33+# Lua version. Currently used only for messages.
34+V= 5.1
35+
3336 all clean:
3437 cd src; $(MAKE) $@
3538
@@ -66,6 +69,14 @@ echo: · 30 unmodified lines
6669 @echo "See also src/luaconf.h ."
6770 @echo ""
6871
72+# echo private config parameters
73+pecho:
74+ @echo "V = $(V)"
75+ @echo "TO_BIN = $(TO_BIN)"
76+ @echo "TO_INC = $(TO_INC)"
77+ @echo "TO_LIB = $(TO_LIB)"
78+ @echo "TO_MAN = $(TO_MAN)"
79+
6980 # echo config parameters as Lua code
7081 # uncomment the last sed expression if you want nil instead of empty strings
7182 lecho:
etc/Makefile+2−2
@@ -20,10 +20,10 @@ all: · 19 unmodified lines
2020 @echo 'choose a target:' $(ALL)
2121
2222 min: min.c
23− $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib
23+ $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua $(MYLIBS)
2424
2525 noparser: noparser.o
26− $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua -llualib $(MYLIBS)
26+ $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS)
2727 $(BIN)/luac $(TST)/hello.lua
2828 -./a.out luac.out
2929 -./a.out -e'a=1'
etc/README+3−3
@@ -13,6 +13,9 @@ lua.ico · 12 unmodified lines
1313 A Lua icon for Windows (and web sites, as favicon.ico).
1414 Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.
1515
16+lua.pc
17+ pkg-config data for Lua
18+
1619 min.c
1720 A minimal Lua interpreter.
1821 Good for learning and for starting your own.
@@ -20,6 +23,3 @@ min.c · 1 unmodified line
2023 noparser.c
2124 Linking with noparser.o avoids loading the parsing modules in lualib.a.
2225 Do "make noparser" to see a demo.
23−
24−saconfig.c
25− Configuration for Lua interpreter.
etc/all.c+1−3
@@ -2,9 +2,7 @@ · 1 unmodified line
22 * all.c -- Lua core, libraries and interpreter in a single file
33 */
44
5−#define LUA_CORE
6−#define LUA_LIB
7−#define lua_c
5+#define luaall_c
86
97 #include "lapi.c"
108 #include "lcode.c"
etc/lua.pc+24−0
@@ -0,0 +1,24 @@
1+# lua.pc -- pkg-config data for Lua
2+
3+# vars from install Makefile
4+# grep ^INSTALL_...= ../Makefile
5+INSTALL_TOP= /usr/local
6+INSTALL_BIN= $(INSTALL_TOP)/bin
7+INSTALL_INC= $(INSTALL_TOP)/include
8+INSTALL_LIB= $(INSTALL_TOP)/lib
9+INSTALL_MAN= $(INSTALL_TOP)/man/man1
10+# grep ^V= ../Makefile
11+V= 5.1
12+
13+prefix=${INSTALL_TOP}
14+exec_prefix=${prefix}
15+libdir=${exec_prefix}/lib
16+includedir=${prefix}/include
17+
18+Name: Lua
19+Description: An Extensible Extension Language
20+Version: ${V}
21+Requires:
22+Libs: -L${libdir} -llua -lm
23+Cflags: -I${includedir}
24+
etc/saconfig.c+0−65
@@ -1,65 +0,0 @@
1−/* saconfig.c -- configuration for stand-alone Lua interpreter
2−*
3−* #define LUA_USERCONFIG to this file
4−*
5−* Here are the features that can be customized using #define:
6−*
7−*** Line editing and history:
8−* #define USE_READLINE to use the GNU readline library.
9−* Add "-lreadline -ltermcap" to MYLIBS.
10−*
11−* To use another library for this, use the code below as a start.
12−* Make sure you #define lua_readline and lua_saveline accordingly.
13−*
14−* If you do not #define lua_readline, you'll get a version based on fgets
15−* that uses a static buffer of size MAXINPUT.
16−*/
17−
18−#define USE_READLINE
19−
20−#ifdef USE_READLINE
21−/*
22−* This section implements of lua_readline and lua_saveline for lua.c using
23−* the GNU readline and history libraries. It should also work with drop-in
24−* replacements such as editline and libedit (you may have to include
25−* different headers, though).
26−*
27−*/
28−
29−#define lua_readline myreadline
30−#define lua_saveline mysaveline
31−
32−#include <ctype.h>
33−#include <readline/readline.h>
34−#include <readline/history.h>
35−
36−static int myreadline (lua_State *L, const char *prompt) {
37− char *s=readline(prompt);
38− if (s==NULL)
39− return 0;
40− else {
41− lua_pushstring(L,s);
42− lua_pushliteral(L,"\n");
43− lua_concat(L,2);
44− free(s);
45− return 1;
46− }
47−}
48−
49−static void mysaveline (lua_State *L, const char *s) {
50− const char *p;
51− for (p=s; isspace(*p); p++)
52− ;
53− if (*p!=0) {
54− size_t n=strlen(s)-1;
55− if (s[n]!='\n')
56− add_history(s);
57− else {
58− lua_pushlstring(L,s,n);
59− s=lua_tostring(L,-1);
60− add_history(s);
61− lua_remove(L,-1);
62− }
63− }
64−}
65−#endif
src/Makefile+15−19
@@ -9,20 +9,21 @@ CFLAGS= -O2 -Wall $(MYCFLAGS) · 8 unmodified lines
99 AR= ar rcu
1010 RANLIB= ranlib
1111 RM= rm -f
12+LIBS= -lm $(MYLIBS)
1213
1314 MYCFLAGS=
1415 MYLDFLAGS=
15−MYLIBS= -lm
16−DL= -ldl -Wl,-E # enable dynamic loading in Linux
16+MYLIBS=
17+# enable dynamic loading and line editing in Linux
18+# MYCFLAGS= -DLUA_USE_DLOPEN -DLUA_USE_READLINE
19+# MYLIBS= -Wl,-E -ldl -lreadline -lhistory -lncurses
1720
1821 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
1922
20−CORE_T= liblua.a
23+LUA_A= liblua.a
2124 CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
2225 lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
2326 lundump.o lvm.o lzio.o
24−
25−LIB_T= liblualib.a
2627 LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
2728 lstrlib.o loadlib.o linit.o
2829
@@ -30,11 +31,11 @@ LUA_T= lua · 1 unmodified line
3031 LUA_O= lua.o
3132
3233 LUAC_T= luac
33−LUAC_O= luac.o print.o lauxlib.o
34+LUAC_O= luac.o print.o
3435
35−ALL_T= $(CORE_T) $(LIB_T) $(LUA_T) $(LUAC_T)
3636 ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
37−ALL_A= $(CORE_T) $(LIB_T)
37+ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
38+ALL_A= $(LUA_A)
3839
3940 all: $(ALL_T)
4041
@@ -42,25 +43,21 @@ o: $(ALL_O) · 1 unmodified line
4243
4344 a: $(ALL_A)
4445
45−$(CORE_T): $(CORE_O)
46− $(AR) $@ $?
47− $(RANLIB) $@
48−
49−$(LIB_T): $(LIB_O)
46+$(LUA_A): $(CORE_O) $(LIB_O)
5047 $(AR) $@ $?
5148 $(RANLIB) $@
5249
53−$(LUA_T): $(LUA_O) $(CORE_T) $(LIB_T)
54− $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) -L. -llua -llualib $(MYLIBS) $(DL)
50+$(LUA_T): $(LUA_O) $(LUA_A)
51+ $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
5552
56−$(LUAC_T): $(LUAC_O) $(CORE_T)
57− $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) -L. -llua $(MYLIBS)
53+$(LUAC_T): $(LUAC_O) $(LUA_A)
54+ $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
5855
5956 clean:
6057 $(RM) $(ALL_T) $(ALL_O)
6158
6259 depend:
63− @$(CC) $(CFLAGS) -MM *.c
60+ @$(CC) $(CFLAGS) -MM l*.c print.c
6461
6562 echo:
6663 @echo "CC = $(CC)"
@@ -71,7 +68,6 @@ echo: · 4 unmodified lines
7168 @echo "MYCFLAGS = $(MYCFLAGS)"
7269 @echo "MYLDFLAGS = $(MYLDFLAGS)"
7370 @echo "MYLIBS = $(MYLIBS)"
74− @echo "DL = $(DL)"
7571
7672 # DO NOT DELETE
7773
src/lapi.c+48−37
@@ -1,11 +1,12 @@
11 /*
2−** $Id: lapi.c,v 2.28 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lapi.c,v 2.41 2005/05/17 19:49:15 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
66
77
88 #include <assert.h>
9+#include <math.h>
910 #include <stdarg.h>
1011 #include <string.h>
1112
@@ -87,14 +88,14 @@ static Table *getcurrenv (lua_State *L) { · 75 unmodified lines
8788
8889 void luaA_pushobject (lua_State *L, const TValue *o) {
8990 setobj2s(L, L->top, o);
90− incr_top(L);
91+ api_incr_top(L);
9192 }
9293
9394
9495 LUA_API int lua_checkstack (lua_State *L, int size) {
9596 int res;
9697 lua_lock(L);
97− if ((L->top - L->base + size) > MAXCSTACK)
98+ if ((L->top - L->base + size) > LUAI_MAXCSTACK)
9899 res = 0; /* stack overflow */
99100 else {
100101 luaD_checkstack(L, size);
@@ -140,7 +141,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 39 unmodified lines
140141 setthvalue(L, L->top, L1);
141142 api_incr_top(L);
142143 lua_unlock(L);
143− lua_userstateopen(L1);
144+ luai_userstateopen(L1);
144145 return L1;
145146 }
146147
@@ -318,7 +319,8 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { · 171 unmodified lines
318319 const TValue *o = index2adr(L, idx);
319320 if (tonumber(o, &n)) {
320321 lua_Integer res;
321− lua_number2integer(res, nvalue(o));
322+ lua_Number num = nvalue(o);
323+ lua_number2integer(res, num);
322324 return res;
323325 }
324326 else
@@ -332,33 +334,37 @@ LUA_API int lua_toboolean (lua_State *L, int idx) { · 7 unmodified lines
332334 }
333335
334336
335−LUA_API const char *lua_tostring (lua_State *L, int idx) {
337+LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
336338 StkId o = index2adr(L, idx);
337− if (ttisstring(o))
338− return svalue(o);
339− else {
340− const char *s;
339+ if (!ttisstring(o)) {
341340 lua_lock(L); /* `luaV_tostring' may create a new string */
342− s = (luaV_tostring(L, o) ? svalue(o) : NULL);
341+ if (!luaV_tostring(L, o)) { /* conversion failed? */
342+ if (len != NULL) *len = 0;
343+ lua_unlock(L);
344+ return NULL;
345+ }
343346 luaC_checkGC(L);
344347 lua_unlock(L);
345− return s;
346348 }
349+ if (len != NULL) *len = tsvalue(o)->len;
350+ return svalue(o);
347351 }
348352
349353
350354 LUA_API size_t lua_objsize (lua_State *L, int idx) {
351355 StkId o = index2adr(L, idx);
352− if (ttisstring(o))
353− return tsvalue(o)->len;
354− else if (ttisuserdata(o))
355− return uvalue(o)->len;
356− else {
357− size_t l;
358− lua_lock(L); /* `luaV_tostring' may create a new string */
359− l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);
360− lua_unlock(L);
361− return l;
356+ switch (ttype(o)) {
357+ case LUA_TSTRING: return tsvalue(o)->len;
358+ case LUA_TUSERDATA: return uvalue(o)->len;
359+ case LUA_TTABLE: return luaH_getn(hvalue(o));
360+ case LUA_TNUMBER: {
361+ size_t l;
362+ lua_lock(L); /* `luaV_tostring' may create a new string */
363+ l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);
364+ lua_unlock(L);
365+ return l;
366+ }
367+ default: return 0;
362368 }
363369 }
364370
@@ -523,7 +529,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) { · 158 unmodified lines
523529 lua_lock(L);
524530 t = index2adr(L, idx);
525531 api_checkvalidindex(L, t);
526− luaV_gettable(L, t, L->top - 1, L->top - 1, NULL);
532+ luaV_gettable(L, t, L->top - 1, L->top - 1);
527533 lua_unlock(L);
528534 }
529535
@@ -535,7 +541,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { · 5 unmodified lines
535541 t = index2adr(L, idx);
536542 api_checkvalidindex(L, t);
537543 setsvalue(L, &key, luaS_new(L, k));
538− luaV_gettable(L, t, &key, L->top, NULL);
544+ luaV_gettable(L, t, &key, L->top);
539545 api_incr_top(L);
540546 lua_unlock(L);
541547 }
@@ -584,6 +590,9 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { · 42 unmodified lines
584590 case LUA_TUSERDATA:
585591 mt = uvalue(obj)->metatable;
586592 break;
593+ default:
594+ mt = G(L)->mt[ttype(obj)];
595+ break;
587596 }
588597 if (mt == NULL)
589598 res = 0;
@@ -629,7 +638,7 @@ LUA_API void lua_settable (lua_State *L, int idx) { · 39 unmodified lines
629638 api_checknelems(L, 2);
630639 t = index2adr(L, idx);
631640 api_checkvalidindex(L, t);
632− luaV_settable(L, t, L->top - 2, L->top - 1, NULL);
641+ luaV_settable(L, t, L->top - 2, L->top - 1);
633642 L->top -= 2; /* pop index and value */
634643 lua_unlock(L);
635644 }
@@ -643,7 +652,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { · 7 unmodified lines
643652 t = index2adr(L, idx);
644653 api_checkvalidindex(L, t);
645654 setsvalue(L, &key, luaS_new(L, k));
646− luaV_settable(L, t, &key, L->top - 1, NULL);
655+ luaV_settable(L, t, &key, L->top - 1);
647656 L->top--; /* pop value */
648657 lua_unlock(L);
649658 }
@@ -678,7 +687,6 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { · 28 unmodified lines
678687 LUA_API int lua_setmetatable (lua_State *L, int objindex) {
679688 TValue *obj;
680689 Table *mt;
681− int res = 1;
682690 lua_lock(L);
683691 api_checknelems(L, 1);
684692 obj = index2adr(L, objindex);
@@ -703,13 +711,13 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { · 18 unmodified lines
703711 break;
704712 }
705713 default: {
706− res = 0; /* cannot set */
714+ G(L)->mt[ttype(obj)] = mt;
707715 break;
708716 }
709717 }
710718 L->top--;
711719 lua_unlock(L);
712− return res;
720+ return 1;
713721 }
714722
715723
@@ -819,9 +827,9 @@ static void f_Ccall (lua_State *L, void *ud) { · 103 unmodified lines
819827 cl = luaF_newCclosure(L, 0, getcurrenv(L));
820828 cl->c.f = c->func;
821829 setclvalue(L, L->top, cl); /* push function */
822− incr_top(L);
830+ api_incr_top(L);
823831 setpvalue(L->top, c->ud); /* push only argument */
824− incr_top(L);
832+ api_incr_top(L);
825833 luaD_call(L, L->top - 2, 0);
826834 }
827835
@@ -838,7 +846,7 @@ LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { · 10 unmodified lines
838846 }
839847
840848
841−LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data,
849+LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
842850 const char *chunkname) {
843851 ZIO z;
844852 int status;
@@ -851,7 +859,7 @@ LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data, · 6 unmodified lines
851859 }
852860
853861
854−LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
862+LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
855863 int status;
856864 TValue *o;
857865 lua_lock(L);
@@ -904,12 +912,15 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 46 unmodified lines
904912 g->GCthreshold = g->totalbytes - a;
905913 else
906914 g->GCthreshold = 0;
907− luaC_step(L);
915+ while (g->GCthreshold <= g->totalbytes)
916+ luaC_step(L);
917+ if (g->gcstate == GCSpause) /* end of cycle? */
918+ res = 1; /* signal it */
908919 break;
909920 }
910− case LUA_GCSETPACE: {
911− res = g->gcpace;
912− g->gcpace = data;
921+ case LUA_GCSETPAUSE: {
922+ res = g->gcpause;
923+ g->gcpause = data;
913924 break;
914925 }
915926 case LUA_GCSETSTEPMUL: {
src/lapi.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.h,v 2.1 2003/12/10 12:13:36 roberto Exp $
2+** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $
33 ** Auxiliary functions from Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -11,6 +11,6 @@ · 5 unmodified lines
1111 #include "lobject.h"
1212
1313
14−void luaA_pushobject (lua_State *L, const TValue *o);
14+LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);
1515
1616 #endif
src/lauxlib.c+20−47
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.129 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lauxlib.c,v 1.133 2005/05/17 19:49:15 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -25,12 +25,7 @@ · 19 unmodified lines
2525 #include "lauxlib.h"
2626
2727
28−/* number of prereserved references (for internal use) */
29−#define RESERVED_REFS 2
30−
31−/* reserved references */
32−#define FREELIST_REF 1 /* free list of references */
33−#define ARRAYSIZE_REF 2 /* array sizes */
28+#define FREELIST_REF 0 /* free list of references */
3429
3530
3631 /* convert a stack index to positive */
@@ -52,11 +47,12 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { · 15 unmodified lines
5247 if (strcmp(ar.namewhat, "method") == 0) {
5348 narg--; /* do not count `self' */
5449 if (narg == 0) /* error is in the self argument itself? */
55− return luaL_error(L, "calling `%s' on bad self (%s)", ar.name, extramsg);
50+ return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
51+ ar.name, extramsg);
5652 }
5753 if (ar.name == NULL)
5854 ar.name = "?";
59− return luaL_error(L, "bad argument #%d to `%s' (%s)",
55+ return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
6056 narg, ar.name, extramsg);
6157 }
6258
@@ -163,9 +159,8 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) { · 100 unmodified lines
163159
164160
165161 LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
166− const char *s = lua_tostring(L, narg);
162+ const char *s = lua_tolstring(L, narg, len);
167163 if (!s) tag_error(L, narg, LUA_TSTRING);
168− if (len) *len = lua_strlen(L, narg);
169164 return s;
170165 }
171166
@@ -250,7 +245,7 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, · 78 unmodified lines
250245 luaL_setfield(L, LUA_GLOBALSINDEX, libname);
251246 }
252247 else if (!lua_istable(L, -1))
253− luaL_error(L, "name conflict for library `%s'", libname);
248+ luaL_error(L, "name conflict for library " LUA_QS, libname);
254249 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
255250 lua_pushvalue(L, -2);
256251 lua_setfield(L, -2, libname); /* _LOADED[modname] = new table */
@@ -275,6 +270,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname, · 18 unmodified lines
275270 ** =======================================================
276271 */
277272
273+#ifndef luaL_getn
274+
278275 static int checkint (lua_State *L, int topop) {
279276 int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1;
280277 lua_pop(L, topop);
@@ -283,7 +280,7 @@ static int checkint (lua_State *L, int topop) { · 2 unmodified lines
283280
284281
285282 static void getsizes (lua_State *L) {
286− lua_rawgeti(L, LUA_REGISTRYINDEX, ARRAYSIZE_REF);
283+ lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES");
287284 if (lua_isnil(L, -1)) { /* no `size' table? */
288285 lua_pop(L, 1); /* remove nil */
289286 lua_newtable(L); /* create it */
@@ -292,7 +289,7 @@ static void getsizes (lua_State *L) { · 2 unmodified lines
292289 lua_pushliteral(L, "kv");
293290 lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */
294291 lua_pushvalue(L, -1);
295− lua_rawseti(L, LUA_REGISTRYINDEX, ARRAYSIZE_REF); /* store in register */
292+ lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */
296293 }
297294 }
298295
@@ -307,31 +304,6 @@ LUALIB_API void luaL_setn (lua_State *L, int t, int n) { · 8 unmodified lines
307304 }
308305
309306
310−/* find an `n' such that t[n] ~= nil and t[n+1] == nil */
311−static int countn (lua_State *L, int t) {
312− int i = LUA_FIRSTINDEX - 1;
313− int j = 2;
314− /* find `i' such that i <= n < i*2 (= j) */
315− for (;;) {
316− lua_rawgeti(L, t, j);
317− if (lua_isnil(L, -1)) break;
318− lua_pop(L, 1);
319− i = j;
320− j = i*2;
321− }
322− lua_pop(L, 1);
323− /* i <= n < j; do a binary search */
324− while (i < j-1) {
325− int m = (i+j)/2;
326− lua_rawgeti(L, t, m);
327− if (lua_isnil(L, -1)) j = m;
328− else i = m;
329− lua_pop(L, 1);
330− }
331− return i - LUA_FIRSTINDEX + 1;
332−}
333−
334−
335307 LUALIB_API int luaL_getn (lua_State *L, int t) {
336308 int n;
337309 t = abs_index(L, t);
@@ -341,9 +313,11 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { · 3 unmodified lines
341313 if ((n = checkint(L, 2)) >= 0) return n;
342314 lua_getfield(L, t, "n"); /* else try t.n */
343315 if ((n = checkint(L, 1)) >= 0) return n;
344− return countn(L, t);
316+ return lua_objsize(L, t);
345317 }
346318
319+#endif
320+
347321 /* }====================================================== */
348322
349323
@@ -392,7 +366,8 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, · 42 unmodified lines
392366 for (;;) {
393367 const char *fname;
394368 if ((p = pushnexttemplate(L, p)) == NULL) {
395− lua_pushfstring(L, "no readable `%s' in path `%s'", name, path);
369+ lua_pushfstring(L, "no readable " LUA_QS " in path " LUA_QS "",
370+ name, path);
396371 return NULL;
397372 }
398373 fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
@@ -523,9 +498,10 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) { · 124 unmodified lines
523498
524499 LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
525500 lua_State *L = B->L;
526− size_t vl = lua_strlen(L, -1);
501+ size_t vl;
502+ const char *s = lua_tolstring(L, -1, &vl);
527503 if (vl <= bufffree(B)) { /* fit into buffer? */
528− memcpy(B->p, lua_tostring(L, -1), vl); /* put it there */
504+ memcpy(B->p, s, vl); /* put it there */
529505 B->p += vl;
530506 lua_pop(L, 1); /* remove from stack */
531507 }
@@ -562,11 +538,8 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { · 30 unmodified lines
562538 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
563539 }
564540 else { /* no free elements */
565− ref = luaL_getn(L, t);
566− if (ref < RESERVED_REFS)
567− ref = RESERVED_REFS; /* skip reserved references */
541+ ref = lua_objsize(L, t);
568542 ref++; /* create new reference */
569− luaL_setn(L, t, ref);
570543 }
571544 lua_rawseti(L, t, ref);
572545 return ref;
src/lauxlib.h+7−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.74 2005/01/10 17:31:50 roberto Exp $
2+** $Id: lauxlib.h,v 1.75 2005/03/29 16:20:48 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -15,6 +15,12 @@ · 9 unmodified lines
1515 #include "lua.h"
1616
1717
18+#if !LUA_COMPAT_GETN
19+#define luaL_getn(L,i) lua_objsize(L, i)
20+#define luaL_setn(L,i,j) ((void)0) /* no op! */
21+#endif
22+
23+
1824 /* extra error code for `luaL_load' */
1925 #define LUA_ERRFILE (LUA_ERRERR+1)
2026
src/lbaselib.c+21−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.169 2005/02/28 17:24:41 roberto Exp $
2+** $Id: lbaselib.c,v 1.176 2005/05/17 19:49:15 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -39,7 +39,8 @@ static int luaB_print (lua_State *L) { · 33 unmodified lines
3939 lua_call(L, 1, 1);
4040 s = lua_tostring(L, -1); /* get result */
4141 if (s == NULL)
42− return luaL_error(L, "`tostring' must return a string to `print'");
42+ return luaL_error(L, LUA_QL("tostring") " must return a string to "
43+ LUA_QL("print"));
4344 if (i>1) fputs("\t", stdout);
4445 fputs(s, stdout);
4546 lua_pop(L, 1); /* pop result */
@@ -148,7 +149,8 @@ static int luaB_setfenv (lua_State *L) { · 102 unmodified lines
148149 return 0;
149150 }
150151 else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)
151− luaL_error(L, "`setfenv' cannot change environment of given object");
152+ luaL_error(L,
153+ LUA_QL("setfenv") " cannot change environment of given object");
152154 return 1;
153155 }
154156
@@ -164,6 +166,7 @@ static int luaB_rawequal (lua_State *L) { · 9 unmodified lines
164166 static int luaB_rawget (lua_State *L) {
165167 luaL_checktype(L, 1, LUA_TTABLE);
166168 luaL_checkany(L, 2);
169+ lua_settop(L, 2);
167170 lua_rawget(L, 1);
168171 return 1;
169172 }
@@ -172,6 +175,7 @@ static int luaB_rawset (lua_State *L) { · 2 unmodified lines
172175 luaL_checktype(L, 1, LUA_TTABLE);
173176 luaL_checkany(L, 2);
174177 luaL_checkany(L, 3);
178+ lua_settop(L, 3);
175179 lua_rawset(L, 1);
176180 return 1;
177181 }
@@ -185,9 +189,9 @@ static int luaB_gcinfo (lua_State *L) { · 7 unmodified lines
185189
186190 static int luaB_collectgarbage (lua_State *L) {
187191 static const char *const opts[] = {"stop", "restart", "collect",
188− "count", "step", "setpace", "setstepmul", NULL};
192+ "count", "step", "setpause", "setstepmul", NULL};
189193 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
190− LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPACE, LUA_GCSETSTEPMUL};
194+ LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};
191195 int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
192196 int ex = luaL_optinteger(L, 2, 0);
193197 luaL_argcheck(L, o >= 0, 1, "invalid option");
@@ -238,7 +242,7 @@ static int luaB_ipairs (lua_State *L) { · 44 unmodified lines
238242 luaL_checktype(L, 1, LUA_TTABLE);
239243 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
240244 lua_pushvalue(L, 1); /* state, */
241− lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */
245+ lua_pushinteger(L, 0); /* and initial value */
242246 return 3;
243247 }
244248
@@ -292,11 +296,8 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { · 47 unmodified lines
292296 return NULL;
293297 }
294298 else if (lua_isstring(L, -1)) {
295− const char *res;
296299 lua_replace(L, 3); /* save string in a reserved stack slot */
297− res = lua_tostring(L, 3);
298− *size = lua_strlen(L, 3);
299− return res;
300+ return lua_tolstring(L, 3, size);
300301 }
301302 else luaL_error(L, "reader function must return a string");
302303 return NULL; /* to avoid warnings */
@@ -330,13 +331,20 @@ static int luaB_assert (lua_State *L) { · 27 unmodified lines
330331 }
331332
332333
334+static int luaB_getn (lua_State *L) {
335+ luaL_checktype(L, 1, LUA_TTABLE);
336+ lua_pushinteger(L, lua_objsize(L, 1));
337+ return 1;
338+}
339+
340+
333341 static int luaB_unpack (lua_State *L) {
334− int i = luaL_optint(L, 2, LUA_FIRSTINDEX);
342+ int i = luaL_optint(L, 2, 1);
335343 int e = luaL_optint(L, 3, -1);
336344 int n;
337345 luaL_checktype(L, 1, LUA_TTABLE);
338346 if (e == -1)
339− e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1;
347+ e = luaL_getn(L, 1);
340348 n = e - i + 1; /* number of elements */
341349 if (n <= 0) return 0; /* empty range */
342350 luaL_checkstack(L, n, "table too big to unpack");
@@ -446,6 +454,7 @@ static const luaL_reg base_funcs[] = { · 103 unmodified lines
446454 {"tostring", luaB_tostring},
447455 {"type", luaB_type},
448456 {"assert", luaB_assert},
457+ {"getn", luaB_getn},
449458 {"unpack", luaB_unpack},
450459 {"select", luaB_select},
451460 {"rawequal", luaB_rawequal},
src/lcode.c+22−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.9 2005/01/10 18:17:39 roberto Exp $
2+** $Id: lcode.c,v 2.12 2005/03/16 16:59:21 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -603,19 +603,32 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { · 597 unmodified lines
603603
604604
605605 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
606− if (op == OPR_MINUS) {
607− luaK_exp2val(fs, e);
608− if (e->k == VK && ttisnumber(&fs->f->k[e->info]))
609− e->info = luaK_numberK(fs, num_unm(nvalue(&fs->f->k[e->info])));
610− else {
606+ switch (op) {
607+ case OPR_MINUS: {
608+ luaK_exp2val(fs, e);
609+ if (e->k == VK && ttisnumber(&fs->f->k[e->info]))
610+ e->info = luaK_numberK(fs, luai_numunm(nvalue(&fs->f->k[e->info])));
611+ else {
612+ luaK_exp2anyreg(fs, e);
613+ freeexp(fs, e);
614+ e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0);
615+ e->k = VRELOCABLE;
616+ }
617+ break;
618+ }
619+ case OPR_NOT: {
620+ codenot(fs, e);
621+ break;
622+ }
623+ case OPR_SIZE: {
611624 luaK_exp2anyreg(fs, e);
612625 freeexp(fs, e);
613− e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0);
626+ e->info = luaK_codeABC(fs, OP_SIZ, 0, e->info, 0);
614627 e->k = VRELOCABLE;
628+ break;
615629 }
630+ default: lua_assert(0);
616631 }
617− else /* op == NOT */
618− codenot(fs, e);
619632 }
620633
621634
src/lcode.h+33−33
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.h,v 1.40 2004/10/04 19:01:53 roberto Exp $
2+** $Id: lcode.h,v 1.43 2005/04/25 19:24:10 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -24,7 +24,7 @@ · 18 unmodified lines
2424 ** grep "ORDER OPR" if you change these enums
2525 */
2626 typedef enum BinOpr {
27− OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW,
27+ OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_MOD, OPR_POW,
2828 OPR_CONCAT,
2929 OPR_NE, OPR_EQ,
3030 OPR_LT, OPR_LE, OPR_GT, OPR_GE,
@@ -34,7 +34,7 @@ typedef enum BinOpr { · 3 unmodified lines
3434
3535 #define binopistest(op) ((op) >= OPR_NE)
3636
37−typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr;
37+typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_SIZE, OPR_NOUNOPR } UnOpr;
3838
3939
4040 #define getcode(fs,e) ((fs)->f->code[(e)->info])
@@ -43,36 +43,36 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; · 2 unmodified lines
4343
4444 #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
4545
46−int luaK_code (FuncState *fs, Instruction i, int line);
47−int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
48−int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
49−void luaK_fixline (FuncState *fs, int line);
50−void luaK_nil (FuncState *fs, int from, int n);
51−void luaK_reserveregs (FuncState *fs, int n);
52−void luaK_checkstack (FuncState *fs, int n);
53−int luaK_stringK (FuncState *fs, TString *s);
54−int luaK_numberK (FuncState *fs, lua_Number r);
55−void luaK_dischargevars (FuncState *fs, expdesc *e);
56−int luaK_exp2anyreg (FuncState *fs, expdesc *e);
57−void luaK_exp2nextreg (FuncState *fs, expdesc *e);
58−void luaK_exp2val (FuncState *fs, expdesc *e);
59−int luaK_exp2RK (FuncState *fs, expdesc *e);
60−void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
61−void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
62−void luaK_goiftrue (FuncState *fs, expdesc *e);
63−void luaK_goiffalse (FuncState *fs, expdesc *e);
64−void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
65−void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
66−void luaK_setoneret (FuncState *fs, expdesc *e);
67−int luaK_jump (FuncState *fs);
68−void luaK_patchlist (FuncState *fs, int list, int target);
69−void luaK_patchtohere (FuncState *fs, int list);
70−void luaK_concat (FuncState *fs, int *l1, int l2);
71−int luaK_getlabel (FuncState *fs);
72−void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
73−void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
74−void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);
75−void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
46+LUAI_FUNC int luaK_code (FuncState *fs, Instruction i, int line);
47+LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
48+LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
49+LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
50+LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
51+LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
52+LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
53+LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);
54+LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);
55+LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
56+LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
57+LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
58+LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
59+LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
60+LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
61+LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
62+LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
63+LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
64+LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
65+LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
66+LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
67+LUAI_FUNC int luaK_jump (FuncState *fs);
68+LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
69+LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
70+LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
71+LUAI_FUNC int luaK_getlabel (FuncState *fs);
72+LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
73+LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
74+LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);
75+LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
7676
7777
7878 #endif
src/ldblib.c+59−55
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.93 2005/02/18 12:40:02 roberto Exp $
2+** $Id: ldblib.c,v 1.98 2005/05/17 19:49:15 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -19,7 +19,7 @@ · 13 unmodified lines
1919
2020
2121
22−static int getmetatable (lua_State *L) {
22+static int db_getmetatable (lua_State *L) {
2323 luaL_checkany(L, 1);
2424 if (!lua_getmetatable(L, 1)) {
2525 lua_pushnil(L); /* no metatable */
@@ -28,7 +28,7 @@ static int getmetatable (lua_State *L) { · 2 unmodified lines
2828 }
2929
3030
31−static int setmetatable (lua_State *L) {
31+static int db_setmetatable (lua_State *L) {
3232 int t = lua_type(L, 2);
3333 luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
3434 "nil or table expected");
@@ -38,17 +38,18 @@ static int setmetatable (lua_State *L) { · 3 unmodified lines
3838 }
3939
4040
41−static int getfenv (lua_State *L) {
41+static int db_getfenv (lua_State *L) {
4242 lua_getfenv(L, 1);
4343 return 1;
4444 }
4545
4646
47−static int setfenv (lua_State *L) {
47+static int db_setfenv (lua_State *L) {
4848 luaL_checktype(L, 2, LUA_TTABLE);
4949 lua_settop(L, 2);
5050 if (lua_setfenv(L, 1) == 0)
51− luaL_error(L, "`setfenv' cannot change environment of given object");
51+ luaL_error(L, LUA_QL("setfenv")
52+ " cannot change environment of given object");
5253 return 1;
5354 }
5455
@@ -77,7 +78,18 @@ static lua_State *getthread (lua_State *L, int *arg) { · 22 unmodified lines
7778 }
7879
7980
80−static int getinfo (lua_State *L) {
81+static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
82+ if (L == L1) {
83+ lua_pushvalue(L, -2);
84+ lua_remove(L, -3);
85+ }
86+ else
87+ lua_xmove(L1, L, 1);
88+ lua_setfield(L, -2, fname);
89+}
90+
91+
92+static int db_getinfo (lua_State *L) {
8193 lua_Debug ar;
8294 int arg;
8395 lua_State *L1 = getthread(L, &arg);
@@ -99,38 +111,30 @@ static int getinfo (lua_State *L) { · 15 unmodified lines
99111 if (!lua_getinfo(L1, options, &ar))
100112 return luaL_argerror(L, arg+2, "invalid option");
101113 lua_newtable(L);
102− for (; *options; options++) {
103− switch (*options) {
104− case 'S':
105− settabss(L, "source", ar.source);
106− settabss(L, "short_src", ar.short_src);
107− settabsi(L, "linedefined", ar.linedefined);
108− settabss(L, "what", ar.what);
109− break;
110− case 'l':
111− settabsi(L, "currentline", ar.currentline);
112− break;
113− case 'u':
114− settabsi(L, "nups", ar.nups);
115− break;
116− case 'n':
117− settabss(L, "name", ar.name);
118− settabss(L, "namewhat", ar.namewhat);
119− break;
120− case 'f':
121− if (L == L1)
122− lua_pushvalue(L, -2);
123− else
124− lua_xmove(L1, L, 1);
125− lua_setfield(L, -2, "func");
126− break;
127− }
114+ if (strchr(options, 'S')) {
115+ settabss(L, "source", ar.source);
116+ settabss(L, "short_src", ar.short_src);
117+ settabsi(L, "linedefined", ar.linedefined);
118+ settabsi(L, "lastlinedefined", ar.lastlinedefined);
119+ settabss(L, "what", ar.what);
120+ }
121+ if (strchr(options, 'l'))
122+ settabsi(L, "currentline", ar.currentline);
123+ if (strchr(options, 'u'))
124+ settabsi(L, "nups", ar.nups);
125+ if (strchr(options, 'n')) {
126+ settabss(L, "name", ar.name);
127+ settabss(L, "namewhat", ar.namewhat);
128128 }
129+ if (strchr(options, 'L'))
130+ treatstackoption(L, L1, "activelines");
131+ if (strchr(options, 'f'))
132+ treatstackoption(L, L1, "func");
129133 return 1; /* return table */
130134 }
131135
132136
133−static int getlocal (lua_State *L) {
137+static int db_getlocal (lua_State *L) {
134138 int arg;
135139 lua_State *L1 = getthread(L, &arg);
136140 lua_Debug ar;
@@ -151,7 +155,7 @@ static int getlocal (lua_State *L) { · 14 unmodified lines
151155 }
152156
153157
154−static int setlocal (lua_State *L) {
158+static int db_setlocal (lua_State *L) {
155159 int arg;
156160 lua_State *L1 = getthread(L, &arg);
157161 lua_Debug ar;
@@ -178,12 +182,12 @@ static int auxupvalue (lua_State *L, int get) { · 20 unmodified lines
178182 }
179183
180184
181−static int getupvalue (lua_State *L) {
185+static int db_getupvalue (lua_State *L) {
182186 return auxupvalue(L, 1);
183187 }
184188
185189
186−static int setupvalue (lua_State *L) {
190+static int db_setupvalue (lua_State *L) {
187191 luaL_checkany(L, 3);
188192 return auxupvalue(L, 0);
189193 }
@@ -244,7 +248,7 @@ static void gethooktable (lua_State *L) { · 54 unmodified lines
244248 }
245249
246250
247−static int sethook (lua_State *L) {
251+static int db_sethook (lua_State *L) {
248252 int arg;
249253 lua_State *L1 = getthread(L, &arg);
250254 if (lua_isnoneornil(L, arg+1)) {
@@ -267,7 +271,7 @@ static int sethook (lua_State *L) { · 16 unmodified lines
267271 }
268272
269273
270−static int gethook (lua_State *L) {
274+static int db_gethook (lua_State *L) {
271275 int arg;
272276 lua_State *L1 = getthread(L, &arg);
273277 char buff[5];
@@ -288,7 +292,7 @@ static int gethook (lua_State *L) { · 14 unmodified lines
288292 }
289293
290294
291−static int debug (lua_State *L) {
295+static int db_debug (lua_State *L) {
292296 for (;;) {
293297 char buffer[250];
294298 fputs("lua_debug> ", stderr);
@@ -308,7 +312,7 @@ static int debug (lua_State *L) { · 13 unmodified lines
308312 #define LEVELS1 12 /* size of the first part of the stack */
309313 #define LEVELS2 10 /* size of the second part of the stack */
310314
311−static int errorfb (lua_State *L) {
315+static int db_errorfb (lua_State *L) {
312316 int level;
313317 int firstpart = 1; /* still before eventual `...' */
314318 int arg;
@@ -344,7 +348,7 @@ static int errorfb (lua_State *L) { · 29 unmodified lines
344348 if (ar.currentline > 0)
345349 lua_pushfstring(L, "%d:", ar.currentline);
346350 if (*ar.namewhat != '\0') /* is there a name? */
347− lua_pushfstring(L, " in function `%s'", ar.name);
351+ lua_pushfstring(L, " in function " LUA_QS, ar.name);
348352 else {
349353 if (*ar.what == 'm') /* main? */
350354 lua_pushfstring(L, " in main chunk");
@@ -362,19 +366,19 @@ static int errorfb (lua_State *L) { · 11 unmodified lines
362366
363367
364368 static const luaL_reg dblib[] = {
365− {"getmetatable", getmetatable},
366− {"setmetatable", setmetatable},
367− {"getfenv", getfenv},
368− {"setfenv", setfenv},
369− {"getlocal", getlocal},
370− {"getinfo", getinfo},
371− {"gethook", gethook},
372− {"getupvalue", getupvalue},
373− {"sethook", sethook},
374− {"setlocal", setlocal},
375− {"setupvalue", setupvalue},
376− {"debug", debug},
377− {"traceback", errorfb},
369+ {"getmetatable", db_getmetatable},
370+ {"setmetatable", db_setmetatable},
371+ {"getfenv", db_getfenv},
372+ {"setfenv", db_setfenv},
373+ {"getlocal", db_getlocal},
374+ {"getinfo", db_getinfo},
375+ {"gethook", db_gethook},
376+ {"getupvalue", db_getupvalue},
377+ {"sethook", db_sethook},
378+ {"setlocal", db_setlocal},
379+ {"setupvalue", db_setupvalue},
380+ {"debug", db_debug},
381+ {"traceback", db_errorfb},
378382 {NULL, NULL}
379383 };
380384
src/ldebug.c+71−44
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 roberto Exp $
2+** $Id: ldebug.c,v 2.20 2005/05/17 19:49:15 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -30,17 +30,19 @@ · 24 unmodified lines
3030
3131
3232
33−static const char *getfuncname (CallInfo *ci, const char **name);
33+static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
3434
3535
36−static int currentpc (CallInfo *ci) {
36+static int currentpc (lua_State *L, CallInfo *ci) {
3737 if (!isLua(ci)) return -1; /* function is not a Lua function? */
38+ if (ci == L->ci)
39+ ci->savedpc = L->savedpc;
3840 return pcRel(ci->savedpc, ci_func(ci)->l.p);
3941 }
4042
4143
42−static int currentline (CallInfo *ci) {
43− int pc = currentpc(ci);
44+static int currentline (lua_State *L, CallInfo *ci) {
45+ int pc = currentpc(L, ci);
4446 if (pc < 0)
4547 return -1; /* only active lua functions have current-line information */
4648 else
@@ -88,15 +90,15 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 41 unmodified lines
8890 if (f_isLua(ci)) /* Lua function? */
8991 level -= ci->tailcalls; /* skip lost tail calls */
9092 }
91− if (level > 0 || ci == L->base_ci) status = 0; /* there is no such level */
92− else if (level < 0) { /* level is of a lost tail call */
93+ if (level == 0 && ci > L->base_ci) { /* level found? */
9394 status = 1;
94− ar->i_ci = 0;
95+ ar->i_ci = ci - L->base_ci;
9596 }
96− else {
97+ else if (level < 0) { /* level is of a lost tail call? */
9798 status = 1;
98− ar->i_ci = ci - L->base_ci;
99+ ar->i_ci = 0;
99100 }
101+ else status = 0; /* no such level */
100102 lua_unlock(L);
101103 return status;
102104 }
@@ -116,7 +118,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { · 13 unmodified lines
116118 ci = L->base_ci + ar->i_ci;
117119 fp = getluaproto(ci);
118120 if (fp) { /* is a Lua function? */
119− name = luaF_getlocalname(fp, n, currentpc(ci));
121+ name = luaF_getlocalname(fp, n, currentpc(L, ci));
120122 if (name)
121123 luaA_pushobject(L, ci->base+(n-1)); /* push value */
122124 }
@@ -135,7 +137,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { · 12 unmodified lines
135137 fp = getluaproto(ci);
136138 L->top--; /* pop new value */
137139 if (fp) { /* is a Lua function? */
138− name = luaF_getlocalname(fp, n, currentpc(ci));
140+ name = luaF_getlocalname(fp, n, currentpc(L, ci));
139141 if (!name || name[0] == '(') /* `(' starts private locals */
140142 name = NULL;
141143 else
@@ -146,8 +148,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { · 4 unmodified lines
146148 }
147149
148150
149−static void funcinfo (lua_Debug *ar, StkId func) {
150− Closure *cl = clvalue(func);
151+static void funcinfo (lua_Debug *ar, Closure *cl) {
151152 if (cl->c.isC) {
152153 ar->source = "=[C]";
153154 ar->linedefined = -1;
@@ -155,7 +156,8 @@ static void funcinfo (lua_Debug *ar, StkId func) { · 1 unmodified line
155156 }
156157 else {
157158 ar->source = getstr(cl->l.p->source);
158− ar->linedefined = cl->l.p->lineDefined;
159+ ar->linedefined = cl->l.p->linedefined;
160+ ar->lastlinedefined = cl->l.p->lastlinedefined;
159161 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
160162 }
161163 luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
@@ -165,17 +167,36 @@ static void funcinfo (lua_Debug *ar, StkId func) { · 3 unmodified lines
165167 static void info_tailcall (lua_State *L, lua_Debug *ar) {
166168 ar->name = ar->namewhat = "";
167169 ar->what = "tail";
168− ar->linedefined = ar->currentline = -1;
170+ ar->lastlinedefined = ar->linedefined = ar->currentline = -1;
169171 ar->source = "=(tail call)";
170172 luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
171173 ar->nups = 0;
172− setnilvalue(L->top);
174+}
175+
176+
177+static void collectvalidlines (lua_State *L, Closure *f) {
178+ if (f == NULL || f->c.isC) {
179+ setnilvalue(L->top);
180+ }
181+ else {
182+ Table *t = luaH_new(L, 0, 0);
183+ int *lineinfo = f->l.p->lineinfo;
184+ int i;
185+ for (i=0; i<f->l.p->sizelineinfo; i++)
186+ setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);
187+ sethvalue(L, L->top, t);
188+ }
189+ incr_top(L);
173190 }
174191
175192
176193 static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
177− StkId f, CallInfo *ci) {
194+ Closure *f, CallInfo *ci) {
178195 int status = 1;
196+ if (f == NULL) {
197+ info_tailcall(L, ar);
198+ return status;
199+ }
179200 for (; *what; what++) {
180201 switch (*what) {
181202 case 'S': {
@@ -183,25 +204,24 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, · 1 unmodified line
183204 break;
184205 }
185206 case 'l': {
186− ar->currentline = (ci) ? currentline(ci) : -1;
207+ ar->currentline = (ci) ? currentline(L, ci) : -1;
187208 break;
188209 }
189210 case 'u': {
190− ar->nups = clvalue(f)->c.nupvalues;
211+ ar->nups = f->c.nupvalues;
191212 break;
192213 }
193214 case 'n': {
194− ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL;
215+ ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
195216 if (ar->namewhat == NULL) {
196217 ar->namewhat = ""; /* not found */
197218 ar->name = NULL;
198219 }
199220 break;
200221 }
201− case 'f': {
202− setobj2s(L, L->top, f);
222+ case 'L':
223+ case 'f': /* handled by lua_getinfo */
203224 break;
204− }
205225 default: status = 0; /* invalid option */
206226 }
207227 }
@@ -210,23 +230,30 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, · 2 unmodified lines
210230
211231
212232 LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
213− int status = 1;
233+ int status;
234+ Closure *f = NULL;
235+ CallInfo *ci = NULL;
214236 lua_lock(L);
215237 if (*what == '>') {
216− StkId f = L->top - 1;
217− if (!ttisfunction(f))
218− luaG_runerror(L, "value for `lua_getinfo' is not a function");
219− status = auxgetinfo(L, what + 1, ar, f, NULL);
238+ StkId func = L->top - 1;
239+ luai_apicheck(L, ttisfunction(func));
240+ what++; /* skip the '>' */
241+ f = clvalue(func);
220242 L->top--; /* pop function */
221243 }
222244 else if (ar->i_ci != 0) { /* no tail call? */
223− CallInfo *ci = L->base_ci + ar->i_ci;
245+ ci = L->base_ci + ar->i_ci;
224246 lua_assert(ttisfunction(ci->func));
225− status = auxgetinfo(L, what, ar, ci->func, ci);
247+ f = clvalue(ci->func);
226248 }
227− else
228− info_tailcall(L, ar);
229− if (strchr(what, 'f')) incr_top(L);
249+ status = auxgetinfo(L, what, ar, f, ci);
250+ if (strchr(what, 'f')) {
251+ if (f == NULL) setnilvalue(L->top);
252+ else setclvalue(L, L->top, f);
253+ incr_top(L);
254+ }
255+ if (strchr(what, 'L'))
256+ collectvalidlines(L, f);
230257 lua_unlock(L);
231258 return status;
232259 }
@@ -366,7 +393,6 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 133 unmodified lines
366393 if (reg >= a+3) last = pc; /* affect all regs above its call base */
367394 break;
368395 }
369− case OP_TFORPREP:
370396 case OP_FORLOOP:
371397 case OP_FORPREP:
372398 checkreg(pt, a+3);
@@ -446,10 +472,11 @@ static const char *kname (Proto *p, int c) { · 73 unmodified lines
446472 }
447473
448474
449−static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
475+static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,
476+ const char **name) {
450477 if (isLua(ci)) { /* a Lua function? */
451478 Proto *p = ci_func(ci)->l.p;
452− int pc = currentpc(ci);
479+ int pc = currentpc(L, ci);
453480 Instruction i;
454481 *name = luaF_getlocalname(p, stackpos+1, pc);
455482 if (*name) /* is a local? */
@@ -467,7 +494,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { · 11 unmodified lines
467494 int a = GETARG_A(i);
468495 int b = GETARG_B(i); /* move from `b' to `a' */
469496 if (b < a)
470− return getobjname(ci, b, name); /* get name for `b' */
497+ return getobjname(L, ci, b, name); /* get name for `b' */
471498 break;
472499 }
473500 case OP_GETTABLE: {
@@ -492,15 +519,15 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { · 18 unmodified lines
492519 }
493520
494521
495−static const char *getfuncname (CallInfo *ci, const char **name) {
522+static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
496523 Instruction i;
497524 if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
498525 return NULL; /* calling function is not Lua (or is unknown) */
499526 ci--; /* calling function */
500− i = ci_func(ci)->l.p->code[currentpc(ci)];
527+ i = ci_func(ci)->l.p->code[currentpc(L, ci)];
501528 if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
502529 GET_OPCODE(i) == OP_TFORLOOP)
503− return getobjname(ci, GETARG_A(i), name);
530+ return getobjname(L, ci, GETARG_A(i), name);
504531 else
505532 return NULL; /* no useful name can be found */
506533 }
@@ -519,9 +546,9 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 12 unmodified lines
519546 const char *name = NULL;
520547 const char *t = luaT_typenames[ttype(o)];
521548 const char *kind = (isinstack(L->ci, o)) ?
522− getobjname(L->ci, o - L->base, &name) : NULL;
549+ getobjname(L, L->ci, o - L->base, &name) : NULL;
523550 if (kind)
524− luaG_runerror(L, "attempt to %s %s `%s' (a %s value)",
551+ luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
525552 op, kind, name, t);
526553 else
527554 luaG_runerror(L, "attempt to %s a %s value", op, t);
@@ -558,7 +585,7 @@ static void addinfo (lua_State *L, const char *msg) { · 30 unmodified lines
558585 CallInfo *ci = L->ci;
559586 if (isLua(ci)) { /* is Lua code? */
560587 char buff[LUA_IDSIZE]; /* add file:line information */
561− int line = currentline(ci);
588+ int line = currentline(L, ci);
562589 luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
563590 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
564591 }
src/ldebug.h+12−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.h,v 2.2 2004/06/02 19:07:55 roberto Exp $
2+** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $
33 ** Auxiliary functions from Debug Interface module
44 ** See Copyright Notice in lua.h
55 */
@@ -18,13 +18,16 @@ · 12 unmodified lines
1818 #define resethookcount(L) (L->hookcount = L->basehookcount)
1919
2020
21−void luaG_typeerror (lua_State *L, const TValue *o, const char *opname);
22−void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
23−void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2);
24−int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2);
25−void luaG_runerror (lua_State *L, const char *fmt, ...);
26−void luaG_errormsg (lua_State *L);
27−int luaG_checkcode (const Proto *pt);
28−int luaG_checkopenop (Instruction i);
21+LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
22+ const char *opname);
23+LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
24+LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
25+ const TValue *p2);
26+LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
27+ const TValue *p2);
28+LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
29+LUAI_FUNC void luaG_errormsg (lua_State *L);
30+LUAI_FUNC int luaG_checkcode (const Proto *pt);
31+LUAI_FUNC int luaG_checkopenop (Instruction i);
2932
3033 #endif
src/ldo.c+24−16
@@ -1,10 +1,11 @@
11 /*
2−** $Id: ldo.c,v 2.14 2005/02/18 12:40:02 roberto Exp $
2+** $Id: ldo.c,v 2.23 2005/05/03 19:01:17 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
66
77
8+#include <setjmp.h>
89 #include <stdlib.h>
910 #include <string.h>
1011
@@ -42,7 +43,7 @@ · 31 unmodified lines
4243 /* chain list of long jump buffers */
4344 struct lua_longjmp {
4445 struct lua_longjmp *previous;
45− l_jmpbuf b;
46+ luai_jmpbuf b;
4647 volatile int status; /* error code */
4748 };
4849
@@ -70,9 +71,10 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 21 unmodified lines
7071 void luaD_throw (lua_State *L, int errcode) {
7172 if (L->errorJmp) {
7273 L->errorJmp->status = errcode;
73− L_THROW(L, L->errorJmp);
74+ LUAI_THROW(L, L->errorJmp);
7475 }
7576 else {
77+ L->status = errcode;
7678 if (G(L)->panic) G(L)->panic(L);
7779 exit(EXIT_FAILURE);
7880 }
@@ -84,7 +86,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 5 unmodified lines
8486 lj.status = 0;
8587 lj.previous = L->errorJmp; /* chain new error handler */
8688 L->errorJmp = &lj;
87− L_TRY(L, &lj,
89+ LUAI_TRY(L, &lj,
8890 (*f)(L, ud);
8991 );
9092 L->errorJmp = lj.previous; /* restore old error handler */
@@ -94,10 +96,10 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 3 unmodified lines
9496
9597 static void restore_stack_limit (lua_State *L) {
9698 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
97− if (L->size_ci > LUA_MAXCALLS) { /* there was an overflow? */
99+ if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */
98100 int inuse = (L->ci - L->base_ci);
99− if (inuse + 1 < LUA_MAXCALLS) /* can `undo' overflow? */
100− luaD_reallocCI(L, LUA_MAXCALLS);
101+ if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
102+ luaD_reallocCI(L, LUAI_MAXCALLS);
101103 }
102104 }
103105
@@ -114,6 +116,7 @@ static void correctstack (lua_State *L, TValue *oldstack) { · 10 unmodified lines
114116 ci->top = (ci->top - oldstack) + L->stack;
115117 ci->base = (ci->base - oldstack) + L->stack;
116118 ci->func = (ci->func - oldstack) + L->stack;
119+ lua_assert(lua_checkpc(L, ci));
117120 }
118121 L->base = L->ci->base;
119122 }
@@ -133,7 +136,7 @@ void luaD_reallocstack (lua_State *L, int newsize) { · 13 unmodified lines
133136 void luaD_reallocCI (lua_State *L, int newsize) {
134137 CallInfo *oldci = L->base_ci;
135138 luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);
136− L->size_ci = cast(unsigned short, newsize);
139+ L->size_ci = newsize;
137140 L->ci = (L->ci - oldci) + L->base_ci;
138141 L->end_ci = L->base_ci + L->size_ci - 1;
139142 }
@@ -148,11 +151,11 @@ void luaD_growstack (lua_State *L, int n) { · 8 unmodified lines
148151
149152
150153 static CallInfo *growCI (lua_State *L) {
151− if (L->size_ci > LUA_MAXCALLS) /* overflow while handling overflow? */
154+ if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */
152155 luaD_throw(L, LUA_ERRERR);
153156 else {
154157 luaD_reallocCI(L, 2*L->size_ci);
155− if (L->size_ci > LUA_MAXCALLS)
158+ if (L->size_ci > LUAI_MAXCALLS)
156159 luaG_runerror(L, "stack overflow");
157160 }
158161 return ++L->ci;
@@ -195,16 +198,18 @@ static StkId adjust_varargs (lua_State *L, int nfixargs, int actual, · 36 unmodified lines
195198 for (; actual < nfixargs; ++actual)
196199 setnilvalue(L->top++);
197200 }
201+#if LUA_COMPAT_VARARG
198202 if (style != NEWSTYLEVARARG) { /* compatibility with old-style vararg */
199203 int nvar = actual - nfixargs; /* number of extra arguments */
200204 luaC_checkGC(L);
201205 htab = luaH_new(L, nvar, 1); /* create `arg' table */
202206 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
203− setobj2n(L, luaH_setnum(L, htab, i+LUA_FIRSTINDEX), L->top - nvar + i);
207+ setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
204208 /* store counter in field `n' */
205209 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),
206210 cast(lua_Number, nvar));
207211 }
212+#endif
208213 /* move fixed parameters to final position */
209214 fixed = L->top - actual; /* first fixed argument */
210215 base = L->top; /* final position of first argument */
@@ -249,6 +254,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 38 unmodified lines
249254 func = tryfuncTM(L, func); /* check the `function' tag method */
250255 funcr = savestack(L, func);
251256 cl = &clvalue(func)->l;
257+ L->ci->savedpc = L->savedpc;
252258 if (!cl->isC) { /* Lua function? prepare its call */
253259 CallInfo *ci;
254260 StkId st, base;
@@ -269,7 +275,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 14 unmodified lines
269275 L->base = ci->base = base;
270276 ci->top = L->base + p->maxstacksize;
271277 lua_assert(ci->top <= L->stack_last);
272− ci->savedpc = p->code; /* starting point */
278+ L->savedpc = p->code; /* starting point */
273279 ci->tailcalls = 0;
274280 ci->nresults = nresults;
275281 for (st = L->top; st < ci->top; st++)
@@ -321,6 +327,7 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { · 45 unmodified lines
321327 res = L->ci->func; /* res == final position of 1st result */
322328 L->ci--;
323329 L->base = L->ci->base; /* restore base */
330+ L->savedpc = L->ci->savedpc; /* restore savedpc */
324331 /* move results to correct place */
325332 while (wanted != 0 && firstResult < L->top) {
326333 setobjs2s(L, res++, firstResult++);
@@ -339,10 +346,10 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { · 12 unmodified lines
339346 ** function position.
340347 */
341348 void luaD_call (lua_State *L, StkId func, int nResults) {
342− if (++L->nCcalls >= LUA_MAXCCALLS) {
343− if (L->nCcalls == LUA_MAXCCALLS)
349+ if (++L->nCcalls >= LUAI_MAXCCALLS) {
350+ if (L->nCcalls == LUAI_MAXCCALLS)
344351 luaG_runerror(L, "C stack overflow");
345− else if (L->nCcalls >= (LUA_MAXCCALLS + (LUA_MAXCCALLS>>3)))
352+ else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
346353 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
347354 }
348355 if (luaD_precall(L, func, nResults) == PCRLUA) { /* is a Lua function? */
@@ -434,7 +441,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { · 85 unmodified lines
434441 int luaD_pcall (lua_State *L, Pfunc func, void *u,
435442 ptrdiff_t old_top, ptrdiff_t ef) {
436443 int status;
437− unsigned short oldnCcalls = L->nCcalls;
444+ int oldnCcalls = L->nCcalls;
438445 ptrdiff_t old_ci = saveci(L, L->ci);
439446 lu_byte old_allowhooks = L->allowhook;
440447 ptrdiff_t old_errfunc = L->errfunc;
@@ -447,6 +454,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, · 6 unmodified lines
447454 L->nCcalls = oldnCcalls;
448455 L->ci = restoreci(L, old_ci);
449456 L->base = L->ci->base;
457+ L->savedpc = L->ci->savedpc;
450458 L->allowhook = old_allowhooks;
451459 restore_stack_limit(L);
452460 }
src/ldo.h+14−14
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.h,v 2.3 2004/09/08 14:23:09 roberto Exp $
2+** $Id: ldo.h,v 2.4 2005/04/25 19:24:10 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -47,20 +47,20 @@ · 41 unmodified lines
4747 /* type of protected functions, to be ran by `runprotected' */
4848 typedef void (*Pfunc) (lua_State *L, void *ud);
4949
50−void luaD_resetprotection (lua_State *L);
51−int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
52−void luaD_callhook (lua_State *L, int event, int line);
53−int luaD_precall (lua_State *L, StkId func, int nresults);
54−void luaD_call (lua_State *L, StkId func, int nResults);
55−int luaD_pcall (lua_State *L, Pfunc func, void *u,
56− ptrdiff_t oldtop, ptrdiff_t ef);
57−void luaD_poscall (lua_State *L, int wanted, StkId firstResult);
58−void luaD_reallocCI (lua_State *L, int newsize);
59−void luaD_reallocstack (lua_State *L, int newsize);
60−void luaD_growstack (lua_State *L, int n);
50+LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
51+LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);
52+LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);
53+LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
54+LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
55+ ptrdiff_t oldtop, ptrdiff_t ef);
56+LUAI_FUNC void luaD_poscall (lua_State *L, int wanted, StkId firstResult);
57+LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
58+LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
59+LUAI_FUNC void luaD_growstack (lua_State *L, int n);
6160
62−void luaD_throw (lua_State *L, int errcode);
63−int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
61+LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
62+LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
6463
6564
6665 #endif
66+
src/ldump.c+3−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldump.c,v 1.9 2004/11/25 09:31:41 lhf Exp $
2+** $Id: ldump.c,v 1.10 2005/05/12 00:26:50 lhf Exp $
33 ** save pre-compiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -136,7 +136,8 @@ static void DumpConstants(const Proto* f, DumpState* D) · 130 unmodified lines
136136 static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
137137 {
138138 DumpString((f->source==p) ? NULL : f->source,D);
139− DumpInt(f->lineDefined,D);
139+ DumpInt(f->linedefined,D);
140+ DumpInt(f->lastlinedefined,D);
140141 DumpByte(f->nups,D);
141142 DumpByte(f->numparams,D);
142143 DumpByte(f->is_vararg,D);
src/lfunc.c+3−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.c,v 2.9 2005/02/18 12:40:02 roberto Exp $
2+** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
@@ -105,10 +105,6 @@ void luaF_close (lua_State *L, StkId level) { · 99 unmodified lines
105105 else {
106106 unlinkupval(uv);
107107 setobj(L, &uv->u.value, uv->v);
108− if (isgray(o)) {
109− gray2black(o); /* closed upvalues are never gray */
110− luaC_barrier(L, uv, &uv->u.value);
111− }
112108 uv->v = &uv->u.value; /* now current value lives here */
113109 luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */
114110 }
@@ -135,7 +131,8 @@ Proto *luaF_newproto (lua_State *L) { · 20 unmodified lines
135131 f->lineinfo = NULL;
136132 f->sizelocvars = 0;
137133 f->locvars = NULL;
138− f->lineDefined = 0;
134+ f->linedefined = 0;
135+ f->lastlinedefined = 0;
139136 f->source = NULL;
140137 return f;
141138 }
src/lfunc.h+12−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.h,v 2.3 2005/02/18 12:40:02 roberto Exp $
2+** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
@@ -18,17 +18,17 @@ · 12 unmodified lines
1818 cast(int, sizeof(TValue *)*((n)-1)))
1919
2020
21−Proto *luaF_newproto (lua_State *L);
22−Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
23−Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
24−UpVal *luaF_newupval (lua_State *L);
25−UpVal *luaF_findupval (lua_State *L, StkId level);
26−void luaF_close (lua_State *L, StkId level);
27−void luaF_freeproto (lua_State *L, Proto *f);
28−void luaF_freeclosure (lua_State *L, Closure *c);
29−void luaF_freeupval (lua_State *L, UpVal *uv);
30−
31−const char *luaF_getlocalname (const Proto *func, int local_number, int pc);
21+LUAI_FUNC Proto *luaF_newproto (lua_State *L);
22+LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
23+LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
24+LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
25+LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
26+LUAI_FUNC void luaF_close (lua_State *L, StkId level);
27+LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
28+LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
29+LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
30+LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
31+ int pc);
3232
3333
3434 #endif
src/lgc.c+13−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.27 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lgc.c,v 2.32 2005/05/05 15:34:03 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -57,7 +57,7 @@ · 51 unmodified lines
5757 reallymarkobject(g, obj2gco(t)); }
5858
5959
60−#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpace)
60+#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause)
6161
6262
6363 static void removeentry (Node *n) {
@@ -242,7 +242,7 @@ static void traverseclosure (global_State *g, Closure *cl) { · 178 unmodified lines
242242 static void checkstacksizes (lua_State *L, StkId max) {
243243 int ci_used = L->ci - L->base_ci; /* number of `ci' in use */
244244 int s_used = max - L->stack; /* part of stack in use */
245− if (L->size_ci > LUA_MAXCALLS) /* handling overflow? */
245+ if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
246246 return; /* do not touch the stacks */
247247 if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
248248 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
@@ -493,6 +493,13 @@ void luaC_freeall (lua_State *L) { · 244 unmodified lines
493493 }
494494
495495
496+static void markmt (global_State *g) {
497+ int i;
498+ for (i=0; i<NUM_TAGS; i++)
499+ if (g->mt[i]) markobject(g, g->mt[i]);
500+}
501+
502+
496503 /* mark root set */
497504 static void markroot (lua_State *L) {
498505 global_State *g = G(L);
@@ -503,6 +510,7 @@ static void markroot (lua_State *L) { · 4 unmodified lines
503510 /* make global table be traversed before main stack */
504511 markvalue(g, gt(g->mainthread));
505512 markvalue(g, registry(L));
513+ markmt(g);
506514 g->gcstate = GCSpropagate;
507515 }
508516
@@ -529,6 +537,7 @@ static void atomic (lua_State *L) { · 20 unmodified lines
529537 g->weak = NULL;
530538 lua_assert(!iswhite(obj2gco(g->mainthread)));
531539 markobject(g, L); /* mark running thread */
540+ markmt(g); /* mark basic metatables (again) */
532541 propagateall(g);
533542 /* remark gray again */
534543 g->gray = g->grayagain;
@@ -539,7 +548,7 @@ static void atomic (lua_State *L) { · 4 unmodified lines
539548 propagateall(g); /* remark, to propagate `preserveness' */
540549 cleartable(g->weak); /* remove collected objects from weak tables */
541550 /* flip current white */
542− g->currentwhite = otherwhite(g);
551+ g->currentwhite = cast(lu_byte, otherwhite(g));
543552 g->sweepstrgc = 0;
544553 g->sweepgc = &g->rootgc;
545554 g->gcstate = GCSsweepstring;
src/lgc.h+10−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.h,v 2.12 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lgc.h,v 2.13 2005/04/25 19:24:10 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -95,15 +95,15 @@ · 89 unmodified lines
9595 { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
9696 luaC_barrierback(L,obj2gco(p)); }
9797
98−size_t luaC_separateudata (lua_State *L, int all);
99−void luaC_callGCTM (lua_State *L);
100−void luaC_freeall (lua_State *L);
101−void luaC_step (lua_State *L);
102−void luaC_fullgc (lua_State *L);
103−void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
104−void luaC_linkupval (lua_State *L, UpVal *uv);
105−void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
106−void luaC_barrierback (lua_State *L, GCObject *o);
98+LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
99+LUAI_FUNC void luaC_callGCTM (lua_State *L);
100+LUAI_FUNC void luaC_freeall (lua_State *L);
101+LUAI_FUNC void luaC_step (lua_State *L);
102+LUAI_FUNC void luaC_fullgc (lua_State *L);
103+LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
104+LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
105+LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
106+LUAI_FUNC void luaC_barrierback (lua_State *L, GCObject *o);
107107
108108
109109 #endif
src/linit.c+6−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: linit.c,v 1.9 2005/02/18 12:40:02 roberto Exp $
2+** $Id: linit.c,v 1.11 2005/04/13 17:24:20 roberto Exp $
33 ** Initialization of libraries for lua.c
44 ** See Copyright Notice in lua.h
55 */
@@ -22,19 +22,17 @@ static const luaL_reg lualibs[] = { · 16 unmodified lines
2222 {LUA_STRLIBNAME, luaopen_string},
2323 {LUA_MATHLIBNAME, luaopen_math},
2424 {LUA_DBLIBNAME, luaopen_debug},
25− {"", luaopen_loadlib},
25+ {LUA_LOADLIBNAME, luaopen_loadlib},
2626 {NULL, NULL}
2727 };
2828
2929
30−LUALIB_API int luaopen_stdlibs (lua_State *L) {
30+LUALIB_API void luaL_openlibs (lua_State *L) {
3131 const luaL_reg *lib = lualibs;
3232 for (; lib->func; lib++) {
33− lib->func(L); /* open library */
34− lua_settop(L, 0); /* discard any results */
35− lua_pushvalue(L, LUA_GLOBALSINDEX);
36− lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */
33+ lua_pushcfunction(L, lib->func);
34+ lua_pushstring(L, lib->name);
35+ lua_call(L, 1, 0);
3736 }
38− return 0;
3937 }
4038
src/liolib.c+3−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.58 2005/02/18 12:40:02 roberto Exp $
2+** $Id: liolib.c,v 2.60 2005/05/16 21:19:00 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -191,9 +191,9 @@ static int io_output (lua_State *L) { · 185 unmodified lines
191191 static int io_readline (lua_State *L);
192192
193193
194−static void aux_lines (lua_State *L, int idx, int close) {
194+static void aux_lines (lua_State *L, int idx, int toclose) {
195195 lua_pushvalue(L, idx);
196− lua_pushboolean(L, close); /* close/not close file when finished */
196+ lua_pushboolean(L, toclose); /* close/not close file when finished */
197197 lua_pushcclosure(L, io_readline, 2);
198198 }
199199
@@ -319,8 +319,6 @@ static int g_read (lua_State *L, FILE *f, int first) { · 119 unmodified lines
319319 read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
320320 success = 1; /* always success */
321321 break;
322− case 'w': /* word */
323− return luaL_error(L, "obsolete option `*w' to `read'");
324322 default:
325323 return luaL_argerror(L, n, "invalid format");
326324 }
src/llex.c+25−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.9 2004/12/03 20:54:12 roberto Exp $
2+** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -102,7 +102,7 @@ void luaX_lexerror (LexState *ls, const char *msg, int token) { · 96 unmodified lines
102102 luaO_chunkid(buff, getstr(ls->source), MAXSRC);
103103 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
104104 if (token)
105− luaO_pushfstring(ls->L, "%s near `%s'", msg, txtToken(ls, token));
105+ luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token));
106106 luaD_throw(ls->L, LUA_ERRSYNTAX);
107107 }
108108
@@ -202,6 +202,7 @@ static int skip_sep (LexState *ls) { · 93 unmodified lines
202202
203203 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
204204 int cont = 0;
205+ (void)(cont); /* avoid warnings when `cont' is not used */
205206 save_and_next(ls); /* skip 2nd `[' */
206207 if (currIsNewline(ls)) /* string starts with a newline? */
207208 inclinenumber(ls); /* skip it */
@@ -211,27 +212,41 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { · 3 unmodified lines
211212 luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
212213 "unfinished long comment", TK_EOS);
213214 break; /* to avoid warnings */
214− case '[':
215+#if defined(LUA_COMPAT_LSTR)
216+ case '[': {
215217 if (skip_sep(ls) == sep) {
216218 save_and_next(ls); /* skip 2nd `[' */
217219 cont++;
220+#if LUA_COMPAT_LSTR == 1
221+ if (sep == 0)
222+ luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
223+#endif
218224 }
219− continue;
220− case ']':
225+ break;
226+ }
227+#endif
228+ case ']': {
221229 if (skip_sep(ls) == sep) {
222230 save_and_next(ls); /* skip 2nd `]' */
223− if (cont-- == 0) goto endloop;
231+#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
232+ cont--;
233+ if (sep == 0 && cont >= 0) break;
234+#endif
235+ goto endloop;
224236 }
225− continue;
237+ break;
238+ }
226239 case '\n':
227− case '\r':
240+ case '\r': {
228241 save(ls, '\n');
229242 inclinenumber(ls);
230243 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
231− continue;
232− default:
244+ break;
245+ }
246+ default: {
233247 if (seminfo) save_and_next(ls);
234248 else next(ls);
249+ }
235250 }
236251 } endloop:
237252 if (seminfo)
src/llex.h+9−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.h,v 1.52 2004/12/03 20:54:12 roberto Exp $
2+** $Id: llex.h,v 1.54 2005/04/25 19:24:10 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -63,17 +63,17 @@ typedef struct LexState { · 57 unmodified lines
6363 ZIO *z; /* input stream */
6464 Mbuffer *buff; /* buffer for tokens */
6565 TString *source; /* current source name */
66− int nestlevel; /* level of nested non-terminals */
6766 } LexState;
6867
6968
70−void luaX_init (lua_State *L);
71−void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
72−TString *luaX_newstring (LexState *LS, const char *str, size_t l);
73−int luaX_lex (LexState *LS, SemInfo *seminfo);
74−void luaX_lexerror (LexState *ls, const char *msg, int token);
75−void luaX_syntaxerror (LexState *ls, const char *s);
76−const char *luaX_token2str (LexState *ls, int token);
69+LUAI_FUNC void luaX_init (lua_State *L);
70+LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,
71+ TString *source);
72+LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);
73+LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo);
74+LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
75+LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
76+LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
7777
7878
7979 #endif
src/llimits.h+8−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.63 2005/01/14 14:19:42 roberto Exp $
2+** $Id: llimits.h,v 1.65 2005/03/09 16:28:07 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -15,12 +15,14 @@ · 9 unmodified lines
1515 #include "lua.h"
1616
1717
18+#define api_check luai_apicheck
1819
19−typedef LUA_UINT32 lu_int32;
2020
21−typedef LU_MEM lu_mem;
21+typedef LUAI_UINT32 lu_int32;
2222
23−typedef L_MEM l_mem;
23+typedef LUAI_UMEM lu_mem;
24+
25+typedef LUAI_MEM l_mem;
2426
2527
2628
@@ -45,11 +47,11 @@ typedef unsigned char lu_byte; · 18 unmodified lines
4547
4648
4749 /* type to ensure maximum alignment */
48−typedef LUSER_ALIGNMENT_T L_Umaxalign;
50+typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
4951
5052
5153 /* result of a `usual argument conversion' over lua_Number */
52−typedef LUA_UACNUMBER l_uacNumber;
54+typedef LUAI_UACNUMBER l_uacNumber;
5355
5456
5557 #define check_exp(c,e) (lua_assert(c), (e))
src/lmathlib.c+30−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmathlib.c,v 1.62 2005/01/07 20:00:33 roberto Exp $
2+** $Id: lmathlib.c,v 1.63 2005/03/04 18:57:03 roberto Exp $
33 ** Standard mathematical library
44 ** See Copyright Notice in lua.h
55 */
@@ -33,16 +33,31 @@ static int math_sin (lua_State *L) { · 27 unmodified lines
3333 return 1;
3434 }
3535
36+static int math_sinh (lua_State *L) {
37+ lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
38+ return 1;
39+}
40+
3641 static int math_cos (lua_State *L) {
3742 lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
3843 return 1;
3944 }
4045
46+static int math_cosh (lua_State *L) {
47+ lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
48+ return 1;
49+}
50+
4151 static int math_tan (lua_State *L) {
4252 lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
4353 return 1;
4454 }
4555
56+static int math_tanh (lua_State *L) {
57+ lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
58+ return 1;
59+}
60+
4661 static int math_asin (lua_State *L) {
4762 lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
4863 return 1;
@@ -78,6 +93,14 @@ static int math_mod (lua_State *L) { · 29 unmodified lines
7893 return 1;
7994 }
8095
96+static int math_modf (lua_State *L) {
97+ double ip;
98+ double fp = modf(luaL_checknumber(L, 1), &ip);
99+ lua_pushnumber(L, ip);
100+ lua_pushnumber(L, fp);
101+ return 2;
102+}
103+
81104 static int math_sqrt (lua_State *L) {
82105 lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
83106 return 1;
@@ -192,8 +215,11 @@ static int math_randomseed (lua_State *L) { · 108 unmodified lines
192215 static const luaL_reg mathlib[] = {
193216 {"abs", math_abs},
194217 {"sin", math_sin},
218+ {"sinh", math_sinh},
195219 {"cos", math_cos},
220+ {"cosh", math_cosh},
196221 {"tan", math_tan},
222+ {"tanh", math_tanh},
197223 {"asin", math_asin},
198224 {"acos", math_acos},
199225 {"atan", math_atan},
@@ -201,6 +227,7 @@ static const luaL_reg mathlib[] = { · 1 unmodified line
201227 {"ceil", math_ceil},
202228 {"floor", math_floor},
203229 {"mod", math_mod},
230+ {"modf", math_modf},
204231 {"frexp", math_frexp},
205232 {"ldexp", math_ldexp},
206233 {"sqrt", math_sqrt},
@@ -225,6 +252,8 @@ LUALIB_API int luaopen_math (lua_State *L) { · 18 unmodified lines
225252 luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0);
226253 lua_pushnumber(L, PI);
227254 lua_setfield(L, -2, "pi");
255+ lua_pushnumber(L, HUGE_VAL);
256+ lua_setfield(L, -2, "huge");
228257 return 1;
229258 }
230259
src/lmem.h+11−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.h,v 1.29 2004/12/01 15:46:18 roberto Exp $
2+** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
@@ -16,18 +16,10 @@ · 10 unmodified lines
1616 #define MEMERRMSG "not enough memory"
1717
1818
19−void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size);
20−
21−void *luaM_toobig (lua_State *L);
22−
2319 #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))
27−
28−
29−void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem,
30− int limit, const char *errormsg);
20+ ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
21+ luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
22+ luaM_toobig(L))
3123
3224 #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
3325 #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
@@ -46,5 +38,12 @@ void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem, · 12 unmodified lines
4638 ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
4739
4840
41+LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
42+ size_t size);
43+LUAI_FUNC void *luaM_toobig (lua_State *L);
44+LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
45+ size_t size_elem, int limit,
46+ const char *errormsg);
47+
4948 #endif
5049
src/loadlib.c+51−23
@@ -1,11 +1,11 @@
11 /*
2−** $Id: loadlib.c,v 1.18 2005/02/28 15:58:48 roberto Exp $
2+** $Id: loadlib.c,v 1.28 2005/05/17 19:49:15 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
5−*
6−* This module contains an implementation of loadlib for Unix systems
7−* that have dlfcn, an implementation for Darwin (Mac OS X), an
8−* implementation for Windows, and a stub for other systems.
5+**
6+** This module contains an implementation of loadlib for Unix systems
7+** that have dlfcn, an implementation for Darwin (Mac OS X), an
8+** implementation for Windows, and a stub for other systems.
99 */
1010
1111
@@ -21,6 +21,17 @@ · 9 unmodified lines
2121 #include "lualib.h"
2222
2323
24+/* environment variables that hold the search path for packages */
25+#define LUA_PATH "LUA_PATH"
26+#define LUA_CPATH "LUA_CPATH"
27+
28+/* prefix for open functions in C libraries */
29+#define LUA_POF "luaopen_"
30+
31+/* separator for open functions in C libraries */
32+#define LUA_OFSEP "_"
33+
34+
2435 #define LIBPREFIX "LOADLIB: "
2536
2637 #define POF LUA_POF
@@ -33,7 +44,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); · 6 unmodified lines
3344
3445
3546
36−#if defined(USE_DLOPEN)
47+#if defined(LUA_DL_DLOPEN)
3748 /*
3849 ** {========================================================================
3950 ** This is an implementation of loadlib based on the dlfcn interface.
@@ -67,7 +78,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 27 unmodified lines
6778
6879
6980
70−#elif defined(USE_DLL)
81+#elif defined(LUA_DL_DLL)
7182 /*
7283 ** {======================================================================
7384 ** This is an implementation of loadlib for Windows using native functions.
@@ -82,7 +93,7 @@ static void pusherror (lua_State *L) { · 8 unmodified lines
8293 char buffer[128];
8394 if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
8495 NULL, error, 0, buffer, sizeof(buffer), NULL))
85− lua_pushstring(L,buffer);
96+ lua_pushstring(L, buffer);
8697 else
8798 lua_pushfstring(L, "system error %d\n", error);
8899 }
@@ -109,7 +120,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 20 unmodified lines
109120
110121
111122
112−#elif defined(USE_DYLD)
123+#elif defined(LUA_DL_DYLD)
113124 /*
114125 ** {======================================================================
115126 ** Native Mac OS X / Darwin Implementation
@@ -119,6 +130,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 3 unmodified lines
119130 #include <mach-o/dyld.h>
120131
121132
133+/* Mac appends a `_' before C function names */
122134 #undef POF
123135 #define POF "_" LUA_POF
124136
@@ -179,7 +191,7 @@ static void *ll_load (lua_State *L, const char *path) { · 54 unmodified lines
179191 static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
180192 NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);
181193 if (nss == NULL) {
182− lua_pushfstring(L, "symbol `%s' not found", sym);
194+ lua_pushfstring(L, "symbol " LUA_QS " not found", sym);
183195 return NULL;
184196 }
185197 return (lua_CFunction)NSAddressOfSymbol(nss);
@@ -200,6 +212,12 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 14 unmodified lines
200212 #define LIB_FAIL "absent"
201213
202214
215+#if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux)
216+#define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation"
217+#else
218+#define DLMSG LUA_QL("loadlib") " not supported"
219+#endif
220+
203221 static void ll_unloadlib (void *lib) {
204222 (void)lib; /* to avoid warnings */
205223 }
@@ -207,14 +225,14 @@ static void ll_unloadlib (void *lib) { · 1 unmodified line
207225
208226 static void *ll_load (lua_State *L, const char *path) {
209227 (void)path; /* to avoid warnings */
210− lua_pushliteral(L,"`loadlib' not supported");
228+ lua_pushliteral(L, DLMSG);
211229 return NULL;
212230 }
213231
214232
215233 static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
216234 (void)lib; (void)sym; /* to avoid warnings */
217− lua_pushliteral(L,"`loadlib' not supported");
235+ lua_pushliteral(L, DLMSG);
218236 return NULL;
219237 }
220238
@@ -296,22 +314,25 @@ static int ll_loadlib (lua_State *L) { · 75 unmodified lines
296314 static int loader_Lua (lua_State *L) {
297315 const char *name = luaL_checkstring(L, 1);
298316 const char *fname = luaL_gsub(L, name, ".", LUA_DIRSEP);
299− const char *path;
317+ const char *path = NULL;
318+#if LUA_COMPAT_PATH
300319 /* try first `LUA_PATH' for compatibility */
301320 lua_pushstring(L, "LUA_PATH");
302321 lua_rawget(L, LUA_GLOBALSINDEX);
303322 path = lua_tostring(L, -1);
323+#endif
304324 if (!path) {
305325 lua_pop(L, 1);
306326 lua_getfield(L, LUA_ENVIRONINDEX, "path");
307327 path = lua_tostring(L, -1);
308328 }
309329 if (path == NULL)
310− luaL_error(L, "`package.path' must be a string");
330+ luaL_error(L, LUA_QL("package.path") " must be a string");
311331 fname = luaL_searchpath(L, fname, path);
312332 if (fname == NULL) return 0; /* library not found in this path */
313333 if (luaL_loadfile(L, fname) != 0)
314− luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1));
334+ luaL_error(L, "error loading package " LUA_QS " (%s)",
335+ name, lua_tostring(L, -1));
315336 return 1; /* library loaded successfully */
316337 }
317338
@@ -324,13 +345,14 @@ static int loader_C (lua_State *L) { · 6 unmodified lines
324345 lua_getfield(L, LUA_ENVIRONINDEX, "cpath");
325346 path = lua_tostring(L, -1);
326347 if (path == NULL)
327− luaL_error(L, "`package.cpath' must be a string");
348+ luaL_error(L, LUA_QL("package.cpath") " must be a string");
328349 fname = luaL_searchpath(L, fname, path);
329350 if (fname == NULL) return 0; /* library not found in this path */
330351 funcname = luaL_gsub(L, name, ".", LUA_OFSEP);
331352 funcname = lua_pushfstring(L, "%s%s", POF, funcname);
332353 if (ll_loadfunc(L, fname, funcname) != 1)
333− luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -2));
354+ luaL_error(L, "error loading package " LUA_QS " (%s)",
355+ name, lua_tostring(L, -2));
334356 return 1; /* library loaded successfully */
335357 }
336358
@@ -338,7 +360,7 @@ static int loader_C (lua_State *L) { · 1 unmodified line
338360 static int loader_preload (lua_State *L) {
339361 lua_getfield(L, LUA_ENVIRONINDEX, "preload");
340362 if (!lua_istable(L, -1))
341− luaL_error(L, "`package.preload' must be a table");
363+ luaL_error(L, LUA_QL("package.preload") " must be a table");
342364 lua_getfield(L, -1, luaL_checkstring(L, 1));
343365 return 1;
344366 }
@@ -358,11 +380,11 @@ static int ll_require (lua_State *L) { · 13 unmodified lines
358380 /* iterate over available loaders */
359381 lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
360382 if (!lua_istable(L, -1))
361− luaL_error(L, "`package.loaders' must be a table");
383+ luaL_error(L, LUA_QL("package.loaders") " must be a table");
362384 for (i=1;; i++) {
363385 lua_rawgeti(L, -1, i); /* get a loader */
364386 if (lua_isnil(L, -1))
365− return luaL_error(L, "package `%s' not found", name);
387+ return luaL_error(L, "package " LUA_QS " not found", name);
366388 lua_pushstring(L, name);
367389 lua_call(L, 1, 1); /* call it */
368390 if (lua_isnil(L, -1)) lua_pop(L, 1);
@@ -401,7 +423,7 @@ static int ll_module (lua_State *L) { · 32 unmodified lines
401423 luaL_setfield(L, LUA_GLOBALSINDEX, modname);
402424 }
403425 else if (!lua_istable(L, -1))
404− return luaL_error(L, "name conflict for module `%s'", modname);
426+ return luaL_error(L, "name conflict for module " LUA_QS, modname);
405427 /* check whether table already has a _NAME field */
406428 lua_getfield(L, -1, "_NAME");
407429 if (!lua_isnil(L, -1)) /* is table an initialized module? */
@@ -434,7 +456,6 @@ static int ll_module (lua_State *L) { · 26 unmodified lines
434456
435457
436458 static const luaL_reg ll_funcs[] = {
437− {"loadlib", ll_loadlib},
438459 {"require", ll_require},
439460 {"module", ll_module},
440461 {NULL, NULL}
@@ -455,7 +476,7 @@ LUALIB_API int luaopen_loadlib (lua_State *L) { · 14 unmodified lines
455476 /* create `package' table */
456477 lua_newtable(L);
457478 lua_pushvalue(L, -1);
458− lua_setglobal(L, "package");
479+ lua_setglobal(L, LUA_LOADLIBNAME);
459480 lua_pushvalue(L, -1);
460481 lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE");
461482 lua_pushvalue(L, -1);
@@ -485,6 +506,13 @@ LUALIB_API int luaopen_loadlib (lua_State *L) { · 23 unmodified lines
485506 /* set field `preload' */
486507 lua_newtable(L);
487508 lua_setfield(L, -2, "preload");
509+ /* create `loadlib' function */
510+ lua_pushcfunction(L, ll_loadlib);
511+#if LUA_COMPAT_LOADLIB
512+ lua_pushvalue(L, -1);
513+ lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
514+#endif
515+ lua_setfield(L, -2, "loadlib");
488516 lua_pushvalue(L, LUA_GLOBALSINDEX);
489517 luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */
490518 return 1;
src/lobject.c+6−4
@@ -1,11 +1,12 @@
11 /*
2−** $Id: lobject.c,v 2.8 2005/01/10 18:17:39 roberto Exp $
2+** $Id: lobject.c,v 2.13 2005/05/16 21:19:00 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
66
77 #include <ctype.h>
88 #include <stdarg.h>
9+#include <stdio.h>
910 #include <stdlib.h>
1011 #include <string.h>
1112
@@ -28,7 +29,8 @@ const TValue luaO_nilobject = {{NULL}, LUA_TNIL}; · 16 unmodified lines
2829
2930 /*
3031 ** converts an integer to a "floating point byte", represented as
31−** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm)
32+** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
33+** eeeee != 0 and (xxx) otherwise.
3234 */
3335 int luaO_int2fb (unsigned int x) {
3436 int e = 0; /* expoent */
@@ -73,7 +75,7 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) { · 38 unmodified lines
7375 case LUA_TNIL:
7476 return 1;
7577 case LUA_TNUMBER:
76− return num_eq(nvalue(t1), nvalue(t2));
78+ return luai_numeq(nvalue(t1), nvalue(t2));
7779 case LUA_TBOOLEAN:
7880 return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
7981 case LUA_TLIGHTUSERDATA:
@@ -182,7 +184,7 @@ void luaO_chunkid (char *out, const char *source, int bufflen) { · 102 unmodified lines
182184 if (*source == '@') {
183185 int l;
184186 source++; /* skip the `@' */
185− bufflen -= sizeof(" `...' ");
187+ bufflen -= sizeof(" '...' ");
186188 l = strlen(source);
187189 strcpy(out, "");
188190 if (l>bufflen) {
src/lobject.h+12−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.11 2005/02/18 12:40:02 roberto Exp $
2+** $Id: lobject.h,v 2.13 2005/05/05 20:47:02 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -244,7 +244,8 @@ typedef struct Proto { · 238 unmodified lines
244244 int sizelineinfo;
245245 int sizep; /* size of `p' */
246246 int sizelocvars;
247− int lineDefined;
247+ int linedefined;
248+ int lastlinedefined;
248249 GCObject *gclist;
249250 lu_byte nups; /* number of upvalues */
250251 lu_byte numparams;
@@ -360,16 +361,15 @@ extern const TValue luaO_nilobject; · 109 unmodified lines
360361
361362 #define ceillog2(x) (luaO_log2((x)-1) + 1)
362363
363−int luaO_log2 (unsigned int x);
364−int luaO_int2fb (unsigned int x);
365−int luaO_fb2int (int x);
366−
367−int luaO_rawequalObj (const TValue *t1, const TValue *t2);
368−int luaO_str2d (const char *s, lua_Number *result);
369−
370−const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp);
371−const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
372−void luaO_chunkid (char *out, const char *source, int len);
364+LUAI_FUNC int luaO_log2 (unsigned int x);
365+LUAI_FUNC int luaO_int2fb (unsigned int x);
366+LUAI_FUNC int luaO_fb2int (int x);
367+LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
368+LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);
369+LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
370+ va_list argp);
371+LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
372+LUAI_FUNC void luaO_chunkid (char *out, const char *source, int len);
373373
374374
375375 #endif
src/lopcodes.c+5−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.c,v 1.30 2004/12/02 12:59:10 roberto Exp $
2+** $Id: lopcodes.c,v 1.33 2005/05/04 20:42:28 roberto Exp $
33 ** See Copyright Notice in lua.h
44 */
55
@@ -32,9 +32,11 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { · 26 unmodified lines
3232 "SUB",
3333 "MUL",
3434 "DIV",
35+ "MOD",
3536 "POW",
3637 "UNM",
3738 "NOT",
39+ "SIZ",
3840 "CONCAT",
3941 "JMP",
4042 "EQ",
@@ -47,7 +49,6 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { · 6 unmodified lines
4749 "FORLOOP",
4850 "FORPREP",
4951 "TFORLOOP",
50− "TFORPREP",
5152 "SETLIST",
5253 "CLOSE",
5354 "CLOSURE",
@@ -76,9 +77,11 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 22 unmodified lines
7677 ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
7778 ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
7879 ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
80+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
7981 ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
8082 ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
8183 ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
84+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_SIZ */
8285 ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
8386 ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
8487 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
@@ -91,7 +94,6 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 6 unmodified lines
9194 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
9295 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
9396 ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */
94− ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_TFORPREP */
9597 ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
9698 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
9799 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
src/lopcodes.h+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.114 2004/12/02 12:59:10 roberto Exp $
2+** $Id: lopcodes.h,v 1.119 2005/05/04 20:42:28 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -51,9 +51,9 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ · 45 unmodified lines
5151 /*
5252 ** limits for opcode arguments.
5353 ** we use (signed) int to manipulate most arguments,
54−** so they must fit in LUA_BITSINT-1 bits (-1 for sign)
54+** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
5555 */
56−#if SIZE_Bx < LUA_BITSINT-1
56+#if SIZE_Bx < LUAI_BITSINT-1
5757 #define MAXARG_Bx ((1<<SIZE_Bx)-1)
5858 #define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */
5959 #else
@@ -172,9 +172,11 @@ OP_ADD,/* A B C R(A) := RK(B) + RK(C) */ · 112 unmodified lines
172172 OP_SUB,/* A B C R(A) := RK(B) - RK(C) */
173173 OP_MUL,/* A B C R(A) := RK(B) * RK(C) */
174174 OP_DIV,/* A B C R(A) := RK(B) / RK(C) */
175+OP_MOD,/* A B C R(A) := RK(B) % RK(C) */
175176 OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */
176177 OP_UNM,/* A B R(A) := -R(B) */
177178 OP_NOT,/* A B R(A) := not R(B) */
179+OP_SIZ,/* A B R(A) := size of R(B) */
178180
179181 OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
180182
@@ -195,8 +197,6 @@ OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ · 14 unmodified lines
195197
196198 OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
197199 if R(A+2) ~= nil then pc++ */
198−OP_TFORPREP,/* A sBx if type(R(A)) == table then R(A+1):=R(A), R(A):=next;
199− pc+=sBx */
200200
201201 OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
202202
src/loslib.c+8−11
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.4 2005/01/10 19:16:29 roberto Exp $
2+** $Id: loslib.c,v 1.9 2005/05/17 19:49:15 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -57,16 +57,13 @@ static int io_rename (lua_State *L) { · 51 unmodified lines
5757
5858
5959 static int io_tmpname (lua_State *L) {
60−#if !USE_TMPNAME
61− luaL_error(L, "`tmpname' not supported");
62− return 0;
63−#else
64− char buff[L_tmpnam];
65− if (tmpnam(buff) != buff)
66− return luaL_error(L, "unable to generate a unique filename in `tmpname'");
60+ char buff[LUA_TMPNAMBUFSIZE];
61+ int err;
62+ lua_tmpnam(buff, err);
63+ if (err)
64+ return luaL_error(L, "unable to generate a unique filename");
6765 lua_pushstring(L, buff);
6866 return 1;
69−#endif
7067 }
7168
7269
@@ -116,7 +113,7 @@ static int getfield (lua_State *L, const char *key, int d) { · 43 unmodified lines
116113 res = (int)lua_tointeger(L, -1);
117114 else {
118115 if (d < 0)
119− return luaL_error(L, "field `%s' missing in date table", key);
116+ return luaL_error(L, "field " LUA_QS " missing in date table", key);
120117 res = d;
121118 }
122119 lua_pop(L, 1);
@@ -154,7 +151,7 @@ static int io_date (lua_State *L) { · 31 unmodified lines
154151 if (strftime(b, sizeof(b), s, stm))
155152 lua_pushstring(L, b);
156153 else
157− return luaL_error(L, "`date' format too long");
154+ return luaL_error(L, LUA_QL("date") " format too long");
158155 }
159156 return 1;
160157 }
src/lparser.c+35−29
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.13 2005/01/05 18:20:51 roberto Exp $
2+** $Id: lparser.c,v 2.27 2005/05/17 19:49:15 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -33,10 +33,6 @@ · 27 unmodified lines
3333
3434 #define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
3535
36−#define enterlevel(ls) if (++(ls)->nestlevel > LUA_MAXPARSERLEVEL) \
37− luaX_lexerror(ls, "chunk has too many syntax levels", 0)
38−#define leavelevel(ls) ((ls)->nestlevel--)
39−
4036
4137 /*
4238 ** nodes for block list (list of active blocks)
@@ -86,15 +82,15 @@ static void anchor_token (LexState *ls) { · 43 unmodified lines
8682
8783 static void error_expected (LexState *ls, int token) {
8884 luaX_syntaxerror(ls,
89− luaO_pushfstring(ls->L, "`%s' expected", luaX_token2str(ls, token)));
85+ luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token)));
9086 }
9187
9288
9389 static void errorlimit (FuncState *fs, int limit, const char *what) {
94− const char *msg = (fs->f->lineDefined == 0) ?
90+ const char *msg = (fs->f->linedefined == 0) ?
9591 luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
9692 luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
97− fs->f->lineDefined, limit, what);
93+ fs->f->linedefined, limit, what);
9894 luaX_lexerror(fs->ls, msg, 0);
9995 }
10096
@@ -129,7 +125,7 @@ static void check_match (LexState *ls, int what, int who, int where) { · 28 unmodified lines
129125 error_expected(ls, what);
130126 else {
131127 luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
132− "`%s' expected (to close `%s' at line %d)",
128+ LUA_QS " expected (to close " LUA_QS " at line %d)",
133129 luaX_token2str(ls, what), luaX_token2str(ls, who), where));
134130 }
135131 }
@@ -167,7 +163,7 @@ static int registerlocalvar (LexState *ls, TString *varname) { · 31 unmodified lines
167163 Proto *f = fs->f;
168164 int oldsize = f->sizelocvars;
169165 luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
170− LocVar, USHRT_MAX, "too many local variables");
166+ LocVar, SHRT_MAX, "too many local variables");
171167 while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
172168 f->locvars[fs->nlocvars].varname = varname;
173169 luaC_objbarrier(ls->L, f, varname);
@@ -181,7 +177,7 @@ static int registerlocalvar (LexState *ls, TString *varname) { · 7 unmodified lines
181177
182178 static void new_localvar (LexState *ls, TString *name, int n) {
183179 FuncState *fs = ls->fs;
184− luaY_checklimit(fs, fs->nactvar+n+1, MAXVARS, "local variables");
180+ luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
185181 fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));
186182 }
187183
@@ -213,7 +209,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 25 unmodified lines
213209 }
214210 }
215211 /* new one */
216− luaY_checklimit(fs, f->nups + 1, MAXUPVALUES, "upvalues");
212+ luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues");
217213 luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues,
218214 TString *, MAX_INT, "");
219215 while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;
@@ -295,6 +291,15 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { · 75 unmodified lines
295291 }
296292
297293
294+static void enterlevel (LexState *ls) {
295+ if (++ls->L->nCcalls > LUAI_MAXCCALLS)
296+ luaX_lexerror(ls, "chunk has too many syntax levels", 0);
297+}
298+
299+
300+#define leavelevel(ls) ((ls)->L->nCcalls--)
301+
302+
298303 static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) {
299304 bl->breaklist = NO_JUMP;
300305 bl->isbreakable = isbreakable;
@@ -395,7 +400,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 94 unmodified lines
395400 struct LexState lexstate;
396401 struct FuncState funcstate;
397402 lexstate.buff = buff;
398− lexstate.nestlevel = 0;
399403 luaX_setinput(L, &lexstate, z, luaS_new(L, name));
400404 open_func(&lexstate, &funcstate);
401405 funcstate.f->is_vararg = NEWSTYLEVARARG;
@@ -405,7 +409,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 3 unmodified lines
405409 close_func(&lexstate);
406410 lua_assert(funcstate.prev == NULL);
407411 lua_assert(funcstate.f->nups == 0);
408− lua_assert(lexstate.nestlevel == 0);
409412 lua_assert(lexstate.fs == NULL);
410413 return funcstate.f;
411414 }
@@ -460,11 +463,11 @@ static void recfield (LexState *ls, struct ConsControl *cc) { · 48 unmodified lines
460463 expdesc key, val;
461464 if (ls->t.token == TK_NAME) {
462465 luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
463− cc->nh++;
464466 checkname(ls, &key);
465467 }
466468 else /* ls->t.token == '[' */
467469 yindex(ls, &key);
470+ cc->nh++;
468471 checknext(ls, '=');
469472 luaK_exp2RK(fs, &key);
470473 expr(ls, &val);
@@ -574,7 +577,7 @@ static void parlist (LexState *ls) { · 103 unmodified lines
574577 f->is_vararg = 1;
575578 break;
576579 }
577− default: luaX_syntaxerror(ls, "<name> or `...' expected");
580+ default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected");
578581 }
579582 } while (!f->is_vararg && testnext(ls, ','));
580583 }
@@ -588,7 +591,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { · 7 unmodified lines
588591 /* body -> `(' parlist `)' chunk END */
589592 FuncState new_fs;
590593 open_func(ls, &new_fs);
591− new_fs.f->lineDefined = line;
594+ new_fs.f->linedefined = line;
592595 checknext(ls, '(');
593596 if (needself) {
594597 new_localvarliteral(ls, "self", 0);
@@ -597,6 +600,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { · 2 unmodified lines
597600 parlist(ls);
598601 checknext(ls, ')');
599602 chunk(ls);
603+ new_fs.f->lastlinedefined = ls->linenumber;
600604 check_match(ls, TK_END, TK_FUNCTION, line);
601605 close_func(ls);
602606 pushclosure(ls, &new_fs, e);
@@ -735,8 +739,8 @@ static void primaryexp (LexState *ls, expdesc *v) { · 132 unmodified lines
735739
736740
737741 static void simpleexp (LexState *ls, expdesc *v) {
738− /* simpleexp -> NUMBER | STRING | NIL | constructor | FUNCTION body
739− | primaryexp */
742+ /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
743+ constructor | FUNCTION body | primaryexp */
740744 switch (ls->t.token) {
741745 case TK_NUMBER: {
742746 init_exp(v, VK, luaK_numberK(ls->fs, ls->t.seminfo.r));
@@ -761,7 +765,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 18 unmodified lines
761765 case TK_DOTS: { /* vararg */
762766 FuncState *fs = ls->fs;
763767 check_condition(ls, fs->f->is_vararg,
764− "cannot use `...' outside a vararg function");
768+ "cannot use " LUA_QL("...") " outside a vararg function");
765769 fs->f->is_vararg = NEWSTYLEVARARG;
766770 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
767771 break;
@@ -788,6 +792,7 @@ static UnOpr getunopr (int op) { · 20 unmodified lines
788792 switch (op) {
789793 case TK_NOT: return OPR_NOT;
790794 case '-': return OPR_MINUS;
795+ case '*': return OPR_SIZE;
791796 default: return OPR_NOUNOPR;
792797 }
793798 }
@@ -799,6 +804,7 @@ static BinOpr getbinopr (int op) { · 5 unmodified lines
799804 case '-': return OPR_SUB;
800805 case '*': return OPR_MULT;
801806 case '/': return OPR_DIV;
807+ case '%': return OPR_MOD;
802808 case '^': return OPR_POW;
803809 case TK_CONCAT: return OPR_CONCAT;
804810 case TK_NE: return OPR_NE;
@@ -818,9 +824,9 @@ static const struct { · 13 unmodified lines
818824 lu_byte left; /* left priority for each binary operator */
819825 lu_byte right; /* right priority */
820826 } priority[] = { /* ORDER OPR */
821− {6, 6}, {6, 6}, {7, 7}, {7, 7}, /* arithmetic */
827+ {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */
822828 {10, 9}, {5, 4}, /* power and concat (right associative) */
823− {3, 3}, {3, 3}, /* equality */
829+ {3, 3}, {3, 3}, /* equality and inequality */
824830 {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */
825831 {2, 2}, {1, 1} /* logical (and/or) */
826832 };
@@ -829,7 +835,7 @@ static const struct { · 2 unmodified lines
829835
830836
831837 /*
832−** subexpr -> (simplexep | unop subexpr) { binop subexpr }
838+** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
833839 ** where `binop' is any binary operator with a priority higher than `limit'
834840 */
835841 static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
@@ -992,7 +998,7 @@ static int cond (LexState *ls) { · 156 unmodified lines
992998
993999 static void whilestat (LexState *ls, int line) {
9941000 /* whilestat -> WHILE cond DO block END */
995− Instruction codeexp[MAXEXPWHILE + EXTRAEXP];
1001+ Instruction codeexp[LUAI_MAXEXPWHILE + EXTRAEXP];
9961002 int lineexp;
9971003 int i;
9981004 int sizeexp;
@@ -1010,8 +1016,8 @@ static void whilestat (LexState *ls, int line) { · 11 unmodified lines
10101016 luaK_concat(fs, &v.f, fs->jpc);
10111017 fs->jpc = NO_JUMP;
10121018 sizeexp = fs->pc - expinit; /* size of expression code */
1013− if (sizeexp > MAXEXPWHILE)
1014− luaX_syntaxerror(ls, "`while' condition too complex");
1019+ if (sizeexp > LUAI_MAXEXPWHILE)
1020+ luaX_syntaxerror(ls, LUA_QL("while") " condition too complex");
10151021 for (i = 0; i < sizeexp; i++) /* save `exp' code */
10161022 codeexp[i] = fs->f->code[expinit + i];
10171023 fs->pc = expinit; /* remove `exp' code */
@@ -1065,7 +1071,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { · 47 unmodified lines
10651071 int prep, endfor;
10661072 adjustlocalvars(ls, 3); /* control variables */
10671073 checknext(ls, TK_DO);
1068− prep = luaK_codeAsBx(fs, (isnum ? OP_FORPREP : OP_TFORPREP), base, NO_JUMP);
1074+ prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
10691075 enterblock(fs, &bl, 0); /* scope for declared variables */
10701076 adjustlocalvars(ls, nvars);
10711077 luaK_reserveregs(fs, nvars);
@@ -1135,7 +1141,7 @@ static void forstat (LexState *ls, int line) { · 63 unmodified lines
11351141 switch (ls->t.token) {
11361142 case '=': fornum(ls, varname, line); break;
11371143 case ',': case TK_IN: forlist(ls, varname); break;
1138− default: luaX_syntaxerror(ls, "`=' or `in' expected");
1144+ default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
11391145 }
11401146 check_match(ls, TK_END, TK_FOR, line);
11411147 leaveblock(fs); /* loop scope (`break' jumps to this point) */
@@ -1284,7 +1290,7 @@ static void retstat (LexState *ls) { · 142 unmodified lines
12841290
12851291
12861292 static void breakstat (LexState *ls) {
1287− /* stat -> BREAK [NAME] */
1293+ /* stat -> BREAK */
12881294 FuncState *fs = ls->fs;
12891295 BlockCnt *bl = fs->bl;
12901296 int upval = 0;
src/lparser.h+6−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.h,v 1.51 2004/05/31 18:51:50 roberto Exp $
2+** $Id: lparser.h,v 1.55 2005/04/25 19:24:10 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -65,14 +65,15 @@ typedef struct FuncState { · 59 unmodified lines
6565 int freereg; /* first free register */
6666 int nk; /* number of elements in `k' */
6767 int np; /* number of elements in `p' */
68− int nlocvars; /* number of elements in `locvars' */
68+ short nlocvars; /* number of elements in `locvars' */
6969 lu_byte nactvar; /* number of active local variables */
70− upvaldesc upvalues[MAXUPVALUES]; /* upvalues */
71− unsigned short actvar[MAXVARS]; /* declared-variable stack */
70+ upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
71+ unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
7272 } FuncState;
7373
7474
75−Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name);
75+LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
76+ const char *name);
7677
7778
7879 #endif
src/lstate.c+17−22
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.c,v 2.25 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lstate.c,v 2.31 2005/05/05 15:34:03 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -24,20 +24,9 @@ · 18 unmodified lines
2424 #include "ltm.h"
2525
2626
27−/*
28−** macro to allow the inclusion of user information in Lua state
29−*/
30−#ifndef LUA_USERSTATE
31−#define EXTRASPACE 0
32−#else
33−union UEXTRASPACE {L_Umaxalign a; LUA_USERSTATE b;};
34−#define EXTRASPACE (sizeof(union UEXTRASPACE))
35−#endif
36−
37−
38−#define state_size(x) (sizeof(x) + EXTRASPACE)
39−#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + EXTRASPACE))
40−#define fromstate(l) (cast(lu_byte *, (l)) - EXTRASPACE)
27+#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
28+#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
29+#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
4130
4231
4332 /*
@@ -51,18 +40,21 @@ typedef struct LG { · 7 unmodified lines
5140
5241
5342 static void stack_init (lua_State *L1, lua_State *L) {
43+ /* initialize CallInfo array */
44+ L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
45+ L1->ci = L1->base_ci;
46+ L1->size_ci = BASIC_CI_SIZE;
47+ L1->end_ci = L1->base_ci + L1->size_ci - 1;
48+ /* initialize stack array */
5449 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
5550 L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
5651 L1->top = L1->stack;
5752 L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
58− L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
59− L1->ci = L1->base_ci;
53+ /* initialize first ci */
6054 L1->ci->func = L1->top;
6155 setnilvalue(L1->top++); /* `function' entry for this `ci' */
6256 L1->base = L1->ci->base = L1->top;
6357 L1->ci->top = L1->top + LUA_MINSTACK;
64− L1->size_ci = BASIC_CI_SIZE;
65− L1->end_ci = L1->base_ci + L1->size_ci - 1;
6658 }
6759
6860
@@ -105,6 +97,7 @@ static void preinit_state (lua_State *L, global_State *g) { · 36 unmodified lines
10597 L->nCcalls = 0;
10698 L->status = 0;
10799 L->base_ci = L->ci = NULL;
100+ L->savedpc = NULL;
108101 L->errfunc = 0;
109102 setnilvalue(gt(L));
110103 }
@@ -148,6 +141,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) { · 37 unmodified lines
148141
149142
150143 LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
144+ int i;
151145 lua_State *L;
152146 global_State *g;
153147 void *l = (*f)(ud, NULL, 0, state_size(LG));
@@ -181,16 +175,17 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 27 unmodified lines
181175 g->weak = NULL;
182176 g->tmudata = NULL;
183177 g->totalbytes = sizeof(LG);
184− g->gcpace = 200; /* 200% (wait memory to double before next collection) */
185− g->gcstepmul = 200; /* GC runs `twice the speed' of memory allocation */
178+ g->gcpause = LUAI_GCPAUSE;
179+ g->gcstepmul = LUAI_GCMUL;
186180 g->gcdept = 0;
181+ for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
187182 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
188183 /* memory allocation error: free partial state */
189184 close_state(L);
190185 L = NULL;
191186 }
192187 else
193− lua_userstateopen(L);
188+ luai_userstateopen(L);
194189 return L;
195190 }
196191
src/lstate.h+7−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.h,v 2.16 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lstate.h,v 2.21 2005/05/05 15:34:03 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -83,12 +83,13 @@ typedef struct global_State { · 77 unmodified lines
8383 lu_mem totalbytes; /* number of bytes currently allocated */
8484 lu_mem estimate; /* an estimate of number of bytes actually in use */
8585 lu_mem gcdept; /* how much GC is `behind schedule' */
86− int gcpace; /* size of pause between successive GCs */
86+ int gcpause; /* size of pause between successive GCs */
8787 int gcstepmul; /* GC `granularity' */
8888 lua_CFunction panic; /* to be called in unprotected errors */
8989 TValue _registry;
9090 struct lua_State *mainthread;
9191 UpVal uvhead; /* head of double-linked list of all open upvalues */
92+ struct Table *mt[NUM_TAGS]; /* metatables for basic types */
9293 TString *tmname[TM_N]; /* array with tag-method names */
9394 } global_State;
9495
@@ -102,12 +103,13 @@ struct lua_State { · 7 unmodified lines
102103 StkId base; /* base of current function */
103104 global_State *l_G;
104105 CallInfo *ci; /* call info for current function */
106+ const Instruction *savedpc; /* `savedpc' of current function */
105107 StkId stack_last; /* last free slot in the stack */
106108 StkId stack; /* stack base */
107109 int stacksize;
108110 CallInfo *end_ci; /* points after end of ci array*/
109111 CallInfo *base_ci; /* array of CallInfo's */
110− unsigned short size_ci; /* size of array `base_ci' */
112+ int size_ci; /* size of array `base_ci' */
111113 unsigned short nCcalls; /* number of nested C calls */
112114 lu_byte hookmask;
113115 lu_byte allowhook;
@@ -159,8 +161,8 @@ union GCObject { · 45 unmodified lines
159161 #define obj2gco(v) (cast(GCObject *, (v)))
160162
161163
162−lua_State *luaE_newthread (lua_State *L);
163−void luaE_freethread (lua_State *L, lua_State *L1);
164+LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
165+LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
164166
165167 #endif
166168
src/lstring.h+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.h,v 1.42 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $
33 ** String table (keep all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
@@ -23,9 +23,9 @@ · 17 unmodified lines
2323
2424 #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
2525
26−void luaS_resize (lua_State *L, int newsize);
27−Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
28−TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
26+LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
27+LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
28+LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
2929
3030
3131 #endif
src/lstrlib.c+38−24
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.109 2004/12/01 15:46:06 roberto Exp $
2+** $Id: lstrlib.c,v 1.115 2005/05/17 19:49:15 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -172,11 +172,11 @@ typedef struct MatchState { · 166 unmodified lines
172172 struct {
173173 const char *init;
174174 ptrdiff_t len;
175− } capture[MAX_CAPTURES];
175+ } capture[LUA_MAXCAPTURES];
176176 } MatchState;
177177
178178
179−#define ESC '%'
179+#define L_ESC '%'
180180 #define SPECIALS "^$*+?.([%-"
181181
182182
@@ -198,17 +198,17 @@ static int capture_to_close (MatchState *ms) { · 15 unmodified lines
198198
199199 static const char *classend (MatchState *ms, const char *p) {
200200 switch (*p++) {
201− case ESC: {
201+ case L_ESC: {
202202 if (*p == '\0')
203− luaL_error(ms->L, "malformed pattern (ends with `%%')");
203+ luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")");
204204 return p+1;
205205 }
206206 case '[': {
207207 if (*p == '^') p++;
208208 do { /* look for a `]' */
209209 if (*p == '\0')
210− luaL_error(ms->L, "malformed pattern (missing `]')");
211− if (*(p++) == ESC && *p != '\0')
210+ luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")");
211+ if (*(p++) == L_ESC && *p != '\0')
212212 p++; /* skip escapes (e.g. `%]') */
213213 } while (*p != ']');
214214 return p+1;
@@ -246,7 +246,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 31 unmodified lines
246246 p++; /* skip the `^' */
247247 }
248248 while (++p < ec) {
249− if (*p == ESC) {
249+ if (*p == L_ESC) {
250250 p++;
251251 if (match_class(c, uchar(*p)))
252252 return sig;
@@ -265,7 +265,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { · 12 unmodified lines
265265 static int singlematch (int c, const char *p, const char *ep) {
266266 switch (*p) {
267267 case '.': return 1; /* matches any char */
268− case ESC: return match_class(c, uchar(*(p+1)));
268+ case L_ESC: return match_class(c, uchar(*(p+1)));
269269 case '[': return matchbracketclass(c, p, ep-1);
270270 default: return (uchar(*p) == c);
271271 }
@@ -327,7 +327,7 @@ static const char *start_capture (MatchState *ms, const char *s, · 55 unmodified lines
327327 const char *p, int what) {
328328 const char *res;
329329 int level = ms->level;
330− if (level >= MAX_CAPTURES) luaL_error(ms->L, "too many captures");
330+ if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures");
331331 ms->capture[level].init = s;
332332 ms->capture[level].len = what;
333333 ms->level = level+1;
@@ -371,7 +371,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 37 unmodified lines
371371 case ')': { /* end capture */
372372 return end_capture(ms, s, p+1);
373373 }
374− case ESC: {
374+ case L_ESC: {
375375 switch (*(p+1)) {
376376 case 'b': { /* balanced string? */
377377 s = matchbalance(ms, s, p+2);
@@ -382,7 +382,8 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 4 unmodified lines
382382 const char *ep; char previous;
383383 p += 2;
384384 if (*p != '[')
385− luaL_error(ms->L, "missing `[' after `%%f' in pattern");
385+ luaL_error(ms->L, "missing " LUA_QL("[") " after "
386+ LUA_QL("%%f") " in pattern");
386387 ep = classend(ms, p); /* points to what is next */
387388 previous = (s == ms->src_init) ? '\0' : *(s-1);
388389 if (matchbracketclass(uchar(previous), p, ep-1) ||
@@ -525,8 +526,8 @@ static int str_find (lua_State *L) { · 136 unmodified lines
525526
526527 static int gfind_aux (lua_State *L) {
527528 MatchState ms;
528− const char *s = lua_tostring(L, lua_upvalueindex(1));
529− size_t ls = lua_strlen(L, lua_upvalueindex(1));
529+ size_t ls;
530+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
530531 const char *p = lua_tostring(L, lua_upvalueindex(2));
531532 const char *src;
532533 ms.L = L;
@@ -563,11 +564,11 @@ static void add_s (MatchState *ms, luaL_Buffer *b, · 30 unmodified lines
563564 const char *s, const char *e) {
564565 lua_State *L = ms->L;
565566 if (lua_isstring(L, 3)) {
566− const char *news = lua_tostring(L, 3);
567− size_t l = lua_strlen(L, 3);
567+ size_t l;
568+ const char *news = lua_tolstring(L, 3, &l);
568569 size_t i;
569570 for (i=0; i<l; i++) {
570− if (news[i] != ESC)
571+ if (news[i] != L_ESC)
571572 luaL_putchar(b, news[i]);
572573 else {
573574 i++; /* skip ESC */
@@ -682,7 +683,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, · 108 unmodified lines
682683 luaL_error(L, "invalid format (width or precision too long)");
683684 if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
684685 luaL_error(L, "invalid format (too long)");
685− form[0] = ESC;
686+ form[0] = L_ESC;
686687 strncpy(form+1, strfrmt, p-strfrmt+1);
687688 form[p-strfrmt+2] = 0;
688689 return p;
@@ -697,16 +698,14 @@ static int str_format (lua_State *L) { · 8 unmodified lines
697698 luaL_Buffer b;
698699 luaL_buffinit(L, &b);
699700 while (strfrmt < strfrmt_end) {
700− if (*strfrmt != ESC)
701+ if (*strfrmt != L_ESC)
701702 luaL_putchar(&b, *strfrmt++);
702− else if (*++strfrmt == ESC)
703+ else if (*++strfrmt == L_ESC)
703704 luaL_putchar(&b, *strfrmt++); /* %% */
704705 else { /* format item */
705706 char form[MAX_FORMAT]; /* to store the format (`%...') */
706707 char buff[MAX_ITEM]; /* to store the formatted item */
707708 int hasprecision = 0;
708− if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$')
709− return luaL_error(L, "obsolete option (d$) to `format'");
710709 arg++;
711710 strfrmt = scanformat(L, strfrmt, form, &hasprecision);
712711 switch (*strfrmt++) {
@@ -725,7 +724,7 @@ static int str_format (lua_State *L) { · 12 unmodified lines
725724 }
726725 case 'q': {
727726 addquoted(L, &b, arg);
728− continue; /* skip the `addsize' at the end */
727+ continue; /* skip the 'addsize' at the end */
729728 }
730729 case 's': {
731730 size_t l;
@@ -743,7 +742,7 @@ static int str_format (lua_State *L) { · 11 unmodified lines
743742 }
744743 }
745744 default: { /* also treat cases `pnLlh' */
746− return luaL_error(L, "invalid option to `format'");
745+ return luaL_error(L, "invalid option to " LUA_QL("format"));
747746 }
748747 }
749748 luaL_addlstring(&b, buff, strlen(buff));
@@ -772,11 +771,26 @@ static const luaL_reg strlib[] = { · 22 unmodified lines
772771 };
773772
774773
774+static void createmetatable (lua_State *L) {
775+ lua_newtable(L); /* create metatable for strings */
776+ lua_pushliteral(L, ""); /* dummy string */
777+ lua_pushvalue(L, -2);
778+ lua_setmetatable(L, -2); /* set string metatable */
779+ lua_pop(L, 1); /* pop dummy string */
780+ lua_pushvalue(L, -2); /* string library... */
781+ lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */
782+ lua_getfield(L, -2, "len");
783+ lua_setfield(L, -2, "__siz");
784+ lua_pop(L, 1); /* pop metatable */
785+}
786+
787+
775788 /*
776789 ** Open string library
777790 */
778791 LUALIB_API int luaopen_string (lua_State *L) {
779792 luaL_openlib(L, LUA_STRLIBNAME, strlib, 0);
793+ createmetatable(L);
780794 return 1;
781795 }
782796
src/ltable.c+58−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.15 2005/01/10 18:17:39 roberto Exp $
2+** $Id: ltable.c,v 2.23 2005/05/17 19:49:15 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -18,6 +18,7 @@ · 12 unmodified lines
1818 ** Hence even when the load factor reaches 100%, performance remains good.
1919 */
2020
21+#include <math.h>
2122 #include <string.h>
2223
2324 #define ltable_c
@@ -37,10 +38,10 @@ · 13 unmodified lines
3738 /*
3839 ** max size of array part is 2^MAXBITS
3940 */
40−#if LUA_BITSINT > 26
41+#if LUAI_BITSINT > 26
4142 #define MAXBITS 26
4243 #else
43−#define MAXBITS (LUA_BITSINT-2)
44+#define MAXBITS (LUAI_BITSINT-2)
4445 #endif
4546
4647 #define MAXASIZE (1 << MAXBITS)
@@ -119,7 +120,7 @@ static int arrayindex (const TValue *key) { · 72 unmodified lines
119120 lua_Number n = nvalue(key);
120121 int k;
121122 lua_number2int(k, n);
122− if (num_eq(cast(lua_Number, k), nvalue(key)))
123+ if (luai_numeq(cast(lua_Number, k), nvalue(key)))
123124 return k;
124125 }
125126 return -1; /* `key' did not match some condition */
@@ -150,7 +151,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 24 unmodified lines
150151 }
151152 else n = gnext(n);
152153 } while (n);
153− luaG_runerror(L, "invalid key for `next'"); /* key not found */
154+ luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
154155 return 0; /* to avoid warnings */
155156 }
156157 }
@@ -436,7 +437,7 @@ const TValue *luaH_getnum (Table *t, int key) { · 279 unmodified lines
436437 lua_Number nk = cast(lua_Number, key);
437438 Node *n = hashnum(t, nk);
438439 do { /* check whether `key' is somewhere in the chain */
439− if (ttisnumber(gkey(n)) && num_eq(nvalue(gkey(n)), nk))
440+ if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
440441 return gval(n); /* that's it */
441442 else n = gnext(n);
442443 } while (n);
@@ -468,8 +469,9 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 25 unmodified lines
468469 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
469470 case LUA_TNUMBER: {
470471 int k;
471− lua_number2int(k, (nvalue(key)));
472− if (num_eq(cast(lua_Number, k), nvalue(key))) /* is an integer index? */
472+ lua_Number n = nvalue(key);
473+ lua_number2int(k, n);
474+ if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is integer? */
473475 return luaH_getnum(t, k); /* use specialized version */
474476 /* else go through */
475477 }
@@ -493,7 +495,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 17 unmodified lines
493495 return cast(TValue *, p);
494496 else {
495497 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
496− else if (ttisnumber(key) && !num_eq(nvalue(key), nvalue(key)))
498+ else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key)))
497499 luaG_runerror(L, "table index is NaN");
498500 return newkey(L, t, key);
499501 }
@@ -523,3 +525,50 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { · 23 unmodified lines
523525 }
524526 }
525527
528+
529+static int unbound_search (Table *t, unsigned int j) {
530+ unsigned int i = j; /* i is zero or a present index */
531+ j = j+1;
532+ /* find `i' and `j' such that i is present and j is not */
533+ while (!ttisnil(luaH_getnum(t, j))) {
534+ i = j;
535+ j = i*2;
536+ if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
537+ /* table was built with bad purposes: resort to linear search */
538+ i = 1;
539+ while (!ttisnil(luaH_getnum(t, i))) i++;
540+ return i - 1;
541+ }
542+ }
543+ /* now do a binary search between them */
544+ while (i < j-1) {
545+ unsigned int m = (i+j)/2;
546+ if (ttisnil(luaH_getnum(t, m))) j = m;
547+ else i = m;
548+ }
549+ return i;
550+}
551+
552+
553+/*
554+** Try to find a boundary in table `t'. A `boundary' is an integer index
555+** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
556+*/
557+int luaH_getn (Table *t) {
558+ unsigned int j = t->sizearray;
559+ if (j > 0 && ttisnil(&t->array[j - 1])) {
560+ /* there is a boundary in the array part: (binary) search for it */
561+ unsigned int i = 0;
562+ while (j - i > 1) {
563+ unsigned int m = (i+j)/2;
564+ if (ttisnil(&t->array[m - 1])) j = m;
565+ else i = m;
566+ }
567+ return i;
568+ }
569+ /* else must find a boundary in hash part */
570+ else if (t->node == &luaH_dummynode) /* hash part is empty? */
571+ return j; /* that is easy... */
572+ else return unbound_search(t, j);
573+}
574+
src/ltable.h+13−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.h,v 2.5 2005/01/05 18:20:51 roberto Exp $
2+** $Id: ltable.h,v 2.7 2005/04/25 19:24:10 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -20,19 +20,20 @@ · 14 unmodified lines
2020
2121 extern const Node luaH_dummynode;
2222
23−const TValue *luaH_getnum (Table *t, int key);
24−TValue *luaH_setnum (lua_State *L, Table *t, int key);
25−const TValue *luaH_getstr (Table *t, TString *key);
26−TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
27−const TValue *luaH_get (Table *t, const TValue *key);
28−TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
29−Table *luaH_new (lua_State *L, int narray, int lnhash);
30−void luaH_resizearray (lua_State *L, Table *t, int nasize);
31−void luaH_free (lua_State *L, Table *t);
32−int luaH_next (lua_State *L, Table *t, StkId key);
23+LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
24+LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
25+LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
26+LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
27+LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
28+LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
29+LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash);
30+LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);
31+LUAI_FUNC void luaH_free (lua_State *L, Table *t);
32+LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
33+LUAI_FUNC int luaH_getn (Table *t);
3334
3435 /* exported only for debugging */
35−Node *luaH_mainposition (const Table *t, const TValue *key);
36+LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
3637
3738
3839 #endif
src/ltablib.c+21−18
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp $
2+** $Id: ltablib.c,v 1.31 2005/05/17 19:49:15 roberto Exp $
33 ** Library for Table Manipulation
44 ** See Copyright Notice in lua.h
55 */
@@ -23,7 +23,7 @@ static int foreachi (lua_State *L) { · 17 unmodified lines
2323 int i;
2424 int n = aux_getn(L, 1);
2525 luaL_checktype(L, 2, LUA_TFUNCTION);
26− for (i=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) {
26+ for (i=1; i <= n; i++) {
2727 lua_pushvalue(L, 2); /* function */
2828 lua_pushinteger(L, i); /* 1st argument */
2929 lua_rawgeti(L, 1, i); /* 2nd argument */
@@ -62,39 +62,42 @@ static int getn (lua_State *L) { · 32 unmodified lines
6262
6363 static int setn (lua_State *L) {
6464 luaL_checktype(L, 1, LUA_TTABLE);
65+#ifndef luaL_setn
6566 luaL_setn(L, 1, luaL_checkint(L, 2));
67+#else
68+ luaL_error(L, LUA_QL("setn") " is obsolete");
69+#endif
6670 lua_pushvalue(L, 1);
6771 return 1;
6872 }
6973
7074
7175 static int tinsert (lua_State *L) {
72− int v = lua_gettop(L); /* number of arguments */
73− int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */
76+ int e = aux_getn(L, 1) + 1; /* first empty element */
7477 int pos; /* where to insert new element */
75− if (v == 2) /* called with only 2 arguments */
78+ if (lua_isnone(L, 3)) /* called with only 2 arguments */
7679 pos = e; /* insert new element at the end */
7780 else {
81+ int i;
7882 pos = luaL_checkint(L, 2); /* 2nd argument is the position */
7983 if (pos > e) e = pos; /* `grow' array if necessary */
80− v = 3; /* function may be called with more than 3 args */
81− }
82− luaL_setn(L, 1, e - LUA_FIRSTINDEX + 1); /* new size */
83− while (--e >= pos) { /* move up elements */
84− lua_rawgeti(L, 1, e);
85− lua_rawseti(L, 1, e+1); /* t[e+1] = t[e] */
84+ lua_settop(L, 3); /* function may be called with more than 3 args */
85+ for (i = e; i > pos; i--) { /* move up elements */
86+ lua_rawgeti(L, 1, i-1);
87+ lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
88+ }
8689 }
87− lua_pushvalue(L, v);
90+ luaL_setn(L, 1, e); /* new size */
8891 lua_rawseti(L, 1, pos); /* t[pos] = v */
8992 return 0;
9093 }
9194
9295
9396 static int tremove (lua_State *L) {
94− int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1;
97+ int e = aux_getn(L, 1);
9598 int pos = luaL_optint(L, 2, e);
96− if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */
97− luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */
99+ if (e == 0) return 0; /* table is `empty' */
100+ luaL_setn(L, 1, e - 1); /* t.n = n-1 */
98101 lua_rawgeti(L, 1, pos); /* result = t[pos] */
99102 for ( ;pos<e; pos++) {
100103 lua_rawgeti(L, 1, pos+1);
@@ -110,11 +113,11 @@ static int str_concat (lua_State *L) { · 9 unmodified lines
110113 luaL_Buffer b;
111114 size_t lsep;
112115 const char *sep = luaL_optlstring(L, 2, "", &lsep);
113− int i = luaL_optint(L, 3, LUA_FIRSTINDEX);
116+ int i = luaL_optint(L, 3, 1);
114117 int last = luaL_optint(L, 4, -2);
115118 luaL_checktype(L, 1, LUA_TTABLE);
116119 if (last == -2)
117− last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1;
120+ last = luaL_getn(L, 1);
118121 luaL_buffinit(L, &b);
119122 for (; i <= last; i++) {
120123 lua_rawgeti(L, 1, i);
@@ -226,7 +229,7 @@ static int sort (lua_State *L) { · 105 unmodified lines
226229 if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
227230 luaL_checktype(L, 2, LUA_TFUNCTION);
228231 lua_settop(L, 2); /* make sure there is two arguments */
229− auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1);
232+ auxsort(L, 1, n);
230233 return 0;
231234 }
232235
src/ltm.c+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltm.c,v 2.3 2004/04/30 20:13:38 roberto Exp $
2+** $Id: ltm.c,v 2.5 2005/05/05 15:34:03 roberto Exp $
33 ** Tag methods
44 ** See Copyright Notice in lua.h
55 */
@@ -31,8 +31,8 @@ void luaT_init (lua_State *L) { · 25 unmodified lines
3131 static const char *const luaT_eventname[] = { /* ORDER TM */
3232 "__index", "__newindex",
3333 "__gc", "__mode", "__eq",
34− "__add", "__sub", "__mul", "__div",
35− "__pow", "__unm", "__lt", "__le",
34+ "__add", "__sub", "__mul", "__div", "__mod",
35+ "__pow", "__unm", "__siz", "__lt", "__le",
3636 "__concat", "__call"
3737 };
3838 int i;
@@ -68,8 +68,8 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { · 29 unmodified lines
6868 mt = uvalue(o)->metatable;
6969 break;
7070 default:
71− mt = NULL;
71+ mt = G(L)->mt[ttype(o)];
7272 }
73− return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);
73+ return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);
7474 }
7575
src/ltm.h+8−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltm.h,v 2.1 2003/12/10 12:13:36 roberto Exp $
2+** $Id: ltm.h,v 2.4 2005/05/05 15:34:03 roberto Exp $
33 ** Tag methods
44 ** See Copyright Notice in lua.h
55 */
@@ -25,8 +25,10 @@ typedef enum { · 19 unmodified lines
2525 TM_SUB,
2626 TM_MUL,
2727 TM_DIV,
28+ TM_MOD,
2829 TM_POW,
2930 TM_UNM,
31+ TM_SIZ,
3032 TM_LT,
3133 TM_LE,
3234 TM_CONCAT,
@@ -41,11 +43,12 @@ typedef enum { · 8 unmodified lines
4143
4244 #define fasttm(l,et,e) gfasttm(G(l), et, e)
4345
46+extern const char *const luaT_typenames[];
4447
45−const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
46−const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event);
47−void luaT_init (lua_State *L);
4848
49−extern const char *const luaT_typenames[];
49+LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
50+LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
51+ TMS event);
52+LUAI_FUNC void luaT_init (lua_State *L);
5053
5154 #endif
src/lua.c+55−82
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.135 2005/01/10 17:21:10 roberto Exp $
2+** $Id: lua.c,v 1.144 2005/05/17 19:49:15 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -18,19 +18,10 @@ · 12 unmodified lines
1818 #include "lualib.h"
1919
2020
21−/*
22−** generic extra include file
23−*/
24−#ifdef LUA_USERCONFIG
25−#include LUA_USERCONFIG
26−#endif
27−
28−
29−
3021
3122 static lua_State *globalL = NULL;
3223
33−static const char *progname = PROGNAME;
24+static const char *progname = LUA_PROGNAME;
3425
3526
3627
@@ -53,10 +44,11 @@ static void print_usage (void) { · 16 unmodified lines
5344 "usage: %s [options] [script [args]].\n"
5445 "Available options are:\n"
5546 " - execute stdin as a file\n"
56− " -e stat execute string `stat'\n"
57− " -i enter interactive mode after executing `script'\n"
58− " -l name load and run library `name'\n"
47+ " -e stat execute string " LUA_QL("stat") "\n"
48+ " -i enter interactive mode after executing " LUA_QL("script") "\n"
49+ " -l name require library " LUA_QL("name") "\n"
5950 " -v show version information\n"
51+ " -w trap access to undefined globals\n"
6052 " -- stop handling options\n" ,
6153 progname);
6254 }
@@ -110,15 +102,14 @@ static void print_version (void) { · 47 unmodified lines
110102 }
111103
112104
113−static int getargs (lua_State *L, char *argv[], int n) {
114− int i, narg;
115− for (i=n+1; argv[i]; i++) {
116− luaL_checkstack(L, 1, "too many arguments to script");
105+static int getargs (lua_State *L, int argc, char **argv, int n) {
106+ int narg = argc - (n + 1); /* number of arguments to the script */
107+ int i;
108+ luaL_checkstack(L, narg + 3, "too many arguments to script");
109+ for (i=n+1; i < argc; i++)
117110 lua_pushstring(L, argv[i]);
118− }
119− narg = i-(n+1); /* number of arguments to the script (not to `lua.c') */
120111 lua_newtable(L);
121− for (i=0; argv[i]; i++) {
112+ for (i=0; i < argc; i++) {
122113 lua_pushstring(L, argv[i]);
123114 lua_rawseti(L, -2, i - n);
124115 }
@@ -139,54 +130,18 @@ static int dostring (lua_State *L, const char *s, const char *name) { · 14 unmodified lines
139130
140131
141132 static int dolibrary (lua_State *L, const char *name) {
142− luaL_getfield(L, LUA_GLOBALSINDEX, "package.path");
143− if (!lua_isstring(L, -1)) {
144− l_message(progname, "`package.path' must be a string");
145− return 1;
146− }
147− name = luaL_searchpath(L, name, lua_tostring(L, -1));
148− if (name == NULL) return report(L, 1);
149− else return dofile(L, name);
150−}
151−
152−
153−
154−/*
155−** this macro defines a function to show the prompt and reads the
156−** next line for manual input
157−*/
158−#ifndef lua_readline
159−#define lua_readline(L,prompt) readline(L,prompt)
160−
161−/* maximum length of an input line */
162−#ifndef MAXINPUT
163−#define MAXINPUT 512
164−#endif
165−
166−
167−static int readline (lua_State *L, const char *prompt) {
168− static char buffer[MAXINPUT];
169− if (prompt) {
170− fputs(prompt, stdout);
171− fflush(stdout);
172− }
173− if (fgets(buffer, sizeof(buffer), stdin) == NULL)
174− return 0; /* read fails */
175− else {
176− lua_pushstring(L, buffer);
177− return 1;
178− }
133+ lua_getglobal(L, "require");
134+ lua_pushstring(L, name);
135+ return report(L, lua_pcall(L, 1, 0, 0));
179136 }
180137
181−#endif
182−
183138
184139 static const char *get_prompt (lua_State *L, int firstline) {
185− const char *p = NULL;
140+ const char *p;
186141 lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2");
187142 lua_rawget(L, LUA_GLOBALSINDEX);
188143 p = lua_tostring(L, -1);
189− if (p == NULL) p = (firstline ? PROMPT : PROMPT2);
144+ if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
190145 lua_pop(L, 1); /* remove global */
191146 return p;
192147 }
@@ -194,7 +149,7 @@ static const char *get_prompt (lua_State *L, int firstline) { · 1 unmodified line
194149
195150 static int incomplete (lua_State *L, int status) {
196151 if (status == LUA_ERRSYNTAX &&
197− strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) {
152+ strstr(lua_tostring(L, -1), "<eof>") != NULL) {
198153 lua_pop(L, 1);
199154 return 1;
200155 }
@@ -203,23 +158,40 @@ static int incomplete (lua_State *L, int status) { · 2 unmodified lines
203158 }
204159
205160
161+static int pushline (lua_State *L, int firstline) {
162+ char buffer[LUA_MAXINPUT];
163+ char *b = buffer;
164+ size_t l;
165+ const char *prmt = get_prompt(L, firstline);
166+ if (lua_readline(L, b, prmt) == 0)
167+ return 0; /* no input */
168+ l = strlen(b);
169+ if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
170+ b[l-1] = '\0'; /* remove it */
171+ if (firstline && b[0] == '=') /* first line starts with `=' ? */
172+ lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
173+ else
174+ lua_pushstring(L, b);
175+ lua_freeline(L, b);
176+ return 1;
177+}
178+
179+
206180 static int loadline (lua_State *L) {
207181 int status;
208182 lua_settop(L, 0);
209− if (lua_readline(L, get_prompt(L, 1)) == 0) /* no input? */
210− return -1;
211− if (lua_tostring(L, -1)[0] == '=') { /* line starts with `=' ? */
212− lua_pushfstring(L, "return %s", lua_tostring(L, -1)+1);/* `=' -> `return' */
213− lua_remove(L, -2); /* remove original line */
214− }
183+ if (!pushline(L, 1))
184+ return -1; /* no input */
215185 for (;;) { /* repeat until gets a complete line */
216186 status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
217187 if (!incomplete(L, status)) break; /* cannot try to add lines? */
218− if (lua_readline(L, get_prompt(L, 0)) == 0) /* no more input? */
188+ if (!pushline(L, 0)) /* no more input? */
219189 return -1;
220− lua_concat(L, lua_gettop(L)); /* join lines */
190+ lua_pushliteral(L, "\n"); /* add a new line... */
191+ lua_insert(L, -2); /* ...between the two lines */
192+ lua_concat(L, 3); /* join them */
221193 }
222− lua_saveline(L, lua_tostring(L, 1));
194+ lua_saveline(L, 1);
223195 lua_remove(L, 1); /* remove line */
224196 return status;
225197 }
@@ -237,8 +209,9 @@ static void dotty (lua_State *L) { · 11 unmodified lines
237209 lua_getglobal(L, "print");
238210 lua_insert(L, 1);
239211 if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
240− l_message(progname, lua_pushfstring(L, "error calling `print' (%s)",
241− lua_tostring(L, -1)));
212+ l_message(progname, lua_pushfstring(L,
213+ "error calling " LUA_QL("print") " (%s)",
214+ lua_tostring(L, -1)));
242215 }
243216 }
244217 lua_settop(L, 0); /* clear stack */
@@ -250,17 +223,17 @@ static void dotty (lua_State *L) { · 5 unmodified lines
250223 static int checkvar (lua_State *L) {
251224 const char *name = lua_tostring(L, 2);
252225 if (name)
253− luaL_error(L, "attempt to access undefined variable `%s'", name);
226+ luaL_error(L, "attempt to access undefined variable " LUA_QS, name);
254227 return 0;
255228 }
256229
257230
258231 #define clearinteractive(i) (*i &= 2)
259232
260−static int handle_argv (lua_State *L, char *argv[], int *interactive) {
233+static int handle_argv (lua_State *L, int argc, char **argv, int *interactive) {
261234 if (argv[1] == NULL) { /* no arguments? */
262235 *interactive = 0;
263− if (stdin_is_tty())
236+ if (lua_stdin_is_tty())
264237 dotty(L);
265238 else
266239 dofile(L, NULL); /* executes stdin as a file */
@@ -330,9 +303,9 @@ static int handle_argv (lua_State *L, char *argv[], int *interactive) { · 63 unmodified lines
330303 }
331304 } endloop:
332305 if (argv[i] != NULL) {
333− const char *filename = argv[i];
334− int narg = getargs(L, argv, i); /* collect arguments */
335306 int status;
307+ const char *filename = argv[i];
308+ int narg = getargs(L, argc, argv, i); /* collect arguments */
336309 lua_setglobal(L, "arg");
337310 clearinteractive(interactive);
338311 status = luaL_loadfile(L, filename);
@@ -371,10 +344,10 @@ static int pmain (lua_State *L) { · 32 unmodified lines
371344 int interactive = 1;
372345 if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
373346 globalL = L;
374− luaopen_stdlibs(L); /* open libraries */
347+ luaL_openlibs(L); /* open libraries */
375348 status = handle_luainit(L);
376349 if (status == 0) {
377− status = handle_argv(L, s->argv, &interactive);
350+ status = handle_argv(L, s->argc, s->argv, &interactive);
378351 if (status == 0 && interactive) dotty(L);
379352 }
380353 s->status = status;
@@ -382,7 +355,7 @@ static int pmain (lua_State *L) { · 1 unmodified line
382355 }
383356
384357
385−int main (int argc, char *argv[]) {
358+int main (int argc, char **argv) {
386359 int status;
387360 struct Smain s;
388361 lua_State *L = lua_open(); /* create state */
src/lua.h+28−28
@@ -1,8 +1,8 @@
11 /*
2−** $Id: lua.h,v 1.202 2005/02/18 12:40:02 roberto Exp $
2+** $Id: lua.h,v 1.208 2005/05/17 19:49:15 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
5−** http://www.lua.org mailto:info@lua.org
5+** http://www.lua.org
66 ** See Copyright Notice at the end of this file
77 */
88
@@ -17,7 +17,7 @@ · 8 unmodified lines
1717 #include "luaconf.h"
1818
1919
20−#define LUA_VERSION "Lua 5.1 (work5)"
20+#define LUA_VERSION "Lua 5.1 (work6)"
2121 #define LUA_VERSION_NUM 501
2222 #define LUA_COPYRIGHT "Copyright (C) 1994-2005 Tecgraf, PUC-Rio"
2323 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@@ -55,10 +55,9 @@ typedef int (*lua_CFunction) (lua_State *L); · 31 unmodified lines
5555 /*
5656 ** functions that read/write blocks when loading/dumping Lua chunks
5757 */
58−typedef const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t *sz);
58+typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
5959
60−typedef int (*lua_Chunkwriter) (lua_State *L, const void* p,
61− size_t sz, void* ud);
60+typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
6261
6362
6463 /*
@@ -70,22 +69,19 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); · 5 unmodified lines
7069 /*
7170 ** basic types
7271 */
73−#define LUA_TNONE (-1)
72+#define LUA_TNONE (-1)
7473
75−#define LUA_TNIL 0
76−#define LUA_TBOOLEAN 1
74+#define LUA_TNIL 0
75+#define LUA_TBOOLEAN 1
7776 #define LUA_TLIGHTUSERDATA 2
78−#define LUA_TNUMBER 3
79−#define LUA_TSTRING 4
80−#define LUA_TTABLE 5
81−#define LUA_TFUNCTION 6
82−#define LUA_TUSERDATA 7
83−#define LUA_TTHREAD 8
77+#define LUA_TNUMBER 3
78+#define LUA_TSTRING 4
79+#define LUA_TTABLE 5
80+#define LUA_TFUNCTION 6
81+#define LUA_TUSERDATA 7
82+#define LUA_TTHREAD 8
8483
8584
86−/* first index for arrays */
87−#define LUA_FIRSTINDEX 1
88−
8985
9086 /* minimum Lua stack available to a C function */
9187 #define LUA_MINSTACK 20
@@ -94,7 +90,7 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); · 2 unmodified lines
9490 /*
9591 ** generic extra include file
9692 */
97−#ifdef LUA_USER_H
93+#if defined(LUA_USER_H)
9894 #include LUA_USER_H
9995 #endif
10096
@@ -150,7 +146,7 @@ LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); · 49 unmodified lines
150146 LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
151147 LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
152148 LUA_API int (lua_toboolean) (lua_State *L, int idx);
153−LUA_API const char *(lua_tostring) (lua_State *L, int idx);
149+LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
154150 LUA_API size_t (lua_objsize) (lua_State *L, int idx);
155151 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
156152 LUA_API void *(lua_touserdata) (lua_State *L, int idx);
@@ -204,11 +200,11 @@ LUA_API int (lua_setfenv) (lua_State *L, int idx); · 47 unmodified lines
204200 */
205201 LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
206202 LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
207−LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
208−LUA_API int (lua_load) (lua_State *L, lua_Chunkreader reader, void *dt,
203+LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
204+LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
209205 const char *chunkname);
210206
211−LUA_API int (lua_dump) (lua_State *L, lua_Chunkwriter writer, void *data);
207+LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
212208
213209
214210 /*
@@ -227,7 +223,7 @@ LUA_API int (lua_status) (lua_State *L); · 12 unmodified lines
227223 #define LUA_GCCOLLECT 2
228224 #define LUA_GCCOUNT 3
229225 #define LUA_GCSTEP 4
230−#define LUA_GCSETPACE 5
226+#define LUA_GCSETPAUSE 5
231227 #define LUA_GCSETSTEPMUL 6
232228
233229 LUA_API int (lua_gc) (lua_State *L, int what, int data);
@@ -278,6 +274,8 @@ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); · 44 unmodified lines
278274 #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
279275 #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
280276
277+#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
278+
281279
282280
283281 /*
@@ -290,7 +288,8 @@ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); · 6 unmodified lines
290288
291289 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
292290
293−
291+#define lua_Chunkreader lua_Reader
292+#define lua_Chunkwriter lua_Writer
294293
295294
296295
@@ -321,6 +320,8 @@ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); · 24 unmodified lines
321320
322321 typedef struct lua_Debug lua_Debug; /* activation record */
323322
323+
324+/* Functions to be called by the debuger in specific events */
324325 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
325326
326327
@@ -337,8 +338,6 @@ LUA_API int lua_gethookmask (lua_State *L); · 10 unmodified lines
337338 LUA_API int lua_gethookcount (lua_State *L);
338339
339340
340−#define LUA_IDSIZE 60
341−
342341 struct lua_Debug {
343342 int event;
344343 const char *name; /* (n) */
@@ -348,6 +347,7 @@ struct lua_Debug { · 3 unmodified lines
348347 int currentline; /* (l) */
349348 int nups; /* (u) number of upvalues */
350349 int linedefined; /* (S) */
350+ int lastlinedefined; /* (S) */
351351 char short_src[LUA_IDSIZE]; /* (S) */
352352 /* private part */
353353 int i_ci; /* active function */
@@ -357,7 +357,7 @@ struct lua_Debug { · 3 unmodified lines
357357
358358
359359 /******************************************************************************
360−* Copyright (C) 1994-2004 Tecgraf, PUC-Rio. All rights reserved.
360+* Copyright (C) 1994-2005 Tecgraf, PUC-Rio. All rights reserved.
361361 *
362362 * Permission is hereby granted, free of charge, to any person obtaining
363363 * a copy of this software and associated documentation files (the
src/luac.c+1−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luac.c,v 1.49 2004/09/01 21:22:34 lhf Exp $
2+** $Id: luac.c,v 1.50 2005/05/12 00:26:50 lhf Exp $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -151,8 +151,6 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 145 unmodified lines
151151 return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
152152 }
153153
154−void unprint(lua_State* L, const char* name);
155−
156154 struct Smain {
157155 int argc;
158156 char **argv;
src/luaconf.h+484−213
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.30 2005/02/28 15:59:11 roberto Exp $
2+** $Id: luaconf.h,v 1.49a 2005/05/17 19:49:15 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -13,387 +13,658 @@ · 7 unmodified lines
1313
1414
1515 /*
16−** {======================================================
17−** Index (search for keyword to find corresponding entry)
18−** =======================================================
16+** ==================================================================
17+** Search for "@@" to find all configurable definitions.
18+** ===================================================================
1919 */
2020
2121
22−/* }====================================================== */
23−
24−
2522
2623
2724 /*
28−** {======================================================
29−** Generic configuration
30−** =======================================================
25+@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
26+@* Lua libraries.
27+@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
28+@* C libraries.
29+** CHANGE them if your machine has a non-conventional directory
30+** hierarchy or if you want to install your libraries in
31+** non-conventional directories.
3132 */
32−
33−/* default path */
3433 #if defined(_WIN32)
3534 #define LUA_ROOT "C:\\Program Files\\Lua51"
3635 #define LUA_LDIR LUA_ROOT "\\lua"
3736 #define LUA_CDIR LUA_ROOT "\\dll"
3837 #define LUA_PATH_DEFAULT \
39− "?.lua;" LUA_LDIR "\\?.lua;" LUA_LDIR "\\?\\init.lua"
40−#define LUA_CPATH_DEFAULT "?.dll;" LUA_CDIR "\\?.dll"
38+ "?.lua;" LUA_LDIR"\\?.lua;" LUA_LDIR"\\?\\init.lua"
39+#define LUA_CPATH_DEFAULT \
40+ "?.dll;" "l?.dll;" LUA_CDIR"\\?.dll;" LUA_CDIR"\\l?.dll"
4141
4242 #else
4343 #define LUA_ROOT "/usr/local"
4444 #define LUA_LDIR LUA_ROOT "/share/lua/5.1"
4545 #define LUA_CDIR LUA_ROOT "/lib/lua/5.1"
4646 #define LUA_PATH_DEFAULT \
47− "./?.lua;" LUA_LDIR "/?.lua;" LUA_LDIR "/?/init.lua"
48−#define LUA_CPATH_DEFAULT "./?.so;" LUA_CDIR "/?.so"
47+ "./?.lua;" LUA_LDIR"/?.lua;" LUA_LDIR"/?/init.lua"
48+#define LUA_CPATH_DEFAULT \
49+ "./?.so;" "./l?.so;" LUA_CDIR"/?.so;" LUA_CDIR"/l?.so"
4950 #endif
5051
5152
53+/*
54+@@ LUA_DIRSEP is the directory separator (for submodules).
55+** CHANGE it if your machine does not use "/" as the directory separator
56+** and is not Windows. (On Windows Lua automatically uses "\".)
57+*/
58+#if defined(_WIN32)
59+#define LUA_DIRSEP "\\"
60+#else
61+#define LUA_DIRSEP "/"
62+#endif
5263
53−/* type of numbers in Lua */
54−#define LUA_NUMBER double
5564
56−/* formats for Lua numbers */
57−#define LUA_NUMBER_SCAN "%lf"
58−#define LUA_NUMBER_FMT "%.14g"
65+/*
66+@@ LUA_PATHSEP is the character that separates templates in a path.
67+** CHANGE it if for some reason your system cannot use a
68+** semicolon. (E.g., if a semicolon is a common character in
69+** file/directory names.) Probably you do not need to change this.
70+*/
71+#define LUA_PATHSEP ';'
5972
6073
6174 /*
62−** type for integer functions
63−** on most machines, `ptrdiff_t' gives a reasonable size for integers
75+@@ LUA_PATH_MARK is the string that marks the substitution points in a
76+@* template.
77+** CHANGE it if for some reason your system cannot use an interrogation
78+** mark. (E.g., if an interogation mark is a common character in
79+** file/directory names.) Probably you do not need to change this.
80+*/
81+#define LUA_PATH_MARK "?"
82+
83+
84+/*
85+@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
86+** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
87+** machines, ptrdiff_t gives a good choice between int or long.)
6488 */
6589 #define LUA_INTEGER ptrdiff_t
6690
6791
68−/* mark for all API functions */
92+/*
93+@@ LUA_API is a mark for all core API functions.
94+@@ LUALIB_API is a mark for all standard library functions.
95+** CHANGE them if you need to define those functions in some special way.
96+** For instance, if you want to create one Windows DLL with the core and
97+** the libraries, you may want to use the following definition (define
98+** LUA_BUILD_AS_DLL to get it).
99+*/
100+#if defined(LUA_BUILD_AS_DLL)
101+
102+#if defined(LUA_CORE) || defined(LUA_LIB)
103+#define LUA_API __declspec(__dllexport)
104+#else
105+#define LUA_API __declspec(__dllimport)
106+#endif
107+
108+#else
109+
69110 #define LUA_API extern
70111
71−/* mark for auxlib functions */
72−#define LUALIB_API extern
112+#endif
73113
74−/* buffer size used by lauxlib buffer system */
75−#define LUAL_BUFFERSIZE BUFSIZ
114+/* more often than not the libs go together with the core */
115+#define LUALIB_API LUA_API
76116
77117
78−/* assertions in Lua (mainly for internal debugging) */
118+/*
119+@@ LUAI_FUNC is a mark for all extern functions that are not to be
120+@* exported to outside modules.
121+** CHANGE it if you need to mark them in some special way. Gcc (versions
122+** 3.2 and later) mark them as "hidden" to optimize their call when Lua
123+** is compiled as a shared library.
124+*/
125+#if defined(luaall_c)
126+#define LUAI_FUNC static
127+#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302)
128+#define LUAI_FUNC __attribute__((visibility("hidden")))
129+#else
130+#define LUAI_FUNC extern
131+#endif
132+
133+
134+/*
135+@@ lua_assert describes the internal assertions in Lua.
136+** CHANGE that only if you need to debug Lua.
137+*/
79138 #define lua_assert(c) ((void)0)
80139
81−/* }====================================================== */
82140
141+/*
142+@@ LUA_QL describes how error messages quote program elements.
143+** CHANGE it if you want a different appearance.
144+*/
145+#define LUA_QL(x) "'" x "'"
146+#define LUA_QS LUA_QL("%s")
83147
84148
85149 /*
86−** {======================================================
150+@@ LUA_IDSIZE gives the maximum size for the description of the source
151+@* of a function in debug information.
152+** CHANGE it if you a different size.
153+*/
154+#define LUA_IDSIZE 60
155+
156+
157+/*
158+** {==================================================================
87159 ** Stand-alone configuration
88−** =======================================================
160+** ===================================================================
89161 */
90162
91−#ifdef lua_c
163+#if defined(lua_c) || defined(luaall_c)
92164
93−/* definition of `isatty' */
94−#ifdef _POSIX_C_SOURCE
165+/*
166+@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
167+@* is, whether we're running lua interactively).
168+** CHANGE it if you have a better definition for non-POSIX/non-Windows
169+** systems.
170+*/
171+#if !defined(__STRICT_ANSI__) && defined(_POSIX_C_SOURCE)
95172 #include <unistd.h>
96−#define stdin_is_tty() isatty(0)
97−#elif defined(_WIN32)
173+#define lua_stdin_is_tty() isatty(0)
174+#elif !defined(__STRICT_ANSI__) && defined(_WIN32)
98175 #include <io.h>
99176 #include <stdio.h>
100−#define stdin_is_tty() _isatty(_fileno(stdin))
177+#define lua_stdin_is_tty() _isatty(_fileno(stdin))
101178 #else
102−#define stdin_is_tty() 1 /* assume stdin is a tty */
179+#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
103180 #endif
104181
105182
106−#define PROMPT "> "
107−#define PROMPT2 ">> "
108−#define PROGNAME "lua"
183+/*
184+@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
185+@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
186+** CHANGE them if you want different prompts. (You can also change the
187+** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
188+*/
189+#define LUA_PROMPT "> "
190+#define LUA_PROMPT2 ">> "
109191
110192
193+/*
194+@@ LUA_PROGNAME is the default name for the stand-alone Lua program.
195+** CHANGE it if your stand-alone interpreter has a different name and
196+** your system is not able to detect that name automatically.
197+*/
198+#define LUA_PROGNAME "lua"
111199
112200
113201 /*
114−** this macro can be used by some `history' system to save lines
115−** read in manual input
202+@@ LUA_MAXINPUT is the maximum length for an input line in the
203+@* stand-alone interpreter.
204+** CHANGE it if you need longer lines.
116205 */
117−#define lua_saveline(L,line) /* empty */
206+#define LUA_MAXINPUT 512
118207
119208
209+/*
210+@@ lua_readline defines how to show a prompt and then read a line from
211+@* the standard input.
212+@@ lua_saveline defines how to "save" a read line in a "history".
213+@@ lua_freeline defines how to free a line read by lua_readline.
214+** CHANGE them if you want to improve this functionality (e.g., by using
215+** GNU readline and history facilities).
216+*/
217+#if !defined(__STRICT_ANSI__) && defined(LUA_USE_READLINE)
218+#include <stdio.h>
219+#include <readline/readline.h>
220+#include <readline/history.h>
221+#define lua_readline(L,b,p) (((b)=readline(p)) != NULL)
222+#define lua_saveline(L,idx) \
223+ if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
224+ add_history(lua_tostring(L, idx)); /* add it to history */
225+#define lua_freeline(L,b) free(b)
226+#else
227+#define lua_readline(L,b,p) \
228+ (fputs(p, stdout), fflush(stdout), /* show prompt */ \
229+ fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
230+#define lua_saveline(L,idx) ((void)0)
231+#define lua_freeline(L,b) ((void)0)
232+#endif
120233
121234 #endif
122235
123−/* }====================================================== */
236+/* }================================================================== */
237+
238+
239+/*
240+@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
241+@* as a percentage.
242+** CHANGE it if you want the GC to run faster or slower (higher
243+** values mean larger pauses which mean slower collection.)
244+*/
245+#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
246+
247+
248+/*
249+@@ LUAI_GCMUL defines the speed of garbage collection relative to
250+@* memory allocation as a percentage.
251+** CHANGE it if you want to change the granularity of the garbage
252+** collection. (Higher values mean coarser collections. 0 represents
253+** infinity, where each step performs a full collection.)
254+*/
255+#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
256+
124257
258+/*
259+@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
260+** CHANGE it to 1 if you want exact compatibility with the behavior of
261+** setn/getn in Lua 5.0.
262+*/
263+#define LUA_COMPAT_GETN 0
125264
265+/*
266+@@ LUA_COMPAT_PATH controls compatibility about LUA_PATH.
267+** CHANGE it to 1 if you want 'require' to look for global LUA_PATH
268+** before checking package.path.
269+*/
270+#define LUA_COMPAT_PATH 0
126271
127272 /*
128−** {======================================================
129−** Core configuration
130−** =======================================================
273+@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
274+** CHANGE it to 1 if you want a global 'loadlib' function (otherwise
275+** the function is only available as 'package.loadlib').
131276 */
277+#define LUA_COMPAT_LOADLIB 1
132278
133−#ifdef LUA_CORE
279+/*
280+@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
281+** CHANGE it to 1 if you want vararg functions that do not use '...'
282+** to get an 'arg' table with their extra arguments.
283+*/
284+#define LUA_COMPAT_VARARG 1
134285
135−/* LUA-C API assertions */
136−#define api_check(L,o) lua_assert(o)
286+/*
287+@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
288+@* facility.
289+** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
290+** off the advisory error when nesting [[...]].
291+*/
292+#define LUA_COMPAT_LSTR 1
293+
294+/*
295+@@ luai_apicheck is the assert macro used by the Lua-C API.
296+** CHANGE luai_apicheck if you want Lua to perform some checks in the
297+** parameters it gets from API calls. This may slow down the interpreter
298+** a bit, but may be quite useful when debugging C code that interfaces
299+** with Lua. A useful redefinition is to use assert.h.
300+*/
301+#if defined(LUA_USE_APICHECK)
302+#include <assert.h>
303+#define luai_apicheck(L,o) assert(o)
304+#else
305+/* (By default lua_assert is empty, so luai_apicheck is also empty.) */
306+#define luai_apicheck(L,o) lua_assert(o)
307+#endif
137308
138309
139−/* number of bits in an `int' */
310+/*
311+@@ LUAI_BITSINT defines the number of bits in an int.
312+** CHANGE here if Lua cannot automatically detect the number of bits of
313+** your machine. Probably you do not need to change this.
314+*/
140315 /* avoid overflows in comparison */
141316 #if INT_MAX-20 < 32760
142−#define LUA_BITSINT 16
317+#define LUAI_BITSINT 16
143318 #elif INT_MAX > 2147483640L
144−/* `int' has at least 32 bits */
145−#define LUA_BITSINT 32
319+/* int has at least 32 bits */
320+#define LUAI_BITSINT 32
146321 #else
147322 #error "you must define LUA_BITSINT with number of bits in an integer"
148323 #endif
149324
150325
151326 /*
152−** L_UINT32: unsigned integer with at least 32 bits
153−** L_INT32: signed integer with at least 32 bits
154−** LU_MEM: an unsigned integer big enough to count the total memory used by Lua
155−** L_MEM: a signed integer big enough to count the total memory used by Lua
327+@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
328+@@ LUAI_INT32 is an signed integer with at least 32 bits.
329+@@ LUAI_UMEM is an unsigned integer big enough to count the total
330+@* memory used by Lua.
331+@@ LUAI_MEM is a signed integer big enough to count the total memory
332+@* used by Lua.
333+** CHANGE here if for some weird reason the default definitions are not
334+** good enough for your machine. (The definitions in the 'else'
335+** part always works, but may waste space on machines with 64-bit
336+** longs.) Probably you do not need to change this.
156337 */
157−#if LUA_BITSINT >= 32
158−#define LUA_UINT32 unsigned int
159−#define LUA_INT32 int
160−#define LUA_MAXINT32 INT_MAX
161−#define LU_MEM size_t
162−#define L_MEM ptrdiff_t
338+#if LUAI_BITSINT >= 32
339+#define LUAI_UINT32 unsigned int
340+#define LUAI_INT32 int
341+#define LUAI_MAXINT32 INT_MAX
342+#define LUAI_UMEM size_t
343+#define LUAI_MEM ptrdiff_t
163344 #else
164345 /* 16-bit ints */
165−#define LUA_UINT32 unsigned long
166−#define LUA_INT32 long
167−#define LUA_MAXINT32 LONG_MAX
168−#define LU_MEM LUA_UINT32
169−#define L_MEM ptrdiff_t
346+#define LUAI_UINT32 unsigned long
347+#define LUAI_INT32 long
348+#define LUAI_MAXINT32 LONG_MAX
349+#define LUAI_UMEM unsigned long
350+#define LUAI_MEM long
170351 #endif
171352
172353
173−/* maximum depth for calls (unsigned short) */
174−#define LUA_MAXCALLS 10000
175−
176354 /*
177−** maximum depth for C calls (unsigned short): Not too big, or may
178−** overflow the C stack...
355+@@ LUAI_MAXCALLS limits the number of nested calls.
356+** CHANGE it if you need really deep recursive calls. This limit is
357+** arbitrary; its only purpose is to stop infinite recursion before
358+** exhausting memory.
179359 */
180−#define LUA_MAXCCALLS 200
181−
182−
183−/* maximum size for the virtual stack of a C function */
184−#define MAXCSTACK 2048
360+#define LUAI_MAXCALLS 20000
185361
186362
187363 /*
188−** maximum number of syntactical nested non-terminals: Not too big,
189−** or may overflow the C stack...
364+@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
365+@* can use.
366+** CHANGE it if you need lots of (Lua) stack space for your C
367+** functions. This limit is arbitrary; its only purpose is to stop C
368+** functions to consume unlimited stack space.
190369 */
191−#define LUA_MAXPARSERLEVEL 200
370+#define LUAI_MAXCSTACK 2048
192371
193372
194−/* maximum number of variables declared in a function */
195−#define MAXVARS 200 /* <MAXSTACK */
196373
197−
198−/* maximum number of upvalues per function */
199−#define MAXUPVALUES 60 /* <MAXSTACK */
374+/*
375+** {==================================================================
376+** CHANGE (to smaller values) the following definitions if your system
377+** has a small C stack. (Or you may want to change them to larger
378+** values if your system has a large C stack and these limits are
379+** too rigid for you.) Some of these constants control the size of
380+** stack-allocated arrays used by the compiler or the interpreter, while
381+** others limit the maximum number of recursive calls that the compiler
382+** or the interpreter can perform. Values too large may cause a C stack
383+** overflow for some forms of deep constructs.
384+** ===================================================================
385+*/
200386
201387
202−/* maximum size of expressions for optimizing `while' code */
203−#define MAXEXPWHILE 100
388+/*
389+@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
390+@* syntactical nested non-terminals in a program.
391+*/
392+#define LUAI_MAXCCALLS 200
204393
205394
206−/* function to convert a lua_Number to int (with any rounding method) */
207−#if defined(__GNUC__) && defined(__i386)
208−#define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st")
395+/*
396+@@ LUAI_MAXVARS is the maximum number of local variables per function
397+@* (must be smaller than 250).
398+*/
399+#define LUAI_MAXVARS 200
209400
210−#elif defined(_MSC_VER) && defined(_M_IX86)
211−#pragma warning(disable: 4514)
212−__inline int l_lrint (double flt)
213−{ int i;
214− _asm {
215− fld flt
216− fistp i
217− };
218− return i;
219−}
220−#define lua_number2int(i,d) ((i)=l_lrint((d)))
221−
222−#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L)
223−/* on machines compliant with C99, you can try `lrint' */
224−#include <math.h>
225−#define lua_number2int(i,d) ((i)=lrint(d))
226401
227−#else
228−#define lua_number2int(i,d) ((i)=(int)(d))
402+/*
403+@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
404+@* (must be smaller than 250).
405+*/
406+#define LUAI_MAXUPVALUES 60
229407
230−#endif
231408
409+/*
410+@@ LUAI_MAXEXPWHILE is the maximum size of code for expressions
411+@* controling a 'while' loop.
412+*/
413+#define LUAI_MAXEXPWHILE 100
232414
233−/* function to convert a lua_Number to lua_Integer (with any rounding method) */
234−#define lua_number2integer(i,n) lua_number2int((i), (n))
235415
416+/*
417+@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
418+*/
419+#define LUAL_BUFFERSIZE BUFSIZ
236420
237−/* function to convert a lua_Number to a string */
238−#include <stdio.h>
239−#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
240−/* maximum size of previous conversion */
241−#define MAX_NUMBER2STR 32 /* 16 digits, sign, point and \0 (+ some extra) */
421+/* }================================================================== */
242422
243−/* function to convert a string to a lua_Number */
244−#define lua_str2number(s,p) strtod((s), (p))
245423
246424
425+/*
426+@@ lua_number2int is a macro to convert lua_Number to int.
427+** CHANGE that if you know a faster way to convert a lua_Number to
428+** int (with any rounding method and without throwing errors) in your
429+** system. In Pentium machines, a naive typecast from double to int
430+** in C is extremely slow, so any alternative is worth trying.
431+*/
247432
248−/* result of a `usual argument conversion' over lua_Number */
249−#define LUA_UACNUMBER double
433+/* On a gcc/Pentium, resort to assembler */
434+#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__i386)
435+#define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st")
250436
437+/* On Windows/Pentium, resort to assembler */
438+#elif !defined(__STRICT_ANSI__) && defined(_MSC_VER) && defined(_M_IX86)
439+#define lua_number2int(i,d) \
440+ __asm fld d \
441+ __asm fistp i
251442
252−/* primitive operators for numbers */
253−#define num_add(a,b) ((a)+(b))
254−#define num_sub(a,b) ((a)-(b))
255−#define num_mul(a,b) ((a)*(b))
256−#define num_div(a,b) ((a)/(b))
257−#define num_unm(a) (-(a))
258−#define num_eq(a,b) ((a)==(b))
259−#define num_lt(a,b) ((a)<(b))
260−#define num_le(a,b) ((a)<=(b))
261−#include <math.h>
262−#define num_pow(a,b) pow(a,b)
263443
444+/* on Pentium machines compliant with C99, you can try lrint */
445+#elif defined (__i386) && defined(__STDC_VERSION__) && \
446+ (__STDC_VERSION__ >= 199900L)
447+#define lua_number2int(i,d) ((i)=lrint(d))
264448
449+/* this option always works, but may be slow */
450+#else
451+#define lua_number2int(i,d) ((i)=(int)(d))
265452
266−/* type to ensure maximum alignment */
267−#define LUSER_ALIGNMENT_T union { double u; void *s; long l; }
453+#endif
268454
269455
270456 /*
271−** exception handling: by default, Lua handles errors with longjmp/setjmp
272−** when compiling as C code and with exceptions when compiling as C++ code.
273−** Change that if you prefer to use longjmp/setjmp even with C++.
457+@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
458+** CHANGE (see lua_number2int).
274459 */
275−#ifndef __cplusplus
276−/* default handling with long jumps */
277−#include <setjmp.h>
278−#define L_THROW(L,c) longjmp((c)->b, 1)
279−#define L_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
280−#define l_jmpbuf jmp_buf
460+/* On a gcc or Windows/Pentium, resort to assembler */
461+#if (defined(__GNUC__) && defined(__i386)) || \
462+ (defined(_MSC_VER) && defined(_M_IX86))
463+#define lua_number2integer(i,n) lua_number2int(i, n)
281464
465+/* this option always works, but may be slow */
282466 #else
283−/* C++ exceptions */
284−#define L_THROW(L,c) throw(c)
285−#define L_TRY(L,c,a) try { a } catch(...) \
286− { if ((c)->status == 0) (c)->status = -1; }
287−#define l_jmpbuf int /* dummy variable */
467+#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
468+
288469 #endif
289470
290471
291472
292473 /*
293−** macros for thread synchronization inside Lua core machine: This is
294−** an attempt to simplify the implementation of a multithreaded version
295−** of Lua. Do not change that unless you know what you are doing. all
296−** accesses to the global state and to global objects are synchronized.
297−** Because threads can read the stack of other threads (when running
298−** garbage collection), a thread must also synchronize any write-access
299−** to its own stack. Unsynchronized accesses are allowed only when
300−** reading its own stack, or when reading immutable fields from global
301−** objects (such as string values and udata values).
474+** {==================================================================
475+@@ LUA_NUMBER is the type of numbers in Lua.
476+** CHANGE the following definitions only if you want to build Lua
477+** with a number type different from double. You may also need to
478+** change lua_number2int & lua_number2integer.
479+** ===================================================================
302480 */
303−#define lua_lock(L) ((void) 0)
304−#define lua_unlock(L) ((void) 0)
305481
306482
307483 /*
308−** this macro allows a thread switch in appropriate places in the Lua
309−** core
484+@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
485+@* over a number.
310486 */
311−#define lua_threadyield(L) {lua_unlock(L); lua_lock(L);}
487+#define LUA_NUMBER double
488+#define LUAI_UACNUMBER LUA_NUMBER
312489
313490
491+/*
492+@@ LUA_NUMBER_SCAN is the format for reading numbers.
493+@@ LUA_NUMBER_FMT is the format for writing numbers.
494+@@ lua_number2str converts a number to a string.
495+@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
496+@@ lua_str2number converts a string to a number.
497+*/
498+#define LUA_NUMBER_SCAN "%lf"
499+#define LUA_NUMBER_FMT "%.14g"
500+#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
501+#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
502+#define lua_str2number(s,p) strtod((s), (p))
314503
315−/* allows user-specific initialization on new threads */
316−#define lua_userstateopen(L) ((void)0)
317504
505+/*
506+@@ The luai_num* macros define the primitive operations over numbers.
507+*/
508+#define luai_numadd(a,b) ((a)+(b))
509+#define luai_numsub(a,b) ((a)-(b))
510+#define luai_nummul(a,b) ((a)*(b))
511+#define luai_numdiv(a,b) ((a)/(b))
512+#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
513+#define luai_numpow(a,b) pow(a,b)
514+#define luai_numunm(a) (-(a))
515+#define luai_numeq(a,b) ((a)==(b))
516+#define luai_numlt(a,b) ((a)<(b))
517+#define luai_numle(a,b) ((a)<=(b))
318518
319−#endif
519+/* }================================================================== */
320520
321−/* }====================================================== */
322521
522+/*
523+@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
524+** CHANGE it if your system requires alignments larger than double. (For
525+** instance, if your system supports long doubles and they must be
526+** aligned in 16-byte boundaries, then you should add long double in the
527+** union.) Probably you do not need to change this.
528+*/
529+#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
323530
324531
325532 /*
326−** {======================================================
327−** Library configuration
328−** =======================================================
533+@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
534+** CHANGE them if you prefer to use longjmp/setjmp even with C++ or
535+** if want/don't want to use _longjmp/_setjmp instead of regular
536+** longjmp/setjmp. By default, Lua handles errors with exceptions when
537+** compiling as C++ code, with _longjmp/_setjmp when compiling as C code
538+** in a Unix system, and with longjmp/setjmp otherwise.
329539 */
540+#if defined(__cplusplus)
541+/* C++ exceptions */
542+#define LUAI_THROW(L,c) throw(c)
543+#define LUAI_TRY(L,c,a) try { a } catch(...) \
544+ { if ((c)->status == 0) (c)->status = -1; }
545+#define luai_jmpbuf int /* dummy variable */
330546
331−#ifdef LUA_LIB
547+#elif !defined(__STRICT_ANSI__) && (defined(unix) || defined(__unix) || \
548+ defined(__unix__))
549+/* in Unix, try _longjmp/_setjmp (more efficient) */
550+#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
551+#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
552+#define luai_jmpbuf jmp_buf
332553
554+#else
555+/* default handling with long jumps */
556+#define LUAI_THROW(L,c) longjmp((c)->b, 1)
557+#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
558+#define luai_jmpbuf jmp_buf
333559
334−/* environment variables that hold the search path for packages */
335−#define LUA_PATH "LUA_PATH"
336−#define LUA_CPATH "LUA_CPATH"
560+#endif
337561
338−/* prefix for open functions in C libraries */
339−#define LUA_POF "luaopen_"
340562
341−/* separator for open functions in C libraries */
342−#define LUA_OFSEP "_"
563+/*
564+@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
565+@* can do during pattern-matching.
566+** CHANGE it if you need more captures. This limit is arbitrary.
567+*/
568+#define LUA_MAXCAPTURES 32
343569
344−/* directory separator (for submodules) */
345−#if defined(_WIN32)
346−#define LUA_DIRSEP "\\"
570+
571+/*
572+@@ lua_tmpnam is the function that the OS library uses to create a
573+@* temporary name.
574+@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
575+** CHANGE them if you have an alternative to tmpnam (which is considered
576+** insecure) or if you want the original tmpnam anyway. By default, Lua
577+** uses tmpnam except when POSIX is available, where it uses mkstemp.
578+*/
579+#if defined(loslib_c) || defined(luaall_c)
580+
581+#if !defined(__STRICT_ANSI__) && defined(_POSIX_C_SOURCE)
582+#include <unistd.h>
583+#define LUA_TMPNAMBUFSIZE 32
584+#define lua_tmpnam(b,e) { \
585+ strcpy(b, "/tmp/lua_XXXXXX"); \
586+ e = mkstemp(b); \
587+ if (e != -1) close(e); \
588+ e = (e == -1); }
347589 #else
348−#define LUA_DIRSEP "/"
590+#define LUA_TMPNAMBUFSIZE L_tmpnam
591+#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
349592 #endif
350593
351−/* separator of templates in a path */
352−#define LUA_PATHSEP ';'
594+#endif
353595
354−/* wild char in each template */
355−#define LUA_PATH_MARK "?"
596+/*
597+@@ LUA_DL_* define which dynamic-library system Lua should use.
598+** CHANGE here if Lua has problems choosing the appropriate
599+** dynamic-library system for your platform (either Windows' DLL, Mac's
600+** dyld, or Unix's dlopen). If your system is some kind of Unix, there
601+** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
602+** it. To use dlopen you also need to adapt the src/Makefile (probably
603+** adding -ldl to the linker options), so Lua does not select it
604+** automatically. (When you change the makefile to add -ldl, you must
605+** also add -DLUA_USE_DLOPEN.)
606+** If you do not want any kind of dynamic library, undefine all these
607+** options (or just remove these definitions).
608+*/
609+#if !defined(__STRICT_ANSI__)
610+#if defined(_WIN32)
611+#define LUA_DL_DLL
612+#elif defined(__APPLE__) && defined(__MACH__)
613+#define LUA_DL_DYLD
614+#elif defined(LUA_USE_DLOPEN)
615+#define LUA_DL_DLOPEN
616+#endif
617+#endif
356618
357619
358−/* maximum number of captures in pattern-matching (arbitrary limit) */
359−#define MAX_CAPTURES 32
620+/*
621+@@ lua_lock/lua_unlock are macros for thread synchronization inside the
622+@* Lua core. This is an attempt to simplify the implementation of a
623+@* multithreaded version of Lua.
624+** CHANGE them only if you know what you are doing. All accesses to
625+** the global state and to global objects are synchronized. Because
626+** threads can read the stack of other threads (when running garbage
627+** collection), a thread must also synchronize any write-access to its
628+** own stack. Unsynchronized accesses are allowed only when reading its
629+** own stack, or when reading immutable fields from global objects (such
630+** as string values and udata values).
631+*/
632+#define lua_lock(L) ((void) 0)
633+#define lua_unlock(L) ((void) 0)
360634
361635
362636 /*
363−** by default, gcc does not get `os.tmpname', because it generates a warning
364−** when using `tmpname'. Change that if you really want (or do not want)
365−** `os.tmpname' available.
637+@@ lua_threadyield allows a thread switch in appropriate places in the core.
638+** CHANGE it only if you know what you are doing. (See lua_lock.)
366639 */
367−#ifdef __GNUC__
368−#define USE_TMPNAME 0
369−#else
370−#define USE_TMPNAME 1
371−#endif
640+#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
372641
373642
374643 /*
375−** Configuration for loadlib: Lua tries to guess the dynamic-library
376−** system that your platform uses (either Windows' DLL, Mac's dyld, or
377−** dlopen). If your system is some kind of Unix, there is a good chance
378−** that USE_DLOPEN will work for it. You may need to adapt also the
379−** makefile.
644+@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
645+@* (the data goes just *before* the lua_State pointer).
646+** CHANGE (define) this if you really need that. This value must be
647+** a multiple of the maximum alignment required for your machine.
380648 */
381−#if defined(_WIN32)
382−#define USE_DLL
383−#elif defined(__APPLE__) && defined(__MACH__)
384−#define USE_DYLD
385−#elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD)
386−#define USE_DLOPEN
387−#endif
649+#define LUAI_EXTRASPACE 0
388650
389651
390−#endif
652+/*
653+@@ luai_userstateopen allows user-specific initialization on new threads.
654+** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that
655+** data whenever a new lua_State is created.
656+*/
657+#define luai_userstateopen(L) ((void)0)
658+
391659
392−/* }====================================================== */
393660
661+/* =================================================================== */
394662
663+/*
664+** Local configuration. You can use this space to add your redefinitions
665+** without modifying the main part of the file.
666+*/
395667
396668
397−/* Local configuration */
398669
399670 #endif
src/lualib.h+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lualib.h,v 1.33 2005/01/10 16:31:30 roberto Exp $
2+** $Id: lualib.h,v 1.34 2005/04/13 17:24:20 roberto Exp $
33 ** Lua standard libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -36,12 +36,12 @@ LUALIB_API int (luaopen_math) (lua_State *L); · 30 unmodified lines
3636 #define LUA_DBLIBNAME "debug"
3737 LUALIB_API int (luaopen_debug) (lua_State *L);
3838
39−
39+#define LUA_LOADLIBNAME "package"
4040 LUALIB_API int (luaopen_loadlib) (lua_State *L);
4141
4242
4343 /* open all previous libraries */
44−LUALIB_API int (luaopen_stdlibs) (lua_State *L);
44+LUALIB_API void (luaL_openlibs) (lua_State *L);
4545
4646
4747 #endif
src/lundump.c+3−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.c,v 1.54 2004/11/25 09:31:41 lhf Exp $
2+** $Id: lundump.c,v 1.55 2005/05/12 00:26:50 lhf Exp $
33 ** load pre-compiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -206,7 +206,8 @@ static Proto* LoadFunction (LoadState* S, TString* p) · 200 unmodified lines
206206 Proto* f=luaF_newproto(S->L);
207207 setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
208208 f->source=LoadString(S); if (f->source==NULL) f->source=p;
209− f->lineDefined=LoadInt(S);
209+ f->linedefined=LoadInt(S);
210+ f->lastlinedefined=LoadInt(S);
210211 f->nups=LoadByte(S);
211212 f->numparams=LoadByte(S);
212213 f->is_vararg=LoadByte(S);
src/lundump.h+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.h,v 1.34 2004/11/25 09:31:41 lhf Exp $
2+** $Id: lundump.h,v 1.35 2005/05/12 00:26:50 lhf Exp $
33 ** load pre-compiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -11,16 +11,16 @@ · 5 unmodified lines
1111 #include "lzio.h"
1212
1313 /* load one chunk; from lundump.c */
14−Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char *name);
14+LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char *name);
1515
1616 /* find byte order; from lundump.c */
17−int luaU_endianness (void);
17+LUAI_FUNC int luaU_endianness (void);
1818
1919 /* dump one chunk; from ldump.c */
20−int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int strip);
20+LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int strip);
2121
2222 /* print one chunk; from print.c */
23−void luaU_print (const Proto* f, int full);
23+LUAI_FUNC void luaU_print (const Proto* f, int full);
2424
2525 /* for header of binary files -- this is Lua 5.1 */
2626 #define VERSION 0x51
src/lvm.c+179−179
@@ -1,10 +1,12 @@
11 /*
2−** $Id: lvm.c,v 2.26 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lvm.c,v 2.44 2005/05/17 19:49:15 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
66
77
8+#include <math.h>
9+#include <stdio.h>
810 #include <stdlib.h>
911 #include <string.h>
1012
@@ -47,8 +49,9 @@ int luaV_tostring (lua_State *L, StkId obj) { · 36 unmodified lines
4749 if (!ttisnumber(obj))
4850 return 0;
4951 else {
50− char s[MAX_NUMBER2STR];
51− lua_number2str(s, nvalue(obj));
52+ char s[LUAI_MAXNUMBER2STR];
53+ lua_Number n = nvalue(obj);
54+ lua_number2str(s, n);
5255 setsvalue2s(L, obj, luaS_new(L, s));
5356 return 1;
5457 }
@@ -57,9 +60,8 @@ int luaV_tostring (lua_State *L, StkId obj) { · 2 unmodified lines
5760
5861 static void traceexec (lua_State *L, const Instruction *pc) {
5962 lu_byte mask = L->hookmask;
60− CallInfo *ci = L->ci;
61− const Instruction *oldpc = ci->savedpc;
62− ci->savedpc = pc;
63+ const Instruction *oldpc = L->savedpc;
64+ L->savedpc = pc;
6365 if (mask > LUA_MASKLINE) { /* instruction-hook set? */
6466 if (L->hookcount == 0) {
6567 resethookcount(L);
@@ -68,7 +70,7 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 2 unmodified lines
6870 }
6971 }
7072 if (mask & LUA_MASKLINE) {
71− Proto *p = ci_func(ci)->l.p;
73+ Proto *p = ci_func(L->ci)->l.p;
7274 int npc = pcRel(pc, p);
7375 int newline = getline(p, npc);
7476 /* call linehook when enter a new function, when jump back (loop),
@@ -79,16 +81,12 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 4 unmodified lines
7981 }
8082
8183
82−static void prepTMcall (lua_State *L, const TValue *f,
84+static void callTMres (lua_State *L, StkId res, const TValue *f,
8385 const TValue *p1, const TValue *p2) {
86+ ptrdiff_t result = savestack(L, res);
8487 setobj2s(L, L->top, f); /* push function */
8588 setobj2s(L, L->top+1, p1); /* 1st argument */
8689 setobj2s(L, L->top+2, p2); /* 2nd argument */
87−}
88−
89−
90−static void callTMres (lua_State *L, StkId res) {
91− ptrdiff_t result = savestack(L, res);
9290 luaD_checkstack(L, 3);
9391 L->top += 3;
9492 luaD_call(L, L->top - 3, 1);
@@ -99,15 +97,18 @@ static void callTMres (lua_State *L, StkId res) { · 4 unmodified lines
9997
10098
10199
102−static void callTM (lua_State *L) {
100+static void callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3) {
101+ setobj2s(L, L->top, f); /* push function */
102+ setobj2s(L, L->top+1, p1); /* 1st argument */
103+ setobj2s(L, L->top+2, p2); /* 2nd argument */
104+ setobj2s(L, L->top+3, p3); /* 3th argument */
103105 luaD_checkstack(L, 4);
104106 L->top += 4;
105107 luaD_call(L, L->top - 4, 0);
106108 }
107109
108110
109−StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val,
110− const Instruction *pc) {
111+void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
111112 int loop;
112113 for (loop = 0; loop < MAXTAGLOOP; loop++) {
113114 const TValue *tm;
@@ -117,30 +118,23 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, · 3 unmodified lines
117118 if (!ttisnil(res) || /* result is no nil? */
118119 (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
119120 setobj2s(L, val, res);
120− return L->base;
121+ return;
121122 }
122123 /* else will try the tag method */
123124 }
124− else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) {
125− L->ci->savedpc = pc;
125+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
126126 luaG_typeerror(L, t, "index");
127− }
128127 if (ttisfunction(tm)) {
129− L->ci->savedpc = pc;
130− prepTMcall(L, tm, t, key);
131− callTMres(L, val);
132− return L->base;
128+ callTMres(L, val, tm, t, key);
129+ return;
133130 }
134131 t = tm; /* else repeat with `tm' */
135132 }
136− L->ci->savedpc = pc;
137133 luaG_runerror(L, "loop in gettable");
138− return NULL; /* to avoid warnings */
139134 }
140135
141136
142−StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val,
143− const Instruction *pc) {
137+void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
144138 int loop;
145139 for (loop = 0; loop < MAXTAGLOOP; loop++) {
146140 const TValue *tm;
@@ -151,26 +145,19 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, · 4 unmodified lines
151145 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
152146 setobj2t(L, oldval, val);
153147 luaC_barriert(L, h, val);
154− return L->base;
148+ return;
155149 }
156150 /* else will try the tag method */
157151 }
158− else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) {
159− L->ci->savedpc = pc;
152+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
160153 luaG_typeerror(L, t, "index");
161− }
162154 if (ttisfunction(tm)) {
163− L->ci->savedpc = pc;
164− prepTMcall(L, tm, t, key);
165− setobj2s(L, L->top+3, val); /* 3th argument */
166− callTM(L);
167− return L->base;
155+ callTM(L, tm, t, key, val);
156+ return;
168157 }
169158 t = tm; /* else repeat with `tm' */
170159 }
171− L->ci->savedpc = pc;
172160 luaG_runerror(L, "loop in settable");
173− return NULL; /* to avoid warnings */
174161 }
175162
176163
@@ -180,8 +167,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, · 3 unmodified lines
180167 if (ttisnil(tm))
181168 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
182169 if (!ttisfunction(tm)) return 0;
183− prepTMcall(L, tm, p1, p2);
184− callTMres(L, res);
170+ callTMres(L, res, tm, p1, p2);
185171 return 1;
186172 }
187173
@@ -208,8 +194,7 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, · 20 unmodified lines
208194 tm2 = luaT_gettmbyobj(L, p2, event);
209195 if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */
210196 return -1;
211− prepTMcall(L, tm1, p1, p2);
212− callTMres(L, L->top);
197+ callTMres(L, L->top, tm1, p1, p2);
213198 return !l_isfalse(L->top);
214199 }
215200
@@ -241,7 +226,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 25 unmodified lines
241226 if (ttype(l) != ttype(r))
242227 return luaG_ordererror(L, l, r);
243228 else if (ttisnumber(l))
244− return num_lt(nvalue(l), nvalue(r));
229+ return luai_numlt(nvalue(l), nvalue(r));
245230 else if (ttisstring(l))
246231 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
247232 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
@@ -255,7 +240,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { · 7 unmodified lines
255240 if (ttype(l) != ttype(r))
256241 return luaG_ordererror(L, l, r);
257242 else if (ttisnumber(l))
258− return num_le(nvalue(l), nvalue(r));
243+ return luai_numle(nvalue(l), nvalue(r));
259244 else if (ttisstring(l))
260245 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
261246 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
@@ -271,7 +256,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { · 9 unmodified lines
271256 lua_assert(ttype(t1) == ttype(t2));
272257 switch (ttype(t1)) {
273258 case LUA_TNIL: return 1;
274− case LUA_TNUMBER: return num_eq(nvalue(t1), nvalue(t2));
259+ case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
275260 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
276261 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
277262 case LUA_TUSERDATA: {
@@ -288,8 +273,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { · 10 unmodified lines
288273 default: return gcvalue(t1) == gcvalue(t2);
289274 }
290275 if (tm == NULL) return 0; /* no TM? */
291− prepTMcall(L, tm, t1, t2);
292− callTMres(L, L->top); /* call TM */
276+ callTMres(L, L->top, tm, t1, t2); /* call TM */
293277 return !l_isfalse(L->top);
294278 }
295279
@@ -328,18 +312,19 @@ void luaV_concat (lua_State *L, int total, int last) { · 32 unmodified lines
328312
329313
330314 static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
331− const TValue *rc, TMS op, const Instruction *pc) {
315+ const TValue *rc, TMS op) {
332316 TValue tempb, tempc;
333317 const TValue *b, *c;
334− L->ci->savedpc = pc;
335318 if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
336319 (c = luaV_tonumber(rc, &tempc)) != NULL) {
320+ lua_Number nb = nvalue(b), nc = nvalue(c);
337321 switch (op) {
338− case TM_ADD: setnvalue(ra, num_add(nvalue(b), nvalue(c))); break;
339− case TM_SUB: setnvalue(ra, num_sub(nvalue(b), nvalue(c))); break;
340− case TM_MUL: setnvalue(ra, num_mul(nvalue(b), nvalue(c))); break;
341− case TM_DIV: setnvalue(ra, num_div(nvalue(b), nvalue(c))); break;
342− case TM_POW: setnvalue(ra, num_pow(nvalue(b), nvalue(c))); break;
322+ case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
323+ case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
324+ case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
325+ case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
326+ case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
327+ case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
343328 default: lua_assert(0); break;
344329 }
345330 }
@@ -354,7 +339,7 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, · 8 unmodified lines
354339 ** some macros for common tasks in `luaV_execute'
355340 */
356341
357−#define runtime_check(L, c) { if (!(c)) return 0; }
342+#define runtime_check(L, c) { if (!(c)) break; }
358343
359344 #define RA(i) (base+GETARG_A(i))
360345 /* to be used after possible stack reallocation */
@@ -367,19 +352,22 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, · 6 unmodified lines
367352 #define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
368353
369354
370−#define dojump(L,pc,i) {(pc) += (i); lua_threadyield(L);}
355+#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);}
356+
357+
358+#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }
371359
372360
373361 StkId luaV_execute (lua_State *L, int nexeccalls) {
374362 LClosure *cl;
375− TValue *k;
376363 StkId base;
364+ TValue *k;
377365 const Instruction *pc;
378366 callentry: /* entry point when calling new functions */
379367 if (L->hookmask & LUA_MASKCALL)
380368 luaD_callhook(L, LUA_HOOKCALL, -1);
381369 retentry: /* entry point when returning to old functions */
382− pc = L->ci->savedpc;
370+ pc = L->savedpc;
383371 cl = &clvalue(L->ci->func)->l;
384372 base = L->base;
385373 k = cl->p->k;
@@ -389,16 +377,16 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines
389377 StkId ra;
390378 if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
391379 (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
392− traceexec(L, pc); /***/
380+ traceexec(L, pc);
393381 if (L->status == LUA_YIELD) { /* did hook yield? */
394− L->ci->savedpc = pc - 1;
382+ L->savedpc = pc - 1;
395383 return NULL;
396384 }
397385 base = L->base;
398386 }
399387 /* warning!! several calls may realloc the stack and invalidate `ra' */
400388 ra = RA(i);
401− lua_assert(base == L->ci->base && base == L->base);
389+ lua_assert(base == L->base && L->base == L->ci->base);
402390 lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
403391 lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
404392 switch (GET_OPCODE(i)) {
@@ -432,18 +420,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 27 unmodified lines
432420 TValue *rb = KBx(i);
433421 sethvalue(L, &g, cl->env);
434422 lua_assert(ttisstring(rb));
435− base = luaV_gettable(L, &g, rb, ra, pc); /***/
423+ Protect(luaV_gettable(L, &g, rb, ra));
436424 continue;
437425 }
438426 case OP_GETTABLE: {
439− base = luaV_gettable(L, RB(i), RKC(i), ra, pc); /***/
427+ Protect(luaV_gettable(L, RB(i), RKC(i), ra));
440428 continue;
441429 }
442430 case OP_SETGLOBAL: {
443431 TValue g;
444432 sethvalue(L, &g, cl->env);
445433 lua_assert(ttisstring(KBx(i)));
446− base = luaV_settable(L, &g, KBx(i), ra, pc); /***/
434+ Protect(luaV_settable(L, &g, KBx(i), ra));
447435 continue;
448436 }
449437 case OP_SETUPVAL: {
@@ -453,86 +441,101 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines
453441 continue;
454442 }
455443 case OP_SETTABLE: {
456− base = luaV_settable(L, ra, RKB(i), RKC(i), pc); /***/
444+ Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
457445 continue;
458446 }
459447 case OP_NEWTABLE: {
460448 int b = GETARG_B(i);
461449 int c = GETARG_C(i);
462450 sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
463− L->ci->savedpc = pc;
464− luaC_checkGC(L); /***/
465− base = L->base;
451+ Protect(luaC_checkGC(L));
466452 continue;
467453 }
468454 case OP_SELF: {
469455 StkId rb = RB(i);
470456 setobjs2s(L, ra+1, rb);
471− base = luaV_gettable(L, rb, RKC(i), ra, pc); /***/
457+ Protect(luaV_gettable(L, rb, RKC(i), ra));
472458 continue;
473459 }
474460 case OP_ADD: {
475461 TValue *rb = RKB(i);
476462 TValue *rc = RKC(i);
477463 if (ttisnumber(rb) && ttisnumber(rc)) {
478− setnvalue(ra, num_add(nvalue(rb), nvalue(rc)));
464+ lua_Number nb = nvalue(rb), nc = nvalue(rc);
465+ setnvalue(ra, luai_numadd(nb, nc));
479466 }
480467 else
481− base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/
468+ Protect(Arith(L, ra, rb, rc, TM_ADD));
482469 continue;
483470 }
484471 case OP_SUB: {
485472 TValue *rb = RKB(i);
486473 TValue *rc = RKC(i);
487474 if (ttisnumber(rb) && ttisnumber(rc)) {
488− setnvalue(ra, num_sub(nvalue(rb), nvalue(rc)));
475+ lua_Number nb = nvalue(rb), nc = nvalue(rc);
476+ setnvalue(ra, luai_numsub(nb, nc));
489477 }
490478 else
491− base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/
479+ Protect(Arith(L, ra, rb, rc, TM_SUB));
492480 continue;
493481 }
494482 case OP_MUL: {
495483 TValue *rb = RKB(i);
496484 TValue *rc = RKC(i);
497485 if (ttisnumber(rb) && ttisnumber(rc)) {
498− setnvalue(ra, num_mul(nvalue(rb), nvalue(rc)));
486+ lua_Number nb = nvalue(rb), nc = nvalue(rc);
487+ setnvalue(ra, luai_nummul(nb, nc));
499488 }
500489 else
501− base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/
490+ Protect(Arith(L, ra, rb, rc, TM_MUL));
502491 continue;
503492 }
504493 case OP_DIV: {
505494 TValue *rb = RKB(i);
506495 TValue *rc = RKC(i);
507496 if (ttisnumber(rb) && ttisnumber(rc)) {
508− setnvalue(ra, num_div(nvalue(rb), nvalue(rc)));
497+ lua_Number nb = nvalue(rb), nc = nvalue(rc);
498+ setnvalue(ra, luai_numdiv(nb, nc));
499+ }
500+ else
501+ Protect(Arith(L, ra, rb, rc, TM_DIV));
502+ continue;
503+ }
504+ case OP_MOD: {
505+ TValue *rb = RKB(i);
506+ TValue *rc = RKC(i);
507+ if (ttisnumber(rb) && ttisnumber(rc)) {
508+ lua_Number nb = nvalue(rb), nc = nvalue(rc);
509+ setnvalue(ra, luai_nummod(nb, nc));
509510 }
510511 else
511− base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/
512+ Protect(Arith(L, ra, rb, rc, TM_MOD));
512513 continue;
513514 }
514515 case OP_POW: {
515516 TValue *rb = RKB(i);
516517 TValue *rc = RKC(i);
517518 if (ttisnumber(rb) && ttisnumber(rc)) {
518− setnvalue(ra, num_pow(nvalue(rb), nvalue(rc)));
519+ lua_Number nb = nvalue(rb), nc = nvalue(rc);
520+ setnvalue(ra, luai_numpow(nb, nc));
519521 }
520522 else
521− base = Arith(L, ra, rb, rc, TM_POW, pc); /***/
523+ Protect(Arith(L, ra, rb, rc, TM_POW));
522524 continue;
523525 }
524526 case OP_UNM: {
525527 const TValue *rb = RB(i);
526528 TValue temp;
527529 if (tonumber(rb, &temp)) {
528− setnvalue(ra, num_unm(nvalue(rb)));
530+ lua_Number nb = nvalue(rb);
531+ setnvalue(ra, luai_numunm(nb));
529532 }
530533 else {
531− setnilvalue(&temp);
532− L->ci->savedpc = pc;
533− if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/
534− luaG_aritherror(L, RB(i), &temp);
535− base = L->base;
534+ rb = RB(i); /* `tonumber' erased `rb' */
535+ Protect(
536+ if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_UNM))
537+ luaG_aritherror(L, rb, &luaO_nilobject);
538+ )
536539 }
537540 continue;
538541 }
@@ -541,13 +544,23 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 2 unmodified lines
541544 setbvalue(ra, res);
542545 continue;
543546 }
547+ case OP_SIZ: {
548+ const TValue *rb = RB(i);
549+ if (ttype(rb) == LUA_TTABLE) {
550+ setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb))));
551+ }
552+ else { /* try metamethod */
553+ Protect(
554+ if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_SIZ))
555+ luaG_typeerror(L, rb, "get size of");
556+ )
557+ }
558+ continue;
559+ }
544560 case OP_CONCAT: {
545561 int b = GETARG_B(i);
546562 int c = GETARG_C(i);
547− L->ci->savedpc = pc;
548− luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/
549− luaC_checkGC(L); /***/
550− base = L->base;
563+ Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
551564 setobjs2s(L, RA(i), base+b);
552565 continue;
553566 }
@@ -556,24 +569,27 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 2 unmodified lines
556569 continue;
557570 }
558571 case OP_EQ: {
559− L->ci->savedpc = pc;
560− if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
561− else dojump(L, pc, GETARG_sBx(*pc) + 1);
562− base = L->base;
572+ Protect(
573+ if (equalobj(L, RKB(i), RKC(i)) == GETARG_A(i))
574+ dojump(L, pc, GETARG_sBx(*pc));
575+ )
576+ pc++;
563577 continue;
564578 }
565579 case OP_LT: {
566− L->ci->savedpc = pc;
567− if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
568− else dojump(L, pc, GETARG_sBx(*pc) + 1);
569− base = L->base;
580+ Protect(
581+ if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
582+ dojump(L, pc, GETARG_sBx(*pc));
583+ )
584+ pc++;
570585 continue;
571586 }
572587 case OP_LE: {
573− L->ci->savedpc = pc;
574− if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/
575− else dojump(L, pc, GETARG_sBx(*pc) + 1);
576− base = L->base;
588+ Protect(
589+ if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
590+ dojump(L, pc, GETARG_sBx(*pc));
591+ )
592+ pc++;
577593 continue;
578594 }
579595 case OP_TEST: {
@@ -585,75 +601,71 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 5 unmodified lines
585601 }
586602 continue;
587603 }
588− case OP_CALL: { /***/
589− int pcr;
604+ case OP_CALL: {
590605 int b = GETARG_B(i);
591606 int nresults = GETARG_C(i) - 1;
592607 if (b != 0) L->top = ra+b; /* else previous instruction set top */
593− L->ci->savedpc = pc;
594− pcr = luaD_precall(L, ra, nresults);
595− if (pcr == PCRLUA) {
596− nexeccalls++;
597− goto callentry; /* restart luaV_execute over new Lua function */
598− }
599− else if (pcr == PCRC) {
600− /* it was a C function (`precall' called it); adjust results */
601− if (nresults >= 0) L->top = L->ci->top;
602− base = L->base;
603− continue;
604− }
605− else {
606− lua_assert(pcr == PCRYIELD);
607− return NULL;
608+ L->savedpc = pc;
609+ switch (luaD_precall(L, ra, nresults)) {
610+ case PCRLUA: {
611+ nexeccalls++;
612+ goto callentry; /* restart luaV_execute over new Lua function */
613+ }
614+ case PCRC: {
615+ /* it was a C function (`precall' called it); adjust results */
616+ if (nresults >= 0) L->top = L->ci->top;
617+ base = L->base;
618+ continue;
619+ }
620+ default: {
621+ return NULL;
622+ }
608623 }
609624 }
610− case OP_TAILCALL: { /***/
611− int pcr;
625+ case OP_TAILCALL: {
612626 int b = GETARG_B(i);
613627 if (b != 0) L->top = ra+b; /* else previous instruction set top */
614− L->ci->savedpc = pc;
628+ L->savedpc = pc;
615629 lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
616− pcr = luaD_precall(L, ra, LUA_MULTRET);
617− if (pcr == PCRLUA) {
618− /* tail call: put new frame in place of previous one */
619− CallInfo *ci = L->ci - 1; /* previous frame */
620− int aux;
621− StkId func = ci->func;
622− StkId pfunc = (ci+1)->func; /* previous function index */
623− if (L->openupval) luaF_close(L, base);
624− base = ci->base = ci->func + ((ci+1)->base - pfunc);
625− L->base = base;
626− for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
627− setobjs2s(L, func+aux, pfunc+aux);
628− ci->top = L->top = func+aux; /* correct top */
629− lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
630− ci->savedpc = L->ci->savedpc;
631− ci->tailcalls++; /* one more call lost */
632− L->ci--; /* remove new frame */
633− goto callentry;
634− }
635− else if (pcr == PCRC) {
636− /* it was a C function (`precall' called it) */
637− base = L->base;
638− continue;
639− }
640− else {
641− lua_assert(pcr == PCRYIELD);
642− return NULL;
630+ switch (luaD_precall(L, ra, LUA_MULTRET)) {
631+ case PCRLUA: {
632+ /* tail call: put new frame in place of previous one */
633+ CallInfo *ci = L->ci - 1; /* previous frame */
634+ int aux;
635+ StkId func = ci->func;
636+ StkId pfunc = (ci+1)->func; /* previous function index */
637+ if (L->openupval) luaF_close(L, ci->base);
638+ L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
639+ for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
640+ setobjs2s(L, func+aux, pfunc+aux);
641+ ci->top = L->top = func+aux; /* correct top */
642+ lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
643+ ci->savedpc = L->savedpc;
644+ ci->tailcalls++; /* one more call lost */
645+ L->ci--; /* remove new frame */
646+ goto callentry;
647+ }
648+ case PCRC: {
649+ /* it was a C function (`precall' called it) */
650+ base = L->base;
651+ continue;
652+ }
653+ default: {
654+ return NULL;
655+ }
643656 }
644657 }
645658 case OP_RETURN: {
646− CallInfo *ci = L->ci - 1; /* previous function frame */
647659 int b = GETARG_B(i);
648660 if (b != 0) L->top = ra+b-1;
649661 if (L->openupval) luaF_close(L, base);
650− L->ci->savedpc = pc;
662+ L->savedpc = pc;
651663 if (--nexeccalls == 0) /* was previous function running `here'? */
652664 return ra; /* no: return */
653665 else { /* yes: continue its execution */
654− int nresults = (ci+1)->nresults;
655− lua_assert(isLua(ci));
656− lua_assert(GET_OPCODE(*(ci->savedpc - 1)) == OP_CALL);
666+ int nresults = L->ci->nresults;
667+ lua_assert(isLua(L->ci - 1));
668+ lua_assert(GET_OPCODE(*((L->ci - 1)->savedpc - 1)) == OP_CALL);
657669 luaD_poscall(L, nresults, ra);
658670 if (nresults >= 0) L->top = L->ci->top;
659671 goto retentry;
@@ -661,27 +673,27 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 1 unmodified line
661673 }
662674 case OP_FORLOOP: {
663675 lua_Number step = nvalue(ra+2);
664− lua_Number idx = num_add(nvalue(ra), step); /* increment index */
676+ lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
665677 lua_Number limit = nvalue(ra+1);
666− if (step > 0 ? num_le(idx, limit) : num_le(limit, idx)) {
678+ if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) {
667679 dojump(L, pc, GETARG_sBx(i)); /* jump back */
668680 setnvalue(ra, idx); /* update internal index... */
669681 setnvalue(ra+3, idx); /* ...and external index */
670682 }
671683 continue;
672684 }
673− case OP_FORPREP: { /***/
685+ case OP_FORPREP: {
674686 const TValue *init = ra;
675687 const TValue *plimit = ra+1;
676688 const TValue *pstep = ra+2;
677− L->ci->savedpc = pc;
689+ L->savedpc = pc; /* next steps may throw errors */
678690 if (!tonumber(init, ra))
679− luaG_runerror(L, "`for' initial value must be a number");
691+ luaG_runerror(L, LUA_QL("for") " initial value must be a number");
680692 else if (!tonumber(plimit, ra+1))
681− luaG_runerror(L, "`for' limit must be a number");
693+ luaG_runerror(L, LUA_QL("for") " limit must be a number");
682694 else if (!tonumber(pstep, ra+2))
683− luaG_runerror(L, "`for' step must be a number");
684− setnvalue(ra, num_sub(nvalue(ra), nvalue(pstep)));
695+ luaG_runerror(L, LUA_QL("for") " step must be a number");
696+ setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
685697 dojump(L, pc, GETARG_sBx(i));
686698 continue;
687699 }
@@ -691,10 +703,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines
691703 setobjs2s(L, cb+1, ra+1);
692704 setobjs2s(L, cb, ra);
693705 L->top = cb+3; /* func. + 2 args (state and index) */
694− L->ci->savedpc = pc;
695− luaD_call(L, cb, GETARG_C(i)); /***/
706+ Protect(luaD_call(L, cb, GETARG_C(i)));
696707 L->top = L->ci->top;
697− base = L->base;
698708 cb = RA(i) + 3; /* previous call may change the stack */
699709 if (ttisnil(cb)) /* break loop? */
700710 pc++; /* skip jump (break loop) */
@@ -704,27 +714,19 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 3 unmodified lines
704714 }
705715 continue;
706716 }
707− case OP_TFORPREP: { /* for compatibility only */
708− if (ttistable(ra)) {
709− setobjs2s(L, ra+1, ra);
710− setobj2s(L, ra, luaH_getstr(hvalue(gt(L)), luaS_new(L, "next")));
711− }
712− dojump(L, pc, GETARG_sBx(i));
713− continue;
714− }
715717 case OP_SETLIST: {
716718 int n = GETARG_B(i);
717719 int c = GETARG_C(i);
718720 int last;
719721 Table *h;
720− runtime_check(L, ttistable(ra));
721− h = hvalue(ra);
722722 if (n == 0) {
723723 n = L->top - ra - 1;
724724 L->top = L->ci->top;
725725 }
726726 if (c == 0) c = cast(int, *pc++);
727− last = ((c-1)*LFIELDS_PER_FLUSH) + n + LUA_FIRSTINDEX - 1;
727+ runtime_check(L, ttistable(ra));
728+ h = hvalue(ra);
729+ last = ((c-1)*LFIELDS_PER_FLUSH) + n;
728730 if (last > h->sizearray) /* needs more space? */
729731 luaH_resizearray(L, h, last); /* pre-alloc it at once */
730732 for (; n > 0; n--) {
@@ -755,9 +757,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { · 24 unmodified lines
755757 }
756758 }
757759 setclvalue(L, ra, ncl);
758− L->ci->savedpc = pc;
759− luaC_checkGC(L); /***/
760− base = L->base;
760+ Protect(luaC_checkGC(L));
761761 continue;
762762 }
763763 case OP_VARARG: {
src/lvm.h+11−11
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.h,v 2.2 2004/05/14 19:25:09 roberto Exp $
2+** $Id: lvm.h,v 2.4 2005/04/25 19:24:10 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -22,15 +22,15 @@ · 16 unmodified lines
2222 (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
2323
2424
25−int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
26−int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
27−const TValue *luaV_tonumber (const TValue *obj, TValue *n);
28−int luaV_tostring (lua_State *L, StkId obj);
29−StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val,
30− const Instruction *pc);
31−StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val,
32− const Instruction *pc);
33−StkId luaV_execute (lua_State *L, int nexeccalls);
34−void luaV_concat (lua_State *L, int total, int last);
25+LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
26+LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
27+LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
28+LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
29+LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
30+ StkId val);
31+LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
32+ StkId val);
33+LUAI_FUNC StkId luaV_execute (lua_State *L, int nexeccalls);
34+LUAI_FUNC void luaV_concat (lua_State *L, int total, int last);
3535
3636 #endif
src/lzio.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lzio.c,v 1.29 2004/04/30 20:13:38 roberto Exp $
2+** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp $
33 ** a generic input stream interface
44 ** See Copyright Notice in lua.h
55 */
@@ -43,7 +43,7 @@ int luaZ_lookahead (ZIO *z) { · 37 unmodified lines
4343 }
4444
4545
46−void luaZ_init (lua_State *L, ZIO *z, lua_Chunkreader reader, void *data) {
46+void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
4747 z->L = L;
4848 z->reader = reader;
4949 z->data = data;
src/lzio.h+10−13
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lzio.h,v 1.19 2003/10/03 16:05:34 roberto Exp $
2+** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $
33 ** Buffered streams
44 ** See Copyright Notice in lua.h
55 */
@@ -17,26 +17,16 @@ · 11 unmodified lines
1717
1818 typedef struct Zio ZIO;
1919
20−
2120 #define char2int(c) cast(int, cast(unsigned char, (c)))
2221
2322 #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
2423
25−void luaZ_init (lua_State *L, ZIO *z, lua_Chunkreader reader, void *data);
26−size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
27−int luaZ_lookahead (ZIO *z);
28−
29−
30−
3124 typedef struct Mbuffer {
3225 char *buffer;
3326 size_t n;
3427 size_t buffsize;
3528 } Mbuffer;
3629
37−
38−char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
39−
4030 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
4131
4232 #define luaZ_buffer(buff) ((buff)->buffer)
@@ -53,18 +43,25 @@ char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); · 10 unmodified lines
5343 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
5444
5545
46+LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
47+LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
48+ void *data);
49+LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
50+LUAI_FUNC int luaZ_lookahead (ZIO *z);
51+
52+
5653
5754 /* --------- Private Part ------------------ */
5855
5956 struct Zio {
6057 size_t n; /* bytes still unread */
6158 const char *p; /* current position in buffer */
62− lua_Chunkreader reader;
59+ lua_Reader reader;
6360 void* data; /* additional data */
6461 lua_State *L; /* Lua state (for reader) */
6562 };
6663
6764
68−int luaZ_fill (ZIO *z);
65+LUAI_FUNC int luaZ_fill (ZIO *z);
6966
7067 #endif
src/print.c+13−20
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.49 2004/11/25 09:31:41 lhf Exp $
2+** $Id: print.c,v 1.50 2005/05/12 00:26:50 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -76,9 +76,6 @@ static void PrintCode(const Proto* f) · 70 unmodified lines
7676 int bx=GETARG_Bx(i);
7777 int sbx=GETARG_sBx(i);
7878 int line=getline(f,pc);
79−#if 0
80− printf("%0*lX",Sizeof(i)*2,i);
81−#endif
8279 printf("\t%d\t",pc+1);
8380 if (line>0) printf("[%d]\t",line); else printf("[-]\t");
8481 printf("%-9s\t",luaP_opnames[o]);
@@ -133,7 +130,6 @@ static void PrintCode(const Proto* f) · 48 unmodified lines
133130 case OP_JMP:
134131 case OP_FORLOOP:
135132 case OP_FORPREP:
136− case OP_TFORPREP:
137133 printf("\t; to %d",sbx+pc+2);
138134 break;
139135 case OP_CLOSURE:
@@ -146,28 +142,25 @@ static void PrintCode(const Proto* f) · 6 unmodified lines
146142 }
147143 }
148144
149−static const char* Source(const Proto* f)
150−{
151− const char* s=getstr(f->source);
152− if (*s=='@' || *s=='=')
153− return s+1;
154− else if (*s==LUA_SIGNATURE[0])
155− return "(bstring)";
156− else
157− return "(string)";
158−}
159−
160145 #define SS(x) (x==1)?"":"s"
161146 #define S(x) x,SS(x)
162147
163148 static void PrintHeader(const Proto* f)
164149 {
165− printf("\n%s <%s:%d> (%d instruction%s, %d bytes at %p)\n",
166− (f->lineDefined==0)?"main":"function",Source(f),f->lineDefined,
150+ const char* s=getstr(f->source);
151+ if (*s=='@' || *s=='=')
152+ s++;
153+ else if (*s==LUA_SIGNATURE[0])
154+ s="(bstring)";
155+ else
156+ s="(string)";
157+ printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
158+ (f->linedefined==0)?"main":"function",s,
159+ f->linedefined,f->lastlinedefined,
167160 S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
168161 printf("%d%s param%s, %d stack%s, %d upvalue%s, ",
169− f->numparams,f->is_vararg?"+":"",SS(f->numparams),S(f->maxstacksize),
170− S(f->nups));
162+ f->numparams,f->is_vararg?"+":"",SS(f->numparams),
163+ S(f->maxstacksize),S(f->nups));
171164 printf("%d local%s, %d constant%s, %d function%s\n",
172165 S(f->sizelocvars),S(f->sizek),S(f->sizep));
173166 }
test/README+0−1
@@ -22,6 +22,5 @@ Here is a one-line summary of each program: · 21 unmodified lines
2222 table.lua make table, grouping all data for the same item
2323 trace-calls.lua trace calls
2424 trace-globals.lua trace assigments to global variables
25− undefined.lua catch "undefined" global variables
2625 xd.lua hex dump
2726
test/luac.lua+2−2
@@ -3,5 +3,5 @@ · 2 unmodified lines
33
44 assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
55 f=assert(io.open("luac.out","wb"))
6−f:write(string.dump(assert(loadfile(arg[1]))))
7−io.close(f)
6+assert(f:write(string.dump(assert(loadfile(arg[1])))))
7+assert(io.close(f))
test/undefined.lua+0−9
@@ -1,9 +0,0 @@
1−-- catch "undefined" global variables
2−
3−local f=function (t,i) error("undefined global variable `"..i.."'",2) end
4−setmetatable(getfenv(),{__index=f})
5−
6−-- an example
7−a=1
8−c=3
9−print(a,b,c) -- `b' is undefined

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