History

Lua 5.1-beta

Lua Team committed 21 years ago

Commit 27f2ec71 parent 573ffb039 files · +1862 −1502Browse files

Unified · Split

39 files
  1. HISTORY +1 −1
  2. INSTALL +3 −1
  3. MANIFEST +107 −107
  4. Makefile +9 −3
  5. README +1 −1
  6. doc/contents.html +272 −1
  7. doc/manual.html +678 −607
  8. src/lapi.c +19 −3
  9. src/lauxlib.c +9 −10
  10. src/lauxlib.h +2 −1
  11. src/lbaselib.c +29 −19
  12. src/lcode.c +161 −118
  13. src/lcode.h +3 −5
  14. src/ldblib.c +9 −2
  15. src/ldebug.c +27 −28
  16. src/ldo.c +9 −7
  17. src/ldump.c +24 −29
  18. src/liolib.c +3 −3
  19. src/llex.c +16 −24
  20. src/loadlib.c +13 −12
  21. src/lobject.c +2 −2
  22. src/lobject.h +2 −2
  23. src/lopcodes.c +2 −4
  24. src/lopcodes.h +5 −5
  25. src/loslib.c +3 −3
  26. src/lparser.c +22 −21
  27. src/lparser.h +6 −2
  28. src/lstate.c +6 −4
  29. src/lstrlib.c +75 −58
  30. src/ltable.c +5 −5
  31. src/ltablib.c +40 −18
  32. src/lua.c +96 −90
  33. src/lua.h +7 −5
  34. src/luac.c +7 −12
  35. src/luaconf.h +95 −73
  36. src/lundump.c +41 −108
  37. src/lundump.h +4 −30
  38. src/lvm.c +43 −75
  39. src/print.c +6 −3
HISTORY+1−1
@@ -1,4 +1,4 @@
1−This is Lua 5.1 (alpha).
1+This is Lua 5.1 (beta).
22
33 * Changes from version 5.0 to 5.1
44 -------------------------------
INSTALL+3−1
@@ -1,10 +1,12 @@
1−This is Lua 5.1 (alpha).
1+This is Lua 5.1 (beta).
22
33 * Installation
44 ------------
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+ There are also special make targets for ansi, linux, bsd, mingw.
9+
810 See below for customization instructions.
911
1012 If you want to install Lua in an official place in your system, then
MANIFEST+107−107
@@ -1,108 +1,108 @@
1−MANIFEST contents of Lua 5.1 (alpha) distribution on Fri Sep 9 16:55:12 BRST 2005
2−lua-5.1-alpha
3−lua-5.1-alpha/COPYRIGHT
4−lua-5.1-alpha/HISTORY
5−lua-5.1-alpha/INSTALL
6−lua-5.1-alpha/MANIFEST
7−lua-5.1-alpha/Makefile
8−lua-5.1-alpha/README
9−lua-5.1-alpha/doc
10−lua-5.1-alpha/doc/contents.html
11−lua-5.1-alpha/doc/logo.gif
12−lua-5.1-alpha/doc/lua.1
13−lua-5.1-alpha/doc/lua.css
14−lua-5.1-alpha/doc/lua.html
15−lua-5.1-alpha/doc/luac.1
16−lua-5.1-alpha/doc/luac.html
17−lua-5.1-alpha/doc/manual.html
18−lua-5.1-alpha/doc/readme.html
19−lua-5.1-alpha/etc
20−lua-5.1-alpha/etc/Makefile
21−lua-5.1-alpha/etc/README
22−lua-5.1-alpha/etc/all.c
23−lua-5.1-alpha/etc/lua.hpp
24−lua-5.1-alpha/etc/lua.ico
25−lua-5.1-alpha/etc/lua.pc
26−lua-5.1-alpha/etc/luavs.bat
27−lua-5.1-alpha/etc/min.c
28−lua-5.1-alpha/etc/noparser.c
29−lua-5.1-alpha/etc/strict.lua
30−lua-5.1-alpha/src
31−lua-5.1-alpha/src/Makefile
32−lua-5.1-alpha/src/lapi.c
33−lua-5.1-alpha/src/lapi.h
34−lua-5.1-alpha/src/lauxlib.c
35−lua-5.1-alpha/src/lauxlib.h
36−lua-5.1-alpha/src/lbaselib.c
37−lua-5.1-alpha/src/lcode.c
38−lua-5.1-alpha/src/lcode.h
39−lua-5.1-alpha/src/ldblib.c
40−lua-5.1-alpha/src/ldebug.c
41−lua-5.1-alpha/src/ldebug.h
42−lua-5.1-alpha/src/ldo.c
43−lua-5.1-alpha/src/ldo.h
44−lua-5.1-alpha/src/ldump.c
45−lua-5.1-alpha/src/lfunc.c
46−lua-5.1-alpha/src/lfunc.h
47−lua-5.1-alpha/src/lgc.c
48−lua-5.1-alpha/src/lgc.h
49−lua-5.1-alpha/src/linit.c
50−lua-5.1-alpha/src/liolib.c
51−lua-5.1-alpha/src/llex.c
52−lua-5.1-alpha/src/llex.h
53−lua-5.1-alpha/src/llimits.h
54−lua-5.1-alpha/src/lmathlib.c
55−lua-5.1-alpha/src/lmem.c
56−lua-5.1-alpha/src/lmem.h
57−lua-5.1-alpha/src/loadlib.c
58−lua-5.1-alpha/src/lobject.c
59−lua-5.1-alpha/src/lobject.h
60−lua-5.1-alpha/src/lopcodes.c
61−lua-5.1-alpha/src/lopcodes.h
62−lua-5.1-alpha/src/loslib.c
63−lua-5.1-alpha/src/lparser.c
64−lua-5.1-alpha/src/lparser.h
65−lua-5.1-alpha/src/lstate.c
66−lua-5.1-alpha/src/lstate.h
67−lua-5.1-alpha/src/lstring.c
68−lua-5.1-alpha/src/lstring.h
69−lua-5.1-alpha/src/lstrlib.c
70−lua-5.1-alpha/src/ltable.c
71−lua-5.1-alpha/src/ltable.h
72−lua-5.1-alpha/src/ltablib.c
73−lua-5.1-alpha/src/ltm.c
74−lua-5.1-alpha/src/ltm.h
75−lua-5.1-alpha/src/lua.c
76−lua-5.1-alpha/src/lua.h
77−lua-5.1-alpha/src/luac.c
78−lua-5.1-alpha/src/luaconf.h
79−lua-5.1-alpha/src/lualib.h
80−lua-5.1-alpha/src/lundump.c
81−lua-5.1-alpha/src/lundump.h
82−lua-5.1-alpha/src/lvm.c
83−lua-5.1-alpha/src/lvm.h
84−lua-5.1-alpha/src/lzio.c
85−lua-5.1-alpha/src/lzio.h
86−lua-5.1-alpha/src/print.c
87−lua-5.1-alpha/test
88−lua-5.1-alpha/test/README
89−lua-5.1-alpha/test/bisect.lua
90−lua-5.1-alpha/test/cf.lua
91−lua-5.1-alpha/test/echo.lua
92−lua-5.1-alpha/test/env.lua
93−lua-5.1-alpha/test/factorial.lua
94−lua-5.1-alpha/test/fib.lua
95−lua-5.1-alpha/test/fibfor.lua
96−lua-5.1-alpha/test/globals.lua
97−lua-5.1-alpha/test/hello.lua
98−lua-5.1-alpha/test/life.lua
99−lua-5.1-alpha/test/luac.lua
100−lua-5.1-alpha/test/printf.lua
101−lua-5.1-alpha/test/readonly.lua
102−lua-5.1-alpha/test/sieve.lua
103−lua-5.1-alpha/test/sort.lua
104−lua-5.1-alpha/test/table.lua
105−lua-5.1-alpha/test/trace-calls.lua
106−lua-5.1-alpha/test/trace-globals.lua
107−lua-5.1-alpha/test/xd.lua
1+MANIFEST contents of Lua 5.1 (beta) distribution on Fri Nov 18 07:42:23 BRST 2005
2+lua-5.1-beta
3+lua-5.1-beta/COPYRIGHT
4+lua-5.1-beta/HISTORY
5+lua-5.1-beta/INSTALL
6+lua-5.1-beta/MANIFEST
7+lua-5.1-beta/Makefile
8+lua-5.1-beta/README
9+lua-5.1-beta/doc
10+lua-5.1-beta/doc/contents.html
11+lua-5.1-beta/doc/logo.gif
12+lua-5.1-beta/doc/lua.1
13+lua-5.1-beta/doc/lua.css
14+lua-5.1-beta/doc/lua.html
15+lua-5.1-beta/doc/luac.1
16+lua-5.1-beta/doc/luac.html
17+lua-5.1-beta/doc/manual.html
18+lua-5.1-beta/doc/readme.html
19+lua-5.1-beta/etc
20+lua-5.1-beta/etc/Makefile
21+lua-5.1-beta/etc/README
22+lua-5.1-beta/etc/all.c
23+lua-5.1-beta/etc/lua.hpp
24+lua-5.1-beta/etc/lua.ico
25+lua-5.1-beta/etc/lua.pc
26+lua-5.1-beta/etc/luavs.bat
27+lua-5.1-beta/etc/min.c
28+lua-5.1-beta/etc/noparser.c
29+lua-5.1-beta/etc/strict.lua
30+lua-5.1-beta/src
31+lua-5.1-beta/src/Makefile
32+lua-5.1-beta/src/lapi.c
33+lua-5.1-beta/src/lapi.h
34+lua-5.1-beta/src/lauxlib.c
35+lua-5.1-beta/src/lauxlib.h
36+lua-5.1-beta/src/lbaselib.c
37+lua-5.1-beta/src/lcode.c
38+lua-5.1-beta/src/lcode.h
39+lua-5.1-beta/src/ldblib.c
40+lua-5.1-beta/src/ldebug.c
41+lua-5.1-beta/src/ldebug.h
42+lua-5.1-beta/src/ldo.c
43+lua-5.1-beta/src/ldo.h
44+lua-5.1-beta/src/ldump.c
45+lua-5.1-beta/src/lfunc.c
46+lua-5.1-beta/src/lfunc.h
47+lua-5.1-beta/src/lgc.c
48+lua-5.1-beta/src/lgc.h
49+lua-5.1-beta/src/linit.c
50+lua-5.1-beta/src/liolib.c
51+lua-5.1-beta/src/llex.c
52+lua-5.1-beta/src/llex.h
53+lua-5.1-beta/src/llimits.h
54+lua-5.1-beta/src/lmathlib.c
55+lua-5.1-beta/src/lmem.c
56+lua-5.1-beta/src/lmem.h
57+lua-5.1-beta/src/loadlib.c
58+lua-5.1-beta/src/lobject.c
59+lua-5.1-beta/src/lobject.h
60+lua-5.1-beta/src/lopcodes.c
61+lua-5.1-beta/src/lopcodes.h
62+lua-5.1-beta/src/loslib.c
63+lua-5.1-beta/src/lparser.c
64+lua-5.1-beta/src/lparser.h
65+lua-5.1-beta/src/lstate.c
66+lua-5.1-beta/src/lstate.h
67+lua-5.1-beta/src/lstring.c
68+lua-5.1-beta/src/lstring.h
69+lua-5.1-beta/src/lstrlib.c
70+lua-5.1-beta/src/ltable.c
71+lua-5.1-beta/src/ltable.h
72+lua-5.1-beta/src/ltablib.c
73+lua-5.1-beta/src/ltm.c
74+lua-5.1-beta/src/ltm.h
75+lua-5.1-beta/src/lua.c
76+lua-5.1-beta/src/lua.h
77+lua-5.1-beta/src/luac.c
78+lua-5.1-beta/src/luaconf.h
79+lua-5.1-beta/src/lualib.h
80+lua-5.1-beta/src/lundump.c
81+lua-5.1-beta/src/lundump.h
82+lua-5.1-beta/src/lvm.c
83+lua-5.1-beta/src/lvm.h
84+lua-5.1-beta/src/lzio.c
85+lua-5.1-beta/src/lzio.h
86+lua-5.1-beta/src/print.c
87+lua-5.1-beta/test
88+lua-5.1-beta/test/README
89+lua-5.1-beta/test/bisect.lua
90+lua-5.1-beta/test/cf.lua
91+lua-5.1-beta/test/echo.lua
92+lua-5.1-beta/test/env.lua
93+lua-5.1-beta/test/factorial.lua
94+lua-5.1-beta/test/fib.lua
95+lua-5.1-beta/test/fibfor.lua
96+lua-5.1-beta/test/globals.lua
97+lua-5.1-beta/test/hello.lua
98+lua-5.1-beta/test/life.lua
99+lua-5.1-beta/test/luac.lua
100+lua-5.1-beta/test/printf.lua
101+lua-5.1-beta/test/readonly.lua
102+lua-5.1-beta/test/sieve.lua
103+lua-5.1-beta/test/sort.lua
104+lua-5.1-beta/test/table.lua
105+lua-5.1-beta/test/trace-calls.lua
106+lua-5.1-beta/test/trace-globals.lua
107+lua-5.1-beta/test/xd.lua
108108 END OF MANIFEST
Makefile+9−3
@@ -55,15 +55,21 @@ ansi: · 54 unmodified lines
5555 cd src; $(MAKE) MYCFLAGS=-DLUA_ANSI
5656
5757 linux:
58− cd src; $(MAKE) MYCFLAGS=-DLUA_USE_DLOPEN MYLIBS="-Wl,-E -ldl"
58+ cd src; $(MAKE) MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
59+
60+macosx:
61+ cd src; $(MAKE) MYCFLAGS=-DLUA_USE_MACOSX
62+
63+posix:
64+ cd src; $(MAKE) MYCFLAGS=-DLUA_USE_POSIX
5965
6066 bsd:
61− cd src; $(MAKE) MYCFLAGS=-DLUA_USE_DLOPEN MYLIBS="-Wl,-E"
67+ cd src; $(MAKE) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
6268
6369 mingw:
6470 cd src; $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
6571 "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \
66− "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" MYLDFLAGS=-s" lua.exe
72+ "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
6773
6874 # echo config parameters
6975 echo:
README+1−1
@@ -1,4 +1,4 @@
1−This is Lua 5.1 (alpha).
1+This is Lua 5.1 (beta).
22 See HISTORY for a summary of changes since the last released version.
33
44 * What is Lua?
doc/contents.html+272−1
@@ -19,6 +19,7 @@ Lua 5.1 Reference Manual · 18 unmodified lines
1919 <HR>
2020
2121 <UL>
22+<LI><A HREF="#words">Word index</A>
2223 <LI><A HREF="manual.html">Top</A>
2324 <LI><A HREF="manual.html#1">1 - Introduction</A>
2425 <LI><A HREF="manual.html#2">2 - The Language</A>
@@ -93,10 +94,280 @@ Lua 5.1 Reference Manual · 68 unmodified lines
9394 <LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>
9495 </UL>
9596
97+<H3><A NAME="words">Word index</A></H3>
98+
99+<A HREF="manual.html#pdf-_G">_G</A><BR>
100+<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
101+<A HREF="manual.html#pdf-assert">assert</A><BR>
102+<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
103+<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
104+<A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>
105+<A HREF="manual.html#pdf-coroutine.running">coroutine.running</A><BR>
106+<A HREF="manual.html#pdf-coroutine.status">coroutine.status</A><BR>
107+<A HREF="manual.html#pdf-coroutine.wrap">coroutine.wrap</A><BR>
108+<A HREF="manual.html#pdf-coroutine.yield">coroutine.yield</A><BR>
109+<A HREF="manual.html#pdf-debug.debug">debug.debug</A><BR>
110+<A HREF="manual.html#pdf-debug.getfenv">debug.getfenv</A><BR>
111+<A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR>
112+<A HREF="manual.html#pdf-debug.getinfo">debug.getinfo</A><BR>
113+<A HREF="manual.html#pdf-debug.getlocal">debug.getlocal</A><BR>
114+<A HREF="manual.html#pdf-debug.getmetatable">debug.getmetatable</A><BR>
115+<A HREF="manual.html#pdf-debug.getregistry">debug.getregistry</A><BR>
116+<A HREF="manual.html#pdf-debug.getupvalue">debug.getupvalue</A><BR>
117+<A HREF="manual.html#pdf-debug.setfenv">debug.setfenv</A><BR>
118+<A HREF="manual.html#pdf-debug.sethook">debug.sethook</A><BR>
119+<A HREF="manual.html#pdf-debug.setlocal">debug.setlocal</A><BR>
120+<A HREF="manual.html#pdf-debug.setmetatable">debug.setmetatable</A><BR>
121+<A HREF="manual.html#pdf-debug.setupvalue">debug.setupvalue</A><BR>
122+<A HREF="manual.html#pdf-debug.traceback">debug.traceback</A><BR>
123+<A HREF="manual.html#pdf-dofile">dofile</A><BR>
124+<A HREF="manual.html#pdf-error">error</A><BR>
125+<A HREF="manual.html#pdf-file:close">file:close</A><BR>
126+<A HREF="manual.html#pdf-file:flush">file:flush</A><BR>
127+<A HREF="manual.html#pdf-file:lines">file:lines</A><BR>
128+<A HREF="manual.html#pdf-file:read">file:read</A><BR>
129+<A HREF="manual.html#pdf-file:seek">file:seek</A><BR>
130+<A HREF="manual.html#pdf-file:setvbuf">file:setvbuf</A><BR>
131+<A HREF="manual.html#pdf-file:write">file:write</A><BR>
132+<A HREF="manual.html#pdf-getfenv">getfenv</A><BR>
133+<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
134+<A HREF="manual.html#pdf-io.close">io.close</A><BR>
135+<A HREF="manual.html#pdf-io.flush">io.flush</A><BR>
136+<A HREF="manual.html#pdf-io.input">io.input</A><BR>
137+<A HREF="manual.html#pdf-io.lines">io.lines</A><BR>
138+<A HREF="manual.html#pdf-io.open">io.open</A><BR>
139+<A HREF="manual.html#pdf-io.output">io.output</A><BR>
140+<A HREF="manual.html#pdf-io.popen">io.popen</A><BR>
141+<A HREF="manual.html#pdf-io.read">io.read</A><BR>
142+<A HREF="manual.html#pdf-io.tmpfile">io.tmpfile</A><BR>
143+<A HREF="manual.html#pdf-io.type">io.type</A><BR>
144+<A HREF="manual.html#pdf-io.write">io.write</A><BR>
145+<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
146+<A HREF="manual.html#pdf-load">load</A><BR>
147+<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
148+<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
149+
150+<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
151+<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
152+<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>
153+<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR>
154+<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR>
155+<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR>
156+<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR>
157+<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR>
158+<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR>
159+<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR>
160+<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>
161+<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>
162+<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
163+<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>
164+<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>
165+<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>
166+<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>
167+<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR>
168+<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR>
169+<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
170+<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
171+<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
172+<A HREF="manual.html#luaL_error">luaL_error</A><BR>
173+<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
174+<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
175+<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>
176+<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
177+<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
178+<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
179+<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
180+<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
181+<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
182+<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
183+<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>
184+<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
185+<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
186+<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
187+<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
188+<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
189+<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
190+<A HREF="manual.html#luaL_register">luaL_register</A><BR>
191+<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
192+<A HREF="manual.html#luaL_typerror">luaL_typerror</A><BR>
193+<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
194+<A HREF="manual.html#luaL_where">luaL_where</A><BR>
195+<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
196+<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
197+<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
198+<A HREF="manual.html#lua_Hook">lua_Hook</A><BR>
199+<A HREF="manual.html#lua_Integer">lua_Integer</A><BR>
200+<A HREF="manual.html#lua_Number">lua_Number</A><BR>
201+<A HREF="manual.html#lua_Reader">lua_Reader</A><BR>
202+<A HREF="manual.html#lua_State">lua_State</A><BR>
203+<A HREF="manual.html#lua_Writer">lua_Writer</A><BR>
204+<A HREF="manual.html#lua_atpanic">lua_atpanic</A><BR>
205+<A HREF="manual.html#lua_call">lua_call</A><BR>
206+<A HREF="manual.html#lua_checkstack">lua_checkstack</A><BR>
207+<A HREF="manual.html#lua_close">lua_close</A><BR>
208+<A HREF="manual.html#lua_concat">lua_concat</A><BR>
209+<A HREF="manual.html#lua_cpcall">lua_cpcall</A><BR>
210+<A HREF="manual.html#lua_createtable">lua_createtable</A><BR>
211+<A HREF="manual.html#lua_dump">lua_dump</A><BR>
212+<A HREF="manual.html#lua_equal">lua_equal</A><BR>
213+<A HREF="manual.html#lua_error">lua_error</A><BR>
214+<A HREF="manual.html#lua_gc">lua_gc</A><BR>
215+<A HREF="manual.html#lua_getallocf">lua_getallocf</A><BR>
216+<A HREF="manual.html#lua_getfenv">lua_getfenv</A><BR>
217+<A HREF="manual.html#lua_getfield">lua_getfield</A><BR>
218+<A HREF="manual.html#lua_gethook">lua_gethook</A><BR>
219+<A HREF="manual.html#lua_gethookcount">lua_gethookcount</A><BR>
220+<A HREF="manual.html#lua_gethookmask">lua_gethookmask</A><BR>
221+<A HREF="manual.html#lua_getinfo">lua_getinfo</A><BR>
222+<A HREF="manual.html#lua_getlocal">lua_getlocal</A><BR>
223+<A HREF="manual.html#lua_getmetatable">lua_getmetatable</A><BR>
224+<A HREF="manual.html#lua_getstack">lua_getstack</A><BR>
225+<A HREF="manual.html#lua_gettable">lua_gettable</A><BR>
226+<A HREF="manual.html#lua_gettop">lua_gettop</A><BR>
227+<A HREF="manual.html#lua_getupvalue">lua_getupvalue</A><BR>
228+<A HREF="manual.html#lua_insert">lua_insert</A><BR>
229+<A HREF="manual.html#lua_isboolean">lua_isboolean</A><BR>
230+<A HREF="manual.html#lua_iscfunction">lua_iscfunction</A><BR>
231+<A HREF="manual.html#lua_isfunction">lua_isfunction</A><BR>
232+<A HREF="manual.html#lua_islightuserdata">lua_islightuserdata</A><BR>
233+<A HREF="manual.html#lua_isnil">lua_isnil</A><BR>
234+<A HREF="manual.html#lua_isnumber">lua_isnumber</A><BR>
235+<A HREF="manual.html#lua_isstring">lua_isstring</A><BR>
236+<A HREF="manual.html#lua_istable">lua_istable</A><BR>
237+<A HREF="manual.html#lua_isthread">lua_isthread</A><BR>
238+<A HREF="manual.html#lua_isuserdata">lua_isuserdata</A><BR>
239+<A HREF="manual.html#lua_lessthan">lua_lessthan</A><BR>
240+<A HREF="manual.html#lua_load">lua_load</A><BR>
241+<A HREF="manual.html#lua_newstate">lua_newstate</A><BR>
242+<A HREF="manual.html#lua_newtable">lua_newtable</A><BR>
243+<A HREF="manual.html#lua_newthread">lua_newthread</A><BR>
244+<A HREF="manual.html#lua_newuserdata">lua_newuserdata</A><BR>
245+<A HREF="manual.html#lua_next">lua_next</A><BR>
246+<A HREF="manual.html#lua_objlen">lua_objlen</A><BR>
247+<A HREF="manual.html#lua_pcall">lua_pcall</A><BR>
248+<A HREF="manual.html#lua_pop">lua_pop</A><BR>
249+<A HREF="manual.html#lua_pushboolean">lua_pushboolean</A><BR>
250+<A HREF="manual.html#lua_pushcclosure">lua_pushcclosure</A><BR>
251+<A HREF="manual.html#lua_pushcfunction">lua_pushcfunction</A><BR>
252+<A HREF="manual.html#lua_pushfstring">lua_pushfstring</A><BR>
253+<A HREF="manual.html#lua_pushinteger">lua_pushinteger</A><BR>
254+<A HREF="manual.html#lua_pushlightuserdata">lua_pushlightuserdata</A><BR>
255+<A HREF="manual.html#lua_pushlstring">lua_pushlstring</A><BR>
256+<A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR>
257+<A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR>
258+<A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR>
259+<A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR>
260+<A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR>
261+<A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR>
262+<A HREF="manual.html#lua_rawget">lua_rawget</A><BR>
263+<A HREF="manual.html#lua_rawgeti">lua_rawgeti</A><BR>
264+<A HREF="manual.html#lua_rawset">lua_rawset</A><BR>
265+<A HREF="manual.html#lua_rawseti">lua_rawseti</A><BR>
266+<A HREF="manual.html#lua_remove">lua_remove</A><BR>
267+<A HREF="manual.html#lua_replace">lua_replace</A><BR>
268+<A HREF="manual.html#lua_resume">lua_resume</A><BR>
269+<A HREF="manual.html#lua_setallocf">lua_setallocf</A><BR>
270+<A HREF="manual.html#lua_setfenv">lua_setfenv</A><BR>
271+<A HREF="manual.html#lua_setfield">lua_setfield</A><BR>
272+<A HREF="manual.html#lua_sethook">lua_sethook</A><BR>
273+<A HREF="manual.html#lua_setlocal">lua_setlocal</A><BR>
274+<A HREF="manual.html#lua_setmetatable">lua_setmetatable</A><BR>
275+<A HREF="manual.html#lua_settable">lua_settable</A><BR>
276+<A HREF="manual.html#lua_settop">lua_settop</A><BR>
277+<A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>
278+<A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>
279+<A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>
280+<A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>
281+<A HREF="manual.html#lua_tolstring">lua_tolstring</A><BR>
282+<A HREF="manual.html#lua_tonumber">lua_tonumber</A><BR>
283+<A HREF="manual.html#lua_topointer">lua_topointer</A><BR>
284+<A HREF="manual.html#lua_tostring">lua_tostring</A><BR>
285+<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
286+<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
287+<A HREF="manual.html#lua_type">lua_type</A><BR>
288+<A HREF="manual.html#lua_xmove">lua_xmove</A><BR>
289+<A HREF="manual.html#lua_yield">lua_yield</A><BR>
290+
291+<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
292+<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
293+<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
294+<A HREF="manual.html#pdf-math.atan">math.atan</A><BR>
295+<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR>
296+<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR>
297+<A HREF="manual.html#pdf-math.cos">math.cos</A><BR>
298+<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR>
299+<A HREF="manual.html#pdf-math.def">math.def</A><BR>
300+<A HREF="manual.html#pdf-math.exp">math.exp</A><BR>
301+<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>
302+<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>
303+<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
304+<A HREF="manual.html#pdf-math.log">math.log</A><BR>
305+<A HREF="manual.html#pdf-math.log10">math.log10</A><BR>
306+<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>
307+<A HREF="manual.html#pdf-math.sin">math.sin</A><BR>
308+<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR>
309+<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>
310+<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>
311+<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
312+<A HREF="manual.html#pdf-module">module</A><BR>
313+<A HREF="manual.html#pdf-next">next</A><BR>
314+<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
315+<A HREF="manual.html#pdf-os.date">os.date</A><BR>
316+<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
317+<A HREF="manual.html#pdf-os.execute">os.execute</A><BR>
318+<A HREF="manual.html#pdf-os.exit">os.exit</A><BR>
319+<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR>
320+<A HREF="manual.html#pdf-os.remove">os.remove</A><BR>
321+<A HREF="manual.html#pdf-os.rename">os.rename</A><BR>
322+<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR>
323+<A HREF="manual.html#pdf-os.time">os.time</A><BR>
324+<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>
325+<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
326+<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
327+<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>
328+<A HREF="manual.html#pdf-package.path">package.path</A><BR>
329+<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
330+<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>
331+<A HREF="manual.html#pdf-pairs">pairs</A><BR>
332+<A HREF="manual.html#pdf-pcall">pcall</A><BR>
333+<A HREF="manual.html#pdf-print">print</A><BR>
334+<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
335+<A HREF="manual.html#pdf-rawget">rawget</A><BR>
336+<A HREF="manual.html#pdf-rawset">rawset</A><BR>
337+<A HREF="manual.html#pdf-require">require</A><BR>
338+<A HREF="manual.html#pdf-select">select</A><BR>
339+<A HREF="manual.html#pdf-setfenv">setfenv</A><BR>
340+<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>
341+<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
342+<A HREF="manual.html#pdf-string.char">string.char</A><BR>
343+<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
344+<A HREF="manual.html#pdf-string.find">string.find</A><BR>
345+<A HREF="manual.html#pdf-string.format">string.format</A><BR>
346+<A HREF="manual.html#pdf-string.gmatch">string.gmatch</A><BR>
347+<A HREF="manual.html#pdf-string.gsub">string.gsub</A><BR>
348+<A HREF="manual.html#pdf-string.len">string.len</A><BR>
349+<A HREF="manual.html#pdf-string.lower">string.lower</A><BR>
350+<A HREF="manual.html#pdf-string.match">string.match</A><BR>
351+<A HREF="manual.html#pdf-string.rep">string.rep</A><BR>
352+<A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR>
353+<A HREF="manual.html#pdf-string.sub">string.sub</A><BR>
354+<A HREF="manual.html#pdf-string.upper">string.upper</A><BR>
355+<A HREF="manual.html#pdf-table.concat">table.concat</A><BR>
356+<A HREF="manual.html#pdf-table.insert">table.insert</A><BR>
357+<A HREF="manual.html#pdf-table.maxn(table)">table.maxn(table)</A><BR>
358+<A HREF="manual.html#pdf-table.remove">table.remove</A><BR>
359+<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
360+<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
361+<A HREF="manual.html#pdf-tostring">tostring</A><BR>
362+<A HREF="manual.html#pdf-type">type</A><BR>
363+<A HREF="manual.html#pdf-unpack">unpack</A><BR>
364+<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
365+<P>
366+
96367 <HR>
97368 <SMALL>
98369 Last update:
99−Fri Sep 9 14:44:10 BRST 2005
370+Tue Nov 1 15:40:46 BRST 2005
100371 </SMALL>
101372
102373 </BODY>
doc/manual.html+678−607
@@ -1,16 +1,16 @@
1−<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
1+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
22 <html>
33
44 <head>
55 <title>Lua 5.1 Reference Manual</title>
6−<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
6+<link rel="stylesheet" href="lua.css">
77 </head>
88
9−<body BGCOLOR="#FFFFFF">
9+<body bgcolor="#FFFFFF">
1010
11−<hr>
11+<hr/>
1212 <h1>
13−<a href="http://www.lua.org/home.html"><img src="logo.gif" ALT="[Lua logo]" border=0></a>
13+<a href="http://www.lua.org/home.html"><img src="logo.gif" alt="[Lua logo]" border="0"/></a>
1414 Lua 5.1 Reference Manual
1515 </h1>
1616
@@ -20,7 +20,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 3 unmodified lines
2020 <a href="http://www.lua.org/copyright.html">Copyright</a>
2121 &copy; 2005 Lua.org, PUC-Rio. All rights reserved.
2222 </small>
23−<hr>
23+<hr/>
2424
2525 <p>
2626 <p>
@@ -28,7 +28,6 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line
2828
2929
3030
31−<p>
3231 <a name="1"></a><h1>1 - Introduction</h1>
3332
3433 <p>Lua is an extension programming language designed to support
@@ -68,21 +67,21 @@ which are available at Lua's web site. · 33 unmodified lines
6867 <ul>
6968 <li>
7069 R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
71−Lua&mdash;an extensible extension language.
72−<em>Software: Practice &#038; Experience</em> <b>26</b>:6 (1996) 635&ndash;652.
70+Lua---an extensible extension language.
71+<em>Software: Practice &#038; Experience</em> <b>26</b>:6 (1996) 635--652.
7372 <li>
7473 L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
7574 The design and implementation of a language for extending applications.
7675 <em>Proceedings of XXI Brazilian Seminar on Software and Hardware</em>
77−(1994) 273&ndash;283.
76+(1994) 273--283.
7877 <li>
7978 L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
8079 Lua: an extensible embedded language.
81−<em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26&ndash;33.
80+<em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26--33.
8281 <li>
8382 R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
8483 The evolution of an extension language: a history of Lua,
85−<em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14&ndash;B-28.
84+<em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14--B-28.
8685 </ul>
8786
8887 <p>Lua means "moon" in Portuguese and is pronounced LOO-ah.
@@ -119,12 +118,12 @@ can be used in an identifier.) · 30 unmodified lines
119118 <p>The following <em>keywords</em> are reserved
120119 and cannot be used as names:
121120
122−<PRE>
121+<pre>
123122 and break do else elseif
124123 end false for function if
125124 in local nil not or
126125 repeat return then true until while
127−</PRE>
126+</pre>
128127
129128 <p>Lua is a case-sensitive language:
130129 <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>
@@ -134,27 +133,27 @@ uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>) · 3 unmodified lines
134133 are reserved for internal variables used by Lua.
135134
136135 <p>The following strings denote other tokens:
137−<PRE>
136+<pre>
138137 + - * / % ^ #
139138 == ~= &#060;= >= &#060; > =
140139 ( ) { } [ ]
141140 ; : , . .. ...
142−</PRE>
141+</pre>
143142
144143 <p><em>Literal strings</em>
145144 can be delimited by matching single or double quotes,
146145 and can contain the following C-like escape sequences:
147146 <ul>
148−<li><b><code>\a</code></b> &mdash; bell
149−<li><b><code>\b</code></b> &mdash; backspace
150−<li><b><code>\f</code></b> &mdash; form feed
151−<li><b><code>\n</code></b> &mdash; newline
152−<li><b><code>\r</code></b> &mdash; carriage return
153−<li><b><code>\t</code></b> &mdash; horizontal tab
154−<li><b><code>\v</code></b> &mdash; vertical tab
155−<li><b><code>\\</code></b> &mdash; backslash
156−<li><b><code>\"</code></b> &mdash; quotation mark
157−<li><b><code>\'</code></b> &mdash; apostrophe
147+<li><b><code>\a</code></b> --- bell
148+<li><b><code>\b</code></b> --- backspace
149+<li><b><code>\f</code></b> --- form feed
150+<li><b><code>\n</code></b> --- newline
151+<li><b><code>\r</code></b> --- carriage return
152+<li><b><code>\t</code></b> --- horizontal tab
153+<li><b><code>\v</code></b> --- vertical tab
154+<li><b><code>\\</code></b> --- backslash
155+<li><b><code>\"</code></b> --- quotation mark
156+<li><b><code>\'</code></b> --- apostrophe
158157 </ul>
159158 Moreover, a `<code>\</code><em>newline</em>&acute;
160159 (that is, a backslash followed by a real newline)
@@ -188,7 +187,7 @@ As an example, in a system using ASCII · 27 unmodified lines
188187 (in which `<code>a</code>&acute; is coded as 97,
189188 newline is coded as 10, and `<code>1</code>&acute; is coded as 49),
190189 the four literals below denote the same string:
191−<PRE>
190+<pre>
192191 (1) "alo\n123\""
193192 (2) '\97lo\10\04923"'
194193 (3) [[alo
@@ -196,14 +195,14 @@ the four literals below denote the same string: · 1 unmodified line
196195 (4) [==[
197196 alo
198197 123"]==]
199−</PRE>
198+</pre>
200199
201200 <p><em>Numerical constants</em> may be written with an optional decimal part
202201 and an optional decimal exponent.
203202 Examples of valid numerical constants are
204−<PRE>
203+<pre>
205204 3 3.0 3.1416 314.16e-2 0.31416E1
206−</PRE>
205+</pre>
207206
208207 <p><em>Comments</em> start anywhere outside a string with a
209208 double hyphen (<code>--</code>).
@@ -225,11 +224,11 @@ All values carry their own type. · 15 unmodified lines
225224 <em>nil</em>, <em>boolean</em>, <em>number</em>,
226225 <em>string</em>, <em>function</em>, <em>userdata</em>,
227226 <em>thread</em>, and <em>table</em>.
228−<em>Nil</em> is the type of the value <B>nil</B>,
227+<em>Nil</em> is the type of the value <b>nil</b>,
229228 whose main property is to be different from any other value;
230229 usually it represents the absence of a useful value.
231−<em>Boolean</em> is the type of the values <B>false</B> and <B>true</B>.
232−In Lua, both <B>nil</B> and <B>false</B> make a condition false;
230+<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
231+In Lua, both <b>nil</b> and <b>false</b> make a condition false;
233232 any other value makes it true.
234233 <em>Number</em> represents real (double-precision floating-point) numbers.
235234 (It is easy to build Lua interpreters that use other
@@ -266,10 +265,10 @@ and it is used to implement coroutines (see <a href="#coroutine">2.11</a>). · 30 unmodified lines
266265
267266 <p>The type <em>table</em> implements associative arrays,
268267 that is, arrays that can be indexed not only with numbers,
269−but with any value (except <B>nil</B>).
268+but with any value (except <b>nil</b>).
270269 Moreover,
271270 tables can be <em>heterogeneous</em>,
272−that is, they can contain values of all types (except <B>nil</B>).
271+that is, they can contain values of all types (except <b>nil</b>).
273272 Tables are the sole data structuring mechanism in Lua;
274273 they may be used to represent ordinary arrays,
275274 symbol tables, sets, records, graphs, trees, etc.
@@ -280,7 +279,7 @@ There are several convenient ways to create tables in Lua · 4 unmodified lines
280279 (see <a href="#tableconstructor">2.5.7</a>).
281280
282281 <p>Like indices,
283−the value of a table field can be of any type (except <B>nil</B>).
282+the value of a table field can be of any type (except <b>nil</b>).
284283 In particular,
285284 because functions are first class values,
286285 table fields may contain functions.
@@ -327,7 +326,7 @@ Local variables are <em>lexically scoped</em>: · 40 unmodified lines
327326 Local variables can be freely accessed by functions
328327 defined inside their scope (see <a href="#visibility">2.6</a>).
329328
330−<p>Before the first assignment to a variable, its value is <B>nil</B>.
329+<p>Before the first assignment to a variable, its value is <b>nil</b>.
331330
332331 <p>Square brackets are used to index a table:
333332 <pre>
@@ -370,9 +369,9 @@ through the debug library; (see <a href="#libdebug">5.9</a>).) · 36 unmodified lines
370369 <p>An access to a global variable <code>x</code>
371370 is equivalent to <code>_env.x</code>,
372371 which in turn is equivalent to
373−<PRE>
372+<pre>
374373 gettable_event(_env, "x")
375−</PRE>
374+</pre>
376375 where <code>_env</code> is the environment of the running function.
377376 (See <a href="#metatable">2.8</a> for a complete description of the
378377 <code>gettable_event</code> function.
@@ -454,7 +453,7 @@ the list of variables. · 75 unmodified lines
454453 If there are more values than needed,
455454 the excess values are thrown away.
456455 If there are fewer values than needed,
457−the list is extended with as many <B>nil</B>'s as needed.
456+the list is extended with as many <b>nil</b>'s as needed.
458457 If the list of expressions ends with a function call,
459458 then all values returned by that function call enter in the list of values,
460459 before the adjustment
@@ -463,17 +462,17 @@ before the adjustment · 2 unmodified lines
463462 <p>The assignment statement first evaluates all its expressions
464463 and only then are the assignments performed.
465464 Thus the code
466−<PRE>
465+<pre>
467466 i = 3
468467 i, a[i] = i+1, 20
469−</PRE>
468+</pre>
470469 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
471470 because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
472471 before it is assigned 4.
473472 Similarly, the line
474−<PRE>
473+<pre>
475474 x, y = y, x
476−</PRE>
475+</pre>
477476 exchanges the values of <code>x</code> and <code>y</code>.
478477
479478 <p>The meaning of assignments to global variables
@@ -489,9 +488,9 @@ We use it here only for explanatory purposes.) · 9 unmodified lines
489488 is equivalent to the assignment
490489 <code>_env.x = val</code>,
491490 which in turn is equivalent to
492−<PRE>
491+<pre>
493492 settable_event(_env, "x", val)
494−</PRE>
493+</pre>
495494 where <code>_env</code> is the environment of the running function.
496495 (The <code>_env</code> variable is not defined in Lua.
497496 We use it here only for explanatory purposes.)
@@ -512,11 +511,11 @@ Lua also has a <b>for</b> statement, in two flavors (see <a href="#for">2.4.5</a · 14 unmodified lines
512511
513512 <p>The condition expression <em>exp</em> of a
514513 control structure may return any value.
515−Both <B>false</B> and <B>nil</B> are considered false.
516−All values different from <B>nil</B> and <B>false</B> are considered true
514+Both <b>false</b> and <b>nil</b> are considered false.
515+All values different from <b>nil</b> and <b>false</b> are considered true
517516 (in particular, the number 0 and the empty string are also true).
518517
519−<p>In the <b>repeat</b>&ndash;<b>until</b> loop,
518+<p>In the <b>repeat</b>--<b>until</b> loop,
520519 the inner block does not end at the <b>until</b> keyword,
521520 but only after the condition.
522521 That means the condition can refer to local variables
@@ -567,11 +566,11 @@ The <em>block</em> is repeated for <em>name</em> starting at the value of · 44 unmodified lines
567566 the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the
568567 third <em>exp</em>.
569568 More precisely, a <b>for</b> statement like
570−<PRE>
569+<pre>
571570 for var = e1, e2, e3 do block end
572−</PRE>
571+</pre>
573572 is equivalent to the code:
574−<PRE>
573+<pre>
575574 do
576575 local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
577576 if not (_var and _limit and _step) then error() end
@@ -581,7 +580,7 @@ is equivalent to the code: · 3 unmodified lines
581580 _var = _var + _step
582581 end
583582 end
584−</PRE>
583+</pre>
585584 Note the following:
586585 <ul>
587586 <li> All three control expressions are evaluated only once,
@@ -601,17 +600,17 @@ then assign it to another variable before breaking or exiting the loop. · 13 unmodified lines
601600 <p>The generic <b>for</b> statement works over functions,
602601 called <em>iterators</em>.
603602 For each iteration, it calls its iterator function to produce a new value,
604−stopping when the new value is <B>nil</B>.
603+stopping when the new value is <b>nil</b>.
605604 The generic <b>for</b> loop has the following syntax:
606605 <pre>
607606 stat ::= <b>for</b> Name {`<b>,</b>&acute; Name} <b>in</b> explist1 <b>do</b> block <b>end</b>
608607 </pre>
609608 A <b>for</b> statement like
610−<PRE>
609+<pre>
611610 for var_1, ..., var_n in explist do block end
612−</PRE>
611+</pre>
613612 is equivalent to the code:
614−<PRE>
613+<pre>
615614 do
616615 local _f, _s, _var = explist
617616 while true do
@@ -621,7 +620,7 @@ is equivalent to the code: · 3 unmodified lines
621620 block
622621 end
623622 end
624−</PRE>
623+</pre>
625624 Note the following:
626625 <ul>
627626 <li> <code>explist</code> is evaluated only once.
@@ -654,7 +653,7 @@ The declaration may include an initial assignment: · 26 unmodified lines
654653 </pre>
655654 If present, an initial assignment has the same semantics
656655 of a multiple assignment (see <a href="#assignment">2.4.3</a>).
657−Otherwise, all variables are initialized with <B>nil</B>.
656+Otherwise, all variables are initialized with <b>nil</b>.
658657
659658 <p>A chunk is also a block (see <a href="#chunks">2.4.1</a>),
660659 so local variables can be declared in a chunk outside any explicit block.
@@ -668,7 +667,7 @@ The scope of such local variables extends until the end of the chunk. · 7 unmodified lines
668667 The basic expressions in Lua are the following:
669668 <pre>
670669 exp ::= prefixexp
671− exp ::= <b>nil</b> | <b>false</b> | <b>true</b>
670+ exp ::= <b>nil</b> | <b>false</b> | <b>true</b>
672671 exp ::= Number
673672 exp ::= Literal
674673 exp ::= function
@@ -676,7 +675,7 @@ The basic expressions in Lua are the following: · 1 unmodified line
676675 exp ::= `<b>...</b>&acute;
677676 exp ::= exp binop exp
678677 exp ::= unop exp
679− prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
678+ prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
680679 </pre>
681680
682681 <p>Numbers and literal strings are explained in <a href="#lexical">2.1</a>;
@@ -710,7 +709,7 @@ then no adjustment is made, · 27 unmodified lines
710709 unless the call is enclosed in parentheses.
711710
712711 <p>Here are some examples:
713−<PRE>
712+<pre>
714713 f() -- adjusted to 0 results
715714 g(f(), x) -- f() is adjusted to 1 result
716715 g(x, f()) -- g gets x plus all values returned by f()
@@ -726,14 +725,14 @@ unless the call is enclosed in parentheses. · 9 unmodified lines
726725 {f()} -- creates a list with all values returned by f()
727726 {...} -- creates a list with all vararg parameters
728727 {f(), nil} -- f() is adjusted to 1 result
729−</PRE>
728+</pre>
730729
731730 <p>An expression enclosed in parentheses always results in only one value.
732731 Thus,
733732 <code>(f(x,y,z))</code> is always a single value,
734733 even if <code>f</code> returns several values.
735734 (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>
736−or <B>nil</B> if <code>f</code> does not return any values.)
735+or <b>nil</b> if <code>f</code> does not return any values.)
737736
738737 <p><a name="arith"></a><a name="2.5.1"></a><h3>2.5.1 - Arithmetic Operators</h3>
739738 Lua supports the usual arithmetic operators:
@@ -747,21 +746,21 @@ then all operations have the usual meaning. · 7 unmodified lines
747746 Exponentiation works for any exponent.
748747 For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>.
749748 Modulus is defined as
750−<PRE>
749+<pre>
751750 a % b == a - math.floor(a/b)*b
752−</PRE>
751+</pre>
753752 That is, it is the remaining of a division that rounds
754753 the quotient towards minus infinity.
755754
756755 <p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3>
757756 The relational operators in Lua are
758−<PRE>
757+<pre>
759758 == ~= &#060; > &#060;= >=
760−</PRE>
761−These operators always result in <B>false</B> or <B>true</B>.
759+</pre>
760+These operators always result in <b>false</b> or <b>true</b>.
762761
763762 <p>Equality (<code>==</code>) first compares the type of its operands.
764−If the types are different, then the result is <B>false</B>.
763+If the types are different, then the result is <b>false</b>.
765764 Otherwise, the values of the operands are compared.
766765 Numbers and strings are compared in the usual way.
767766 Objects (tables, userdata, threads, and functions)
@@ -775,7 +774,7 @@ using the "eq" metamethod (see <a href="#metatable">2.8</a>). · 7 unmodified lines
775774
776775 <p>The conversion rules of <a href="#coercion">2.2.1</a>
777776 <em>do not</em> apply to equality comparisons.
778−Thus, <code>"0"==0</code> evaluates to <B>false</B>,
777+Thus, <code>"0"==0</code> evaluates to <b>false</b>,
779778 and <code>t[0]</code> and <code>t["0"]</code> denote different
780779 entries in a table.
781780
@@ -792,27 +791,27 @@ metamethod (see <a href="#metatable">2.8</a>). · 10 unmodified lines
792791 <p><a name="logic"></a><a name="2.5.3"></a><h3>2.5.3 - Logical Operators</h3>
793792 The logical operators in Lua are
794793
795−<PRE>
794+<pre>
796795 and or not
797−</PRE>
796+</pre>
798797 Like the control structures (see <a href="#control">2.4.4</a>),
799−all logical operators consider both <B>false</B> and <B>nil</B> as false
798+all logical operators consider both <b>false</b> and <b>nil</b> as false
800799 and anything else as true.
801800
802801
803−<p>The operator <b>not</b> always returns <B>false</B> or <B>true</B>.
802+<p>The operator <b>not</b> always returns <b>false</b> or <b>true</b>.
804803
805804 <p>The conjunction operator <b>and</b> returns its first argument
806−if this value is <B>false</B> or <B>nil</B>;
805+if this value is <b>false</b> or <b>nil</b>;
807806 otherwise, <b>and</b> returns its second argument.
808807 The disjunction operator <b>or</b> returns its first argument
809−if this value is different from <B>nil</B> and <B>false</B>;
808+if this value is different from <b>nil</b> and <b>false</b>;
810809 otherwise, <b>or</b> returns its second argument.
811810 Both <b>and</b> and <b>or</b> use short-cut evaluation,
812811 that is,
813812 the second operand is evaluated only if necessary.
814813 For example,
815−<PRE>
814+<pre>
816815 10 or error() -> 10
817816 nil or "a" -> "a"
818817 nil and 10 -> nil
@@ -820,7 +819,7 @@ For example, · 1 unmodified line
820819 false and nil -> false
821820 false or nil -> nil
822821 10 and 20 -> 20
823−</PRE>
822+</pre>
824823
825824 <p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3>
826825 The string concatenation operator in Lua is
@@ -837,22 +836,22 @@ The length of a string is its number of bytes · 10 unmodified lines
837836 character is one byte).
838837 The length of a table <code>t</code> is defined to be any
839838 integer index <code>n</code>
840−such that <code>t[n]</code> is not <B>nil</B> and <code>t[n+1]</code> is <B>nil</B>;
841−moreover, if <code>t[1]</code> is <B>nil</B>, <code>n</code> may be zero.
839+such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;
840+moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> may be zero.
842841
843842 <p>For a regular array, with non-nil values from 1 to a given <code>n</code>,
844843 its length is exactly that <code>n</code>,
845844 the index of its last value.
846845 If the array has "holes"
847−(that is, <B>nil</B> values between other non-nil values),
848−then <code>#t</code> may be any of the indices that precede a <B>nil</B> value
849−(that is, it may consider any such <B>nil</B> value as the end of
846+(that is, <b>nil</b> values between other non-nil values),
847+then <code>#t</code> may be any of the indices that precede a <b>nil</b> value
848+(that is, it may consider any such <b>nil</b> value as the end of
850849 the array).
851850
852851 <p><a name="2.5.6"></a><h3>2.5.6 - Precedence</h3>
853852 Operator precedence in Lua follows the table below,
854853 from lower to higher priority:
855−<PRE>
854+<pre>
856855 or
857856 and
858857 &#060; > &#060;= >= ~= ==
@@ -861,7 +860,7 @@ from lower to higher priority: · 2 unmodified lines
861860 * / %
862861 not # - (unary)
863862 ^
864−</PRE>
863+</pre>
865864 You can use parentheses to change the precedences of an expression.
866865 The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)
867866 operators are right associative.
@@ -876,8 +875,8 @@ The general syntax for constructors is · 8 unmodified lines
876875 <pre>
877876 tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;
878877 fieldlist ::= field {fieldsep field} [fieldsep]
879− field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp
880− fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
878+ field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp
879+ fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
881880 </pre>
882881
883882 <p>Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry
@@ -889,11 +888,11 @@ Finally, fields of the form <code>exp</code> are equivalent to · 5 unmodified lines
889888 starting with 1.
890889 Fields in the other formats do not affect this counting.
891890 For example,
892−<PRE>
891+<pre>
893892 a = {[f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45}
894−</PRE>
893+</pre>
895894 is equivalent to
896−<PRE>
895+<pre>
897896 do
898897 local temp = {}
899898 temp[f(1)] = g
@@ -905,7 +904,7 @@ is equivalent to · 5 unmodified lines
905904 temp[4] = 45 -- 4th exp
906905 a = temp
907906 end
908−</PRE>
907+</pre>
909908
910909 <p>If the last field in the list has the form <code>exp</code>
911910 and the expression is a function call or a vararg expression,
@@ -961,10 +960,10 @@ the argument list is a single literal string. · 49 unmodified lines
961960 you cannot put a line break before the `<code>(</code>&acute; in a function call.
962961 That restriction avoids some ambiguities in the language.
963962 If you write
964−<PRE>
963+<pre>
965964 a = f
966965 (g).x(a)
967−</PRE>
966+</pre>
968967 Lua would read that as <code>a = f(g).x(a)</code>.
969968 So, if you want two statements, you must add a semi-colon between them.
970969 If you actually want to call <code>f</code>,
@@ -985,13 +984,13 @@ where the <b>return</b> has one single function call as argument; · 14 unmodified lines
985984 this syntax makes the calling function returns exactly
986985 the returns of the called function.
987986 So, all the following examples are not tail calls:
988−<PRE>
987+<pre>
989988 return (f(x)) -- results adjusted to 1
990989 return 2 * f(x)
991990 return x, f(x) -- additional results
992991 f(x); return -- results discarded
993992 return x or f(x) -- results adjusted to 1
994−</PRE>
993+</pre>
995994
996995 <p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3>
997996
@@ -1008,29 +1007,29 @@ So, all the following examples are not tail calls: · 10 unmodified lines
10081007 funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]
10091008 </pre>
10101009 The statement
1011−<PRE>
1010+<pre>
10121011 function f () ... end
1013−</PRE>
1012+</pre>
10141013 translates to
1015−<PRE>
1014+<pre>
10161015 f = function () ... end
1017−</PRE>
1016+</pre>
10181017 The statement
1019−<PRE>
1018+<pre>
10201019 function t.a.b.c.f () ... end
1021−</PRE>
1020+</pre>
10221021 translates to
1023−<PRE>
1022+<pre>
10241023 t.a.b.c.f = function () ... end
1025−</PRE>
1024+</pre>
10261025 The statement
1027−<PRE>
1026+<pre>
10281027 local function f () ... end
1029−</PRE>
1028+</pre>
10301029 translates to
1031−<PRE>
1030+<pre>
10321031 local f; f = function () ... end
1033−</PRE>
1032+</pre>
10341033
10351034 <p>A function definition is an executable expression,
10361035 whose value has type <em>function</em>.
@@ -1047,7 +1046,7 @@ and may have different environment tables. · 10 unmodified lines
10471046 <p>Parameters act as local variables that are
10481047 initialized with the argument values:
10491048 <pre>
1050− parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;
1049+ parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;
10511050 </pre>
10521051 When a function is called,
10531052 the list of arguments is adjusted to
@@ -1069,14 +1068,14 @@ then no adjustment is made · 15 unmodified lines
10691068 (unless the call is enclosed in parentheses).
10701069
10711070 <p>As an example, consider the following definitions:
1072−<PRE>
1071+<pre>
10731072 function f(a, b) end
10741073 function g(a, b, ...) end
10751074 function r() return 1,2,3 end
1076−</PRE>
1075+</pre>
10771076 Then, we have the following mapping from arguments to parameters and
10781077 to the vararg expression:
1079−<PRE>
1078+<pre>
10801079 CALL PARAMETERS
10811080
10821081 f(3) a=3, b=nil
@@ -1089,7 +1088,7 @@ to the vararg expression: · 6 unmodified lines
10891088 g(3, 4) a=3, b=4, ... -> (nothing)
10901089 g(3, 4, 5, 8) a=3, b=4, ... -> 5 8
10911090 g(5, r()) a=5, b=1, ... -> 2 3
1092−</PRE>
1091+</pre>
10931092
10941093 <p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>).
10951094 If control reaches the end of a function
@@ -1100,13 +1099,13 @@ then the function returns with no results. · 4 unmodified lines
11001099 is used for defining <em>methods</em>,
11011100 that is, functions that have an implicit extra parameter <code>self</code>.
11021101 Thus, the statement
1103−<PRE>
1102+<pre>
11041103 function t.a.b.c:f (...) ... end
1105−</PRE>
1104+</pre>
11061105 is syntactic sugar for
1107−<PRE>
1106+<pre>
11081107 t.a.b.c.f = function (self, ...) ... end
1109−</PRE>
1108+</pre>
11101109
11111110 <p><a name="visibility"></a><a name="2.6"></a><h2>2.6 - Visibility Rules</h2>
11121111
@@ -1116,7 +1115,7 @@ The scope of variables begins at the first statement <em>after</em> · 3 unmodified lines
11161115 their declaration and lasts until the end of the innermost block that
11171116 includes the declaration.
11181117 For instance:
1119−<PRE>
1118+<pre>
11201119 x = 10 -- global variable
11211120 do -- new block
11221121 local x = x -- new `x', with value 10
@@ -1129,7 +1128,7 @@ For instance: · 6 unmodified lines
11291128 print(x) --> 11
11301129 end
11311130 print(x) --> 10 (the global one)
1132−</PRE>
1131+</pre>
11331132 Notice that, in a declaration like <code>local x = x</code>,
11341133 the new <code>x</code> being declared is not in scope yet,
11351134 and so the second <code>x</code> refers to the outside variable.
@@ -1138,13 +1137,13 @@ and so the second <code>x</code> refers to the outside variable. · 2 unmodified lines
11381137 local variables can be freely accessed by functions
11391138 defined inside their scope.
11401139 For instance:
1141−<PRE>
1140+<pre>
11421141 local counter = 0
11431142 function inc (x)
11441143 counter = counter + x
11451144 return counter
11461145 end
1147−</PRE>
1146+</pre>
11481147 A local variable used by an inner function is called
11491148 an <em>upvalue</em>, or <em>external local variable</em>,
11501149 inside the inner function.
@@ -1152,14 +1151,14 @@ inside the inner function. · 1 unmodified line
11521151 <p>Notice that each execution of a <b>local</b> statement
11531152 defines new local variables.
11541153 Consider the following example:
1155−<PRE>
1154+<pre>
11561155 a = {}
11571156 local x = 20
11581157 for i=1,10 do
11591158 local y = 0
11601159 a[i] = function () y=y+1; return x+y end
11611160 end
1162−</PRE>
1161+</pre>
11631162 The loop creates ten closures
11641163 (that is, ten instances of the anonymous function).
11651164 Each of these closures uses a different <code>y</code> variable,
@@ -1243,16 +1242,16 @@ All functions used in these descriptions · 77 unmodified lines
12431242 are described in <a href="#predefined">5.1</a>.
12441243 In particular, to retrieve the metamethod of a given object,
12451244 we use the expression
1246−<PRE>
1245+<pre>
12471246 metatable(obj)[event]
1248−</PRE>
1247+</pre>
12491248 This should be read as
1250−<PRE>
1249+<pre>
12511250 rawget(metatable(obj) or {}, event)
1252−</PRE>
1251+</pre>
12531252 That is, the access to a metamethod does not invoke other metamethods,
12541253 and the access to objects with no metatables does not fail
1255−(it simply results in <B>nil</B>).
1254+(it simply results in <b>nil</b>).
12561255
12571256 <p><ul>
12581257 <li><b>"add":</b>
@@ -1263,14 +1262,14 @@ for a binary operation. · 4 unmodified lines
12631262 First, Lua tries the first operand.
12641263 If its type does not define a handler for the operation,
12651264 then Lua tries the second operand.
1266−<PRE>
1265+<pre>
12671266 function getbinhandler (op1, op2, event)
12681267 return metatable(op1)[event] or metatable(op2)[event]
12691268 end
1270−</PRE>
1269+</pre>
12711270 Using that function,
12721271 the behavior of the <code>op1 + op2</code> is
1273−<PRE>
1272+<pre>
12741273 function add_event (op1, op2)
12751274 local o1, o2 = tonumber(op1), tonumber(op2)
12761275 if o1 and o2 then -- both operands are numeric?
@@ -1285,7 +1284,7 @@ the behavior of the <code>op1 + op2</code> is · 8 unmodified lines
12851284 end
12861285 end
12871286 end
1288−</PRE>
1287+</pre>
12891288
12901289 <p><li><b>"sub":</b>
12911290 the <code>-</code> operation.
@@ -1313,7 +1312,7 @@ as the primitive operation. · 21 unmodified lines
13131312
13141313 <p><li><b>"unm":</b>
13151314 the unary <code>-</code> operation.
1316−<PRE>
1315+<pre>
13171316 function unm_event (op)
13181317 local o = tonumber(op)
13191318 if o then -- operand is numeric?
@@ -1329,11 +1328,11 @@ the unary <code>-</code> operation. · 9 unmodified lines
13291328 end
13301329 end
13311330 end
1332−</PRE>
1331+</pre>
13331332
13341333 <p><li><b>"concat":</b>
13351334 the <code>..</code> (concatenation) operation.
1336−<PRE>
1335+<pre>
13371336 function concat_event (op1, op2)
13381337 if (type(op1) == "string" or type(op1) == "number") and
13391338 (type(op2) == "string" or type(op2) == "number") then
@@ -1347,11 +1346,11 @@ the <code>..</code> (concatenation) operation. · 7 unmodified lines
13471346 end
13481347 end
13491348 end
1350−</PRE>
1349+</pre>
13511350
13521351 <p><li><b>"len":</b>
13531352 the <code>#</code> operation.
1354−<PRE>
1353+<pre>
13551354 function len_event (op)
13561355 if type(op) == "string" then
13571356 return strlen(op) -- primitive string length
@@ -1367,7 +1366,7 @@ the <code>#</code> operation. · 9 unmodified lines
13671366 end
13681367 end
13691368 end
1370−</PRE>
1369+</pre>
13711370 See <a href="#len-op">2.5.5</a> for a description of the length of a table.
13721371
13731372 <p><li><b>"eq":</b>
@@ -1377,16 +1376,16 @@ for comparison operators. · 3 unmodified lines
13771376 A metamethod only is selected when both objects
13781377 being compared have the same type
13791378 and the same metamethod for the selected operation.
1380−<PRE>
1379+<pre>
13811380 function getcomphandler (op1, op2, event)
13821381 if type(op1) ~= type(op2) then return nil end
13831382 local mm1 = metatable(op1)[event]
13841383 local mm2 = metatable(op2)[event]
13851384 if mm1 == mm2 then return mm1 else return nil end
13861385 end
1387−</PRE>
1386+</pre>
13881387 The "eq" event is defined as follows:
1389−<PRE>
1388+<pre>
13901389 function eq_event (op1, op2)
13911390 if type(op1) ~= type(op2) then -- different types?
13921391 return false -- different objects
@@ -1402,12 +1401,12 @@ The "eq" event is defined as follows: · 9 unmodified lines
14021401 return false
14031402 end
14041403 end
1405−</PRE>
1404+</pre>
14061405 <code>a ~= b</code> is equivalent to <code>not (a == b)</code>.
14071406
14081407 <p><li><b>"lt":</b>
14091408 the <code>&#060;</code> operation.
1410−<PRE>
1409+<pre>
14111410 function lt_event (op1, op2)
14121411 if type(op1) == "number" and type(op2) == "number" then
14131412 return op1 &#060; op2 -- numeric comparison
@@ -1422,12 +1421,12 @@ the <code>&#060;</code> operation. · 8 unmodified lines
14221421 end
14231422 end
14241423 end
1425−</PRE>
1424+</pre>
14261425 <code>a > b</code> is equivalent to <code>b &#060; a</code>.
14271426
14281427 <p><li><b>"le":</b>
14291428 the <code>&#060;=</code> operation.
1430−<PRE>
1429+<pre>
14311430 function le_event (op1, op2)
14321431 if type(op1) == "number" and type(op2) == "number" then
14331432 return op1 &#060;= op2 -- numeric comparison
@@ -1447,7 +1446,7 @@ the <code>&#060;=</code> operation. · 13 unmodified lines
14471446 end
14481447 end
14491448 end
1450−</PRE>
1449+</pre>
14511450 <code>a >= b</code> is equivalent to <code>b &#060;= a</code>.
14521451 Note that, in the absence of a "le" metamethod,
14531452 Lua tries the "lt", assuming that <code>a &#060;= b</code> is
@@ -1455,7 +1454,7 @@ equivalent to <code>not (b &#060; a)</code>. · 1 unmodified line
14551454
14561455 <p><li><b>"index":</b>
14571456 The indexing access <code>table[key]</code>.
1458−<PRE>
1457+<pre>
14591458 function gettable_event (table, key)
14601459 local h
14611460 if type(table) == "table" then
@@ -1474,11 +1473,11 @@ The indexing access <code>table[key]</code>. · 12 unmodified lines
14741473 else return h[key] -- or repeat operation on it
14751474 end
14761475 end
1477−</PRE>
1476+</pre>
14781477
14791478 <p><li><b>"newindex":</b>
14801479 The indexing assignment <code>table[key] = value</code>.
1481−<PRE>
1480+<pre>
14821481 function settable_event (table, key, value)
14831482 local h
14841483 if type(table) == "table" then
@@ -1497,11 +1496,11 @@ The indexing assignment <code>table[key] = value</code>. · 12 unmodified lines
14971496 else h[key] = value -- or repeat operation on it
14981497 end
14991498 end
1500−</PRE>
1499+</pre>
15011500
15021501 <p><li><b>"call":</b>
15031502 called when Lua calls a value.
1504−<PRE>
1503+<pre>
15051504 function function_event (func, ...)
15061505 if type(func) == "function" then
15071506 return func(unpack(arg)) -- primitive call
@@ -1514,7 +1513,7 @@ called when Lua calls a value. · 6 unmodified lines
15141513 end
15151514 end
15161515 end
1517−</PRE>
1516+</pre>
15181517
15191518 <p></ul>
15201519
@@ -1612,14 +1611,14 @@ Instead, Lua puts them in a list. · 91 unmodified lines
16121611 After the collection,
16131612 Lua does the equivalent of the following function
16141613 for each userdata in that list:
1615−<PRE>
1614+<pre>
16161615 function gc_event (udata)
16171616 local h = metatable(udata).__gc
16181617 if h then
16191618 h(udata)
16201619 end
16211620 end
1622−</PRE>
1621+</pre>
16231622
16241623 <p>At the end of each garbage-collection cycle,
16251624 the finalizers for userdata are called in <em>reverse</em>
@@ -1686,9 +1685,9 @@ it runs until it terminates or <em>yields</em>. · 60 unmodified lines
16861685 Normally, when its main function returns
16871686 (explicitly or implicitly, after the last instruction);
16881687 and abnormally, if there is an unprotected error.
1689−In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <B>true</B>,
1688+In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>,
16901689 plus any values returned by the coroutine main function.
1691−In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <B>false</B>
1690+In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>false</b>
16921691 plus an error message.
16931692
16941693 <p>A coroutine yields by calling <code>coroutine.yield</code>.
@@ -1697,7 +1696,7 @@ the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code>< · 2 unmodified lines
16971696 even if the yield happens inside nested function calls
16981697 (that is, not in the main function,
16991698 but in a function directly or indirectly called by the main function).
1700−In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <B>true</B>,
1699+In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <b>true</b>,
17011700 plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
17021701 The next time you resume the same coroutine,
17031702 it continues its execution from the point where it yielded,
@@ -1718,7 +1717,7 @@ any error is propagated to the caller. · 14 unmodified lines
17181717
17191718 <p>As an example,
17201719 consider the next code:
1721−<PRE>
1720+<pre>
17221721 function foo1 (a)
17231722 print("foo", a)
17241723 return coroutine.yield(2*a)
@@ -1741,9 +1740,9 @@ a, b, c = coroutine.resume(co, "x", "y") · 16 unmodified lines
17411740 print("main", a, b, c)
17421741 a, b = coroutine.resume(co, "x", "y")
17431742 print("main", a, b)
1744−</PRE>
1743+</pre>
17451744 When you run it, it produces the following output:
1746−<PRE>
1745+<pre>
17471746 co-body 1 10
17481747 foo 2
17491748 main true 4
@@ -1752,7 +1751,7 @@ main true 11 -9 · 2 unmodified lines
17521751 co-body x y
17531752 main true 10 end
17541753 main false cannot resume dead coroutine
1755−</PRE>
1754+</pre>
17561755
17571756 <p>
17581757 <a name="API"></a><a name="3"></a><h1>3 - The Application Program Interface</h1>
@@ -1780,7 +1779,7 @@ in file <code>luaconf.h</code>. · 21 unmodified lines
17801779
17811780 <p>Lua uses a <em>virtual stack</em> to pass values to and from C.
17821781 Each element in this stack represents a Lua value
1783−(<B>nil</B>, number, string, etc.).
1782+(<b>nil</b>, number, string, etc.).
17841783
17851784 <p>Whenever Lua calls C, the called function gets a new stack,
17861785 which is independent of previous stacks and of stacks of
@@ -1828,9 +1827,9 @@ you have set through <a href="#lua_checkstack"><code>lua_checkstack</code></a>. · 41 unmodified lines
18281827 Such indices are called <em>acceptable indices</em>.
18291828 More formally, we define an <em>acceptable index</em>
18301829 as follows:
1831−<PRE>
1830+<pre>
18321831 (index &#060; 0 &#038;&#038; abs(index) &#060;= top) || (index > 0 &#038;&#038; index &#060;= stackspace)
1833−</PRE>
1832+</pre>
18341833 Note that 0 is never an acceptable index.
18351834
18361835 <p><a name="pseudo-index"></a><a name="3.3"></a><h2>3.3 - Pseudo-Indices</h2>
@@ -1853,9 +1852,9 @@ at pseudo-index <code>LUA_ENVIRONINDEX</code>. · 16 unmodified lines
18531852 <p>To access and change the value of global variables,
18541853 you can use regular table operations over an environment table.
18551854 For instance, to access the value of a global variable, do
1856−<PRE>
1855+<pre>
18571856 lua_getfield(L, LUA_GLOBALSINDEX, varname);
1858−</PRE>
1857+</pre>
18591858
18601859 <p><a name="c-closure"></a><a name="3.4"></a><h2>3.4 - C Closures</h2>
18611860
@@ -1918,7 +1917,7 @@ so they never raise an error: · 56 unmodified lines
19181917 alphabetical order.
19191918
19201919 <p><a name="lua_Alloc"></a>
1921−<hr><h3><code>lua_Alloc</code></h3>
1920+<hr/><h3><code>lua_Alloc</code></h3>
19221921 <pre>
19231922 typedef void * (*lua_Alloc) (void *ud,
19241923 void *ptr,
@@ -1950,8 +1949,9 @@ the allocator behaves like <code>realloc</code>. · 25 unmodified lines
19501949 Lua assumes that the allocator never fails when
19511950 <code>osize >= nsize</code>.
19521951
1953−<p>A simple implementation for the allocator function could be like this:
1954−<PRE>
1952+<p>A simple implementation for the allocator function
1953+could be like this:
1954+<pre>
19551955 static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
19561956 (void)ud; /* not used */
19571957 (void)osize; /* not used */
@@ -1963,10 +1963,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { · 5 unmodified lines
19631963 /* ANSI ensures that realloc(NULL, size) == malloc(size) */
19641964 return realloc(ptr, nsize);
19651965 }
1966−</PRE>
1966+</pre>
19671967
19681968 <p><a name="lua_atpanic"></a>
1969−<hr><h3><code>lua_atpanic</code></h3>
1969+<hr/><h3><code>lua_atpanic</code></h3>
19701970 <pre>
19711971 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
19721972 </pre>
@@ -1983,7 +1983,7 @@ never returning (e.g., doing a long jump). · 10 unmodified lines
19831983 <p>The panic function can access the error message at the top of the stack.
19841984
19851985 <p><a name="lua_call"></a>
1986−<hr><h3><code>lua_call</code></h3>
1986+<hr/><h3><code>lua_call</code></h3>
19871987 <pre>
19881988 void lua_call (lua_State *L, int nargs, int nresults);
19891989 </pre>
@@ -2012,11 +2012,11 @@ so that after the call the last result is on the top. · 22 unmodified lines
20122012
20132013 <p>The following example shows how the host program may do the
20142014 equivalent to this Lua code:
2015−<PRE>
2015+<pre>
20162016 a = f("how", t.x, 14)
2017−</PRE>
2017+</pre>
20182018 Here it is in C:
2019−<PRE>
2019+<pre>
20202020 lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */
20212021 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
20222022 lua_pushstring(L, "how"); /* 1st argument */
@@ -2025,13 +2025,13 @@ Here it is in C: · 2 unmodified lines
20252025 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */
20262026 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */
20272027 lua_pop(L, 1); /* remove `t' from the stack */
2028−</PRE>
2028+</pre>
20292029 Note that the code above is "balanced":
20302030 at its end, the stack is back to its original configuration.
20312031 This is considered good programming practice.
20322032
20332033 <p><a name="lua_CFunction"></a>
2034−<hr><h3><code>lua_CFunction</code></h3>
2034+<hr/><h3><code>lua_CFunction</code></h3>
20352035 <pre>
20362036 typedef int (*lua_CFunction) (lua_State *L);
20372037 </pre>
@@ -2056,7 +2056,7 @@ many results. · 18 unmodified lines
20562056
20572057 <p>As an example, the following function receives a variable number
20582058 of numerical arguments and returns their average and sum:
2059−<PRE>
2059+<pre>
20602060 static int foo (lua_State *L) {
20612061 int n = lua_gettop(L); /* number of arguments */
20622062 lua_Number sum = 0;
@@ -2072,10 +2072,10 @@ of numerical arguments and returns their average and sum: · 9 unmodified lines
20722072 lua_pushnumber(L, sum); /* second result */
20732073 return 2; /* number of results */
20742074 }
2075−</PRE>
2075+</pre>
20762076
20772077 <p><a name="lua_checkstack"></a>
2078−<hr><h3><code>lua_checkstack</code></h3>
2078+<hr/><h3><code>lua_checkstack</code></h3>
20792079 <pre>
20802080 int lua_checkstack (lua_State *L, int extra);
20812081 </pre>
@@ -2088,7 +2088,7 @@ if the stack is already larger than the new size, · 6 unmodified lines
20882088 it is left unchanged.
20892089
20902090 <p><a name="lua_close"></a>
2091−<hr><h3><code>lua_close</code></h3>
2091+<hr/><h3><code>lua_close</code></h3>
20922092 <pre>
20932093 void lua_close (lua_State *L);
20942094 </pre>
@@ -2105,7 +2105,7 @@ might need to release states as soon as they are not needed, · 10 unmodified lines
21052105 to avoid growing too large.
21062106
21072107 <p><a name="lua_concat"></a>
2108−<hr><h3><code>lua_concat</code></h3>
2108+<hr/><h3><code>lua_concat</code></h3>
21092109 <pre>
21102110 void lua_concat (lua_State *L, int n);
21112111 </pre>
@@ -2120,7 +2120,7 @@ Concatenation is done following the usual semantics of Lua · 8 unmodified lines
21202120 (see <a href="#concat">2.5.4</a>).
21212121
21222122 <p><a name="lua_cpcall"></a>
2123−<hr><h3><code>lua_cpcall</code></h3>
2123+<hr/><h3><code>lua_cpcall</code></h3>
21242124 <pre>
21252125 int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
21262126 </pre>
@@ -2136,7 +2136,7 @@ otherwise, it returns zero, and does not change the stack. · 9 unmodified lines
21362136 Any value returned by <code>func</code> is discarded.
21372137
21382138 <p><a name="lua_createtable"></a>
2139−<hr><h3><code>lua_createtable</code></h3>
2139+<hr/><h3><code>lua_createtable</code></h3>
21402140 <pre>
21412141 void lua_createtable (lua_State *L, int narr, int nrec);
21422142 </pre>
@@ -2150,7 +2150,7 @@ the table will have. · 7 unmodified lines
21502150 Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
21512151
21522152 <p><a name="lua_dump"></a>
2153−<hr><h3><code>lua_dump</code></h3>
2153+<hr/><h3><code>lua_dump</code></h3>
21542154 <pre>
21552155 int lua_dump (lua_State *L, lua_Writer writer, void *data);
21562156 </pre>
@@ -2172,7 +2172,7 @@ call to the writer; · 15 unmodified lines
21722172 <p>This function does not pop the function from the stack.
21732173
21742174 <p><a name="lua_equal"></a>
2175−<hr><h3><code>lua_equal</code></h3>
2175+<hr/><h3><code>lua_equal</code></h3>
21762176 <pre>
21772177 int lua_equal (lua_State *L, int index1, int index2);
21782178 </pre>
@@ -2180,13 +2180,13 @@ call to the writer; · 1 unmodified line
21802180
21812181 <p>Returns 1 if the two values in acceptable indices <code>index1</code> and
21822182 <code>index2</code> are equal,
2183−following the semantics of the Lua <code>=</code> operator
2183+following the semantics of the Lua <code>==</code> operator
21842184 (that is, may call metamethods).
21852185 Otherwise returns 0.
21862186 Also returns 0 if any of the indices are non valid.
21872187
21882188 <p><a name="lua_error"></a>
2189−<hr><h3><code>lua_error</code></h3>
2189+<hr/><h3><code>lua_error</code></h3>
21902190 <pre>
21912191 int lua_error (lua_State *L);
21922192 </pre>
@@ -2199,7 +2199,7 @@ This function does a long jump, · 6 unmodified lines
21992199 and therefore never returns.
22002200
22012201 <p><a name="lua_gc"></a>
2202−<hr><h3><code>lua_gc</code></h3>
2202+<hr/><h3><code>lua_gc</code></h3>
22032203 <pre>
22042204 int lua_gc (lua_State *L, int what, int data);
22052205 </pre>
@@ -2210,12 +2210,15 @@ and therefore never returns. · 4 unmodified lines
22102210 <p>This function performs several tasks,
22112211 according to the value of the parameter <code>what</code>:
22122212 <ul>
2213−<li> <code>LUA_GCSTOP</code>&mdash; stops the garbage collector.
2214−<li> <code>LUA_GCRESTART</code>&mdash; restarts the garbage collector.
2215−<li> <code>LUA_GCCOLLECT</code>&mdash; performs a full garbage-collection cycle.
2216−<li> <code>LUA_GCCOUNT</code>&mdash; returns the current
2213+<li> <code>LUA_GCSTOP</code>--- stops the garbage collector.
2214+<li> <code>LUA_GCRESTART</code>--- restarts the garbage collector.
2215+<li> <code>LUA_GCCOLLECT</code>--- performs a full garbage-collection cycle.
2216+<li> <code>LUA_GCCOUNT</code>--- returns the current
22172217 amount of memory (in Kbytes) in use by Lua.
2218−<li> <code>LUA_GCSTEP</code>&mdash; performs an incremental step of
2218+<li> <code>LUA_GCCOUNTB</code>--- returns the remainder of
2219+dividing the current amount of bytes of memory in use by Lua
2220+by 1024.
2221+<li> <code>LUA_GCSTEP</code>--- performs an incremental step of
22192222 garbage collection.
22202223 The step "size" is controlled by <code>data</code>
22212224 (larger values mean more steps) in a non-specified way.
@@ -2223,16 +2226,18 @@ If you want to control the step size · 1 unmodified line
22232226 you must tune experimentally the value of <code>data</code>.
22242227 The function returns 1 if that step finished a
22252228 garbage-collection cycle.
2226−<li> <code>LUA_GCSETPAUSE</code>&mdash;
2229+<li> <code>LUA_GCSETPAUSE</code>---
22272230 sets <em><code>data</code>/100</em> as the new value
22282231 for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>).
2229−<li> <code>LUA_GCSETSTEPMUL</code>&mdash;
2232+The function returns the previous value of the pause.
2233+<li> <code>LUA_GCSETSTEPMUL</code>---
22302234 sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of
22312235 the collector (see <a href="#GC">2.10</a>).
2236+The function returns the previous value of the step multiplier.
22322237 </ul>
22332238
22342239 <p><a name="lua_getallocf"></a>
2235−<hr><h3><code>lua_getallocf</code></h3>
2240+<hr/><h3><code>lua_getallocf</code></h3>
22362241 <pre>
22372242 lua_Alloc lua_getallocf (lua_State *L, void **ud);
22382243 </pre>
@@ -2243,7 +2248,7 @@ If <code>ud</code> is not <code>NULL</code> Lua stores in <code>*ud</code> the · 4 unmodified lines
22432248 opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.
22442249
22452250 <p><a name="lua_getfenv"></a>
2246−<hr><h3><code>lua_getfenv</code></h3>
2251+<hr/><h3><code>lua_getfenv</code></h3>
22472252 <pre>
22482253 void lua_getfenv (lua_State *L, int index);
22492254 </pre>
@@ -2253,7 +2258,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 3 unmodified lines
22532258 the value at the given index.
22542259
22552260 <p><a name="lua_getfield"></a>
2256−<hr><h3><code>lua_getfield</code></h3>
2261+<hr/><h3><code>lua_getfield</code></h3>
22572262 <pre>
22582263 void lua_getfield (lua_State *L, int index, const char *k);
22592264 </pre>
@@ -2265,7 +2270,7 @@ As in Lua, this function may trigger a metamethod · 5 unmodified lines
22652270 for the "index" event (see <a href="#metatable">2.8</a>).
22662271
22672272 <p><a name="lua_getmetatable"></a>
2268−<hr><h3><code>lua_getmetatable</code></h3>
2273+<hr/><h3><code>lua_getmetatable</code></h3>
22692274 <pre>
22702275 int lua_getmetatable (lua_State *L, int index);
22712276 </pre>
@@ -2278,7 +2283,7 @@ or if the value does not have a metatable, · 6 unmodified lines
22782283 returns 0 and pushes nothing on the stack.
22792284
22802285 <p><a name="lua_gettable"></a>
2281−<hr><h3><code>lua_gettable</code></h3>
2286+<hr/><h3><code>lua_gettable</code></h3>
22822287 <pre>
22832288 void lua_gettable (lua_State *L, int index);
22842289 </pre>
@@ -2294,7 +2299,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
22942299 for the "index" event (see <a href="#metatable">2.8</a>).
22952300
22962301 <p><a name="lua_gettop"></a>
2297−<hr><h3><code>lua_gettop</code></h3>
2302+<hr/><h3><code>lua_gettop</code></h3>
22982303 <pre>
22992304 int lua_gettop (lua_State *L);
23002305 </pre>
@@ -2306,7 +2311,7 @@ that result is equal to the number of elements in the stack · 5 unmodified lines
23062311 (and so 0 means an empty stack).
23072312
23082313 <p><a name="lua_insert"></a>
2309−<hr><h3><code>lua_insert</code></h3>
2314+<hr/><h3><code>lua_insert</code></h3>
23102315 <pre>
23112316 void lua_insert (lua_State *L, int index);
23122317 </pre>
@@ -2318,7 +2323,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
23182323 because a pseudo-index is not an actual stack position.
23192324
23202325 <p><a name="lua_Integer"></a>
2321−<hr><h3><code>lua_Integer</code></h3>
2326+<hr/><h3><code>lua_Integer</code></h3>
23222327 <pre>
23232328 typedef ptrdiff_t lua_Integer;
23242329 </pre>
@@ -2331,7 +2336,7 @@ which is usually the largest type the machine handles · 6 unmodified lines
23312336 "comfortably".
23322337
23332338 <p><a name="lua_isboolean"></a>
2334−<hr><h3><code>lua_isboolean</code></h3>
2339+<hr/><h3><code>lua_isboolean</code></h3>
23352340 <pre>
23362341 int lua_isboolean (lua_State *L, int index);
23372342 </pre>
@@ -2341,7 +2346,7 @@ which is usually the largest type the machine handles · 3 unmodified lines
23412346 and 0 otherwise.
23422347
23432348 <p><a name="lua_iscfunction"></a>
2344−<hr><h3><code>lua_iscfunction</code></h3>
2349+<hr/><h3><code>lua_iscfunction</code></h3>
23452350 <pre>
23462351 int lua_iscfunction (lua_State *L, int index);
23472352 </pre>
@@ -2351,7 +2356,7 @@ and 0 otherwise. · 3 unmodified lines
23512356 and 0 otherwise.
23522357
23532358 <p><a name="lua_isfunction"></a>
2354−<hr><h3><code>lua_isfunction</code></h3>
2359+<hr/><h3><code>lua_isfunction</code></h3>
23552360 <pre>
23562361 int lua_isfunction (lua_State *L, int index);
23572362 </pre>
@@ -2361,7 +2366,7 @@ and 0 otherwise. · 3 unmodified lines
23612366 (either C or Lua), and 0 otherwise.
23622367
23632368 <p><a name="lua_islightuserdata"></a>
2364−<hr><h3><code>lua_islightuserdata</code></h3>
2369+<hr/><h3><code>lua_islightuserdata</code></h3>
23652370 <pre>
23662371 int lua_islightuserdata (lua_State *L, int index);
23672372 </pre>
@@ -2371,17 +2376,17 @@ and 0 otherwise. · 3 unmodified lines
23712376 and 0 otherwise.
23722377
23732378 <p><a name="lua_isnil"></a>
2374−<hr><h3><code>lua_isnil</code></h3>
2379+<hr/><h3><code>lua_isnil</code></h3>
23752380 <pre>
23762381 int lua_isnil (lua_State *L, int index);
23772382 </pre>
23782383
23792384
2380−<p>Returns 1 if the value at the given acceptable index is <B>nil</B>,
2385+<p>Returns 1 if the value at the given acceptable index is <b>nil</b>,
23812386 and 0 otherwise.
23822387
23832388 <p><a name="lua_isnumber"></a>
2384−<hr><h3><code>lua_isnumber</code></h3>
2389+<hr/><h3><code>lua_isnumber</code></h3>
23852390 <pre>
23862391 int lua_isnumber (lua_State *L, int index);
23872392 </pre>
@@ -2392,7 +2397,7 @@ or a string convertible to a number, · 4 unmodified lines
23922397 and 0 otherwise.
23932398
23942399 <p><a name="lua_isstring"></a>
2395−<hr><h3><code>lua_isstring</code></h3>
2400+<hr/><h3><code>lua_isstring</code></h3>
23962401 <pre>
23972402 int lua_isstring (lua_State *L, int index);
23982403 </pre>
@@ -2403,7 +2408,7 @@ or a number (which is always convertible to a string), · 4 unmodified lines
24032408 and 0 otherwise.
24042409
24052410 <p><a name="lua_istable"></a>
2406−<hr><h3><code>lua_istable</code></h3>
2411+<hr/><h3><code>lua_istable</code></h3>
24072412 <pre>
24082413 int lua_istable (lua_State *L, int index);
24092414 </pre>
@@ -2413,7 +2418,7 @@ and 0 otherwise. · 3 unmodified lines
24132418 and 0 otherwise.
24142419
24152420 <p><a name="lua_isthread"></a>
2416−<hr><h3><code>lua_isthread</code></h3>
2421+<hr/><h3><code>lua_isthread</code></h3>
24172422 <pre>
24182423 int lua_isthread (lua_State *L, int index);
24192424 </pre>
@@ -2423,7 +2428,7 @@ and 0 otherwise. · 3 unmodified lines
24232428 and 0 otherwise.
24242429
24252430 <p><a name="lua_isuserdata"></a>
2426−<hr><h3><code>lua_isuserdata</code></h3>
2431+<hr/><h3><code>lua_isuserdata</code></h3>
24272432 <pre>
24282433 int lua_isuserdata (lua_State *L, int index);
24292434 </pre>
@@ -2433,7 +2438,7 @@ and 0 otherwise. · 3 unmodified lines
24332438 (either full or light), and 0 otherwise.
24342439
24352440 <p><a name="lua_lessthan"></a>
2436−<hr><h3><code>lua_lessthan</code></h3>
2441+<hr/><h3><code>lua_lessthan</code></h3>
24372442 <pre>
24382443 int lua_lessthan (lua_State *L, int index1, int index2);
24392444 </pre>
@@ -2447,7 +2452,7 @@ Otherwise returns 0. · 7 unmodified lines
24472452 Also returns 0 if any of the indices are non valid.
24482453
24492454 <p><a name="lua_load"></a>
2450−<hr><h3><code>lua_load</code></h3>
2455+<hr/><h3><code>lua_load</code></h3>
24512456 <pre>
24522457 int lua_load (lua_State *L, lua_Reader reader, void *data,
24532458 const char *chunkname);
@@ -2462,10 +2467,10 @@ function on top of the stack. · 8 unmodified lines
24622467 Otherwise, it pushes an error message.
24632468 The return values of <a href="#lua_load"><code>lua_load</code></a> are:
24642469 <ul>
2465−<li> 0 &mdash; no errors;
2466−<li> <code>LUA_ERRSYNTAX</code> &mdash;
2470+<li> 0 --- no errors;
2471+<li> <code>LUA_ERRSYNTAX</code> ---
24672472 syntax error during pre-compilation.
2468−<li> <code>LUA_ERRMEM</code> &mdash;
2473+<li> <code>LUA_ERRMEM</code> ---
24692474 memory allocation error.
24702475 </ul>
24712476
@@ -2480,7 +2485,7 @@ The <code>data</code> argument is an opaque value passed to the reader function. · 8 unmodified lines
24802485 It is used for error messages and debug information (see <a href="#debugI">3.8</a>).
24812486
24822487 <p><a name="lua_newstate"></a>
2483−<hr><h3><code>lua_newstate</code></h3>
2488+<hr/><h3><code>lua_newstate</code></h3>
24842489 <pre>
24852490 lua_State *lua_newstate (lua_Alloc f, void *ud);
24862491 </pre>
@@ -2495,7 +2500,7 @@ The second argument, <code>ud</code>, is an opaque pointer that Lua · 8 unmodified lines
24952500 simply passes to the allocator in every call.
24962501
24972502 <p><a name="lua_newtable"></a>
2498−<hr><h3><code>lua_newtable</code></h3>
2503+<hr/><h3><code>lua_newtable</code></h3>
24992504 <pre>
25002505 void lua_newtable (lua_State *L);
25012506 </pre>
@@ -2505,7 +2510,7 @@ simply passes to the allocator in every call. · 3 unmodified lines
25052510 Equivalent to <code>lua_createtable(L, 0, 0)</code>.
25062511
25072512 <p><a name="lua_newthread"></a>
2508−<hr><h3><code>lua_newthread</code></h3>
2513+<hr/><h3><code>lua_newthread</code></h3>
25092514 <pre>
25102515 lua_State *lua_newthread (lua_State *L);
25112516 </pre>
@@ -2522,7 +2527,7 @@ Threads are subject to garbage collection, · 10 unmodified lines
25222527 like any Lua object.
25232528
25242529 <p><a name="lua_newuserdata"></a>
2525−<hr><h3><code>lua_newuserdata</code></h3>
2530+<hr/><h3><code>lua_newuserdata</code></h3>
25262531 <pre>
25272532 void *lua_newuserdata (lua_State *L, size_t size);
25282533 </pre>
@@ -2544,7 +2549,7 @@ it calls the userdata's <code>gc</code> metamethod, if any, · 15 unmodified lines
25442549 and then it frees the userdata's corresponding memory.
25452550
25462551 <p><a name="lua_next"></a>
2547−<hr><h3><code>lua_next</code></h3>
2552+<hr/><h3><code>lua_next</code></h3>
25482553 <pre>
25492554 int lua_next (lua_State *L, int index);
25502555 </pre>
@@ -2557,7 +2562,7 @@ If there are no more elements, · 6 unmodified lines
25572562 then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).
25582563
25592564 <p>A typical traversal looks like this:
2560−<PRE>
2565+<pre>
25612566 /* table is in the stack at index `t' */
25622567 lua_pushnil(L); /* first key */
25632568 while (lua_next(L, t) != 0) {
@@ -2566,7 +2571,7 @@ then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing · 2 unmodified lines
25662571 lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)));
25672572 lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */
25682573 }
2569−</PRE>
2574+</pre>
25702575
25712576 <p>While traversing a table,
25722577 do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,
@@ -2576,7 +2581,7 @@ the value at the given index; · 3 unmodified lines
25762581 this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
25772582
25782583 <p><a name="lua_Number"></a>
2579−<hr><h3><code>lua_Number</code></h3>
2584+<hr/><h3><code>lua_Number</code></h3>
25802585 <pre>
25812586 typedef double lua_Number;
25822587 </pre>
@@ -2588,7 +2593,7 @@ this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>. · 5 unmodified lines
25882593 Lua to operate with other type for numbers (e.g., float or long).
25892594
25902595 <p><a name="lua_objlen"></a>
2591−<hr><h3><code>lua_objlen</code></h3>
2596+<hr/><h3><code>lua_objlen</code></h3>
25922597 <pre>
25932598 size_t lua_objlen (lua_State *L, int index);
25942599 </pre>
@@ -2602,7 +2607,7 @@ for the userdatum. · 7 unmodified lines
26022607 For other values, returns 0.
26032608
26042609 <p><a name="lua_pcall"></a>
2605−<hr><h3><code>lua_pcall</code></h3>
2610+<hr/><h3><code>lua_pcall</code></h3>
26062611 <pre>
26072612 lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
26082613 </pre>
@@ -2640,15 +2645,15 @@ since by then the stack has unwound. · 31 unmodified lines
26402645 or one of the following error codes
26412646 (defined in <code>lua.h</code>):
26422647 <ul>
2643−<li> <code>LUA_ERRRUN</code> &mdash; a runtime error.
2644−<li> <code>LUA_ERRMEM</code> &mdash; memory allocation error.
2648+<li> <code>LUA_ERRRUN</code> --- a runtime error.
2649+<li> <code>LUA_ERRMEM</code> --- memory allocation error.
26452650 For such errors, Lua does not call the error handler function.
2646−<li> <code>LUA_ERRERR</code> &mdash;
2651+<li> <code>LUA_ERRERR</code> ---
26472652 error while running the error handler function.
26482653 </ul>
26492654
26502655 <p><a name="lua_pop"></a>
2651−<hr><h3><code>lua_pop</code></h3>
2656+<hr/><h3><code>lua_pop</code></h3>
26522657 <pre>
26532658 void lua_pop (lua_State *L, int n);
26542659 </pre>
@@ -2657,7 +2662,7 @@ error while running the error handler function. · 2 unmodified lines
26572662 <p>Pops <code>n</code> elements from the stack.
26582663
26592664 <p><a name="lua_pushboolean"></a>
2660−<hr><h3><code>lua_pushboolean</code></h3>
2665+<hr/><h3><code>lua_pushboolean</code></h3>
26612666 <pre>
26622667 void lua_pushboolean (lua_State *L, int b);
26632668 </pre>
@@ -2666,7 +2671,7 @@ error while running the error handler function. · 2 unmodified lines
26662671 <p>Pushes a boolean value with value <code>b</code> onto the stack.
26672672
26682673 <p><a name="lua_pushcclosure"></a>
2669−<hr><h3><code>lua_pushcclosure</code></h3>
2674+<hr/><h3><code>lua_pushcclosure</code></h3>
26702675 <pre>
26712676 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
26722677 </pre>
@@ -2688,7 +2693,7 @@ associated with the function. · 15 unmodified lines
26882693 <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
26892694
26902695 <p><a name="lua_pushcfunction"></a>
2691−<hr><h3><code>lua_pushcfunction</code></h3>
2696+<hr/><h3><code>lua_pushcfunction</code></h3>
26922697 <pre>
26932698 void lua_pushcfunction (lua_State *L, lua_CFunction f);
26942699 </pre>
@@ -2698,7 +2703,7 @@ associated with the function. · 3 unmodified lines
26982703 This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>.
26992704
27002705 <p><a name="lua_pushfstring"></a>
2701−<hr><h3><code>lua_pushfstring</code></h3>
2706+<hr/><h3><code>lua_pushfstring</code></h3>
27022707 <pre>
27032708 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
27042709 </pre>
@@ -2724,7 +2729,7 @@ The conversion specifiers can be simply · 19 unmodified lines
27242729 </ul>
27252730
27262731 <p><a name="lua_pushinteger"></a>
2727−<hr><h3><code>lua_pushinteger</code></h3>
2732+<hr/><h3><code>lua_pushinteger</code></h3>
27282733 <pre>
27292734 void lua_pushinteger (lua_State *L, lua_Integer n);
27302735 </pre>
@@ -2733,7 +2738,7 @@ The conversion specifiers can be simply · 2 unmodified lines
27332738 <p>Pushes a number with value <code>n</code> onto the stack.
27342739
27352740 <p><a name="lua_pushlightuserdata"></a>
2736−<hr><h3><code>lua_pushlightuserdata</code></h3>
2741+<hr/><h3><code>lua_pushlightuserdata</code></h3>
27372742 <pre>
27382743 void lua_pushlightuserdata (lua_State *L, void *p);
27392744 </pre>
@@ -2750,7 +2755,7 @@ A light userdata is equal to "any" · 10 unmodified lines
27502755 light userdata with the same C address.
27512756
27522757 <p><a name="lua_pushlstring"></a>
2753−<hr><h3><code>lua_pushlstring</code></h3>
2758+<hr/><h3><code>lua_pushlstring</code></h3>
27542759 <pre>
27552760 void lua_pushlstring (lua_State *L, const char *s, size_t len);
27562761 </pre>
@@ -2763,7 +2768,7 @@ so the memory at <code>s</code> can be freed or reused immediately after · 6 unmodified lines
27632768 the function returns.
27642769
27652770 <p><a name="lua_pushnil"></a>
2766−<hr><h3><code>lua_pushnil</code></h3>
2771+<hr/><h3><code>lua_pushnil</code></h3>
27672772 <pre>
27682773 void lua_pushnil (lua_State *L);
27692774 </pre>
@@ -2772,7 +2777,7 @@ the function returns. · 2 unmodified lines
27722777 <p>Pushes a nil value onto the stack.
27732778
27742779 <p><a name="lua_pushnumber"></a>
2775−<hr><h3><code>lua_pushnumber</code></h3>
2780+<hr/><h3><code>lua_pushnumber</code></h3>
27762781 <pre>
27772782 void lua_pushnumber (lua_State *L, lua_Number n);
27782783 </pre>
@@ -2781,7 +2786,7 @@ the function returns. · 2 unmodified lines
27812786 <p>Pushes a number with value <code>n</code> onto the stack.
27822787
27832788 <p><a name="lua_pushstring"></a>
2784−<hr><h3><code>lua_pushstring</code></h3>
2789+<hr/><h3><code>lua_pushstring</code></h3>
27852790 <pre>
27862791 void lua_pushstring (lua_State *L, const char *s);
27872792 </pre>
@@ -2794,7 +2799,7 @@ so the memory at <code>s</code> can be freed or reused immediately after · 6 unmodified lines
27942799 the function returns.
27952800
27962801 <p><a name="lua_pushvalue"></a>
2797−<hr><h3><code>lua_pushvalue</code></h3>
2802+<hr/><h3><code>lua_pushvalue</code></h3>
27982803 <pre>
27992804 void lua_pushvalue (lua_State *L, int index);
28002805 </pre>
@@ -2804,7 +2809,7 @@ the function returns. · 3 unmodified lines
28042809 onto the stack.
28052810
28062811 <p><a name="lua_pushvfstring"></a>
2807−<hr><h3><code>lua_pushvfstring</code></h3>
2812+<hr/><h3><code>lua_pushvfstring</code></h3>
28082813 <pre>
28092814 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
28102815 </pre>
@@ -2814,7 +2819,7 @@ onto the stack. · 3 unmodified lines
28142819 instead of a variable number of arguments.
28152820
28162821 <p><a name="lua_rawequal"></a>
2817−<hr><h3><code>lua_rawequal</code></h3>
2822+<hr/><h3><code>lua_rawequal</code></h3>
28182823 <pre>
28192824 int lua_rawequal (lua_State *L, int index1, int index2);
28202825 </pre>
@@ -2827,7 +2832,7 @@ Otherwise returns 0. · 6 unmodified lines
28272832 Also returns 0 if any of the indices are non valid.
28282833
28292834 <p><a name="lua_rawget"></a>
2830−<hr><h3><code>lua_rawget</code></h3>
2835+<hr/><h3><code>lua_rawget</code></h3>
28312836 <pre>
28322837 void lua_rawget (lua_State *L, int index);
28332838 </pre>
@@ -2837,7 +2842,7 @@ Also returns 0 if any of the indices are non valid. · 3 unmodified lines
28372842 (i.e., without metamethods).
28382843
28392844 <p><a name="lua_rawgeti"></a>
2840−<hr><h3><code>lua_rawgeti</code></h3>
2845+<hr/><h3><code>lua_rawgeti</code></h3>
28412846 <pre>
28422847 void lua_rawgeti (lua_State *L, int index, int n);
28432848 </pre>
@@ -2849,7 +2854,7 @@ The access is raw, · 5 unmodified lines
28492854 that is, it does not invoke metamethods.
28502855
28512856 <p><a name="lua_rawset"></a>
2852−<hr><h3><code>lua_rawset</code></h3>
2857+<hr/><h3><code>lua_rawset</code></h3>
28532858 <pre>
28542859 void lua_rawset (lua_State *L, int index);
28552860 </pre>
@@ -2859,7 +2864,7 @@ that is, it does not invoke metamethods. · 3 unmodified lines
28592864 (i.e., without metamethods).
28602865
28612866 <p><a name="lua_rawseti"></a>
2862−<hr><h3><code>lua_rawseti</code></h3>
2867+<hr/><h3><code>lua_rawseti</code></h3>
28632868 <pre>
28642869 void lua_rawseti (lua_State *L, int index, int n);
28652870 </pre>
@@ -2874,7 +2879,7 @@ The assignment is raw, · 8 unmodified lines
28742879 that is, it does not invoke metamethods.
28752880
28762881 <p><a name="lua_Reader"></a>
2877−<hr><h3><code>lua_Reader</code></h3>
2882+<hr/><h3><code>lua_Reader</code></h3>
28782883 <pre>
28792884 typedef const char * (*lua_Reader)
28802885 (lua_State *L, void *data, size_t *size);
@@ -2893,7 +2898,7 @@ To signal the end of the chunk, the reader returns <code>NULL</code>. · 12 unmodified lines
28932898 The reader function may return pieces of any size greater than zero.
28942899
28952900 <p><a name="lua_remove"></a>
2896−<hr><h3><code>lua_remove</code></h3>
2901+<hr/><h3><code>lua_remove</code></h3>
28972902 <pre>
28982903 void lua_remove (lua_State *L, int index);
28992904 </pre>
@@ -2905,7 +2910,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
29052910 because a pseudo-index is not an actual stack position.
29062911
29072912 <p><a name="lua_replace"></a>
2908−<hr><h3><code>lua_replace</code></h3>
2913+<hr/><h3><code>lua_replace</code></h3>
29092914 <pre>
29102915 void lua_replace (lua_State *L, int index);
29112916 </pre>
@@ -2916,7 +2921,7 @@ without shifting any element · 4 unmodified lines
29162921 (therefore replacing the value at the given position).
29172922
29182923 <p><a name="lua_resume"></a>
2919−<hr><h3><code>lua_resume</code></h3>
2924+<hr/><h3><code>lua_resume</code></h3>
29202925 <pre>
29212926 int lua_resume (lua_State *L, int narg);
29222927 </pre>
@@ -2932,8 +2937,11 @@ with <code>narg</code> being the number of arguments. · 9 unmodified lines
29322937 This call returns when the coroutine suspends or finishes its execution.
29332938 When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>,
29342939 or all values returned by the body function.
2935−<a href="#lua_resume"><code>lua_resume</code></a> returns 0 if there are no errors running the coroutine,
2936−or an error code (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
2940+<a href="#lua_resume"><code>lua_resume</code></a> returns
2941+<a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields,
2942+0 if the coroutine finishes its execution
2943+without errors,
2944+or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
29372945 In case of errors,
29382946 the stack is not unwound,
29392947 so you can use the debug API over it;
@@ -2942,8 +2950,18 @@ To restart a coroutine, you put on its stack only the values to · 2 unmodified lines
29422950 be passed as results from <code>yield</code>,
29432951 and then call <a href="#lua_resume"><code>lua_resume</code></a>.
29442952
2953+<p><a name="lua_setallocf"></a>
2954+<hr/><h3><code>lua_setallocf</code></h3>
2955+<pre>
2956+ void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
2957+</pre>
2958+
2959+
2960+<p>Changes the allocator function of a given state to <code>f</code>
2961+with user data <code>ud</code>.
2962+
29452963 <p><a name="lua_setfenv"></a>
2946−<hr><h3><code>lua_setfenv</code></h3>
2964+<hr/><h3><code>lua_setfenv</code></h3>
29472965 <pre>
29482966 int lua_setfenv (lua_State *L, int index);
29492967 </pre>
@@ -2956,7 +2974,7 @@ neither a function nor a thread nor a userdata, · 6 unmodified lines
29562974 <a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0 (false).
29572975
29582976 <p><a name="lua_setfield"></a>
2959−<hr><h3><code>lua_setfield</code></h3>
2977+<hr/><h3><code>lua_setfield</code></h3>
29602978 <pre>
29612979 void lua_setfield (lua_State *L, int index, const char *k);
29622980 </pre>
@@ -2971,7 +2989,7 @@ As in Lua, this function may trigger a metamethod · 8 unmodified lines
29712989 for the "newindex" event (see <a href="#metatable">2.8</a>).
29722990
29732991 <p><a name="lua_setmetatable"></a>
2974−<hr><h3><code>lua_setmetatable</code></h3>
2992+<hr/><h3><code>lua_setmetatable</code></h3>
29752993 <pre>
29762994 int lua_setmetatable (lua_State *L, int index);
29772995 </pre>
@@ -2982,7 +3000,7 @@ sets it as the new metatable for the value at the given · 4 unmodified lines
29823000 acceptable index.
29833001
29843002 <p><a name="lua_settable"></a>
2985−<hr><h3><code>lua_settable</code></h3>
3003+<hr/><h3><code>lua_settable</code></h3>
29863004 <pre>
29873005 void lua_settable (lua_State *L, int index);
29883006 </pre>
@@ -2998,7 +3016,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
29983016 for the "newindex" event (see <a href="#metatable">2.8</a>).
29993017
30003018 <p><a name="lua_settop"></a>
3001−<hr><h3><code>lua_settop</code></h3>
3019+<hr/><h3><code>lua_settop</code></h3>
30023020 <pre>
30033021 void lua_settop (lua_State *L, int index);
30043022 </pre>
@@ -3007,11 +3025,11 @@ for the "newindex" event (see <a href="#metatable">2.8</a>). · 2 unmodified lines
30073025 <p>Accepts any acceptable index, or 0,
30083026 and sets the stack top to that index.
30093027 If the new top is larger than the old one,
3010−then the new elements are filled with <B>nil</B>.
3028+then the new elements are filled with <b>nil</b>.
30113029 If <code>index</code> is 0, then all stack elements are removed.
30123030
30133031 <p><a name="lua_State"></a>
3014−<hr><h3><code>lua_State</code></h3>
3032+<hr/><h3><code>lua_State</code></h3>
30153033 <pre>
30163034 typedef struct lua_State lua_State;
30173035 </pre>
@@ -3027,7 +3045,7 @@ every function in the library, except to <a href="#lua_newstate"><code>lua_newst · 9 unmodified lines
30273045 which creates a Lua state from scratch.
30283046
30293047 <p><a name="lua_toboolean"></a>
3030−<hr><h3><code>lua_toboolean</code></h3>
3048+<hr/><h3><code>lua_toboolean</code></h3>
30313049 <pre>
30323050 int lua_toboolean (lua_State *L, int index);
30333051 </pre>
@@ -3037,14 +3055,14 @@ which creates a Lua state from scratch. · 3 unmodified lines
30373055 value ((0 or 1).
30383056 Like all tests in Lua,
30393057 <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns 1 for any Lua value
3040−different from <B>false</B> and <B>nil</B>;
3058+different from <b>false</b> and <b>nil</b>;
30413059 otherwise it returns 0.
30423060 It also returns 0 when called with a non-valid index.
30433061 (If you want to accept only real boolean values,
30443062 use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
30453063
30463064 <p><a name="lua_tocfunction"></a>
3047−<hr><h3><code>lua_tocfunction</code></h3>
3065+<hr/><h3><code>lua_tocfunction</code></h3>
30483066 <pre>
30493067 lua_CFunction lua_tocfunction (lua_State *L, int index);
30503068 </pre>
@@ -3055,7 +3073,7 @@ That value must be a C function; · 4 unmodified lines
30553073 otherwise, returns <code>NULL</code>.
30563074
30573075 <p><a name="lua_tointeger"></a>
3058−<hr><h3><code>lua_tointeger</code></h3>
3076+<hr/><h3><code>lua_tointeger</code></h3>
30593077 <pre>
30603078 lua_Integer lua_tointeger (lua_State *L, int idx);
30613079 </pre>
@@ -3071,7 +3089,7 @@ otherwise, <a href="#lua_tointeger"><code>lua_tointeger</code></a> returns 0. · 9 unmodified lines
30713089 it is truncated in some non-specified way.
30723090
30733091 <p><a name="lua_tolstring"></a>
3074−<hr><h3><code>lua_tolstring</code></h3>
3092+<hr/><h3><code>lua_tolstring</code></h3>
30753093 <pre>
30763094 const char *lua_tolstring (lua_State *L, int index, size_t *len);
30773095 </pre>
@@ -3099,7 +3117,7 @@ there is no guarantee that the pointer returned by <a href="#lua_tolstring"><cod · 21 unmodified lines
30993117 will be valid after the corresponding value is removed from the stack.
31003118
31013119 <p><a name="lua_tonumber"></a>
3102−<hr><h3><code>lua_tonumber</code></h3>
3120+<hr/><h3><code>lua_tonumber</code></h3>
31033121 <pre>
31043122 lua_Number lua_tonumber (lua_State *L, int index);
31053123 </pre>
@@ -3112,7 +3130,7 @@ The Lua value must be a number or a string convertible to number · 6 unmodified lines
31123130 otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0.
31133131
31143132 <p><a name="lua_topointer"></a>
3115−<hr><h3><code>lua_topointer</code></h3>
3133+<hr/><h3><code>lua_topointer</code></h3>
31163134 <pre>
31173135 const void *lua_topointer (lua_State *L, int index);
31183136 </pre>
@@ -3128,7 +3146,7 @@ There is no direct way to convert the pointer back to its original value. · 9 unmodified lines
31283146 <p>Typically this function is used for debug information.
31293147
31303148 <p><a name="lua_tostring"></a>
3131−<hr><h3><code>lua_tostring</code></h3>
3149+<hr/><h3><code>lua_tostring</code></h3>
31323150 <pre>
31333151 const char *lua_tostring (lua_State *L, int index);
31343152 </pre>
@@ -3137,7 +3155,7 @@ There is no direct way to convert the pointer back to its original value. · 2 unmodified lines
31373155 <p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.
31383156
31393157 <p><a name="lua_tothread"></a>
3140−<hr><h3><code>lua_tothread</code></h3>
3158+<hr/><h3><code>lua_tothread</code></h3>
31413159 <pre>
31423160 lua_State *lua_tothread (lua_State *L, int index);
31433161 </pre>
@@ -3149,7 +3167,7 @@ This value must be a thread; · 5 unmodified lines
31493167 otherwise, the function returns <code>NULL</code>.
31503168
31513169 <p><a name="lua_touserdata"></a>
3152−<hr><h3><code>lua_touserdata</code></h3>
3170+<hr/><h3><code>lua_touserdata</code></h3>
31533171 <pre>
31543172 void *lua_touserdata (lua_State *L, int index);
31553173 </pre>
@@ -3162,7 +3180,7 @@ returns its pointer. · 6 unmodified lines
31623180 Otherwise, returns <code>NULL</code>.
31633181
31643182 <p><a name="lua_type"></a>
3165−<hr><h3><code>lua_type</code></h3>
3183+<hr/><h3><code>lua_type</code></h3>
31663184 <pre>
31673185 int lua_type (lua_State *L, int index);
31683186 </pre>
@@ -3184,7 +3202,7 @@ defined in <code>lua.h</code>: · 15 unmodified lines
31843202 <code>LUA_TLIGHTUSERDATA</code>.
31853203
31863204 <p><a name="lua_Writer"></a>
3187−<hr><h3><code>lua_Writer</code></h3>
3205+<hr/><h3><code>lua_Writer</code></h3>
31883206 <pre>
31893207 typedef int (*lua_Writer)
31903208 (lua_State *L, const void* p, size_t sz, void* ud);
@@ -3205,7 +3223,7 @@ any other value means an error and stops <a href="#lua_dump"><code>lua_dump</cod · 14 unmodified lines
32053223 calling the writer again.
32063224
32073225 <p><a name="lua_xmove"></a>
3208−<hr><h3><code>lua_xmove</code></h3>
3226+<hr/><h3><code>lua_xmove</code></h3>
32093227 <pre>
32103228 void lua_xmove (lua_State *from, lua_State *to, int n);
32113229 </pre>
@@ -3217,7 +3235,7 @@ calling the writer again. · 5 unmodified lines
32173235 and pushes them into the stack <code>to</code>.
32183236
32193237 <p><a name="lua_yield"></a>
3220−<hr><h3><code>lua_yield</code></h3>
3238+<hr/><h3><code>lua_yield</code></h3>
32213239 <pre>
32223240 int lua_yield (lua_State *L, int nresults);
32233241 </pre>
@@ -3227,9 +3245,9 @@ and pushes them into the stack <code>to</code>. · 3 unmodified lines
32273245
32283246 <p>This function can only be called as the
32293247 return expression of a C function, as follows:
3230−<PRE>
3248+<pre>
32313249 return lua_yield (L, nresults);
3232−</PRE>
3250+</pre>
32333251 When a C function calls <a href="#lua_yield"><code>lua_yield</code></a> in that way,
32343252 the running coroutine suspends its execution,
32353253 and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns.
@@ -3247,7 +3265,7 @@ kinds of debuggers, profilers, and other tools · 11 unmodified lines
32473265 that need "inside information" from the interpreter.
32483266
32493267 <p><a name="lua_Debug"></a>
3250−<hr><h3><code>lua_Debug</code></h3>
3268+<hr/><h3><code>lua_Debug</code></h3>
32513269 <pre>
32523270 typedef struct lua_Debug {
32533271 int event;
@@ -3260,8 +3278,8 @@ that need "inside information" from the interpreter. · 6 unmodified lines
32603278 int linedefined; /* (S) */
32613279 int lastlinedefined; /* (S) */
32623280 char short_src[LUA_IDSIZE]; /* (S) */
3263−
3264−<p> /* private part */
3281+
3282+ /* private part */
32653283 ...
32663284 } lua_Debug;
32673285
@@ -3329,7 +3347,7 @@ The number of upvalues of the function. · 61 unmodified lines
33293347 <p></ul>
33303348
33313349 <p><a name="lua_gethook"></a>
3332−<hr><h3><code>lua_gethook</code></h3>
3350+<hr/><h3><code>lua_gethook</code></h3>
33333351 <pre>
33343352 lua_Hook lua_gethook (lua_State *L);
33353353 </pre>
@@ -3338,7 +3356,7 @@ The number of upvalues of the function. · 2 unmodified lines
33383356 <p>Returns the current hook function.
33393357
33403358 <p><a name="lua_gethookcount"></a>
3341−<hr><h3><code>lua_gethookcount</code></h3>
3359+<hr/><h3><code>lua_gethookcount</code></h3>
33423360 <pre>
33433361 int lua_gethookcount (lua_State *L);
33443362 </pre>
@@ -3347,7 +3365,7 @@ The number of upvalues of the function. · 2 unmodified lines
33473365 <p>Returns the current hook count.
33483366
33493367 <p><a name="lua_gethookmask"></a>
3350−<hr><h3><code>lua_gethookmask</code></h3>
3368+<hr/><h3><code>lua_gethookmask</code></h3>
33513369 <pre>
33523370 int lua_gethookmask (lua_State *L);
33533371 </pre>
@@ -3356,7 +3374,7 @@ The number of upvalues of the function. · 2 unmodified lines
33563374 <p>Returns the current hook mask.
33573375
33583376 <p><a name="lua_getinfo"></a>
3359−<hr><h3><code>lua_getinfo</code></h3>
3377+<hr/><h3><code>lua_getinfo</code></h3>
33603378 <pre>
33613379 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
33623380 </pre>
@@ -3382,15 +3400,15 @@ you push it onto the stack · 19 unmodified lines
33823400 and start the <code>what</code> string with the character `<code>></code>&acute;.
33833401 For instance, to know in which line a function <code>f</code> was defined,
33843402 you can write the following code:
3385−<PRE>
3403+<pre>
33863404 lua_Debug ar;
33873405 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global `f' */
33883406 lua_getinfo(L, ">S", &#038;ar);
33893407 printf("%d\n", ar.linedefined);
3390−</PRE>
3408+</pre>
33913409
33923410 <p><a name="lua_getlocal"></a>
3393−<hr><h3><code>lua_getlocal</code></h3>
3411+<hr/><h3><code>lua_getlocal</code></h3>
33943412 <pre>
33953413 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
33963414 </pre>
@@ -3406,12 +3424,16 @@ until the last active local variable). · 9 unmodified lines
34063424 <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack,
34073425 and returns its name.
34083426
3427+<p>Variable names starting with `<code>(</code>&acute; (open parentheses)
3428+represent internal variables
3429+(loop control variables, temporaries, and C function locals).
3430+
34093431 <p>Returns <code>NULL</code> (and pushes nothing)
34103432 when the index is greater than
34113433 the number of active local variables.
34123434
34133435 <p><a name="lua_getstack"></a>
3414−<hr><h3><code>lua_getstack</code></h3>
3436+<hr/><h3><code>lua_getstack</code></h3>
34153437 <pre>
34163438 int lua_getstack (lua_State *L, int level, lua_Debug *ar);
34173439 </pre>
@@ -3429,7 +3451,7 @@ when called with a level greater than the stack depth, · 11 unmodified lines
34293451 it returns 0.
34303452
34313453 <p><a name="lua_getupvalue"></a>
3432−<hr><h3><code>lua_getupvalue</code></h3>
3454+<hr/><h3><code>lua_getupvalue</code></h3>
34333455 <pre>
34343456 const char *lua_getupvalue (lua_State *L, int funcindex, int n);
34353457 </pre>
@@ -3452,7 +3474,7 @@ For C functions, this function uses the empty string <code>""</code> · 16 unmodified lines
34523474 as a name for all upvalues.
34533475
34543476 <p><a name="lua_Hook"></a>
3455−<hr><h3><code>lua_Hook</code></h3>
3477+<hr/><h3><code>lua_Hook</code></h3>
34563478 <pre>
34573479 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
34583480 </pre>
@@ -3480,7 +3502,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 21 unmodified lines
34803502 that execution occurs without any calls to hooks.
34813503
34823504 <p><a name="lua_sethook"></a>
3483−<hr><h3><code>lua_sethook</code></h3>
3505+<hr/><h3><code>lua_sethook</code></h3>
34843506 <pre>
34853507 int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
34863508 </pre>
@@ -3515,7 +3537,7 @@ or when it jumps back in the code (even to the same line). · 28 unmodified lines
35153537 <p>A hook is disabled by setting <code>mask</code> to zero.
35163538
35173539 <p><a name="lua_setlocal"></a>
3518−<hr><h3><code>lua_setlocal</code></h3>
3540+<hr/><h3><code>lua_setlocal</code></h3>
35193541 <pre>
35203542 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
35213543 </pre>
@@ -3533,7 +3555,7 @@ when the index is greater than · 11 unmodified lines
35333555 the number of active local variables.
35343556
35353557 <p><a name="lua_setupvalue"></a>
3536−<hr><h3><code>lua_setupvalue</code></h3>
3558+<hr/><h3><code>lua_setupvalue</code></h3>
35373559 <pre>
35383560 const char *lua_setupvalue (lua_State *L, int funcindex, int n);
35393561 </pre>
@@ -3582,7 +3604,7 @@ you should not use those functions for other stack values. · 42 unmodified lines
35823604 in alphabetical order.
35833605
35843606 <p><a name="luaL_addchar"></a>
3585−<hr><h3><code>luaL_addchar</code></h3>
3607+<hr/><h3><code>luaL_addchar</code></h3>
35863608 <pre>
35873609 void luaL_addchar (luaL_Buffer B, char c);
35883610 </pre>
@@ -3592,7 +3614,7 @@ in alphabetical order. · 3 unmodified lines
35923614 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
35933615
35943616 <p><a name="luaL_addlstring"></a>
3595−<hr><h3><code>luaL_addlstring</code></h3>
3617+<hr/><h3><code>luaL_addlstring</code></h3>
35963618 <pre>
35973619 void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
35983620 </pre>
@@ -3603,7 +3625,7 @@ the buffer <code>B</code> · 4 unmodified lines
36033625 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
36043626
36053627 <p><a name="luaL_addsize"></a>
3606−<hr><h3><code>luaL_addsize</code></h3>
3628+<hr/><h3><code>luaL_addsize</code></h3>
36073629 <pre>
36083630 void luaL_addsize (luaL_Buffer B, size_t n);
36093631 </pre>
@@ -3614,7 +3636,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 4 unmodified lines
36143636 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
36153637
36163638 <p><a name="luaL_addstring"></a>
3617−<hr><h3><code>luaL_addstring</code></h3>
3639+<hr/><h3><code>luaL_addstring</code></h3>
36183640 <pre>
36193641 void luaL_addstring (luaL_Buffer *B, const char *s);
36203642 </pre>
@@ -3625,7 +3647,7 @@ to the buffer <code>B</code> · 4 unmodified lines
36253647 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
36263648
36273649 <p><a name="luaL_addvalue"></a>
3628−<hr><h3><code>luaL_addvalue</code></h3>
3650+<hr/><h3><code>luaL_addvalue</code></h3>
36293651 <pre>
36303652 void luaL_addvalue (luaL_Buffer *B);
36313653 </pre>
@@ -3641,7 +3663,7 @@ be called with an extra element on the stack, · 9 unmodified lines
36413663 which is the value to be added to the buffer.
36423664
36433665 <p><a name="luaL_argcheck"></a>
3644−<hr><h3><code>luaL_argcheck</code></h3>
3666+<hr/><h3><code>luaL_argcheck</code></h3>
36453667 <pre>
36463668 void luaL_argcheck (lua_State *L, int cond, int numarg,
36473669 const char *extramsg);
@@ -3654,7 +3676,7 @@ If not, raise an error with message · 6 unmodified lines
36543676 where <code>func</code> is retrieved from the call stack.
36553677
36563678 <p><a name="luaL_argerror"></a>
3657−<hr><h3><code>luaL_argerror</code></h3>
3679+<hr/><h3><code>luaL_argerror</code></h3>
36583680 <pre>
36593681 int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
36603682 </pre>
@@ -3667,7 +3689,7 @@ where <code>func</code> is retrieved from the call stack. · 6 unmodified lines
36673689 <p>This function never returns.
36683690
36693691 <p><a name="luaL_Buffer"></a>
3670−<hr><h3><code>luaL_Buffer</code></h3>
3692+<hr/><h3><code>luaL_Buffer</code></h3>
36713693 <pre>
36723694 typedef struct luaL_Buffer luaL_Buffer;
36733695 </pre>
@@ -3700,7 +3722,7 @@ level when the buffer was initialized, · 26 unmodified lines
37003722 plus the final string on its top.
37013723
37023724 <p><a name="luaL_buffinit"></a>
3703−<hr><h3><code>luaL_buffinit</code></h3>
3725+<hr/><h3><code>luaL_buffinit</code></h3>
37043726 <pre>
37053727 void luaL_buffinit (lua_State *L, luaL_Buffer *B);
37063728 </pre>
@@ -3712,7 +3734,7 @@ the buffer must be declared as a variable · 5 unmodified lines
37123734 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
37133735
37143736 <p><a name="luaL_callmeta"></a>
3715−<hr><h3><code>luaL_callmeta</code></h3>
3737+<hr/><h3><code>luaL_callmeta</code></h3>
37163738 <pre>
37173739 int luaL_callmeta (lua_State *L, int obj, const char *e);
37183740 </pre>
@@ -3729,7 +3751,7 @@ If there is no metatable or no metamethod returns 0 · 10 unmodified lines
37293751 (without pushing any value on the stack).
37303752
37313753 <p><a name="luaL_checkany"></a>
3732−<hr><h3><code>luaL_checkany</code></h3>
3754+<hr/><h3><code>luaL_checkany</code></h3>
37333755 <pre>
37343756 void luaL_checkany (lua_State *L, int narg);
37353757 </pre>
@@ -3738,7 +3760,7 @@ If there is no metatable or no metamethod returns 0 · 2 unmodified lines
37383760 <p>Checks whether the function has an argument <code>narg</code>.
37393761
37403762 <p><a name="luaL_checkint"></a>
3741−<hr><h3><code>luaL_checkint</code></h3>
3763+<hr/><h3><code>luaL_checkint</code></h3>
37423764 <pre>
37433765 int luaL_checkint (lua_State *L, int narg);
37443766 </pre>
@@ -3748,7 +3770,7 @@ If there is no metatable or no metamethod returns 0 · 3 unmodified lines
37483770 and returns that number casted to an <code>int</code>.
37493771
37503772 <p><a name="luaL_checkinteger"></a>
3751−<hr><h3><code>luaL_checkinteger</code></h3>
3773+<hr/><h3><code>luaL_checkinteger</code></h3>
37523774 <pre>
37533775 lua_Integer luaL_checkinteger (lua_State *L, int numArg);
37543776 </pre>
@@ -3758,7 +3780,7 @@ and returns that number casted to an <code>int</code>. · 3 unmodified lines
37583780 and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
37593781
37603782 <p><a name="luaL_checklong"></a>
3761−<hr><h3><code>luaL_checklong</code></h3>
3783+<hr/><h3><code>luaL_checklong</code></h3>
37623784 <pre>
37633785 long luaL_checklong (lua_State *L, int narg);
37643786 </pre>
@@ -3768,7 +3790,7 @@ and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</co · 3 unmodified lines
37683790 and returns that number casted to a <code>long</code>.
37693791
37703792 <p><a name="luaL_checklstring"></a>
3771−<hr><h3><code>luaL_checklstring</code></h3>
3793+<hr/><h3><code>luaL_checklstring</code></h3>
37723794 <pre>
37733795 const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);
37743796 </pre>
@@ -3780,7 +3802,7 @@ if <code>l</code> is not <code>NULL</code> fills the position <code>*l</code> · 5 unmodified lines
37803802 with the string's length.
37813803
37823804 <p><a name="luaL_checknumber"></a>
3783−<hr><h3><code>luaL_checknumber</code></h3>
3805+<hr/><h3><code>luaL_checknumber</code></h3>
37843806 <pre>
37853807 lua_Number luaL_checknumber (lua_State *L, int numArg);
37863808 </pre>
@@ -3790,7 +3812,7 @@ with the string's length. · 3 unmodified lines
37903812 and returns that number.
37913813
37923814 <p><a name="luaL_checkoption"></a>
3793−<hr><h3><code>luaL_checkoption</code></h3>
3815+<hr/><h3><code>luaL_checkoption</code></h3>
37943816 <pre>
37953817 int luaL_checkoption (lua_State *L, int narg, const char *def,
37963818 const char *const lst[]);
@@ -3802,14 +3824,14 @@ searches for that string into the array <code>lst</code> · 5 unmodified lines
38023824 (which must be NULL-terminated).
38033825 If <code>def</code> is not <code>NULL</code>,
38043826 uses <code>def</code> as a default value when
3805−the function has no argument <code>narg</code> or if that argument is <B>nil</B>.
3827+the function has no argument <code>narg</code> or if that argument is <b>nil</b>.
38063828
38073829 <p>Returns the index in the array where the string was found.
38083830 Raises an error if the argument is not a string or
38093831 if the string cannot be found.
38103832
38113833 <p><a name="luaL_checkstack"></a>
3812−<hr><h3><code>luaL_checkstack</code></h3>
3834+<hr/><h3><code>luaL_checkstack</code></h3>
38133835 <pre>
38143836 void luaL_checkstack (lua_State *L, int sz, const char *msg);
38153837 </pre>
@@ -3820,7 +3842,7 @@ raising an error if the stack cannot grow to that size. · 4 unmodified lines
38203842 <code>msg</code> is an additional text to go into the error message.
38213843
38223844 <p><a name="luaL_checkstring"></a>
3823−<hr><h3><code>luaL_checkstring</code></h3>
3845+<hr/><h3><code>luaL_checkstring</code></h3>
38243846 <pre>
38253847 const char *luaL_checkstring (lua_State *L, int narg);
38263848 </pre>
@@ -3830,7 +3852,7 @@ raising an error if the stack cannot grow to that size. · 3 unmodified lines
38303852 and returns that string.
38313853
38323854 <p><a name="luaL_checktype"></a>
3833−<hr><h3><code>luaL_checktype</code></h3>
3855+<hr/><h3><code>luaL_checktype</code></h3>
38343856 <pre>
38353857 void luaL_checktype (lua_State *L, int narg, int t);
38363858 </pre>
@@ -3839,7 +3861,7 @@ and returns that string. · 2 unmodified lines
38393861 <p>Checks whether the function argument <code>narg</code> has type <code>t</code>.
38403862
38413863 <p><a name="luaL_checkudata"></a>
3842−<hr><h3><code>luaL_checkudata</code></h3>
3864+<hr/><h3><code>luaL_checkudata</code></h3>
38433865 <pre>
38443866 void *luaL_checkudata (lua_State *L, int ud, const char *tname);
38453867 </pre>
@@ -3849,7 +3871,7 @@ and returns that string. · 3 unmodified lines
38493871 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
38503872
38513873 <p><a name="luaL_error"></a>
3852−<hr><h3><code>luaL_error</code></h3>
3874+<hr/><h3><code>luaL_error</code></h3>
38533875 <pre>
38543876 int luaL_error (lua_State *L, const char *fmt, ...);
38553877 </pre>
@@ -3866,7 +3888,7 @@ if that information is available. · 10 unmodified lines
38663888 <p>This function never returns.
38673889
38683890 <p><a name="luaL_getmetafield"></a>
3869−<hr><h3><code>luaL_getmetafield</code></h3>
3891+<hr/><h3><code>luaL_getmetafield</code></h3>
38703892 <pre>
38713893 int luaL_getmetafield (lua_State *L, int obj, const char *e);
38723894 </pre>
@@ -3879,7 +3901,7 @@ or if the metatable does not have that field, · 6 unmodified lines
38793901 returns 0 (false) and pushes nothing.
38803902
38813903 <p><a name="luaL_getmetatable"></a>
3882−<hr><h3><code>luaL_getmetatable</code></h3>
3904+<hr/><h3><code>luaL_getmetatable</code></h3>
38833905 <pre>
38843906 void luaL_getmetatable (lua_State *L, const char *tname);
38853907 </pre>
@@ -3889,7 +3911,7 @@ returns 0 (false) and pushes nothing. · 3 unmodified lines
38893911 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
38903912
38913913 <p><a name="luaL_gsub"></a>
3892−<hr><h3><code>luaL_gsub</code></h3>
3914+<hr/><h3><code>luaL_gsub</code></h3>
38933915 <pre>
38943916 const char *luaL_gsub (lua_State *L, const char *s,
38953917 const char *p, const char *r);
@@ -3901,7 +3923,7 @@ by the string <code>r</code>. · 5 unmodified lines
39013923 Pushes the resulting string on the stack and returns it.
39023924
39033925 <p><a name="luaL_loadbuffer"></a>
3904−<hr><h3><code>luaL_loadbuffer</code></h3>
3926+<hr/><h3><code>luaL_loadbuffer</code></h3>
39053927 <pre>
39063928 int luaL_loadbuffer (lua_State *L, const char *buff,
39073929 size_t sz, const char *name);
@@ -3917,7 +3939,7 @@ buffer pointed by <code>buff</code> with size <code>sz</code>. · 9 unmodified lines
39173939 used for debug information and error messages.
39183940
39193941 <p><a name="luaL_loadfile"></a>
3920−<hr><h3><code>luaL_loadfile</code></h3>
3942+<hr/><h3><code>luaL_loadfile</code></h3>
39213943 <pre>
39223944 int luaL_loadfile (lua_State *L, const char *filename);
39233945 </pre>
@@ -3933,7 +3955,7 @@ but it has an extra error code <code>LUA_ERRFILE</code> · 9 unmodified lines
39333955 if it cannot open the file.
39343956
39353957 <p><a name="luaL_loadstring"></a>
3936−<hr><h3><code>luaL_loadstring</code></h3>
3958+<hr/><h3><code>luaL_loadstring</code></h3>
39373959 <pre>
39383960 int luaL_loadstring (lua_State *L, const char *s);
39393961 </pre>
@@ -3946,7 +3968,7 @@ the zero-terminated string <code>s</code>. · 6 unmodified lines
39463968 <p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
39473969
39483970 <p><a name="luaL_newmetatable"></a>
3949−<hr><h3><code>luaL_newmetatable</code></h3>
3971+<hr/><h3><code>luaL_newmetatable</code></h3>
39503972 <pre>
39513973 int luaL_newmetatable (lua_State *L, const char *tname);
39523974 </pre>
@@ -3963,7 +3985,7 @@ and returns 1. · 10 unmodified lines
39633985 with <code>"tname"</code> in the registry.
39643986
39653987 <p><a name="luaL_newstate"></a>
3966−<hr><h3><code>luaL_newstate</code></h3>
3988+<hr/><h3><code>luaL_newstate</code></h3>
39673989 <pre>
39683990 lua_State *luaL_newstate (void);
39693991 </pre>
@@ -3979,7 +4001,7 @@ errors. · 9 unmodified lines
39794001 or <code>NULL</code> if there is a memory allocation error.
39804002
39814003 <p><a name="luaL_optint"></a>
3982−<hr><h3><code>luaL_optint</code></h3>
4004+<hr/><h3><code>luaL_optint</code></h3>
39834005 <pre>
39844006 int luaL_optint (lua_State *L, int narg, int d);
39854007 </pre>
@@ -3987,12 +4009,12 @@ or <code>NULL</code> if there is a memory allocation error. · 1 unmodified line
39874009
39884010 <p>If the function argument <code>narg</code> is a number,
39894011 returns that number casted to an <code>int</code>.
3990−If that argument is absent or is <B>nil</B>,
4012+If that argument is absent or is <b>nil</b>,
39914013 returns <code>d</code>.
39924014 Otherwise, raise an error.
39934015
39944016 <p><a name="luaL_optinteger"></a>
3995−<hr><h3><code>luaL_optinteger</code></h3>
4017+<hr/><h3><code>luaL_optinteger</code></h3>
39964018 <pre>
39974019 lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d);
39984020 </pre>
@@ -4000,12 +4022,12 @@ Otherwise, raise an error. · 1 unmodified line
40004022
40014023 <p>If the function argument <code>narg</code> is a number,
40024024 returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
4003−If that argument is absent or is <B>nil</B>,
4025+If that argument is absent or is <b>nil</b>,
40044026 returns <code>d</code>.
40054027 Otherwise, raise an error.
40064028
40074029 <p><a name="luaL_optlong"></a>
4008−<hr><h3><code>luaL_optlong</code></h3>
4030+<hr/><h3><code>luaL_optlong</code></h3>
40094031 <pre>
40104032 long luaL_optlong (lua_State *L, int narg, long d);
40114033 </pre>
@@ -4013,12 +4035,12 @@ Otherwise, raise an error. · 1 unmodified line
40134035
40144036 <p>If the function argument <code>narg</code> is a number,
40154037 returns that number casted to a <code>long</code>.
4016−If that argument is absent or is <B>nil</B>,
4038+If that argument is absent or is <b>nil</b>,
40174039 returns <code>d</code>.
40184040 Otherwise, raise an error.
40194041
40204042 <p><a name="luaL_optlstring"></a>
4021−<hr><h3><code>luaL_optlstring</code></h3>
4043+<hr/><h3><code>luaL_optlstring</code></h3>
40224044 <pre>
40234045 const char *luaL_optlstring (lua_State *L, int numArg,
40244046 const char *d, size_t *l);
@@ -4027,7 +4049,7 @@ Otherwise, raise an error. · 2 unmodified lines
40274049
40284050 <p>If the function argument <code>narg</code> is a string,
40294051 returns that string.
4030−If that argument is absent or is <B>nil</B>,
4052+If that argument is absent or is <b>nil</b>,
40314053 returns <code>d</code>.
40324054 Otherwise, raise an error.
40334055
@@ -4035,7 +4057,7 @@ Otherwise, raise an error. · 1 unmodified line
40354057 with the results's length.
40364058
40374059 <p><a name="luaL_optnumber"></a>
4038−<hr><h3><code>luaL_optnumber</code></h3>
4060+<hr/><h3><code>luaL_optnumber</code></h3>
40394061 <pre>
40404062 lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d);
40414063 </pre>
@@ -4043,12 +4065,12 @@ with the results's length. · 1 unmodified line
40434065
40444066 <p>If the function argument <code>narg</code> is a number,
40454067 returns that number.
4046−If that argument is absent or is <B>nil</B>,
4068+If that argument is absent or is <b>nil</b>,
40474069 returns <code>d</code>.
40484070 Otherwise, raise an error.
40494071
40504072 <p><a name="luaL_optstring"></a>
4051−<hr><h3><code>luaL_optstring</code></h3>
4073+<hr/><h3><code>luaL_optstring</code></h3>
40524074 <pre>
40534075 const char *luaL_optstring (lua_State *L, int narg, const char *d);
40544076 </pre>
@@ -4056,12 +4078,12 @@ Otherwise, raise an error. · 1 unmodified line
40564078
40574079 <p>If the function argument <code>narg</code> is a string,
40584080 returns that string.
4059−If that argument is absent or is <B>nil</B>,
4081+If that argument is absent or is <b>nil</b>,
40604082 returns <code>d</code>.
40614083 Otherwise, raise an error.
40624084
40634085 <p><a name="luaL_prepbuffer"></a>
4064−<hr><h3><code>luaL_prepbuffer</code></h3>
4086+<hr/><h3><code>luaL_prepbuffer</code></h3>
40654087 <pre>
40664088 char *luaL_prepbuffer (luaL_Buffer *B);
40674089 </pre>
@@ -4075,7 +4097,7 @@ After copying the string into that space you must call · 7 unmodified lines
40754097 it to the buffer.
40764098
40774099 <p><a name="luaL_pushresult"></a>
4078−<hr><h3><code>luaL_pushresult</code></h3>
4100+<hr/><h3><code>luaL_pushresult</code></h3>
40794101 <pre>
40804102 void luaL_pushresult (luaL_Buffer *B);
40814103 </pre>
@@ -4085,7 +4107,7 @@ it to the buffer. · 3 unmodified lines
40854107 the top of the stack.
40864108
40874109 <p><a name="luaL_ref"></a>
4088−<hr><h3><code>luaL_ref</code></h3>
4110+<hr/><h3><code>luaL_ref</code></h3>
40894111 <pre>
40904112 int luaL_ref (lua_State *L, int t);
40914113 </pre>
@@ -4102,13 +4124,13 @@ You can retrieve an object referred by reference <code>r</code> · 10 unmodified lines
41024124 calling <code>lua_rawgeti(L, t, r)</code>.
41034125 Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.
41044126
4105−<p>Whenever the object at the top of the stack is <B>nil</B>,
4127+<p>Whenever the object at the top of the stack is <b>nil</b>,
41064128 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>.
41074129 The constant <code>LUA_NOREF</code> is garanteed to be different
41084130 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
41094131
41104132 <p><a name="luaL_Reg"></a>
4111−<hr><h3><code>luaL_Reg</code></h3>
4133+<hr/><h3><code>luaL_Reg</code></h3>
41124134 <pre>
41134135 typedef struct luaL_Reg {
41144136 const char *name;
@@ -4126,7 +4148,7 @@ Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sent · 11 unmodified lines
41264148 wherein both <code>name</code> and <code>func</code> are <code>NULL</code>.
41274149
41284150 <p><a name="luaL_register"></a>
4129−<hr><h3><code>luaL_register</code></h3>
4151+<hr/><h3><code>luaL_register</code></h3>
41304152 <pre>
41314153 void luaL_register (lua_State *L, const char *libname,
41324154 const luaL_Reg *l);
@@ -4152,7 +4174,7 @@ reuses that table instead of creating a new one. · 19 unmodified lines
41524174 on the top of the stack.
41534175
41544176 <p><a name="luaL_typename"></a>
4155−<hr><h3><code>luaL_typename</code></h3>
4177+<hr/><h3><code>luaL_typename</code></h3>
41564178 <pre>
41574179 const char *luaL_typename (lua_State *L, int idx);
41584180 </pre>
@@ -4161,22 +4183,22 @@ on the top of the stack. · 2 unmodified lines
41614183 <p>Returns the name of the type of the value at index <code>idx</code>.
41624184
41634185 <p><a name="luaL_typerror"></a>
4164−<hr><h3><code>luaL_typerror</code></h3>
4186+<hr/><h3><code>luaL_typerror</code></h3>
41654187 <pre>
41664188 int luaL_typerror (lua_State *L, int narg, const char *tname);
41674189 </pre>
41684190
41694191
41704192 <p>Generates an error with a message like
4171−<PRE>
4193+<pre>
41724194 &#060;location>: bad argument &#060;narg> to &#060;function> (&#060;tname> expected, got &#060;realt>)
4173−</PRE>
4195+</pre>
41744196 where <code>&#060;location></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
41754197 <code>&#060;function></code> is the name of the current function,
41764198 and <code>&#060;realt></code> is the type name of the actual argument.
41774199
41784200 <p><a name="luaL_unref"></a>
4179−<hr><h3><code>luaL_unref</code></h3>
4201+<hr/><h3><code>luaL_unref</code></h3>
41804202 <pre>
41814203 void luaL_unref (lua_State *L, int t, int ref);
41824204 </pre>
@@ -4192,7 +4214,7 @@ The reference <code>ref</code> is also freed to be used again. · 9 unmodified lines
41924214 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
41934215
41944216 <p><a name="luaL_where"></a>
4195−<hr><h3><code>luaL_where</code></h3>
4217+<hr/><h3><code>luaL_where</code></h3>
41964218 <pre>
41974219 void luaL_where (lua_State *L, int lvl);
41984220 </pre>
@@ -4255,14 +4277,14 @@ If you do not include this library in your application, · 56 unmodified lines
42554277 you should check carefully whether you need to provide some alternative
42564278 implementation for some of its facilities.
42574279
4258−<p><a name="pdf-assert"></a><hr><h3><code>assert (v [, message])</code></h3>
4280+<p><a name="pdf-assert"></a><hr/><h3><code>assert (v [, message])</code></h3>
42594281 Issues an error when
4260−the value of its argument <code>v</code> is <B>nil</B> or <B>false</B>;
4282+the value of its argument <code>v</code> is <b>nil</b> or <b>false</b>;
42614283 otherwise, returns all its arguments.
42624284 <code>message</code> is an error message;
42634285 when absent, it defaults to "assertion failed!"
42644286
4265−<p><a name="pdf-collectgarbage"></a><hr><h3><code>collectgarbage (opt [, arg])</code></h3>
4287+<p><a name="pdf-collectgarbage"></a><hr/><h3><code>collectgarbage (opt [, arg])</code></h3>
42664288
42674289 <p>This function is a generic interface to the garbage collector.
42684290 It performs different functions according to its first argument, <code>opt</code>:
@@ -4276,6 +4298,7 @@ The step "size" is controlled by <code>arg</code> · 7 unmodified lines
42764298 (larger values mean more steps) in a non-specified way.
42774299 If you want to control the step size
42784300 you must tune experimentally the value of <code>arg</code>.
4301+Returns <b>true</b> if that step finished a collection cycle.
42794302 <li><b>"steppause"</b>
42804303 sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of
42814304 the collector (see <a href="#GC">2.10</a>).
@@ -4284,7 +4307,7 @@ sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier< · 2 unmodified lines
42844307 the collector (see <a href="#GC">2.10</a>).
42854308 </ul>
42864309
4287−<p><a name="pdf-dofile"></a><hr><h3><code>dofile (filename)</code></h3>
4310+<p><a name="pdf-dofile"></a><hr/><h3><code>dofile (filename)</code></h3>
42884311 Opens the named file and executes its contents as a Lua chunk.
42894312 When called without arguments,
42904313 <a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>).
@@ -4292,7 +4315,7 @@ Returns any value returned by the chunk. · 1 unmodified line
42924315 In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error
42934316 to its caller (that is, it does not run in protected mode).
42944317
4295−<p><a name="pdf-error"></a><hr><h3><code>error (message [, level])</code></h3>
4318+<p><a name="pdf-error"></a><hr/><h3><code>error (message [, level])</code></h3>
42964319 Terminates the last protected function called
42974320 and returns <code>message</code> as the error message.
42984321 Function <a href="#pdf-error"><code>error</code></a> never returns.
@@ -4307,14 +4330,14 @@ that called <a href="#pdf-error"><code>error</code></a> was called; and so on. · 8 unmodified lines
43074330 Passing a level 0 avoids the addition of error position information
43084331 to the message.
43094332
4310−<p><a name="pdf-_G"></a><hr><h3><code>_G</code></h3>
4333+<p><a name="pdf-_G"></a><hr/><h3><code>_G</code></h3>
43114334 A global variable (not a function) that
43124335 holds the global environment (that is, <code>_G._G = _G</code>).
43134336 Lua itself does not use this variable;
43144337 changing its value does not affect any environment.
43154338 (Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.)
43164339
4317−<p><a name="pdf-getfenv"></a><hr><h3><code>getfenv (f)</code></h3>
4340+<p><a name="pdf-getfenv"></a><hr/><h3><code>getfenv (f)</code></h3>
43184341 Returns the current environment in use by the function.
43194342 <code>f</code> can be a Lua function or a number,
43204343 which specifies the function at that stack level:
@@ -4324,73 +4347,73 @@ or if <code>f</code> is 0, · 3 unmodified lines
43244347 <a href="#pdf-getfenv"><code>getfenv</code></a> returns the global environment.
43254348 The default for <code>f</code> is 1.
43264349
4327−<p><a name="pdf-getmetatable"></a><hr><h3><code>getmetatable (object)</code></h3>
4350+<p><a name="pdf-getmetatable"></a><hr/><h3><code>getmetatable (object)</code></h3>
43284351
4329−<p>If <code>object</code> does not have a metatable, returns <B>nil</B>.
4352+<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
43304353 Otherwise,
43314354 if the object's metatable has a <code>"__metatable"</code> field,
43324355 returns the associated value.
43334356 Otherwise, returns the metatable of the given object.
43344357
4335−<p><a name="pdf-ipairs"></a><hr><h3><code>ipairs (t)</code></h3>
4358+<p><a name="pdf-ipairs"></a><hr/><h3><code>ipairs (t)</code></h3>
43364359
43374360 <p>Returns an iterator function, the table <code>t</code>, and 0,
43384361 so that the construction
4339−<PRE>
4362+<pre>
43404363 for i,v in ipairs(t) do ... end
4341−</PRE>
4364+</pre>
43424365 will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
43434366 up to the first integer key with a nil value in the table.
43444367
4345−<p><a name="pdf-load"></a><hr><h3><code>load (func [, chunkname])</code></h3>
4368+<p><a name="pdf-load"></a><hr/><h3><code>load (func [, chunkname])</code></h3>
43464369
43474370 <p>Loads a chunk using function <code>func</code> to get its pieces.
43484371 Each call to <code>func</code> must return a string that concatenates
43494372 with previous results.
4350−A return of <B>nil</B> (or no value) signals the end of the chunk.
4373+A return of <b>nil</b> (or no value) signals the end of the chunk.
43514374
43524375 <p>If there are no errors,
43534376 returns the compiled chunk as a function;
4354−otherwise, returns <B>nil</B> plus the error message.
4377+otherwise, returns <b>nil</b> plus the error message.
43554378 The environment of the returned function is the global environment.
43564379
43574380 <p><code>chunkname</code> is used as the chunk name for error messages
43584381 and debug information.
43594382
4360−<p><a name="pdf-loadfile"></a><hr><h3><code>loadfile (filename)</code></h3>
4383+<p><a name="pdf-loadfile"></a><hr/><h3><code>loadfile (filename)</code></h3>
43614384
43624385 <p>Similar to <a href="#pdf-load"><code>load</code></a>,
43634386 but gets the chunk from file <code>filename</code>.
43644387
4365−<p><a name="pdf-loadstring"></a><hr><h3><code>loadstring (string [, chunkname])</code></h3>
4388+<p><a name="pdf-loadstring"></a><hr/><h3><code>loadstring (string [, chunkname])</code></h3>
43664389
43674390 <p>Similar to <a href="#pdf-load"><code>load</code></a>,
43684391 but gets the chunk from the given string.
43694392
43704393 <p>To load and run a given string, use the idiom
4371−<PRE>
4394+<pre>
43724395 assert(loadstring(s))()
4373−</PRE>
4396+</pre>
43744397
4375−<p><a name="pdf-next"></a><hr><h3><code>next (table [, index])</code></h3>
4398+<p><a name="pdf-next"></a><hr/><h3><code>next (table [, index])</code></h3>
43764399
43774400 <p>Allows a program to traverse all fields of a table.
43784401 Its first argument is a table and its second argument
43794402 is an index in this table.
43804403 <a href="#pdf-next"><code>next</code></a> returns the next index of the table and the
43814404 value associated with the index.
4382−When called with <B>nil</B> as its second argument,
4405+When called with <b>nil</b> as its second argument,
43834406 <a href="#pdf-next"><code>next</code></a> returns the first index
43844407 of the table and its associated value.
43854408 When called with the last index,
4386−or with <B>nil</B> in an empty table,
4387−<a href="#pdf-next"><code>next</code></a> returns <B>nil</B>.
4388−If the second argument is absent, then it is interpreted as <B>nil</B>.
4409+or with <b>nil</b> in an empty table,
4410+<a href="#pdf-next"><code>next</code></a> returns <b>nil</b>.
4411+If the second argument is absent, then it is interpreted as <b>nil</b>.
43894412
43904413 <p>Lua has no declaration of fields;
43914414 There is no difference between a
4392−field not present in a table or a field with value <B>nil</B>.
4393−Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<B>nil</B> values.
4415+field not present in a table or a field with value <b>nil</b>.
4416+Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<b>nil</b> values.
43944417 The order in which the indices are enumerated is not specified,
43954418 <em>even for numeric indices</em>.
43964419 (To traverse a table in numeric order,
@@ -4400,16 +4423,16 @@ use a numerical <b>for</b> or the <a href="#pdf-ipairs"><code>ipairs</code></a> · 3 unmodified lines
44004423 during the traversal,
44014424 you assign any value to a non-existent field in the table.
44024425
4403−<p><a name="pdf-pairs"></a><hr><h3><code>pairs (t)</code></h3>
4426+<p><a name="pdf-pairs"></a><hr/><h3><code>pairs (t)</code></h3>
44044427
4405−<p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <B>nil</B>),
4428+<p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <b>nil</b>),
44064429 so that the construction
4407−<PRE>
4430+<pre>
44084431 for k,v in pairs(t) do ... end
4409−</PRE>
4410−will iterate over all key&ndash;value pairs of table <code>t</code>.
4432+</pre>
4433+will iterate over all key--value pairs of table <code>t</code>.
44114434
4412−<p><a name="pdf-pcall"></a><hr><h3><code>pcall (f, arg1, arg2, ...)</code></h3>
4435+<p><a name="pdf-pcall"></a><hr/><h3><code>pcall (f, arg1, arg2, ...)</code></h3>
44134436
44144437 <p>Calls function <code>f</code> with
44154438 the given arguments in protected mode.
@@ -4420,9 +4443,9 @@ Its first result is the status code (a boolean), · 4 unmodified lines
44204443 which is true if the call succeeds without errors.
44214444 In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call,
44224445 after this first result.
4423−In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <B>false</B> plus the error message.
4446+In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <b>false</b> plus the error message.
44244447
4425−<p><a name="pdf-print"></a><hr><h3><code>print (e1, e2, ...)</code></h3>
4448+<p><a name="pdf-print"></a><hr/><h3><code>print (e1, e2, ...)</code></h3>
44264449 Receives any number of arguments,
44274450 and prints their values in <code>stdout</code>,
44284451 using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.
@@ -4431,32 +4454,32 @@ but only as a quick way to show a value, · 2 unmodified lines
44314454 typically for debugging.
44324455 For formatted output, use <code>format</code> (see <a href="#format">5.4</a>).
44334456
4434−<p><a name="pdf-rawequal"></a><hr><h3><code>rawequal (v1, v2)</code></h3>
4457+<p><a name="pdf-rawequal"></a><hr/><h3><code>rawequal (v1, v2)</code></h3>
44354458 Checks whether <code>v1</code> is equal to <code>v2</code>,
44364459 without invoking any metamethod.
44374460 Returns a boolean.
44384461
4439−<p><a name="pdf-rawget"></a><hr><h3><code>rawget (table, index)</code></h3>
4462+<p><a name="pdf-rawget"></a><hr/><h3><code>rawget (table, index)</code></h3>
44404463 Gets the real value of <code>table[index]</code>,
44414464 without invoking any metamethod.
44424465 <code>table</code> must be a table;
4443−<code>index</code> is any value different from <B>nil</B>.
4466+<code>index</code> is any value different from <b>nil</b>.
44444467
4445−<p><a name="pdf-rawset"></a><hr><h3><code>rawset (table, index, value)</code></h3>
4468+<p><a name="pdf-rawset"></a><hr/><h3><code>rawset (table, index, value)</code></h3>
44464469 Sets the real value of <code>table[index]</code> to <code>value</code>,
44474470 without invoking any metamethod.
44484471 <code>table</code> must be a table,
4449−<code>index</code> is any value different from <B>nil</B>,
4472+<code>index</code> is any value different from <b>nil</b>,
44504473 and <code>value</code> is any Lua value.
44514474
4452−<p><a name="pdf-select"></a><hr><h3><code>select (index, ...)</code></h3>
4475+<p><a name="pdf-select"></a><hr/><h3><code>select (index, ...)</code></h3>
44534476
44544477 <p>If <code>index</code> is a number,
44554478 returns all argument after argument number <code>index</code>.
44564479 Otherwise, <code>index</code> must be the string <code>"#"</code>,
44574480 and <code>select</code> returns the total number of extra arguments it received.
44584481
4459−<p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr><h3><code>setfenv (f, table)</code></h3>
4482+<p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr/><h3><code>setfenv (f, table)</code></h3>
44604483
44614484 <p>Sets the environment to be used by the given function.
44624485 <code>f</code> can be a Lua function or a number,
@@ -4468,22 +4491,22 @@ Level 1 is the function calling <a href="#pdf-setfenv"><code>setfenv</code></a>. · 5 unmodified lines
44684491 the environment of the running thread.
44694492 In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values.
44704493
4471−<p><a name="pdf-setmetatable"></a><hr><h3><code>setmetatable (table, metatable)</code></h3>
4494+<p><a name="pdf-setmetatable"></a><hr/><h3><code>setmetatable (table, metatable)</code></h3>
44724495
44734496 <p>Sets the metatable for the given table.
44744497 (You cannot change the metatable of other types from Lua.)
4475−If <code>metatable</code> is <B>nil</B>,
4498+If <code>metatable</code> is <b>nil</b>,
44764499 removes the metatable of the given table.
44774500 If the original metatable has a <code>"__metatable"</code> field,
44784501 raises an error.
44794502
44804503 <p>This function returns <code>table</code>.
44814504
4482−<p><a name="pdf-tonumber"></a><hr><h3><code>tonumber (e [, base])</code></h3>
4505+<p><a name="pdf-tonumber"></a><hr/><h3><code>tonumber (e [, base])</code></h3>
44834506 Tries to convert its argument to a number.
44844507 If the argument is already a number or a string convertible
44854508 to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number;
4486−otherwise, it returns <B>nil</B>.
4509+otherwise, it returns <b>nil</b>.
44874510
44884511 <p>An optional argument specifies the base to interpret the numeral.
44894512 The base may be any integer between 2 and 36, inclusive.
@@ -4494,7 +4517,7 @@ In base 10 (the default), the number may have a decimal part, · 4 unmodified lines
44944517 as well as an optional exponent part (see <a href="#coercion">2.2.1</a>).
44954518 In other bases, only unsigned integers are accepted.
44964519
4497−<p><a name="pdf-tostring"></a><hr><h3><code>tostring (e)</code></h3>
4520+<p><a name="pdf-tostring"></a><hr/><h3><code>tostring (e)</code></h3>
44984521 Receives an argument of any type and
44994522 converts it to a string in a reasonable format.
45004523 For complete control of how numbers are converted,
@@ -4505,10 +4528,10 @@ use <a href="#pdf-string.format"><code>string.format</code></a> (see <a href="#f · 4 unmodified lines
45054528 with <code>e</code> as argument,
45064529 and uses the result of the call as its result.
45074530
4508−<p><a name="pdf-type"></a><hr><h3><code>type (v)</code></h3>
4531+<p><a name="pdf-type"></a><hr/><h3><code>type (v)</code></h3>
45094532 Returns the type of its only argument, coded as a string.
45104533 The possible results of this function are
4511−<code>"nil"</code> (a string, not the value <B>nil</B>),
4534+<code>"nil"</code> (a string, not the value <b>nil</b>),
45124535 <code>"number"</code>,
45134536 <code>"string"</code>,
45144537 <code>"boolean</code>,
@@ -4517,23 +4540,23 @@ The possible results of this function are · 2 unmodified lines
45174540 <code>"thread"</code>,
45184541 and <code>"userdata"</code>.
45194542
4520−<p><a name="pdf-unpack"></a><hr><h3><code>unpack (list [, i [, j]])</code></h3>
4543+<p><a name="pdf-unpack"></a><hr/><h3><code>unpack (list [, i [, j]])</code></h3>
45214544 Returns the elements from the given list.
45224545 This function is equivalent to
4523−<PRE>
4546+<pre>
45244547 return list[i], list[i+1], ..., list[j]
4525−</PRE>
4548+</pre>
45264549 except that the above code can be written only for a fixed number
45274550 of elements.
45284551 By default, <code>i</code> is 1 and <code>j</code> is the length of the list,
45294552 as defined by the length operator.
45304553
4531−<p><a name="pdf-_VERSION"></a><hr><h3><code>_VERSION</code></h3>
4554+<p><a name="pdf-_VERSION"></a><hr/><h3><code>_VERSION</code></h3>
45324555 A global variable (not a function) that
45334556 holds a string containing the current interpreter version.
45344557 The current contents of this variable is <code>"Lua 5.1"</code>.
45354558
4536−<p><a name="pdf-xpcall"></a><hr><h3><code>xpcall (f, err)</code></h3>
4559+<p><a name="pdf-xpcall"></a><hr/><h3><code>xpcall (f, err)</code></h3>
45374560
45384561 <p>This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
45394562 except that you can set a new error handler.
@@ -4557,14 +4580,14 @@ In case of any error, · 17 unmodified lines
45574580 the basic library and come inside the table <code>coroutine</code>.
45584581 See <a href="#coroutine">2.11</a> for a general description of coroutines.
45594582
4560−<p><a name="pdf-coroutine.create"></a><hr><h3><code>coroutine.create (f)</code></h3>
4583+<p><a name="pdf-coroutine.create"></a><hr/><h3><code>coroutine.create (f)</code></h3>
45614584
45624585 <p>Creates a new coroutine, with body <code>f</code>.
45634586 <code>f</code> must be a Lua function.
45644587 Returns this new coroutine,
45654588 an object with type <code>"thread"</code>.
45664589
4567−<p><a name="pdf-coroutine.resume"></a><hr><h3><code>coroutine.resume (co, val1, ...)</code></h3>
4590+<p><a name="pdf-coroutine.resume"></a><hr/><h3><code>coroutine.resume (co, val1, ...)</code></h3>
45684591
45694592 <p>Starts or continues the execution of coroutine <code>co</code>.
45704593 The first time you resume a coroutine,
@@ -4575,18 +4598,18 @@ If the coroutine has yielded, · 4 unmodified lines
45754598 the arguments <code>val1</code>, ... go as the results from the yield.
45764599
45774600 <p>If the coroutine runs without any errors,
4578−<code>resume</code> returns <B>true</B> plus any values passed to <code>yield</code>
4601+<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>
45794602 (if the coroutine yields) or any values returned by the body function
45804603 (if the coroutine terminates).
45814604 If there is any error,
4582−<code>resume</code> returns <B>false</B> plus the error message.
4605+<code>resume</code> returns <b>false</b> plus the error message.
45834606
4584−<p><a name="pdf-coroutine.running"></a><hr><h3><code>coroutine.running ()</code></h3>
4607+<p><a name="pdf-coroutine.running"></a><hr/><h3><code>coroutine.running ()</code></h3>
45854608
45864609 <p>Returns the running coroutine,
4587−or <B>nil</B> when called by the main thread.
4610+or <b>nil</b> when called by the main thread.
45884611
4589−<p><a name="pdf-coroutine.status"></a><hr><h3><code>coroutine.status (co)</code></h3>
4612+<p><a name="pdf-coroutine.status"></a><hr/><h3><code>coroutine.status (co)</code></h3>
45904613
45914614 <p>Returns the status of coroutine <code>co</code>, as a string:
45924615 <code>"running"</code>,
@@ -4598,7 +4621,7 @@ or if it has not started running yet; · 5 unmodified lines
45984621 and <code>"dead"</code> if the coroutine has finished its body function,
45994622 or if it has stopped with an error.
46004623
4601−<p><a name="pdf-coroutine.wrap"></a><hr><h3><code>coroutine.wrap (f)</code></h3>
4624+<p><a name="pdf-coroutine.wrap"></a><hr/><h3><code>coroutine.wrap (f)</code></h3>
46024625
46034626 <p>Creates a new coroutine, with body <code>f</code>.
46044627 <code>f</code> must be a Lua function.
@@ -4609,7 +4632,7 @@ Returns the same values returned by <code>resume</code>, · 4 unmodified lines
46094632 except the first boolean.
46104633 In case of error, propagates the error.
46114634
4612−<p><a name="pdf-coroutine.yield"></a><hr><h3><code>coroutine.yield (val1, ...)</code></h3>
4635+<p><a name="pdf-coroutine.yield"></a><hr/><h3><code>coroutine.yield (val1, ...)</code></h3>
46134636
46144637 <p>Suspends the execution of the calling coroutine.
46154638 The coroutine cannot be running neither a C function,
@@ -4624,7 +4647,7 @@ It exports two of its functions directly in the global environment: · 8 unmodified lines
46244647 <a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.
46254648 Everything else is exported in a table <code>package</code>.
46264649
4627−<p><a name="pdf-module"></a><hr><h3><code>module (name [, ...])</code></h3>
4650+<p><a name="pdf-module"></a><hr/><h3><code>module (name [, ...])</code></h3>
46284651
46294652 <p>Creates a module.
46304653 If there is a table in <code>package.loaded[name]</code>,
@@ -4654,7 +4677,7 @@ field <code>b</code> of global <code>a</code>. · 23 unmodified lines
46544677 the module name,
46554678 where each option is a function to be applied over the module.
46564679
4657−<p><a name="pdf-require"></a><hr><h3><code>require (modname)</code></h3>
4680+<p><a name="pdf-require"></a><hr/><h3><code>require (modname)</code></h3>
46584681
46594682 <p>Loads the given module.
46604683 The function starts by looking into the table <code>package.loaded</code>
@@ -4682,9 +4705,9 @@ be used as the loader. · 21 unmodified lines
46824705 The name of that C function is the string <code>"luaopen_"</code>
46834706 concatenated with a copy of the module name wherein each dot
46844707 is replaced by an underscore.
4685−Moreover, if the module name has a colon,
4686−its prefix up to (and including) the first colon is removed.
4687−For instance, if the module name is <code>a.v1:b.c</code>,
4708+Moreover, if the module name has a hyphen,
4709+its prefix up to (and including) the first hyphen is removed.
4710+For instance, if the module name is <code>a.v1-b.c</code>,
46884711 the function name will be <code>luaopen_b_c</code>.
46894712
46904713 <p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a
@@ -4715,7 +4738,7 @@ final value of <code>package.loaded[modname]</code>. · 24 unmodified lines
47154738 or if it cannot find any loader for that module,
47164739 then <a href="#pdf-require"><code>require</code></a> signals an error.
47174740
4718−<p><a name="pdf-package.cpath"></a><hr><h3><code>package.cpath</code></h3>
4741+<p><a name="pdf-package.cpath"></a><hr/><h3><code>package.cpath</code></h3>
47194742
47204743 <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader.
47214744
@@ -4724,7 +4747,7 @@ it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code · 2 unmodified lines
47244747 using the environment variable <code>LUA_CPATH</code>
47254748 (plus another compiled-defined default path).
47264749
4727−<p><a name="pdf-package.loaded"></a><hr><h3><code>package.loaded</code></h3>
4750+<p><a name="pdf-package.loaded"></a><hr/><h3><code>package.loaded</code></h3>
47284751
47294752 <p>A table used by <a href="#pdf-require"><code>require</code></a> to control which
47304753 modules are already loaded.
@@ -4732,7 +4755,7 @@ When you require a module <code>modname</code> and · 1 unmodified line
47324755 <code>package.loaded[modname]</code> is not false,
47334756 <a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
47344757
4735−<p><a name="pdf-package.loadlib"></a><hr><h3><code>package.loadlib (libname, funcname)</code></h3>
4758+<p><a name="pdf-package.loadlib"></a><hr/><h3><code>package.loadlib (libname, funcname)</code></h3>
47364759
47374760 <p>Links the program with the dynamic C library <code>libname</code>.
47384761 Inside this library, looks for a function <code>funcname</code>
@@ -4746,7 +4769,7 @@ As such, it is only available on some platforms · 7 unmodified lines
47464769 (Windows, Linux, Solaris, BSD, plus other Unix systems that
47474770 support the <code>dlfcn</code> standard).
47484771
4749−<p><a name="pdf-package.path"></a><hr><h3><code>package.path</code></h3>
4772+<p><a name="pdf-package.path"></a><hr/><h3><code>package.path</code></h3>
47504773
47514774 <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader.
47524775
@@ -4764,20 +4787,20 @@ which is <code>modname</code> with each dot replaced by a · 11 unmodified lines
47644787 "directory separator" (such as <code>"/"</code> in Unix);
47654788 then it will try to load the resulting file name.
47664789 So, for instance, if the Lua path is
4767−<PRE>
4790+<pre>
47684791 "./?.lua;./?.lc;/usr/local/?/init.lua"
4769−</PRE>
4792+</pre>
47704793 the search for a Lua loader for module <code>mod</code>
47714794 will try to load the files
47724795 <code>./mod.lua</code>, <code>./mod.lc</code>, and
47734796 <code>/usr/local/mod/init.lua</code>, in that order.
47744797
4775−<p><a name="pdf-package.preload"></a><hr><h3><code>package.preload</code></h3>
4798+<p><a name="pdf-package.preload"></a><hr/><h3><code>package.preload</code></h3>
47764799
47774800 <p>A table to store loaders for specific modules
47784801 (see <a href="#pdf-require"><code>require</code></a>).
47794802
4780−<p><a name="pdf-package.seeall"></a><hr><h3><code>package.seeall (module)</code></h3>
4803+<p><a name="pdf-package.seeall"></a><hr/><h3><code>package.seeall (module)</code></h3>
47814804
47824805 <p>Sets a metatable for <code>module</code> with
47834806 its <code>__index</code> field refering to the global environment,
@@ -4803,7 +4826,7 @@ Therefore, you can use the string function is object-oriented style. · 19 unmodified lines
48034826 For instance, <code>string.byte(s, i)</code>
48044827 can be written as <code>s:byte(i)</code>.
48054828
4806−<p><a name="pdf-string.byte"></a><hr><h3><code>string.byte (s [, i [, j]])</code></h3>
4829+<p><a name="pdf-string.byte"></a><hr/><h3><code>string.byte (s [, i [, j]])</code></h3>
48074830 Returns the internal numerical codes of the characters <code>s[i]</code>,
48084831 <code>s[i+1]</code>, ..., <code>s[j]</code>.
48094832 The default value for <code>i</code> is 1;
@@ -4811,7 +4834,7 @@ the default value for <code>j</code> is <code>i</code>. · 1 unmodified line
48114834
48124835 <p>Note that numerical codes are not necessarily portable across platforms.
48134836
4814−<p><a name="pdf-string.char"></a><hr><h3><code>string.char (i1, i2, ...)</code></h3>
4837+<p><a name="pdf-string.char"></a><hr/><h3><code>string.char (i1, i2, ...)</code></h3>
48154838 Receives 0 or more integers.
48164839 Returns a string with length equal to the number of arguments,
48174840 in which each character has the internal numerical code equal
@@ -4819,29 +4842,34 @@ to its correspondent argument. · 1 unmodified line
48194842
48204843 <p>Note that numerical codes are not necessarily portable across platforms.
48214844
4822−<p><a name="pdf-string.dump"></a><hr><h3><code>string.dump (function)</code></h3>
4845+<p><a name="pdf-string.dump"></a><hr/><h3><code>string.dump (function)</code></h3>
48234846
48244847 <p>Returns a binary representation of the given function,
48254848 so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns
48264849 a copy of the function.
48274850 <code>function</code> must be a Lua function.
48284851
4829−<p><a name="pdf-string.find"></a><hr><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>
4852+<p><a name="pdf-string.find"></a><hr/><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>
48304853 Looks for the first <em>match</em> of
48314854 <code>pattern</code> in the string <code>s</code>.
48324855 If it finds one, then <code>find</code> returns the indices of <code>s</code>
48334856 where this occurrence starts and ends;
4834−otherwise, it returns <B>nil</B>.
4857+otherwise, it returns <b>nil</b>.
48354858 A third, optional numerical argument <code>init</code> specifies
48364859 where to start the search;
48374860 its default value is 1 and may be negative.
4838−A value of <B>true</B> as a fourth, optional argument <code>plain</code>
4861+A value of <b>true</b> as a fourth, optional argument <code>plain</code>
48394862 turns off the pattern matching facilities,
48404863 so the function does a plain "find substring" operation,
48414864 with no characters in <code>pattern</code> being considered "magic".
48424865 Note that if <code>plain</code> is given, then <code>init</code> must be given too.
48434866
4844−<p><a name="format"></a><a name="pdf-string.format"></a><hr><h3><code>string.format (formatstring, e1, e2, ...)</code></h3>
4867+<p>If the pattern has captures,
4868+then in a successful match
4869+the captured values are also returned,
4870+after the two indices.
4871+
4872+<p><a name="format"></a><a name="pdf-string.format"></a><hr/><h3><code>string.format (formatstring, e1, e2, ...)</code></h3>
48454873 Returns a formatted version of its variable number of arguments
48464874 following the description given in its first argument (which must be a string).
48474875 The format string follows the same rules as the <code>printf</code> family of
@@ -4856,14 +4884,14 @@ The string is written between double quotes, · 8 unmodified lines
48564884 and all double quotes, newlines, and backslashes in the string
48574885 are correctly escaped when written.
48584886 For instance, the call
4859−<PRE>
4887+<pre>
48604888 string.format('%q', 'a string with "quotes" and \n new line')
4861−</PRE>
4889+</pre>
48624890 will produce the string:
4863−<PRE>
4891+<pre>
48644892 "a string with \"quotes\" and \
48654893 new line"
4866−</PRE>
4894+</pre>
48674895
48684896 <p>The options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>,
48694897 <code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all
@@ -4873,7 +4901,7 @@ whereas <code>q</code> and <code>s</code> expect a string. · 3 unmodified lines
48734901 <p>This function does not accept string values
48744902 containing embedded zeros.
48754903
4876−<p><a name="pdf-string.gmatch"></a><hr><h3><code>string.gmatch (s, pat)</code></h3>
4904+<p><a name="pdf-string.gmatch"></a><hr/><h3><code>string.gmatch (s, pat)</code></h3>
48774905 Returns an iterator function that,
48784906 each time it is called,
48794907 returns the next captures from pattern <code>pat</code> over string <code>s</code>.
@@ -4882,25 +4910,25 @@ returns the next captures from pattern <code>pat</code> over string <code>s</cod · 2 unmodified lines
48824910 then the whole match is produced in each call.
48834911
48844912 <p>As an example, the following loop
4885−<PRE>
4913+<pre>
48864914 s = "hello world from Lua"
48874915 for w in string.gmatch(s, "%a+") do
48884916 print(w)
48894917 end
4890−</PRE>
4918+</pre>
48914919 will iterate over all the words from string <code>s</code>,
48924920 printing one per line.
48934921 The next example collects all pairs <code>key=value</code> from the
48944922 given string into a table:
4895−<PRE>
4923+<pre>
48964924 t = {}
48974925 s = "from=world, to=Lua"
48984926 for k, v in string.gmatch(s, "(%w+)=(%w+)") do
48994927 t[k] = v
49004928 end
4901−</PRE>
4929+</pre>
49024930
4903−<p><a name="pdf-string.gsub"></a><hr><h3><code>string.gsub (s, pat, repl [, n])</code></h3>
4931+<p><a name="pdf-string.gsub"></a><hr/><h3><code>string.gsub (s, pat, repl [, n])</code></h3>
49044932 Returns a copy of <code>s</code>
49054933 in which all occurrences of the pattern <code>pat</code> have been
49064934 replaced by a replacement string specified by <code>repl</code>.
@@ -4920,9 +4948,16 @@ match occurs, with all captured substrings passed as arguments, · 13 unmodified lines
49204948 in order;
49214949 if the pattern specifies no captures,
49224950 then the whole match is passed as a sole argument.
4923−If the value returned by this function is a string,
4951+If <code>repl</code> is a table, then this table is queried with the
4952+value of the first capture or of the whole match,
4953+if the pattern specifies no captures.
4954+In both cases,
4955+if the value returned by the function or resulted by the query
4956+is a string,
49244957 then it is used as the replacement string;
4925−otherwise, the replacement string is the empty string.
4958+otherwise, if it is <b>false</b> or <b>nil</b>,
4959+then there is no replacement
4960+(that is, the original match is kept in the string).
49264961
49274962 <p>The optional last parameter <code>n</code> limits
49284963 the maximum number of substitutions to occur.
@@ -4930,7 +4965,7 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 1 unmodified line
49304965 <code>pat</code> is replaced.
49314966
49324967 <p>Here are some examples:
4933−<PRE>
4968+<pre>
49344969 x = string.gsub("hello world", "(%w+)", "%1 %1")
49354970 --> x="hello hello world world"
49364971
@@ -4949,44 +4984,42 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 12 unmodified lines
49494984 --> x="4+5 = 9"
49504985
49514986 local t = {name="lua", version="5.0"}
4952− x = string.gsub("$name_$version.tar.gz", "%$(%w+)", function (v)
4953− return t[v]
4954− end)
4987+ x = string.gsub("$name_$version.tar.gz", "%$(%w+)", t)
49554988 --> x="lua_5.0.tar.gz"
4956−</PRE>
4989+</pre>
49574990
4958−<p><a name="pdf-string.len"></a><hr><h3><code>string.len (s)</code></h3>
4991+<p><a name="pdf-string.len"></a><hr/><h3><code>string.len (s)</code></h3>
49594992 Receives a string and returns its length.
49604993 The empty string <code>""</code> has length 0.
49614994 Embedded zeros are counted,
49624995 so <code>"a\000bc\000"</code> has length 5.
49634996
4964−<p><a name="pdf-string.lower"></a><hr><h3><code>string.lower (s)</code></h3>
4997+<p><a name="pdf-string.lower"></a><hr/><h3><code>string.lower (s)</code></h3>
49654998 Receives a string and returns a copy of that string with all
49664999 uppercase letters changed to lowercase.
49675000 All other characters are left unchanged.
49685001 The definition of what is an uppercase letter depends on the current locale.
49695002
4970−<p><a name="pdf-string.match"></a><hr><h3><code>string.match (s, pattern [, init])</code></h3>
5003+<p><a name="pdf-string.match"></a><hr/><h3><code>string.match (s, pattern [, init])</code></h3>
49715004 Looks for the first <em>match</em> of
49725005 <code>pattern</code> in the string <code>s</code>.
49735006 If it finds one, then <code>match</code> returns
49745007 the captures from the pattern;
4975−otherwise it returns <B>nil</B>.
5008+otherwise it returns <b>nil</b>.
49765009 If <code>pattern</code> specifies no captures,
49775010 then the whole match is returned.
49785011 A third, optional numerical argument <code>init</code> specifies
49795012 where to start the search;
49805013 its default value is 1 and may be negative.
49815014
4982−<p><a name="pdf-string.rep"></a><hr><h3><code>string.rep (s, n)</code></h3>
5015+<p><a name="pdf-string.rep"></a><hr/><h3><code>string.rep (s, n)</code></h3>
49835016 Returns a string that is the concatenation of <code>n</code> copies of
49845017 the string <code>s</code>.
49855018
4986−<p><a name="pdf-string.reverse"></a><hr><h3><code>string.reverse (s)</code></h3>
5019+<p><a name="pdf-string.reverse"></a><hr/><h3><code>string.reverse (s)</code></h3>
49875020 Returns a string that is the string <code>s</code> reversed.
49885021
4989−<p><a name="pdf-string.sub"></a><hr><h3><code>string.sub (s, i [, j])</code></h3>
5022+<p><a name="pdf-string.sub"></a><hr/><h3><code>string.sub (s, i [, j])</code></h3>
49905023 Returns the substring of <code>s</code> that
49915024 starts at <code>i</code> and continues until <code>j</code>;
49925025 <code>i</code> and <code>j</code> may be negative.
@@ -4998,7 +5031,7 @@ with length <code>j</code>, · 5 unmodified lines
49985031 and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>
49995032 with length <code>i</code>.
50005033
5001−<p><a name="pdf-string.upper"></a><hr><h3><code>string.upper (s)</code></h3>
5034+<p><a name="pdf-string.upper"></a><hr/><h3><code>string.upper (s)</code></h3>
50025035 Receives a string and returns a copy of that string with all
50035036 lowercase letters changed to uppercase.
50045037 All other characters are left unchanged.
@@ -5012,26 +5045,26 @@ The following combinations are allowed in describing a character class: · 7 unmodified lines
50125045 <ul>
50135046 <li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters
50145047 <code>^$()%.[]*+-?</code>)
5015−&mdash; represents the character <em>x</em> itself.
5016−<li><b><code>.</code></b> &mdash; (a dot) represents all characters.
5017−<li><b><code>%a</code></b> &mdash; represents all letters.
5018−<li><b><code>%c</code></b> &mdash; represents all control characters.
5019−<li><b><code>%d</code></b> &mdash; represents all digits.
5020−<li><b><code>%l</code></b> &mdash; represents all lowercase letters.
5021−<li><b><code>%p</code></b> &mdash; represents all punctuation characters.
5022−<li><b><code>%s</code></b> &mdash; represents all space characters.
5023−<li><b><code>%u</code></b> &mdash; represents all uppercase letters.
5024−<li><b><code>%w</code></b> &mdash; represents all alphanumeric characters.
5025−<li><b><code>%x</code></b> &mdash; represents all hexadecimal digits.
5026−<li><b><code>%z</code></b> &mdash; represents the character with representation 0.
5027−<li><b><code>%<em>x</em></code></b> (where <em>x</em> is any non-alphanumeric character) &mdash;
5048+--- represents the character <em>x</em> itself.
5049+<li><b><code>.</code></b> --- (a dot) represents all characters.
5050+<li><b><code>%a</code></b> --- represents all letters.
5051+<li><b><code>%c</code></b> --- represents all control characters.
5052+<li><b><code>%d</code></b> --- represents all digits.
5053+<li><b><code>%l</code></b> --- represents all lowercase letters.
5054+<li><b><code>%p</code></b> --- represents all punctuation characters.
5055+<li><b><code>%s</code></b> --- represents all space characters.
5056+<li><b><code>%u</code></b> --- represents all uppercase letters.
5057+<li><b><code>%w</code></b> --- represents all alphanumeric characters.
5058+<li><b><code>%x</code></b> --- represents all hexadecimal digits.
5059+<li><b><code>%z</code></b> --- represents the character with representation 0.
5060+<li><b><code>%<em>x</em></code></b> (where <em>x</em> is any non-alphanumeric character) ---
50285061 represents the character <em>x</em>.
50295062 This is the standard way to escape the magic characters.
50305063 Any punctuation character (even the non magic)
50315064 can be preceded by a `<code>%</code>&acute;
50325065 when used to represent itself in a pattern.
50335066
5034−<p><li><b><code>[<em>set</em>]</code></b> &mdash;
5067+<p><li><b><code>[<em>set</em>]</code></b> ---
50355068 represents the class which is the union of all
50365069 characters in <em>set</em>.
50375070 A range of characters may be specified by
@@ -5049,7 +5082,7 @@ the lowercase letters plus the `<code>-</code>&acute; character. · 11 unmodified lines
50495082 Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>
50505083 have no meaning.
50515084
5052−<p><li><b><code>[^<em>set</em>]</code></b> &mdash;
5085+<p><li><b><code>[^<em>set</em>]</code></b> ---
50535086 represents the complement of <em>set</em>,
50545087 where <em>set</em> is interpreted as above.
50555088 </ul>
@@ -5135,30 +5168,14 @@ represents an array or a list. · 79 unmodified lines
51355168 For those functions, when we talk about "the length" of a table
51365169 we mean the result of the length operator.
51375170
5138−<p><a name="pdf-table.concat"></a><hr><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3>
5171+<p><a name="pdf-table.concat"></a><hr/><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3>
51395172 Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>.
51405173 The default value for <code>sep</code> is the empty string,
51415174 the default for <code>i</code> is 1,
51425175 and the default for <code>j</code> is the length of the table.
51435176 If <code>i</code> is greater than <code>j</code>, returns the empty string.
51445177
5145−<p><a name="pdf-table.sort"></a><hr><h3><code>table.sort (table [, comp])</code></h3>
5146−Sorts table elements in a given order, <em>in-place</em>,
5147−from <code>table[1]</code> to <code>table[n]</code>,
5148−where <code>n</code> is the length of the table.
5149−If <code>comp</code> is given,
5150−then it must be a function that receives two table elements,
5151−and returns true
5152−when the first is less than the second
5153−(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).
5154−If <code>comp</code> is not given,
5155−then the standard Lua operator <code>&#060;</code> is used instead.
5156−
5157−<p>The sort algorithm is not stable,
5158−that is, elements considered equal by the given order
5159−may have their relative positions changed by the sort.
5160−
5161−<p><a name="pdf-table.insert"></a><hr><h3><code>table.insert (table, [pos,] value)</code></h3>
5178+<p><a name="pdf-table.insert"></a><hr/><h3><code>table.insert (table, [pos,] value)</code></h3>
51625179
51635180 <p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>,
51645181 shifting up other elements to open space, if necessary.
@@ -5167,7 +5184,12 @@ where <code>n</code> is the length of the table (see <a href="#len-op">2.5.5</a> · 2 unmodified lines
51675184 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
51685185 of table <code>t</code>.
51695186
5170−<p><a name="pdf-table.remove"></a><hr><h3><code>table.remove (table [, pos])</code></h3>
5187+<p><a name="pdf-table.maxn(table)"></a><hr/><h3><code>table.maxn(table)</code></h3>
5188+
5189+<p>Returns the largest positive numerical index of the given table,
5190+or zero if the table has no positive numerical indices.
5191+
5192+<p><a name="pdf-table.remove"></a><hr/><h3><code>table.remove (table [, pos])</code></h3>
51715193
51725194 <p>Removes from <code>table</code> the element at position <code>pos</code>,
51735195 shifting down other elements to close the space, if necessary.
@@ -5177,26 +5199,42 @@ where <code>n</code> is the length of the table, · 3 unmodified lines
51775199 so that a call <code>table.remove(t)</code> removes the last element
51785200 of table <code>t</code>.
51795201
5202+<p><a name="pdf-table.sort"></a><hr/><h3><code>table.sort (table [, comp])</code></h3>
5203+Sorts table elements in a given order, <em>in-place</em>,
5204+from <code>table[1]</code> to <code>table[n]</code>,
5205+where <code>n</code> is the length of the table.
5206+If <code>comp</code> is given,
5207+then it must be a function that receives two table elements,
5208+and returns true
5209+when the first is less than the second
5210+(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).
5211+If <code>comp</code> is not given,
5212+then the standard Lua operator <code>&#060;</code> is used instead.
5213+
5214+<p>The sort algorithm is not stable,
5215+that is, elements considered equal by the given order
5216+may have their relative positions changed by the sort.
5217+
51805218 <p><a name="mathlib"></a><a name="5.6"></a><h2>5.6 - Mathematical Functions</h2>
51815219
51825220 <p>This library is an interface to the standard C math library.
51835221 It provides all its functions inside the table <code>math</code>.
51845222 The library provides the following functions:
5185−
5186−
5187−
5188−
5189−
5190−
5191−
5192−<PRE>
5223+<a name="pdf-math.abs"></a><a name="pdf-math.acos"></a><a name="pdf-math.asin"></a><a name="pdf-math.atan"></a>
5224+<a name="pdf-math.atan2"></a><a name="pdf-math.ceil"></a><a name="pdf-math.cos"></a><a name="pdf-math.cosh"></a>
5225+<a name="pdf-math.def"></a><a name="pdf-math.exp"></a>
5226+<a name="pdf-math.floor"></a><a name="pdf-math.log"></a><a name="pdf-math.log10"></a>
5227+<a name="pdf-math.fmod"></a><a name="pdf-math.pow"></a><a name="pdf-math.sin"></a>
5228+<a name="pdf-math.sqrt"></a><a name="pdf-math.tan"></a><a name="pdf-math.ldexp"></a>
5229+<a name="pdf-math.sinh"></a><a name="pdf-math.tanh"></a>
5230+<pre>
51935231 math.abs math.acos math.asin math.atan math.atan2
51945232 math.ceil math.cosh math.cos math.deg math.exp
51955233 math.floor math.fmod math.frexp math.ldexp math.log
51965234 math.log10 math.max math.min math.modf math.pow
51975235 math.rad math.random math.randomseed math.sin
51985236 math.sinh math.sqrt math.tan math.tanh
5199−</PRE>
5237+</pre>
52005238 plus a variable <code>math.pi</code> and
52015239 a variable <code>math.huge</code>,
52025240 with the value <code>HUGE_VAL</code>.
@@ -5255,20 +5293,20 @@ three predefined file descriptors with their usual meanings from C: · 52 unmodified lines
52555293 <code>io.stdin</code>, <code>io.stdout</code>, and <code>io.stderr</code>.
52565294
52575295 <p>Unless otherwise stated,
5258−all I/O functions return <B>nil</B> on failure
5296+all I/O functions return <b>nil</b> on failure
52595297 (plus an error message as a second result)
5260−and some value different from <B>nil</B> on success.
5298+and some value different from <b>nil</b> on success.
52615299
5262−<p><a name="pdf-io.close"></a><hr><h3><code>io.close ([file])</code></h3>
5300+<p><a name="pdf-io.close"></a><hr/><h3><code>io.close ([file])</code></h3>
52635301
52645302 <p>Equivalent to <code>file:close()</code>.
52655303 Without a <code>file</code>, closes the default output file.
52665304
5267−<p><a name="pdf-io.flush"></a><hr><h3><code>io.flush ()</code></h3>
5305+<p><a name="pdf-io.flush"></a><hr/><h3><code>io.flush ()</code></h3>
52685306
52695307 <p>Equivalent to <code>file:flush</code> over the default output file.
52705308
5271−<p><a name="pdf-io.input"></a><hr><h3><code>io.input ([file])</code></h3>
5309+<p><a name="pdf-io.input"></a><hr/><h3><code>io.input ([file])</code></h3>
52725310
52735311 <p>When called with a file name, it opens the named file (in text mode),
52745312 and sets its handle as the default input file.
@@ -5280,31 +5318,31 @@ it returns the current default input file. · 5 unmodified lines
52805318 <p>In case of errors this function raises the error,
52815319 instead of returning an error code.
52825320
5283−<p><a name="pdf-io.lines"></a><hr><h3><code>io.lines ([filename])</code></h3>
5321+<p><a name="pdf-io.lines"></a><hr/><h3><code>io.lines ([filename])</code></h3>
52845322
52855323 <p>Opens the given file name in read mode
52865324 and returns an iterator function that,
52875325 each time it is called,
52885326 returns a new line from the file.
52895327 Therefore, the construction
5290−<PRE>
5328+<pre>
52915329 for line in io.lines(filename) do ... end
5292−</PRE>
5330+</pre>
52935331 will iterate over all lines of the file.
52945332 When the iterator function detects the end of file,
5295−it returns <B>nil</B> (to finish the loop) and automatically closes the file.
5333+it returns <b>nil</b> (to finish the loop) and automatically closes the file.
52965334
52975335 <p>The call <code>io.lines()</code> (without a file name) is equivalent
52985336 to <code>io.input():lines()</code>, that is, it iterates over the
52995337 lines of the default input file.
53005338 In that case it does not close the file when the loop ends.
53015339
5302−<p><a name="pdf-io.open"></a><hr><h3><code>io.open (filename [, mode])</code></h3>
5340+<p><a name="pdf-io.open"></a><hr/><h3><code>io.open (filename [, mode])</code></h3>
53035341
53045342 <p>This function opens a file,
53055343 in the mode specified in the string <code>mode</code>.
53065344 It returns a new file handle,
5307−or, in case of errors, <B>nil</B> plus an error message.
5345+or, in case of errors, <b>nil</b> plus an error message.
53085346
53095347 <p>The <code>mode</code> string can be any of the following:
53105348 <ul>
@@ -5321,11 +5359,11 @@ which is needed in some systems to open the file in binary mode. · 10 unmodified lines
53215359 This string is exactly what is used in the
53225360 standard C function <code>fopen</code>.
53235361
5324−<p><a name="pdf-io.output"></a><hr><h3><code>io.output ([file])</code></h3>
5362+<p><a name="pdf-io.output"></a><hr/><h3><code>io.output ([file])</code></h3>
53255363
53265364 <p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file.
53275365
5328−<p><a name="pdf-io.popen"></a><hr><h3><code>io.popen ([prog [, mode]])</code></h3>
5366+<p><a name="pdf-io.popen"></a><hr/><h3><code>io.popen ([prog [, mode]])</code></h3>
53295367
53305368 <p>Starts program <code>prog</code> in a separated process and returns
53315369 a file handle that you can use to read data from that program
@@ -5336,57 +5374,57 @@ or to write data to that program · 4 unmodified lines
53365374 <p>This function is system dependent and is not available
53375375 in all platforms.
53385376
5339−<p><a name="pdf-io.read"></a><hr><h3><code>io.read (format1, ...)</code></h3>
5377+<p><a name="pdf-io.read"></a><hr/><h3><code>io.read (format1, ...)</code></h3>
53405378
53415379 <p>Equivalent to <code>io.input():read</code>.
53425380
5343−<p><a name="pdf-io.tmpfile"></a><hr><h3><code>io.tmpfile ()</code></h3>
5381+<p><a name="pdf-io.tmpfile"></a><hr/><h3><code>io.tmpfile ()</code></h3>
53445382
53455383 <p>Returns a handle for a temporary file.
53465384 This file is open in update mode
53475385 and it is automatically removed when the program ends.
53485386
5349−<p><a name="pdf-io.type"></a><hr><h3><code>io.type (obj)</code></h3>
5387+<p><a name="pdf-io.type"></a><hr/><h3><code>io.type (obj)</code></h3>
53505388
53515389 <p>Checks whether <code>obj</code> is a valid file handle.
53525390 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
53535391 <code>"closed file"</code> if <code>obj</code> is a closed file handle,
5354−and <B>nil</B> if <code>obj</code> is not a file handle.
5392+and <b>nil</b> if <code>obj</code> is not a file handle.
53555393
5356−<p><a name="pdf-io.write"></a><hr><h3><code>io.write (value1, ...)</code></h3>
5394+<p><a name="pdf-io.write"></a><hr/><h3><code>io.write (value1, ...)</code></h3>
53575395
53585396 <p>Equivalent to <code>io.output():write</code>.
53595397
5360−<p><a name="pdf-file:close"></a><hr><h3><code>file:close ()</code></h3>
5398+<p><a name="pdf-file:close"></a><hr/><h3><code>file:close ()</code></h3>
53615399
53625400 <p>Closes <code>file</code>.
53635401 Note that files are automatically closed when garbage collected,
53645402 but that takes an unpredictable time to happen.
53655403
5366−<p><a name="flush"></a><a name="pdf-file:flush"></a><hr><h3><code>file:flush ()</code></h3>
5404+<p><a name="flush"></a><a name="pdf-file:flush"></a><hr/><h3><code>file:flush ()</code></h3>
53675405
53685406 <p>Saves any written data to <code>file</code>.
53695407
5370−<p><a name="pdf-file:lines"></a><hr><h3><code>file:lines ()</code></h3>
5408+<p><a name="pdf-file:lines"></a><hr/><h3><code>file:lines ()</code></h3>
53715409
53725410 <p>Returns an iterator function that,
53735411 each time it is called,
53745412 returns a new line from the file.
53755413 Therefore, the construction
5376−<PRE>
5414+<pre>
53775415 for line in file:lines() do ... end
5378−</PRE>
5416+</pre>
53795417 will iterate over all lines of the file.
53805418 (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
53815419 when the loop ends.)
53825420
5383−<p><a name="pdf-file:read"></a><hr><h3><code>file:read (format1, ...)</code></h3>
5421+<p><a name="pdf-file:read"></a><hr/><h3><code>file:read (format1, ...)</code></h3>
53845422
53855423 <p>Reads the file <code>file</code>,
53865424 according to the given formats, which specify what to read.
53875425 For each format,
53885426 the function returns a string (or a number) with the characters read,
5389−or <B>nil</B> if it cannot read data with the specified format.
5427+or <b>nil</b> if it cannot read data with the specified format.
53905428 When called without formats,
53915429 it uses a default format that reads the entire next line
53925430 (see below).
@@ -5398,16 +5436,16 @@ this is the only format that returns a number instead of a string. · 5 unmodified lines
53985436 <li><b>"*a"</b> reads the whole file, starting at the current position.
53995437 On end of file, it returns the empty string.
54005438 <li><b>"*l"</b> reads the next line (skipping the end of line),
5401−returning <B>nil</B> on end of file.
5439+returning <b>nil</b> on end of file.
54025440 This is the default format.
54035441 <li><b><em>number</em></b> reads a string with up to that number of characters,
5404−returning <B>nil</B> on end of file.
5442+returning <b>nil</b> on end of file.
54055443 If number is zero,
54065444 it reads nothing and returns an empty string,
5407−or <B>nil</B> on end of file.
5445+or <b>nil</b> on end of file.
54085446 </ul>
54095447
5410−<p><a name="pdf-file:seek"></a><hr><h3><code>file:seek ([whence] [, offset])</code></h3>
5448+<p><a name="pdf-file:seek"></a><hr/><h3><code>file:seek ([whence] [, offset])</code></h3>
54115449
54125450 <p>Sets and gets the file position,
54135451 measured from the beginning of the file,
@@ -5420,7 +5458,7 @@ specified by the string <code>whence</code>, as follows: · 6 unmodified lines
54205458 </ul>
54215459 In case of success, function <code>seek</code> returns the final file position,
54225460 measured in bytes from the beginning of the file.
5423−If this function fails, it returns <B>nil</B>,
5461+If this function fails, it returns <b>nil</b>,
54245462 plus a string describing the error.
54255463
54265464 <p>The default value for <code>whence</code> is <code>"cur"</code>,
@@ -5432,7 +5470,7 @@ beginning of the file (and returns 0); · 5 unmodified lines
54325470 and the call <code>file:seek("end")</code> sets the position to the
54335471 end of the file, and returns its size.
54345472
5435−<p><a name="pdf-file:setvbuf"></a><hr><h3><code>file:setvbuf (mode [, size])</code></h3>
5473+<p><a name="pdf-file:setvbuf"></a><hr/><h3><code>file:setvbuf (mode [, size])</code></h3>
54365474
54375475 <p>Sets the buffering mode for an output file.
54385476 There are three available modes:
@@ -5448,7 +5486,7 @@ For the last two cases, <code>sizes</code> · 9 unmodified lines
54485486 specifies the size of the buffer, in bytes.
54495487 The default is an appropriate size.
54505488
5451−<p><a name="pdf-file:write"></a><hr><h3><code>file:write (value1, ...)</code></h3>
5489+<p><a name="pdf-file:write"></a><hr/><h3><code>file:write (value1, ...)</code></h3>
54525490
54535491 <p>Writes the value of each of its arguments to
54545492 the filehandle <code>file</code>.
@@ -5460,12 +5498,12 @@ use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.fo · 5 unmodified lines
54605498
54615499 <p>This library is implemented through table <code>os</code>.
54625500
5463−<p><a name="pdf-os.clock"></a><hr><h3><code>os.clock ()</code></h3>
5501+<p><a name="pdf-os.clock"></a><hr/><h3><code>os.clock ()</code></h3>
54645502
54655503 <p>Returns an approximation of the amount of CPU time
54665504 used by the program, in seconds.
54675505
5468−<p><a name="pdf-os.date"></a><hr><h3><code>os.date ([format [, time]])</code></h3>
5506+<p><a name="pdf-os.date"></a><hr/><h3><code>os.date ([format [, time]])</code></h3>
54695507
54705508 <p>Returns a string or a table containing date and time,
54715509 formatted according to the given string <code>format</code>.
@@ -5495,43 +5533,43 @@ formatted according to the same rules as the C function <code>strftime</code>. · 23 unmodified lines
54955533 the host system and on the current locale
54965534 (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).
54975535
5498−<p><a name="pdf-os.difftime"></a><hr><h3><code>os.difftime (t2, t1)</code></h3>
5536+<p><a name="pdf-os.difftime"></a><hr/><h3><code>os.difftime (t2, t1)</code></h3>
54995537
55005538 <p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>.
55015539 In Posix, Windows, and some other systems,
55025540 this value is exactly <code>t2</code><em>-</em><code>t1</code>.
55035541
5504−<p><a name="pdf-os.execute"></a><hr><h3><code>os.execute (command)</code></h3>
5542+<p><a name="pdf-os.execute"></a><hr/><h3><code>os.execute (command)</code></h3>
55055543
55065544 <p>This function is equivalent to the C function <code>system</code>.
55075545 It passes <code>command</code> to be executed by an operating system shell.
55085546 It returns a status code, which is system-dependent.
55095547
5510−<p><a name="pdf-os.exit"></a><hr><h3><code>os.exit ([code])</code></h3>
5548+<p><a name="pdf-os.exit"></a><hr/><h3><code>os.exit ([code])</code></h3>
55115549
55125550 <p>Calls the C function <code>exit</code>,
55135551 with an optional <code>code</code>,
55145552 to terminate the host program.
55155553 The default value for <code>code</code> is the success code.
55165554
5517−<p><a name="pdf-os.getenv"></a><hr><h3><code>os.getenv (varname)</code></h3>
5555+<p><a name="pdf-os.getenv"></a><hr/><h3><code>os.getenv (varname)</code></h3>
55185556
55195557 <p>Returns the value of the process environment variable <code>varname</code>,
5520−or <B>nil</B> if the variable is not defined.
5558+or <b>nil</b> if the variable is not defined.
55215559
5522−<p><a name="pdf-os.remove"></a><hr><h3><code>os.remove (filename)</code></h3>
5560+<p><a name="pdf-os.remove"></a><hr/><h3><code>os.remove (filename)</code></h3>
55235561
55245562 <p>Deletes the file with the given name.
5525−If this function fails, it returns <B>nil</B>,
5563+If this function fails, it returns <b>nil</b>,
55265564 plus a string describing the error.
55275565
5528−<p><a name="pdf-os.rename"></a><hr><h3><code>os.rename (oldname, newname)</code></h3>
5566+<p><a name="pdf-os.rename"></a><hr/><h3><code>os.rename (oldname, newname)</code></h3>
55295567
55305568 <p>Renames file named <code>oldname</code> to <code>newname</code>.
5531−If this function fails, it returns <B>nil</B>,
5569+If this function fails, it returns <b>nil</b>,
55325570 plus a string describing the error.
55335571
5534−<p><a name="pdf-os.setlocale"></a><hr><h3><code>os.setlocale (locale [, category])</code></h3>
5572+<p><a name="pdf-os.setlocale"></a><hr/><h3><code>os.setlocale (locale [, category])</code></h3>
55355573
55365574 <p>Sets the current locale of the program.
55375575 <code>locale</code> is a string specifying a locale;
@@ -5540,9 +5578,9 @@ plus a string describing the error. · 2 unmodified lines
55405578 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;
55415579 the default category is <code>"all"</code>.
55425580 The function returns the name of the new locale,
5543−or <B>nil</B> if the request cannot be honored.
5581+or <b>nil</b> if the request cannot be honored.
55445582
5545−<p><a name="pdf-os.time"></a><hr><h3><code>os.time ([table])</code></h3>
5583+<p><a name="pdf-os.time"></a><hr/><h3><code>os.time ([table])</code></h3>
55465584
55475585 <p>Returns the current time when called without arguments,
55485586 or a time representing the date and time specified by the given table.
@@ -5557,7 +5595,7 @@ In other systems, the meaning is not specified, · 8 unmodified lines
55575595 and the number returned by <code>time</code> can be used only as an argument to
55585596 <code>date</code> and <code>difftime</code>.
55595597
5560−<p><a name="pdf-os.tmpname"></a><hr><h3><code>os.tmpname ()</code></h3>
5598+<p><a name="pdf-os.tmpname"></a><hr/><h3><code>os.tmpname ()</code></h3>
55615599
55625600 <p>Returns a string with a file name that can
55635601 be used for a temporary file.
@@ -5583,7 +5621,7 @@ and therefore can compromise some otherwise secure code. · 19 unmodified lines
55835621 <p>All functions in this library are provided
55845622 inside a <code>debug</code> table.
55855623
5586−<p><a name="pdf-debug.debug"></a><hr><h3><code>debug.debug ()</code></h3>
5624+<p><a name="pdf-debug.debug"></a><hr/><h3><code>debug.debug ()</code></h3>
55875625
55885626 <p>Enters an interactive mode with the user,
55895627 running each string that the user enters.
@@ -5596,17 +5634,17 @@ so that the caller continues its execution. · 6 unmodified lines
55965634 <p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested
55975635 with any function, so they have no direct access to local variables.
55985636
5599−<p><a name="pdf-debug.getfenv"></a><hr><h3><code>debug.getfenv (o)</code></h3>
5637+<p><a name="pdf-debug.getfenv"></a><hr/><h3><code>debug.getfenv (o)</code></h3>
56005638 Returns the environment of object <code>o</code>.
56015639
5602−<p><a name="pdf-debug.gethook"></a><hr><h3><code>debug.gethook ()</code></h3>
5640+<p><a name="pdf-debug.gethook"></a><hr/><h3><code>debug.gethook ()</code></h3>
56035641
56045642 <p>Returns the current hook settings, as three values:
56055643 the current hook function, the current hook mask,
56065644 and the current hook count
56075645 (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).
56085646
5609−<p><a name="pdf-debug.getinfo"></a><hr><h3><code>debug.getinfo (function [, what])</code></h3>
5647+<p><a name="pdf-debug.getinfo"></a><hr/><h3><code>debug.getinfo (function [, what])</code></h3>
56105648
56115649 <p>This function returns a table with information about a function.
56125650 You can give the function directly,
@@ -5616,7 +5654,7 @@ Level 0 is the current function (<code>getinfo</code> itself); · 3 unmodified lines
56165654 level 1 is the function that called <code>getinfo</code>;
56175655 and so on.
56185656 If <code>function</code> is a number larger than the number of active functions,
5619−then <code>getinfo</code> returns <B>nil</B>.
5657+then <code>getinfo</code> returns <b>nil</b>.
56205658
56215659 <p>The returned table contains all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>,
56225660 with the string <code>what</code> describing which fields to fill in.
@@ -5630,33 +5668,41 @@ the name of the current function, if a reasonable name can be found, · 7 unmodified lines
56305668 and <code>debug.getinfo(print)</code> returns a table with all available information
56315669 about the <a href="#pdf-print"><code>print</code></a> function.
56325670
5633−<p><a name="pdf-debug.getlocal"></a><hr><h3><code>debug.getlocal (level, local)</code></h3>
5671+<p><a name="pdf-debug.getlocal"></a><hr/><h3><code>debug.getlocal (level, local)</code></h3>
56345672
56355673 <p>This function returns the name and the value of the local variable
56365674 with index <code>local</code> of the function at level <code>level</code> of the stack.
56375675 (The first parameter or local variable has index 1, and so on,
56385676 until the last active local variable.)
5639−The function returns <B>nil</B> if there is no local
5677+The function returns <b>nil</b> if there is no local
56405678 variable with the given index,
56415679 and raises an error when called with a <code>level</code> out of range.
56425680 (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.)
56435681
5644−<p><a name="pdf-debug.getmetatable"></a><hr><h3><code>debug.getmetatable (object)</code></h3>
5682+<p>Variable names starting with `<code>(</code>&acute; (open parentheses)
5683+represent internal variables
5684+(loop control variables, temporaries, and C function locals).
56455685
5646−<p>If <code>object</code> does not have a metatable, returns <B>nil</B>.
5686+<p><a name="pdf-debug.getmetatable"></a><hr/><h3><code>debug.getmetatable (object)</code></h3>
5687+
5688+<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
56475689 Otherwise, returns the metatable of the given object.
56485690
5649−<p><a name="pdf-debug.getupvalue"></a><hr><h3><code>debug.getupvalue (func, up)</code></h3>
5691+<p><a name="pdf-debug.getregistry"></a><hr/><h3><code>debug.getregistry ()</code></h3>
5692+
5693+<p>Returns the registry table (see <a href="#registry">3.5</a>).
5694+
5695+<p><a name="pdf-debug.getupvalue"></a><hr/><h3><code>debug.getupvalue (func, up)</code></h3>
56505696
56515697 <p>This function returns the name and the value of the upvalue
56525698 with index <code>up</code> of the function <code>func</code>.
5653−The function returns <B>nil</B> if there is no upvalue with the given index.
5699+The function returns <b>nil</b> if there is no upvalue with the given index.
56545700
5655−<p><a name="pdf-debug.setfenv"></a><hr><h3><code>debug.setfenv (o, table)</code></h3>
5701+<p><a name="pdf-debug.setfenv"></a><hr/><h3><code>debug.setfenv (o, table)</code></h3>
56565702
56575703 <p>Sets the environment of the given object.
56585704
5659−<p><a name="pdf-debug.sethook"></a><hr><h3><code>debug.sethook (hook, mask [, count])</code></h3>
5705+<p><a name="pdf-debug.sethook"></a><hr/><h3><code>debug.sethook (hook, mask [, count])</code></h3>
56605706
56615707 <p>Sets the given function as a hook.
56625708 The string <code>mask</code> and the number <code>count</code> describe
@@ -5689,29 +5735,29 @@ unless the event is <code>"tail return"</code>. · 26 unmodified lines
56895735 In this case, Lua is only simulating the return,
56905736 and a call to <code>getinfo</code> will return invalid data.
56915737
5692−<p><a name="pdf-debug.setlocal"></a><hr><h3><code>debug.setlocal (level, local, value)</code></h3>
5738+<p><a name="pdf-debug.setlocal"></a><hr/><h3><code>debug.setlocal (level, local, value)</code></h3>
56935739
56945740 <p>This function assigns the value <code>value</code> to the local variable
56955741 with index <code>local</code> of the function at level <code>level</code> of the stack.
5696−The function returns <B>nil</B> if there is no local
5742+The function returns <b>nil</b> if there is no local
56975743 variable with the given index,
56985744 and raises an error when called with a <code>level</code> out of range.
56995745 (You can call <code>getinfo</code> to check whether the level is valid.)
57005746 Otherwise, it returns the name of the local variable.
57015747
5702−<p><a name="pdf-debug.setmetatable"></a><hr><h3><code>debug.setmetatable (o, metatable)</code></h3>
5748+<p><a name="pdf-debug.setmetatable"></a><hr/><h3><code>debug.setmetatable (o, metatable)</code></h3>
57035749
57045750 <p>Sets the metatable for the given object.
57055751
5706−<p><a name="pdf-debug.setupvalue"></a><hr><h3><code>debug.setupvalue (func, up, value)</code></h3>
5752+<p><a name="pdf-debug.setupvalue"></a><hr/><h3><code>debug.setupvalue (func, up, value)</code></h3>
57075753
57085754 <p>This function assigns the value <code>value</code> to the upvalue
57095755 with index <code>up</code> of the function <code>func</code>.
5710−The function returns <B>nil</B> if there is no upvalue
5756+The function returns <b>nil</b> if there is no upvalue
57115757 with the given index.
57125758 Otherwise, it returns the name of the upvalue.
57135759
5714−<p><a name="pdf-debug.traceback"></a><hr><h3><code>debug.traceback ([message])</code></h3>
5760+<p><a name="pdf-debug.traceback"></a><hr/><h3><code>debug.traceback ([message])</code></h3>
57155761
57165762 <p>Returns a string with a traceback of the call stack.
57175763 An optional <code>message</code> string is appended
@@ -5731,17 +5777,17 @@ is provided with the standard distribution. · 13 unmodified lines
57315777 The stand-alone interpreter includes
57325778 all standard libraries plus the reflexive debug interface.
57335779 Its usage is:
5734−<PRE>
5780+<pre>
57355781 lua [options] [script [args]]
5736−</PRE>
5782+</pre>
57375783 The options are:
57385784 <ul>
5739−<li><b><code>-</code> </b> executes <code>stdin</code> as a file;
57405785 <li><b><code>-e</code> <em>stat</em></b> executes string <em>stat</em>;
57415786 <li><b><code>-l</code> <em>mod</em></b> "requires" <em>mod</em>;
57425787 <li><b><code>-i</code></b> enters interactive mode after running <em>script</em>;
57435788 <li><b><code>-v</code></b> prints version information;
5744−<li><b><code>--</code></b> stop handling options.
5789+<li><b><code>--</code></b> stops handling options;
5790+<li><b><code>-</code> </b> executes <code>stdin</code> as a file and stops handling options.
57455791 </ul>
57465792 After handling its options, <code>lua</code> runs the given <em>script</em>,
57475793 passing to it the given <em>args</em>.
@@ -5757,9 +5803,9 @@ Otherwise, lua executes the string itself. · 9 unmodified lines
57575803
57585804 <p>All options are handled in order, except <code>-i</code>.
57595805 For instance, an invocation like
5760−<PRE>
5806+<pre>
57615807 $ lua -e'a=1' -e 'print(a)' script.lua
5762−</PRE>
5808+</pre>
57635809 will first set <code>a</code> to 1, then print <code>a</code>,
57645810 and finally run the file <code>script.lua</code>.
57655811 (Here <code>$</code> is the shell prompt. Your prompt may be different.)
@@ -5774,15 +5820,15 @@ Any arguments before the script name · 8 unmodified lines
57745820 (that is, the interpreter name plus the options)
57755821 go to negative indices.
57765822 For instance, in the call
5777−<PRE>
5823+<pre>
57785824 $ lua -la.lua b.lua t1 t2
5779−</PRE>
5825+</pre>
57805826 the interpreter first runs the file <code>a.lua</code>,
57815827 then creates a table
5782−<PRE>
5828+<pre>
57835829 arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua",
57845830 [1] = "t1", [2] = "t2" }
5785−</PRE>
5831+</pre>
57865832 and finally runs the file <code>b.lua</code>.
57875833 The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...
57885834 as arguments;
@@ -5795,9 +5841,9 @@ the interpreter waits for its completion. · 6 unmodified lines
57955841 <p>If the global variable <code>_PROMPT</code> is defined as a string,
57965842 then its value is used as the prompt.
57975843 Therefore, the prompt can be changed directly on the command line:
5798−<PRE>
5844+<pre>
57995845 $ lua -e"_PROMPT='myprompt> '" -i
5800−</PRE>
5846+</pre>
58015847 (the outer pair of quotes is for the shell,
58025848 the inner is for Lua),
58035849 or in any Lua programs by assigning to <code>_PROMPT</code>.
@@ -5811,19 +5857,19 @@ the first line of a chunk if it starts with <code>#</code>. · 7 unmodified lines
58115857 Therefore, Lua scripts can be made into executable programs
58125858 by using <code>chmod +x</code> and the <code>#!</code> form,
58135859 as in
5814−<PRE>
5860+<pre>
58155861 #!/usr/local/bin/lua
5816−</PRE>
5862+</pre>
58175863 (Of course,
58185864 the location of the Lua interpreter may be different in your machine.
58195865 If <code>lua</code> is in your <code>PATH</code>,
58205866 then
5821−<PRE>
5867+<pre>
58225868 #!/usr/bin/env lua
5823−</PRE>
5869+</pre>
58245870 is a more portable solution.)
58255871
5826−<p><hr>
5872+<p><hr/>
58275873
58285874 <p><h1>Incompatibilities with Previous Version</h1>
58295875
@@ -5866,6 +5912,13 @@ Use <a href="#pdf-string.match"><code>string.match</code></a> for that. · 36 unmodified lines
58665912 Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.
58675913 (Option <code>LUA_COMPAT_GFIND</code>)
58685914
5915+<p><li>
5916+When <a href="#pdf-string.gsub"><code>string.gsub</code></a> is called with a function as its
5917+third argument,
5918+whenever that function returns <b>nil</b> or <b>false</b> the
5919+replacement string is the whole match,
5920+instead of the empty string.
5921+
58695922 <p><li>
58705923 Function <code>table.setn</code> was deprecated.
58715924 Function <code>table.getn</code> corresponds
@@ -5924,48 +5977,66 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 52 unmodified lines
59245977
59255978 <p><pre>
59265979
5927−<p> chunk ::= {stat [`<b>;</b>&acute;]}
5980+ chunk ::= {stat [`<b>;</b>&acute;]} [laststat[`<b>;</b>&acute;]]
5981+
5982+ block ::= chunk
59285983
5929−<p> block ::= chunk
5984+ stat ::= varlist1 `<b>=</b>&acute; explist1 |
5985+ functioncall |
5986+ <b>do</b> block <b>end</b> |
5987+ <b>while</b> exp <b>do</b> block <b>end</b> |
5988+ <b>repeat</b> block <b>until</b> exp |
5989+ <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> |
5990+ <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b> |
5991+ <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> |
5992+ <b>function</b> funcname funcbody |
5993+ <b>local</b> <b>function</b> Name funcbody |
5994+ <b>local</b> namelist [init]
59305995
5931−<p> stat ::= varlist1 `<b>=</b>&acute; explist1 | functioncall | <b>do</b> block <b>end</b> | <b>while</b> exp <b>do</b> block <b>end</b> | <b>repeat</b> block <b>until</b> exp | <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | <b>return</b> [explist1] | <b>break</b> | <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b> | <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | <b>function</b> funcname funcbody | <b>local</b> <b>function</b> Name funcbody | <b>local</b> namelist [init]
5996+ laststat ::= <b>return</b> [explist1] | <b>break</b>
59325997
5933−<p> funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]
5998+ funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]
5999+
6000+ varlist1 ::= var {`<b>,</b>&acute; var}
59346001
5935−<p> varlist1 ::= var {`<b>,</b>&acute; var}
6002+ var ::= Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Name
59366003
5937−<p> var ::= Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Name
6004+ namelist ::= Name {`<b>,</b>&acute; Name}
59386005
5939−<p> namelist ::= Name {`<b>,</b>&acute; Name}
6006+ init ::= `<b>=</b>&acute; explist1
59406007
5941−<p> init ::= `<b>=</b>&acute; explist1
6008+ explist1 ::= {exp `<b>,</b>&acute;} exp
59426009
5943−<p> explist1 ::= {exp `<b>,</b>&acute;} exp
6010+ exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>&acute; |
6011+ function | prefixexp | tableconstructor | exp binop exp | unop exp
59446012
5945−<p> exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>&acute; | function | prefixexp | tableconstructor | exp binop exp | unop exp
6013+ prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
59466014
5947−<p> prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
6015+ functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args
59486016
5949−<p> functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args
6017+ args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Literal
59506018
5951−<p> args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Literal
6019+ function ::= <b>function</b> funcbody
59526020
5953−<p> function ::= <b>function</b> funcbody
6021+ funcbody ::= `<b>(</b>&acute; [parlist1] `<b>)</b>&acute; block <b>end</b>
59546022
5955−<p> funcbody ::= `<b>(</b>&acute; [parlist1] `<b>)</b>&acute; block <b>end</b>
6023+ parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;
59566024
5957−<p> parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;
6025+ tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;
59586026
5959−<p> tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;
59606027 fieldlist ::= field {fieldsep field} [fieldsep]
5961− field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | name `<b>=</b>&acute; exp | exp
5962− fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
59636028
5964−<p> binop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; | `<b>&#060;</b>&acute; | `<b>&#060;=</b>&acute; | `<b>></b>&acute; | `<b>>=</b>&acute; | `<b>==</b>&acute; | `<b>~=</b>&acute; | <b>and</b> | <b>or</b>
6029+ field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | name `<b>=</b>&acute; exp | exp
59656030
5966−<p> unop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;
6031+ fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
59676032
5968−<p></pre>
6033+ binop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; |
6034+ `<b>&#060;</b>&acute; | `<b>&#060;=</b>&acute; | `<b>></b>&acute; | `<b>>=</b>&acute; | `<b>==</b>&acute; | `<b>~=</b>&acute; |
6035+ <b>and</b> | <b>or</b>
6036+
6037+ unop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;
6038+
6039+</pre>
59696040
59706041 <p>
59716042
@@ -5974,7 +6045,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 2 unmodified lines
59746045 <HR>
59756046 <SMALL>
59766047 Last update:
5977−Wed Sep 7 13:53:49 BRT 2005
6048+Tue Nov 1 15:20:21 BRST 2005
59786049 </SMALL>
59796050
59806051 </body></html>
src/lapi.c+19−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.48 2005/09/01 17:42:22 roberto Exp $
2+** $Id: lapi.c,v 2.51 2005/10/20 11:35:50 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -141,7 +141,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 135 unmodified lines
141141 setthvalue(L, L->top, L1);
142142 api_incr_top(L);
143143 lua_unlock(L);
144− luai_userstateopen(L1);
144+ luai_userstatethread(L, L1);
145145 return L1;
146146 }
147147
@@ -913,6 +913,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 765 unmodified lines
913913 res = cast(int, g->totalbytes >> 10);
914914 break;
915915 }
916+ case LUA_GCCOUNTB: {
917+ res = cast(int, g->totalbytes & 0x3ff);
918+ break;
919+ }
916920 case LUA_GCSTEP: {
917921 lu_mem a = (cast(lu_mem, data) << 10);
918922 if (a <= g->totalbytes)
@@ -992,8 +996,20 @@ LUA_API void lua_concat (lua_State *L, int n) { · 73 unmodified lines
992996
993997
994998 LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
999+ lua_Alloc f;
1000+ lua_lock(L);
9951001 if (ud) *ud = G(L)->ud;
996− return G(L)->frealloc;
1002+ f = G(L)->frealloc;
1003+ lua_unlock(L);
1004+ return f;
1005+}
1006+
1007+
1008+LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
1009+ lua_lock(L);
1010+ G(L)->ud = ud;
1011+ G(L)->frealloc = f;
1012+ lua_unlock(L);
9971013 }
9981014
9991015
src/lauxlib.c+9−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.152 2005/09/06 17:20:11 roberto Exp $
2+** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -176,8 +176,7 @@ LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { · 170 unmodified lines
176176
177177
178178 LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
179− if (lua_isnoneornil(L, narg)) return def;
180− else return luaL_checknumber(L, narg);
179+ return luaL_opt(L, luaL_checknumber, narg, def);
181180 }
182181
183182
@@ -190,16 +189,16 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { · 6 unmodified lines
190189
191190
192191 LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
193− lua_Integer def) {
194− if (lua_isnoneornil(L, narg)) return def;
195− else return luaL_checkinteger(L, narg);
192+ lua_Integer def) {
193+ return luaL_opt(L, luaL_checkinteger, narg, def);
196194 }
197195
198196
199197 LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
200198 if (!lua_getmetatable(L, obj)) /* no metatable? */
201199 return 0;
202− lua_getfield(L, -1, event);
200+ lua_pushstring(L, event);
201+ lua_rawget(L, -2);
203202 if (lua_isnil(L, -1)) {
204203 lua_pop(L, 2); /* remove metatable and metafield */
205204 return 0;
@@ -231,7 +230,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, · 25 unmodified lines
231230 const luaL_Reg *l, int nup) {
232231 if (libname) {
233232 /* check whether lib already exists */
234− lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
233+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
235234 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
236235 if (!lua_istable(L, -1)) { /* not found? */
237236 lua_pop(L, 1); /* remove previous result */
@@ -305,7 +304,7 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { · 67 unmodified lines
305304 if ((n = checkint(L, 2)) >= 0) return n;
306305 lua_getfield(L, t, "n"); /* else try t.n */
307306 if ((n = checkint(L, 1)) >= 0) return n;
308− return lua_objlen(L, t);
307+ return (int)lua_objlen(L, t);
309308 }
310309
311310 #endif
@@ -470,7 +469,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { · 158 unmodified lines
470469 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
471470 }
472471 else { /* no free elements */
473− ref = lua_objlen(L, t);
472+ ref = (int)lua_objlen(L, t);
474473 ref++; /* create new reference */
475474 }
476475 lua_rawseti(L, t, ref);
src/lauxlib.h+2−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.85 2005/09/06 17:19:51 roberto Exp $
2+** $Id: lauxlib.h,v 1.86 2005/10/21 13:47:42 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -114,6 +114,7 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, · 108 unmodified lines
114114
115115 #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
116116
117+#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
117118
118119 /*
119120 ** {======================================================
src/lbaselib.c+29−19
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.182 2005/08/26 17:36:32 roberto Exp $
2+** $Id: lbaselib.c,v 1.186 2005/10/21 13:47:42 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -196,9 +196,23 @@ static int luaB_collectgarbage (lua_State *L) { · 190 unmodified lines
196196 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
197197 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};
198198 int o = luaL_checkoption(L, 1, "collect", opts);
199− int ex = luaL_optinteger(L, 2, 0);
200− lua_pushinteger(L, lua_gc(L, optsnum[o], ex));
201− return 1;
199+ int ex = luaL_optint(L, 2, 0);
200+ int res = lua_gc(L, optsnum[o], ex);
201+ switch (optsnum[o]) {
202+ case LUA_GCCOUNT: {
203+ int b = lua_gc(L, LUA_GCCOUNTB, 0);
204+ lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000);
205+ return 1;
206+ }
207+ case LUA_GCSTEP: {
208+ lua_pushboolean(L, res);
209+ return 1;
210+ }
211+ default: {
212+ lua_pushnumber(L, res);
213+ return 1;
214+ }
215+ }
202216 }
203217
204218
@@ -326,12 +340,10 @@ static int luaB_assert (lua_State *L) { · 121 unmodified lines
326340
327341
328342 static int luaB_unpack (lua_State *L) {
329− int i = luaL_optint(L, 2, 1);
330− int e = luaL_optint(L, 3, -1);
331− int n;
343+ int i, e, n;
332344 luaL_checktype(L, 1, LUA_TTABLE);
333− if (e == -1)
334− e = luaL_getn(L, 1);
345+ i = luaL_optint(L, 2, 1);
346+ e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
335347 n = e - i + 1; /* number of elements */
336348 if (n <= 0) return 0; /* empty range */
337349 luaL_checkstack(L, n, "table too big to unpack");
@@ -349,8 +361,9 @@ static int luaB_select (lua_State *L) { · 11 unmodified lines
349361 }
350362 else {
351363 int i = luaL_checkint(L, 1);
352− if (i <= 0) i = 1;
353− else if (i >= n) i = n;
364+ if (i < 0) i = n + i;
365+ else if (i > n) i = n;
366+ luaL_argcheck(L, 1 <= i, 1, "index out of range");
354367 return n - i;
355368 }
356369 }
@@ -560,7 +573,7 @@ static int luaB_costatus (lua_State *L) { · 203 unmodified lines
560573 lua_pushliteral(L, "dead");
561574 else
562575 lua_pushliteral(L, "suspended"); /* initial state */
563− break;
576+ break;
564577 }
565578 default: /* some error occured */
566579 lua_pushliteral(L, "dead");
@@ -601,8 +614,11 @@ static void auxopen (lua_State *L, const char *name, · 34 unmodified lines
601614
602615
603616 static void base_open (lua_State *L) {
617+ /* set global _G */
604618 lua_pushvalue(L, LUA_GLOBALSINDEX);
605− luaL_register(L, NULL, base_funcs); /* open lib into global table */
619+ lua_setglobal(L, "_G");
620+ /* open lib into global table */
621+ luaL_register(L, "_G", base_funcs);
606622 lua_pushliteral(L, LUA_VERSION);
607623 lua_setglobal(L, "_VERSION"); /* set global _VERSION */
608624 /* `ipairs' and `pairs' need auxliliary functions as upvalues */
@@ -616,12 +632,6 @@ static void base_open (lua_State *L) { · 7 unmodified lines
616632 lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
617633 lua_pushcclosure(L, luaB_newproxy, 1);
618634 lua_setglobal(L, "newproxy"); /* set global `newproxy' */
619− /* create register._LOADED to track loaded modules */
620− lua_newtable(L);
621− lua_setfield(L, LUA_REGISTRYINDEX, "_LOADED");
622− /* set global _G */
623− lua_pushvalue(L, LUA_GLOBALSINDEX);
624− lua_setglobal(L, "_G");
625635 }
626636
627637
src/lcode.c+161−118
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.16 2005/08/29 20:49:21 roberto Exp $
2+** $Id: lcode.c,v 2.22 2005/11/16 11:55:27 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -27,16 +27,24 @@ · 21 unmodified lines
2727 #define hasjumps(e) ((e)->t != (e)->f)
2828
2929
30+static int isnumeral(expdesc *e) {
31+ return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
32+}
33+
34+
3035 void luaK_nil (FuncState *fs, int from, int n) {
3136 Instruction *previous;
32− if (fs->pc > fs->lasttarget && /* no jumps to current position? */
33− GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
34− int pfrom = GETARG_A(*previous);
35− int pto = GETARG_B(*previous);
36− if (pfrom <= from && from <= pto+1) { /* can connect both? */
37− if (from+n-1 > pto)
38− SETARG_B(*previous, from+n-1);
39− return;
37+ if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38+ if (fs->pc == 0) /* function start? */
39+ return; /* positions are already clean */
40+ if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
41+ int pfrom = GETARG_A(*previous);
42+ int pto = GETARG_B(*previous);
43+ if (pfrom <= from && from <= pto+1) { /* can connect both? */
44+ if (from+n-1 > pto)
45+ SETARG_B(*previous, from+n-1);
46+ return;
47+ }
4048 }
4149 }
4250 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
@@ -115,20 +123,22 @@ static int need_value (FuncState *fs, int list) { · 72 unmodified lines
115123 }
116124
117125
118−static void patchtestreg (Instruction *i, int reg) {
119− if (reg != NO_REG)
126+static int patchtestreg (FuncState *fs, int node, int reg) {
127+ Instruction *i = getjumpcontrol(fs, node);
128+ if (GET_OPCODE(*i) != OP_TESTSET)
129+ return 0; /* cannot patch other instructions */
130+ if (reg != NO_REG && reg != GETARG_B(*i))
120131 SETARG_A(*i, reg);
121− else /* no register to put value; change TESTSET to TEST */
132+ else /* no register to put value or register already has the value */
122133 *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
134+
135+ return 1;
123136 }
124137
125138
126139 static void removevalues (FuncState *fs, int list) {
127− for (; list != NO_JUMP; list = getjump(fs, list)) {
128− Instruction *i = getjumpcontrol(fs, list);
129− if (GET_OPCODE(*i) == OP_TESTSET)
130− patchtestreg(i, NO_REG);
131− }
140+ for (; list != NO_JUMP; list = getjump(fs, list))
141+ patchtestreg(fs, list, NO_REG);
132142 }
133143
134144
@@ -136,11 +146,8 @@ static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, · 1 unmodified line
136146 int dtarget) {
137147 while (list != NO_JUMP) {
138148 int next = getjump(fs, list);
139− Instruction *i = getjumpcontrol(fs, list);
140− if (GET_OPCODE(*i) == OP_TESTSET) {
141− patchtestreg(i, reg);
149+ if (patchtestreg(fs, list, reg))
142150 fixjump(fs, list, vtarget);
143− }
144151 else
145152 fixjump(fs, list, dtarget); /* jump to default target */
146153 list = next;
@@ -210,7 +217,7 @@ static void freereg (FuncState *fs, int reg) { · 63 unmodified lines
210217
211218 static void freeexp (FuncState *fs, expdesc *e) {
212219 if (e->k == VNONRELOC)
213− freereg(fs, e->info);
220+ freereg(fs, e->u.s.info);
214221 }
215222
216223
@@ -280,7 +287,7 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { · 63 unmodified lines
280287 void luaK_setoneret (FuncState *fs, expdesc *e) {
281288 if (e->k == VCALL) { /* expression is an open function call? */
282289 e->k = VNONRELOC;
283− e->info = GETARG_A(getcode(fs, e));
290+ e->u.s.info = GETARG_A(getcode(fs, e));
284291 }
285292 else if (e->k == VVARARG) {
286293 SETARG_B(getcode(fs, e), 2);
@@ -296,19 +303,19 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 9 unmodified lines
296303 break;
297304 }
298305 case VUPVAL: {
299− e->info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->info, 0);
306+ e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
300307 e->k = VRELOCABLE;
301308 break;
302309 }
303310 case VGLOBAL: {
304− e->info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->info);
311+ e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);
305312 e->k = VRELOCABLE;
306313 break;
307314 }
308315 case VINDEXED: {
309− freereg(fs, e->aux);
310− freereg(fs, e->info);
311− e->info = luaK_codeABC(fs, OP_GETTABLE, 0, e->info, e->aux);
316+ freereg(fs, e->u.s.aux);
317+ freereg(fs, e->u.s.info);
318+ e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
312319 e->k = VRELOCABLE;
313320 break;
314321 }
@@ -340,7 +347,11 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { · 25 unmodified lines
340347 break;
341348 }
342349 case VK: {
343− luaK_codeABx(fs, OP_LOADK, reg, e->info);
350+ luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);
351+ break;
352+ }
353+ case VKNUM: {
354+ luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));
344355 break;
345356 }
346357 case VRELOCABLE: {
@@ -349,8 +360,8 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { · 2 unmodified lines
349360 break;
350361 }
351362 case VNONRELOC: {
352− if (reg != e->info)
353− luaK_codeABC(fs, OP_MOVE, reg, e->info, 0);
363+ if (reg != e->u.s.info)
364+ luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);
354365 break;
355366 }
356367 default: {
@@ -358,7 +369,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { · 1 unmodified line
358369 return; /* nothing to do... */
359370 }
360371 }
361− e->info = reg;
372+ e->u.s.info = reg;
362373 e->k = VNONRELOC;
363374 }
364375
@@ -374,15 +385,13 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { · 9 unmodified lines
374385 static void exp2reg (FuncState *fs, expdesc *e, int reg) {
375386 discharge2reg(fs, e, reg);
376387 if (e->k == VJMP)
377− luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */
388+ luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */
378389 if (hasjumps(e)) {
379390 int final; /* position after whole expression */
380391 int p_f = NO_JUMP; /* position of an eventual LOAD false */
381392 int p_t = NO_JUMP; /* position of an eventual LOAD true */
382393 if (need_value(fs, e->t) || need_value(fs, e->f)) {
383− int fj = NO_JUMP; /* first jump (over LOAD ops.) */
384− if (e->k != VJMP)
385− fj = luaK_jump(fs);
394+ int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
386395 p_f = code_label(fs, reg, 0, 1);
387396 p_t = code_label(fs, reg, 1, 0);
388397 luaK_patchtohere(fs, fj);
@@ -392,7 +401,7 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { · 3 unmodified lines
392401 patchlistaux(fs, e->t, final, reg, p_t);
393402 }
394403 e->f = e->t = NO_JUMP;
395− e->info = reg;
404+ e->u.s.info = reg;
396405 e->k = VNONRELOC;
397406 }
398407
@@ -408,14 +417,14 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { · 9 unmodified lines
408417 int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
409418 luaK_dischargevars(fs, e);
410419 if (e->k == VNONRELOC) {
411− if (!hasjumps(e)) return e->info; /* exp is already in a register */
412− if (e->info >= fs->nactvar) { /* reg. is not a local? */
413− exp2reg(fs, e, e->info); /* put value on it */
414− return e->info;
420+ if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */
421+ if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */
422+ exp2reg(fs, e, e->u.s.info); /* put value on it */
423+ return e->u.s.info;
415424 }
416425 }
417426 luaK_exp2nextreg(fs, e); /* default */
418− return e->info;
427+ return e->u.s.info;
419428 }
420429
421430
@@ -430,19 +439,22 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { · 8 unmodified lines
430439 int luaK_exp2RK (FuncState *fs, expdesc *e) {
431440 luaK_exp2val(fs, e);
432441 switch (e->k) {
442+ case VKNUM:
433443 case VTRUE:
434444 case VFALSE:
435445 case VNIL: {
436446 if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
437− e->info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
447+ e->u.s.info = (e->k == VNIL) ? nilK(fs) :
448+ (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
449+ boolK(fs, (e->k == VTRUE));
438450 e->k = VK;
439− return RKASK(e->info);
451+ return RKASK(e->u.s.info);
440452 }
441453 else break;
442454 }
443455 case VK: {
444− if (e->info <= MAXINDEXRK) /* constant fit in argC? */
445− return RKASK(e->info);
456+ if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */
457+ return RKASK(e->u.s.info);
446458 else break;
447459 }
448460 default: break;
@@ -456,22 +468,22 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { · 7 unmodified lines
456468 switch (var->k) {
457469 case VLOCAL: {
458470 freeexp(fs, ex);
459− exp2reg(fs, ex, var->info);
471+ exp2reg(fs, ex, var->u.s.info);
460472 return;
461473 }
462474 case VUPVAL: {
463475 int e = luaK_exp2anyreg(fs, ex);
464− luaK_codeABC(fs, OP_SETUPVAL, e, var->info, 0);
476+ luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
465477 break;
466478 }
467479 case VGLOBAL: {
468480 int e = luaK_exp2anyreg(fs, ex);
469− luaK_codeABx(fs, OP_SETGLOBAL, e, var->info);
481+ luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);
470482 break;
471483 }
472484 case VINDEXED: {
473485 int e = luaK_exp2RK(fs, ex);
474− luaK_codeABC(fs, OP_SETTABLE, var->info, var->aux, e);
486+ luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
475487 break;
476488 }
477489 default: {
@@ -489,15 +501,15 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { · 11 unmodified lines
489501 freeexp(fs, e);
490502 func = fs->freereg;
491503 luaK_reserveregs(fs, 2);
492− luaK_codeABC(fs, OP_SELF, func, e->info, luaK_exp2RK(fs, key));
504+ luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
493505 freeexp(fs, key);
494− e->info = func;
506+ e->u.s.info = func;
495507 e->k = VNONRELOC;
496508 }
497509
498510
499511 static void invertjump (FuncState *fs, expdesc *e) {
500− Instruction *pc = getjumpcontrol(fs, e->info);
512+ Instruction *pc = getjumpcontrol(fs, e->u.s.info);
501513 lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
502514 GET_OPCODE(*pc) != OP_TEST);
503515 SETARG_A(*pc, !(GETARG_A(*pc)));
@@ -515,7 +527,7 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) { · 11 unmodified lines
515527 }
516528 discharge2anyreg(fs, e);
517529 freeexp(fs, e);
518− return condjump(fs, OP_TESTSET, NO_REG, e->info, cond);
530+ return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);
519531 }
520532
521533
@@ -523,7 +535,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 1 unmodified line
523535 int pc; /* pc of last jump */
524536 luaK_dischargevars(fs, e);
525537 switch (e->k) {
526− case VK: case VTRUE: {
538+ case VK: case VKNUM: case VTRUE: {
527539 pc = NO_JUMP; /* always true; do nothing */
528540 break;
529541 }
@@ -533,7 +545,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 3 unmodified lines
533545 }
534546 case VJMP: {
535547 invertjump(fs, e);
536− pc = e->info;
548+ pc = e->u.s.info;
537549 break;
538550 }
539551 default: {
@@ -547,7 +559,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 7 unmodified lines
547559 }
548560
549561
550−void luaK_goiffalse (FuncState *fs, expdesc *e) {
562+static void luaK_goiffalse (FuncState *fs, expdesc *e) {
551563 int pc; /* pc of last jump */
552564 luaK_dischargevars(fs, e);
553565 switch (e->k) {
@@ -560,7 +572,7 @@ void luaK_goiffalse (FuncState *fs, expdesc *e) { · 6 unmodified lines
560572 break;
561573 }
562574 case VJMP: {
563− pc = e->info;
575+ pc = e->u.s.info;
564576 break;
565577 }
566578 default: {
@@ -581,7 +593,7 @@ static void codenot (FuncState *fs, expdesc *e) { · 14 unmodified lines
581593 e->k = VTRUE;
582594 break;
583595 }
584− case VK: case VTRUE: {
596+ case VK: case VKNUM: case VTRUE: {
585597 e->k = VFALSE;
586598 break;
587599 }
@@ -593,7 +605,7 @@ static void codenot (FuncState *fs, expdesc *e) { · 5 unmodified lines
593605 case VNONRELOC: {
594606 discharge2anyreg(fs, e);
595607 freeexp(fs, e);
596− e->info = luaK_codeABC(fs, OP_NOT, 0, e->info, 0);
608+ e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);
597609 e->k = VRELOCABLE;
598610 break;
599611 }
@@ -610,34 +622,81 @@ static void codenot (FuncState *fs, expdesc *e) { · 10 unmodified lines
610622
611623
612624 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
613− t->aux = luaK_exp2RK(fs, k);
625+ t->u.s.aux = luaK_exp2RK(fs, k);
614626 t->k = VINDEXED;
615627 }
616628
617629
630+static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
631+ lua_Number v1, v2, r;
632+ if (!isnumeral(e1) || !isnumeral(e2)) return 0;
633+ v1 = e1->u.nval;
634+ v2 = e2->u.nval;
635+ switch (op) {
636+ case OP_ADD: r = luai_numadd(v1, v2); break;
637+ case OP_SUB: r = luai_numsub(v1, v2); break;
638+ case OP_MUL: r = luai_nummul(v1, v2); break;
639+ case OP_DIV:
640+ if (v2 == 0) return 0; /* do not attempt to divide by 0 */
641+ r = luai_numdiv(v1, v2); break;
642+ case OP_MOD:
643+ if (v2 == 0) return 0; /* do not attempt to divide by 0 */
644+ r = luai_nummod(v1, v2); break;
645+ case OP_POW: r = luai_numpow(v1, v2); break;
646+ case OP_UNM: r = luai_numunm(v1); break;
647+ case OP_LEN: return 0; /* no constant folding for 'len' */
648+ default: lua_assert(0); r = 0; break;
649+ }
650+ if (r != r) return 0; /* do not attempt to produce NaN */
651+ e1->u.nval = r;
652+ return 1;
653+}
654+
655+
656+static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
657+ if (constfolding(op, e1, e2))
658+ return;
659+ else {
660+ int o1 = luaK_exp2RK(fs, e1);
661+ int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
662+ freeexp(fs, e2);
663+ freeexp(fs, e1);
664+ e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665+ e1->k = VRELOCABLE;
666+ }
667+}
668+
669+
670+static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
671+ expdesc *e2) {
672+ int o1 = luaK_exp2RK(fs, e1);
673+ int o2 = luaK_exp2RK(fs, e2);
674+ freeexp(fs, e2);
675+ freeexp(fs, e1);
676+ if (cond == 0 && op != OP_EQ) {
677+ int temp; /* exchange args to replace by `<' or `<=' */
678+ temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
679+ cond = 1;
680+ }
681+ e1->u.s.info = condjump(fs, op, cond, o1, o2);
682+ e1->k = VJMP;
683+}
684+
685+
618686 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
687+ expdesc e2;
688+ e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
619689 switch (op) {
620690 case OPR_MINUS: {
621− luaK_exp2val(fs, e);
622− if (e->k == VK && ttisnumber(&fs->f->k[e->info]))
623− e->info = luaK_numberK(fs, luai_numunm(L, nvalue(&fs->f->k[e->info])));
624− else {
625− luaK_exp2anyreg(fs, e);
626− freeexp(fs, e);
627− e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0);
628− e->k = VRELOCABLE;
629− }
630− break;
631− }
632− case OPR_NOT: {
633− codenot(fs, e);
691+ if (e->k == VK)
692+ luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
693+ codearith(fs, OP_UNM, e, &e2);
634694 break;
635695 }
696+ case OPR_NOT: codenot(fs, e); break;
636697 case OPR_LEN: {
637− luaK_exp2anyreg(fs, e);
638− freeexp(fs, e);
639− e->info = luaK_codeABC(fs, OP_LEN, 0, e->info, 0);
640− e->k = VRELOCABLE;
698+ luaK_exp2anyreg(fs, e); /* cannot operate on constants */
699+ codearith(fs, OP_LEN, e, &e2);
641700 break;
642701 }
643702 default: lua_assert(0);
@@ -660,74 +719,58 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 16 unmodified lines
660719 break;
661720 }
662721 default: {
663− luaK_exp2RK(fs, v);
722+ if (!isnumeral(v)) luaK_exp2RK(fs, v);
664723 break;
665724 }
666725 }
667726 }
668727
669728
670−static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
671− int o1, int o2) {
672− if (op <= OPR_POW) { /* arithmetic operator? */
673− OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); /* ORDER OP */
674− res->info = luaK_codeABC(fs, opc, 0, o1, o2);
675− res->k = VRELOCABLE;
676− }
677− else { /* test operator */
678− static const OpCode ops[] = {OP_EQ, OP_EQ, OP_LT, OP_LE, OP_LT, OP_LE};
679− int cond = 1;
680− if (op >= OPR_GT) { /* `>' or `>='? */
681− int temp; /* exchange args and replace by `<' or `<=' */
682− temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
683− }
684− else if (op == OPR_NE) cond = 0;
685− res->info = condjump(fs, ops[op - OPR_NE], cond, o1, o2);
686− res->k = VJMP;
687− }
688−}
689−
690−
691729 void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
692730 switch (op) {
693731 case OPR_AND: {
694732 lua_assert(e1->t == NO_JUMP); /* list must be closed */
695733 luaK_dischargevars(fs, e2);
696734 luaK_concat(fs, &e1->f, e2->f);
697− e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->t = e2->t;
735+ e1->k = e2->k; e1->u.s.info = e2->u.s.info;
736+ e1->u.s.aux = e2->u.s.aux; e1->t = e2->t;
698737 break;
699738 }
700739 case OPR_OR: {
701740 lua_assert(e1->f == NO_JUMP); /* list must be closed */
702741 luaK_dischargevars(fs, e2);
703742 luaK_concat(fs, &e1->t, e2->t);
704− e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->f = e2->f;
743+ e1->k = e2->k; e1->u.s.info = e2->u.s.info;
744+ e1->u.s.aux = e2->u.s.aux; e1->f = e2->f;
705745 break;
706746 }
707747 case OPR_CONCAT: {
708748 luaK_exp2val(fs, e2);
709749 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
710− lua_assert(e1->info == GETARG_B(getcode(fs, e2))-1);
750+ lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
711751 freeexp(fs, e1);
712− SETARG_B(getcode(fs, e2), e1->info);
713− e1->k = e2->k; e1->info = e2->info;
752+ SETARG_B(getcode(fs, e2), e1->u.s.info);
753+ e1->k = e2->k; e1->u.s.info = e2->u.s.info;
714754 }
715755 else {
716− luaK_exp2nextreg(fs, e2);
717− freeexp(fs, e2);
718− freeexp(fs, e1);
719− e1->info = luaK_codeABC(fs, OP_CONCAT, 0, e1->info, e2->info);
720− e1->k = VRELOCABLE;
756+ luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
757+ codearith(fs, OP_CONCAT, e1, e2);
721758 }
722759 break;
723760 }
724− default: {
725− int o1 = luaK_exp2RK(fs, e1);
726− int o2 = luaK_exp2RK(fs, e2);
727− freeexp(fs, e2);
728− freeexp(fs, e1);
729− codebinop(fs, e1, op, o1, o2);
730− }
761+ case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
762+ case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
763+ case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
764+ case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
765+ case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
766+ case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
767+ case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
768+ case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
769+ case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
770+ case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
771+ case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
772+ case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
773+ default: lua_assert(0);
731774 }
732775 }
733776
@@ -737,7 +780,7 @@ void luaK_fixline (FuncState *fs, int line) { · 3 unmodified lines
737780 }
738781
739782
740−int luaK_code (FuncState *fs, Instruction i, int line) {
783+static int luaK_code (FuncState *fs, Instruction i, int line) {
741784 Proto *f = fs->f;
742785 dischargejpc(fs); /* `pc' will change */
743786 /* put new instruction in code array */
src/lcode.h+3−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.h,v 1.45 2005/08/29 20:49:21 roberto Exp $
2+** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 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_MOD, OPR_POW,
27+ OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
2828 OPR_CONCAT,
2929 OPR_NE, OPR_EQ,
3030 OPR_LT, OPR_LE, OPR_GT, OPR_GE,
@@ -37,13 +37,12 @@ typedef enum BinOpr { · 6 unmodified lines
3737 typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
3838
3939
40−#define getcode(fs,e) ((fs)->f->code[(e)->info])
40+#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info])
4141
4242 #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
4343
4444 #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
4545
46−LUAI_FUNC int luaK_code (FuncState *fs, Instruction i, int line);
4746 LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
4847 LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
4948 LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
@@ -60,7 +59,6 @@ LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); · 10 unmodified lines
6059 LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
6160 LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
6261 LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
63−LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
6462 LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
6563 LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
6664 LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
src/ldblib.c+9−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.101 2005/08/26 17:36:32 roberto Exp $
2+** $Id: ldblib.c,v 1.103 2005/11/01 16:08:32 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -19,6 +19,12 @@ · 13 unmodified lines
1919
2020
2121
22+static int db_getregistry (lua_State *L) {
23+ lua_pushvalue(L, LUA_REGISTRYINDEX);
24+ return 1;
25+}
26+
27+
2228 static int db_getmetatable (lua_State *L) {
2329 luaL_checkany(L, 1);
2430 if (!lua_getmetatable(L, 1)) {
@@ -319,7 +325,7 @@ static int db_errorfb (lua_State *L) { · 294 unmodified lines
319325 lua_State *L1 = getthread(L, &arg);
320326 lua_Debug ar;
321327 if (lua_isnumber(L, arg+2)) {
322− level = lua_tointeger(L, arg+2);
328+ level = (int)lua_tointeger(L, arg+2);
323329 lua_pop(L, 1);
324330 }
325331 else
@@ -371,6 +377,7 @@ static const luaL_Reg dblib[] = { · 45 unmodified lines
371377 {"gethook", db_gethook},
372378 {"getinfo", db_getinfo},
373379 {"getlocal", db_getlocal},
380+ {"getregistry", db_getregistry},
374381 {"getmetatable", db_getmetatable},
375382 {"getupvalue", db_getupvalue},
376383 {"setfenv", db_setfenv},
src/ldebug.c+27−28
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.26 2005/08/04 13:37:38 roberto Exp $
2+** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -109,40 +109,39 @@ static Proto *getluaproto (CallInfo *ci) { · 103 unmodified lines
109109 }
110110
111111
112−LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
112+static const char *findlocal (lua_State *L, CallInfo *ci, int n) {
113113 const char *name;
114− CallInfo *ci;
115− Proto *fp;
116− lua_lock(L);
117− name = NULL;
118− ci = L->base_ci + ar->i_ci;
119− fp = getluaproto(ci);
120− if (fp) { /* is a Lua function? */
121− name = luaF_getlocalname(fp, n, currentpc(L, ci));
122− if (name)
123− luaA_pushobject(L, ci->base+(n-1)); /* push value */
114+ Proto *fp = getluaproto(ci);
115+ if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
116+ return name; /* is a local variable in a Lua function */
117+ else {
118+ StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
119+ if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */
120+ return "(*temporary)";
121+ else
122+ return NULL;
124123 }
124+}
125+
126+
127+LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
128+ CallInfo *ci = L->base_ci + ar->i_ci;
129+ const char *name = findlocal(L, ci, n);
130+ lua_lock(L);
131+ if (name)
132+ luaA_pushobject(L, ci->base + (n - 1));
125133 lua_unlock(L);
126134 return name;
127135 }
128136
129137
130138 LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
131− const char *name;
132− CallInfo *ci;
133− Proto *fp;
139+ CallInfo *ci = L->base_ci + ar->i_ci;
140+ const char *name = findlocal(L, ci, n);
134141 lua_lock(L);
135− name = NULL;
136− ci = L->base_ci + ar->i_ci;
137− fp = getluaproto(ci);
138− L->top--; /* pop new value */
139− if (fp) { /* is a Lua function? */
140− name = luaF_getlocalname(fp, n, currentpc(L, ci));
141− if (!name || name[0] == '(') /* `(' starts private locals */
142− name = NULL;
143− else
144− setobjs2s(L, ci->base+(n-1), L->top);
145− }
142+ if (name)
143+ setobjs2s(L, ci->base + (n - 1), L->top - 1);
144+ L->top--; /* pop value */
146145 lua_unlock(L);
147146 return name;
148147 }
@@ -321,7 +320,7 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 172 unmodified lines
321320 last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */
322321 check(precheck(pt));
323322 for (pc = 0; pc < lastpc; pc++) {
324− const Instruction i = pt->code[pc];
323+ Instruction i = pt->code[pc];
325324 OpCode op = GET_OPCODE(i);
326325 int a = GETARG_A(i);
327326 int b = 0;
@@ -348,7 +347,7 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 20 unmodified lines
348347 check(0 <= dest && dest < pt->sizecode);
349348 if (dest > 0) {
350349 /* cannot jump to a setlist count */
351− const Instruction d = pt->code[dest-1];
350+ Instruction d = pt->code[dest-1];
352351 check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
353352 }
354353 }
src/ldo.c+9−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.33 2005/09/09 18:16:28 roberto Exp $
2+** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -276,8 +276,11 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 270 unmodified lines
276276 Proto *p = cl->p;
277277 luaD_checkstack(L, p->maxstacksize);
278278 func = restorestack(L, funcr);
279− if (!p->is_vararg) /* no varargs? */
279+ if (!p->is_vararg) { /* no varargs? */
280280 base = func + 1;
281+ if (L->top > base + p->numparams)
282+ L->top = base + p->numparams;
283+ }
281284 else { /* vararg function */
282285 int nargs = cast(int, L->top - func) - 1;
283286 base = adjust_varargs(L, p, nargs);
@@ -316,14 +319,12 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 32 unmodified lines
316319 lua_unlock(L);
317320 n = (*curr_func(L)->c.f)(L); /* do the actual call */
318321 lua_lock(L);
319− if (n >= 0) { /* no yielding? */
322+ if (n < 0) /* yielding? */
323+ return PCRYIELD;
324+ else {
320325 luaD_poscall(L, L->top - n);
321326 return PCRC;
322327 }
323− else {
324− ci->nresults = nresults;
325− return PCRYIELD;
326− }
327328 }
328329 }
329330
@@ -428,6 +429,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 98 unmodified lines
428429 if (status != 0) { /* error? */
429430 L->status = cast(lu_byte, status); /* mark thread as `dead' */
430431 luaD_seterrorobj(L, status, L->top);
432+ L->ci->top = L->top;
431433 }
432434 else
433435 status = L->status;
src/ldump.c+24−29
@@ -1,6 +1,6 @@
11 /*
2−** $Id: ldump.c,v 1.12 2005/06/08 14:40:44 lhf Exp $
3−** save pre-compiled Lua chunks
2+** $Id: ldump.c,v 1.14 2005/11/11 14:03:13 lhf Exp $
3+** save precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
66
@@ -12,7 +12,6 @@ · 5 unmodified lines
1212 #include "lua.h"
1313
1414 #include "lobject.h"
15−#include "lopcodes.h"
1615 #include "lstate.h"
1716 #include "lundump.h"
1817
@@ -24,11 +23,8 @@ typedef struct { · 5 unmodified lines
2423 int status;
2524 } DumpState;
2625
27−#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
28−#define DumpLines(f,D) DumpVector(f->lineinfo,f->sizelineinfo,sizeof(int),D)
29−#define DumpLiteral(s,D) DumpBlock("" s,(sizeof(s))-1,D)
30−#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
3126 #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
27+#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
3228
3329 static void DumpBlock(const void* b, size_t size, DumpState* D)
3430 {
@@ -77,24 +73,7 @@ static void DumpString(const TString* s, DumpState* D) · 42 unmodified lines
7773 }
7874 }
7975
80−static void DumpLocals(const Proto* f, DumpState* D)
81−{
82− int i,n=f->sizelocvars;
83− DumpInt(n,D);
84− for (i=0; i<n; i++)
85− {
86− DumpString(f->locvars[i].varname,D);
87− DumpInt(f->locvars[i].startpc,D);
88− DumpInt(f->locvars[i].endpc,D);
89− }
90−}
91−
92−static void DumpUpvalues(const Proto* f, DumpState* D)
93−{
94− int i,n=f->sizeupvalues;
95− DumpInt(n,D);
96− for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
97−}
76+#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
9877
9978 static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
10079
@@ -129,6 +108,24 @@ static void DumpConstants(const Proto* f, DumpState* D) · 28 unmodified lines
129108 for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
130109 }
131110
111+static void DumpDebug(const Proto* f, DumpState* D)
112+{
113+ int i,n;
114+ n= (D->strip) ? 0 : f->sizelineinfo;
115+ DumpVector(f->lineinfo,n,sizeof(int),D);
116+ n= (D->strip) ? 0 : f->sizelocvars;
117+ DumpInt(n,D);
118+ for (i=0; i<n; i++)
119+ {
120+ DumpString(f->locvars[i].varname,D);
121+ DumpInt(f->locvars[i].startpc,D);
122+ DumpInt(f->locvars[i].endpc,D);
123+ }
124+ n= (D->strip) ? 0 : f->sizeupvalues;
125+ DumpInt(n,D);
126+ for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
127+}
128+
132129 static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
133130 {
134131 DumpString((f->source==p) ? NULL : f->source,D);
@@ -138,11 +135,9 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D) · 3 unmodified lines
138135 DumpChar(f->numparams,D);
139136 DumpChar(f->is_vararg,D);
140137 DumpChar(f->maxstacksize,D);
141− if (D->strip) DumpInt(0,D); else DumpLines(f,D);
142− if (D->strip) DumpInt(0,D); else DumpLocals(f,D);
143− if (D->strip) DumpInt(0,D); else DumpUpvalues(f,D);
144− DumpConstants(f,D);
145138 DumpCode(f,D);
139+ DumpConstants(f,D);
140+ DumpDebug(f,D);
146141 }
147142
148143 static void DumpHeader(DumpState* D)
src/liolib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.67 2005/08/26 17:36:32 roberto Exp $
2+** $Id: liolib.c,v 2.69 2005/10/19 13:05:11 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -424,7 +424,7 @@ static int f_seek (lua_State *L) { · 418 unmodified lines
424424 static const char *const modenames[] = {"set", "cur", "end", NULL};
425425 FILE *f = tofile(L);
426426 int op = luaL_checkoption(L, 2, "cur", modenames);
427− lua_Integer offset = luaL_optinteger(L, 3, 0);
427+ long offset = luaL_optlong(L, 3, 0);
428428 op = fseek(f, offset, mode[op]);
429429 if (op)
430430 return pushresult(L, 0, NULL); /* error */
@@ -440,7 +440,7 @@ static int f_setvbuf (lua_State *L) { · 9 unmodified lines
440440 static const char *const modenames[] = {"no", "full", "line", NULL};
441441 FILE *f = tofile(L);
442442 int op = luaL_checkoption(L, 2, NULL, modenames);
443− lua_Integer sz = luaL_optinteger(L, 3, BUFSIZ);
443+ lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
444444 int res = setvbuf(f, NULL, mode[op], sz);
445445 return pushresult(L, res == 0, NULL);
446446 }
src/llex.c+16−24
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp $
2+** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -155,28 +155,23 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 149 unmodified lines
155155
156156
157157
158+static int check_next (LexState *ls, const char *set) {
159+ if (!strchr(set, ls->current))
160+ return 0;
161+ save_and_next(ls);
162+ return 1;
163+}
164+
165+
158166
159167 /* LUA_NUMBER */
160168 static void read_numeral (LexState *ls, SemInfo *seminfo) {
161− while (isdigit(ls->current)) {
169+ lua_assert(isdigit(ls->current));
170+ do {
162171 save_and_next(ls);
163− }
164− if (ls->current == '.') {
165− save_and_next(ls);
166− if (ls->current == '.') {
167− save_and_next(ls);
168− luaX_lexerror(ls,
169− "ambiguous syntax (decimal point x string concatenation)",
170− TK_NUMBER);
171− }
172− }
173− while (isdigit(ls->current)) {
174− save_and_next(ls);
175− }
176− if (ls->current == 'e' || ls->current == 'E') {
177− save_and_next(ls); /* read `E' */
178− if (ls->current == '+' || ls->current == '-')
179− save_and_next(ls); /* optional exponent sign */
172+ } while (isdigit(ls->current) || ls->current == '.');
173+ if (check_next(ls, "Ee")) { /* `E'? */
174+ check_next(ls, "+-"); /* optional exponent sign */
180175 while (isdigit(ls->current)) {
181176 save_and_next(ls);
182177 }
@@ -375,12 +370,9 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 192 unmodified lines
375370 }
376371 case '.': {
377372 save_and_next(ls);
378− if (ls->current == '.') {
379− next(ls);
380− if (ls->current == '.') {
381− next(ls);
373+ if (check_next(ls, ".")) {
374+ if (check_next(ls, "."))
382375 return TK_DOTS; /* ... */
383− }
384376 else return TK_CONCAT; /* .. */
385377 }
386378 else if (!isdigit(ls->current)) return '.';
src/loadlib.c+13−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.44 2005/09/06 17:20:25 roberto Exp $
2+** $Id: loadlib.c,v 1.48 2005/10/17 18:01:51 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -97,16 +97,18 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 91 unmodified lines
9797
9898 #undef setprogdir
9999
100−void setprogdir (lua_State *L) {
100+static void setprogdir (lua_State *L) {
101101 char buff[MAX_PATH + 1];
102102 char *lb;
103103 DWORD nsize = sizeof(buff)/sizeof(char);
104104 DWORD n = GetModuleFileName(NULL, buff, nsize);
105105 if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
106106 luaL_error(L, "unable to get ModuleFileName");
107− *lb = '\0';
108− luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
109− lua_remove(L, -2); /* remove original string */
107+ else {
108+ *lb = '\0';
109+ luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
110+ lua_remove(L, -2); /* remove original string */
111+ }
110112 }
111113
112114
@@ -440,7 +442,8 @@ static int loader_preload (lua_State *L) { · 327 unmodified lines
440442 }
441443
442444
443−static const int sentinel = 0;
445+static const int sentinel_ = 0;
446+#define sentinel ((void *)&sentinel_)
444447
445448
446449 static int ll_require (lua_State *L) {
@@ -450,7 +453,7 @@ static int ll_require (lua_State *L) { · 3 unmodified lines
450453 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
451454 lua_getfield(L, 2, name);
452455 if (lua_toboolean(L, -1)) { /* is it there? */
453− if (lua_touserdata(L, -1) == &sentinel) /* check loops */
456+ if (lua_touserdata(L, -1) == sentinel) /* check loops */
454457 luaL_error(L, "loop or previous error loading module " LUA_QS, name);
455458 return 1; /* package is already loaded */
456459 }
@@ -467,14 +470,14 @@ static int ll_require (lua_State *L) { · 10 unmodified lines
467470 if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */
468471 else break; /* module loaded successfully */
469472 }
470− lua_pushlightuserdata(L, (void *)&sentinel);
473+ lua_pushlightuserdata(L, sentinel);
471474 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
472475 lua_pushstring(L, name); /* pass name as argument to module */
473476 lua_call(L, 1, 1); /* run loaded module */
474477 if (!lua_isnil(L, -1)) /* non-nil return? */
475478 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
476479 lua_getfield(L, 2, name);
477− if (lua_touserdata(L, -1) == &sentinel) { /* module did not set a value? */
480+ if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
478481 lua_pushboolean(L, 1); /* use true as result */
479482 lua_pushvalue(L, -1); /* extra copy to be returned */
480483 lua_setfield(L, 2, name); /* _LOADED[name] = true */
@@ -623,8 +626,6 @@ LUALIB_API int luaopen_package (lua_State *L) { · 142 unmodified lines
623626 lua_getfield(L, -1, "loadlib");
624627 lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
625628 #endif
626− lua_pushvalue(L, -1);
627− lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE");
628629 lua_pushvalue(L, -1);
629630 lua_replace(L, LUA_ENVIRONINDEX);
630631 /* create `loaders' table */
@@ -642,7 +643,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 11 unmodified lines
642643 LUA_EXECDIR "\n" LUA_IGMARK);
643644 lua_setfield(L, -2, "config");
644645 /* set field `loaded' */
645− lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
646+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
646647 lua_setfield(L, -2, "loaded");
647648 /* set field `preload' */
648649 lua_newtable(L);
src/lobject.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.18 2005/08/01 04:22:23 roberto Exp $
2+** $Id: lobject.c,v 2.19 2005/10/24 17:37:52 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -75,7 +75,7 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) { · 69 unmodified lines
7575 case LUA_TNIL:
7676 return 1;
7777 case LUA_TNUMBER:
78− return luai_numeq(L, nvalue(t1), nvalue(t2));
78+ return luai_numeq(nvalue(t1), nvalue(t2));
7979 case LUA_TBOOLEAN:
8080 return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
8181 case LUA_TLIGHTUSERDATA:
src/lobject.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.17 2005/06/13 14:19:00 roberto Exp $
2+** $Id: lobject.h,v 2.18 2005/10/24 17:37:33 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -353,7 +353,7 @@ typedef struct Table { · 347 unmodified lines
353353 ** `module' operation for hashing (size is always a power of 2)
354354 */
355355 #define lmod(s,size) \
356− check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))
356+ (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
357357
358358
359359 #define twoto(x) (1<<(x))
src/lopcodes.c+2−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.c,v 1.35 2005/08/29 20:49:21 roberto Exp $
2+** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $
33 ** See Copyright Notice in lua.h
44 */
55
@@ -7,9 +7,7 @@ · 1 unmodified line
77 #define lopcodes_c
88 #define LUA_CORE
99
10−#include "lua.h"
1110
12−#include "lobject.h"
1311 #include "lopcodes.h"
1412
1513
@@ -88,7 +86,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 72 unmodified lines
8886 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
8987 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
9088 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
91− ,opmode(1, 0, OpArgR, OpArgU, iABC) /* OP_TEST */
89+ ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */
9290 ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
9391 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
9492 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
src/lopcodes.h+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.122 2005/08/29 20:49:21 roberto Exp $
2+** $Id: lopcodes.h,v 1.123 2005/10/23 17:37:55 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -193,12 +193,12 @@ OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ · 187 unmodified lines
193193 OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
194194 OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */
195195
196−OP_FORLOOP,/* A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then pc+=sBx */
196+OP_FORLOOP,/* A sBx R(A)+=R(A+2);
197+ if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
197198 OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
198199
199−OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
200− if R(A+2) ~= nil then pc++ */
201−
200+OP_TFORLOOP,/* A C R(A+3), ... ,R(A+3+C) := R(A)(R(A+1), R(A+2));
201+ if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); } */
202202 OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
203203
204204 OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
src/loslib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.13 2005/09/09 18:22:46 roberto Exp $
2+** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -125,8 +125,8 @@ static int getfield (lua_State *L, const char *key, int d) { · 119 unmodified lines
125125
126126 static int io_date (lua_State *L) {
127127 const char *s = luaL_optstring(L, 1, "%c");
128− lua_Number n = luaL_optnumber(L, 2, -1);
129− time_t t = (n == -1) ? time(NULL) : (time_t)n;
128+ time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
129+ (time_t)luaL_checknumber(L, 2);
130130 struct tm *stm;
131131 if (*s == '!') { /* UTC? */
132132 stm = gmtime(&t);
src/lparser.c+22−21
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.35 2005/08/29 20:49:21 roberto Exp $
2+** $Id: lparser.c,v 2.38 2005/10/24 17:38:47 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -144,7 +144,7 @@ static TString *str_checkname (LexState *ls) { · 138 unmodified lines
144144 static void init_exp (expdesc *e, expkind k, int i) {
145145 e->f = e->t = NO_JUMP;
146146 e->k = k;
147− e->info = i;
147+ e->u.s.info = i;
148148 }
149149
150150
@@ -184,7 +184,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { · 33 unmodified lines
184184
185185 static void adjustlocalvars (LexState *ls, int nvars) {
186186 FuncState *fs = ls->fs;
187− fs->nactvar += nvars;
187+ fs->nactvar = cast(lu_byte, fs->nactvar + nvars);
188188 for (; nvars; nvars--) {
189189 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
190190 }
@@ -203,7 +203,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 12 unmodified lines
203203 Proto *f = fs->f;
204204 int oldsize = f->sizeupvalues;
205205 for (i=0; i<f->nups; i++) {
206− if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->info) {
206+ if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
207207 lua_assert(f->upvalues[i] == name);
208208 return i;
209209 }
@@ -217,7 +217,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 7 unmodified lines
217217 luaC_objbarrier(fs->L, f, name);
218218 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
219219 fs->upvalues[f->nups].k = cast(lu_byte, v->k);
220− fs->upvalues[f->nups].info = cast(lu_byte, v->info);
220+ fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);
221221 return f->nups++;
222222 }
223223
@@ -255,7 +255,7 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { · 31 unmodified lines
255255 else { /* not found at current level; try upper one */
256256 if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)
257257 return VGLOBAL;
258− var->info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */
258+ var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */
259259 var->k = VUPVAL; /* upvalue in this level */
260260 return VUPVAL;
261261 }
@@ -267,7 +267,7 @@ static void singlevar (LexState *ls, expdesc *var) { · 5 unmodified lines
267267 TString *varname = str_checkname(ls);
268268 FuncState *fs = ls->fs;
269269 if (singlevaraux(fs, varname, var, 1) == VGLOBAL)
270− var->info = luaK_stringK(fs, varname); /* info points to global name */
270+ var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */
271271 }
272272
273273
@@ -351,7 +351,7 @@ static void open_func (LexState *ls, FuncState *fs) { · 77 unmodified lines
351351 fs->L = L;
352352 ls->fs = fs;
353353 fs->pc = 0;
354− fs->lasttarget = 0;
354+ fs->lasttarget = -1;
355355 fs->jpc = NO_JUMP;
356356 fs->freereg = 0;
357357 fs->nk = 0;
@@ -472,8 +472,8 @@ static void recfield (LexState *ls, struct ConsControl *cc) { · 114 unmodified lines
472472 checknext(ls, '=');
473473 luaK_exp2RK(fs, &key);
474474 expr(ls, &val);
475− luaK_codeABC(fs, OP_SETTABLE, cc->t->info, luaK_exp2RK(fs, &key),
476− luaK_exp2RK(fs, &val));
475+ luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key),
476+ luaK_exp2RK(fs, &val));
477477 fs->freereg = reg; /* free registers */
478478 }
479479
@@ -483,7 +483,7 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) { · 3 unmodified lines
483483 luaK_exp2nextreg(fs, &cc->v);
484484 cc->v.k = VVOID;
485485 if (cc->tostore == LFIELDS_PER_FLUSH) {
486− luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); /* flush */
486+ luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */
487487 cc->tostore = 0; /* no more items pending */
488488 }
489489 }
@@ -493,13 +493,13 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 3 unmodified lines
493493 if (cc->tostore == 0) return;
494494 if (hasmultret(cc->v.k)) {
495495 luaK_setmultret(fs, &cc->v);
496− luaK_setlist(fs, cc->t->info, cc->na, LUA_MULTRET);
496+ luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
497497 cc->na--; /* do not count last expression (unknown number of elements) */
498498 }
499499 else {
500500 if (cc->v.k != VVOID)
501501 luaK_exp2nextreg(fs, &cc->v);
502− luaK_setlist(fs, cc->t->info, cc->na, cc->tostore);
502+ luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
503503 }
504504 }
505505
@@ -657,7 +657,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 151 unmodified lines
657657 }
658658 }
659659 lua_assert(f->k == VNONRELOC);
660− base = f->info; /* base register for call */
660+ base = f->u.s.info; /* base register for call */
661661 if (hasmultret(args.k))
662662 nparams = LUA_MULTRET; /* open call */
663663 else {
@@ -746,7 +746,8 @@ static void simpleexp (LexState *ls, expdesc *v) { · 82 unmodified lines
746746 constructor | FUNCTION body | primaryexp */
747747 switch (ls->t.token) {
748748 case TK_NUMBER: {
749− init_exp(v, VK, luaK_numberK(ls->fs, ls->t.seminfo.r));
749+ init_exp(v, VKNUM, 0);
750+ v->u.nval = ls->t.seminfo.r;
750751 break;
751752 }
752753 case TK_STRING: {
@@ -805,7 +806,7 @@ static BinOpr getbinopr (int op) { · 52 unmodified lines
805806 switch (op) {
806807 case '+': return OPR_ADD;
807808 case '-': return OPR_SUB;
808− case '*': return OPR_MULT;
809+ case '*': return OPR_MUL;
809810 case '/': return OPR_DIV;
810811 case '%': return OPR_MOD;
811812 case '^': return OPR_POW;
@@ -927,18 +928,18 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { · 115 unmodified lines
927928 int conflict = 0;
928929 for (; lh; lh = lh->prev) {
929930 if (lh->v.k == VINDEXED) {
930− if (lh->v.info == v->info) { /* conflict? */
931+ if (lh->v.u.s.info == v->u.s.info) { /* conflict? */
931932 conflict = 1;
932− lh->v.info = extra; /* previous assignment will use safe copy */
933+ lh->v.u.s.info = extra; /* previous assignment will use safe copy */
933934 }
934− if (lh->v.aux == v->info) { /* conflict? */
935+ if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */
935936 conflict = 1;
936− lh->v.aux = extra; /* previous assignment will use safe copy */
937+ lh->v.u.s.aux = extra; /* previous assignment will use safe copy */
937938 }
938939 }
939940 }
940941 if (conflict) {
941− luaK_codeABC(fs, OP_MOVE, fs->freereg, v->info, 0); /* make copy */
942+ luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */
942943 luaK_reserveregs(fs, 1);
943944 }
944945 }
src/lparser.h+6−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.h,v 1.55 2005/04/25 19:24:10 roberto Exp $
2+** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -23,6 +23,7 @@ typedef enum { · 17 unmodified lines
2323 VTRUE,
2424 VFALSE,
2525 VK, /* info = index of constant in `k' */
26+ VKNUM, /* nval = numerical value */
2627 VLOCAL, /* info = local register */
2728 VUPVAL, /* info = index of upvalue in `upvalues' */
2829 VGLOBAL, /* info = index of table; aux = index of global name in `k' */
@@ -36,7 +37,10 @@ typedef enum { · 7 unmodified lines
3637
3738 typedef struct expdesc {
3839 expkind k;
39− int info, aux;
40+ union {
41+ struct { int info, aux; } s;
42+ lua_Number nval;
43+ } u;
4044 int t; /* patch list of `exit when true' */
4145 int f; /* patch list of `exit when false' */
4246 } expdesc;
src/lstate.c+6−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.c,v 2.33 2005/08/25 15:39:16 roberto Exp $
2+** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -71,8 +71,8 @@ static void f_luaopen (lua_State *L, void *ud) { · 65 unmodified lines
7171 global_State *g = G(L);
7272 UNUSED(ud);
7373 stack_init(L, L); /* init stack */
74− sethvalue(L, gt(L), luaH_new(L, 0, 20)); /* table of globals */
75− sethvalue(L, registry(L), luaH_new(L, 6, 20)); /* registry */
74+ sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
75+ sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
7676 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
7777 luaT_init(L);
7878 luaX_init(L);
@@ -134,6 +134,7 @@ lua_State *luaE_newthread (lua_State *L) { · 55 unmodified lines
134134 void luaE_freethread (lua_State *L, lua_State *L1) {
135135 luaF_close(L1, L1->stack); /* close all upvalues for this thread */
136136 lua_assert(L1->openupval == NULL);
137+ luai_userstatefree(L1);
137138 freestack(L, L1);
138139 luaM_freemem(L, fromstate(L1), state_size(lua_State));
139140 }
@@ -196,8 +197,9 @@ static void callallgcTM (lua_State *L, void *ud) { · 56 unmodified lines
196197
197198
198199 LUA_API void lua_close (lua_State *L) {
199− lua_lock(L);
200200 L = G(L)->mainthread; /* only the main thread can be closed */
201+ luai_userstateclose(L);
202+ lua_lock(L);
201203 luaF_close(L, L->stack); /* close all upvalues for this thread */
202204 luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
203205 L->errfunc = 0; /* no error function during GC metamethods */
src/lstrlib.c+75−58
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.123 2005/08/26 17:36:32 roberto Exp $
2+** $Id: lstrlib.c,v 1.127 2005/10/26 13:28:19 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -111,7 +111,9 @@ static int str_byte (lua_State *L) { · 105 unmodified lines
111111 if (posi <= 0) posi = 1;
112112 if ((size_t)pose > l) pose = l;
113113 if (posi > pose) return 0; /* empty interval; return no values */
114− n = pose - posi + 1;
114+ n = (int)(pose - posi + 1);
115+ if (posi + n <= pose) /* overflow? */
116+ luaL_error(L, "string slice too long");
115117 luaL_checkstack(L, n, "string slice too long");
116118 for (i=0; i<n; i++)
117119 lua_pushinteger(L, uchar(s[posi+i-1]));
@@ -460,28 +462,32 @@ static const char *lmemfind (const char *s1, size_t l1, · 342 unmodified lines
460462 }
461463
462464
463−static void push_onecapture (MatchState *ms, int i) {
464− ptrdiff_t l = ms->capture[i].len;
465− if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
466− if (l == CAP_POSITION)
467− lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
468− else
469− lua_pushlstring(ms->L, ms->capture[i].init, l);
465+static void push_onecapture (MatchState *ms, int i, const char *s,
466+ const char *e) {
467+ if (i >= ms->level) {
468+ if (i == 0) /* ms->level == 0, too */
469+ lua_pushlstring(ms->L, s, e - s); /* add whole match */
470+ else
471+ luaL_error(ms->L, "invalid capture index");
472+ }
473+ else {
474+ ptrdiff_t l = ms->capture[i].len;
475+ if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
476+ if (l == CAP_POSITION)
477+ lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
478+ else
479+ lua_pushlstring(ms->L, ms->capture[i].init, l);
480+ }
470481 }
471482
472483
473484 static int push_captures (MatchState *ms, const char *s, const char *e) {
474485 int i;
475− luaL_checkstack(ms->L, ms->level, "too many captures");
476− if (ms->level == 0 && s) { /* no explicit captures? */
477− lua_pushlstring(ms->L, s, e-s); /* return whole match */
478− return 1;
479− }
480− else { /* return all captures */
481− for (i=0; i<ms->level; i++)
482− push_onecapture(ms, i);
483− return ms->level; /* number of strings pushed */
484− }
486+ int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
487+ luaL_checkstack(ms->L, nlevels, "too many captures");
488+ for (i = 0; i < nlevels; i++)
489+ push_onecapture(ms, i, s, e);
490+ return nlevels; /* number of strings pushed */
485491 }
486492
487493
@@ -516,12 +522,7 @@ static int str_find_aux (lua_State *L, int find) { · 28 unmodified lines
516522 if (find) {
517523 lua_pushinteger(L, s1-s+1); /* start */
518524 lua_pushinteger(L, res-s); /* end */
519−#if defined(LUA_COMPAT_FIND)
520525 return push_captures(&ms, NULL, 0) + 2;
521−#else
522− return 2;
523−#endif
524−
525526 }
526527 else
527528 return push_captures(&ms, s1, res);
@@ -585,42 +586,61 @@ static int gfind_nodef (lua_State *L) { · 57 unmodified lines
585586 }
586587
587588
588−static void add_s (MatchState *ms, luaL_Buffer *b,
589− const char *s, const char *e) {
590− lua_State *L = ms->L;
591− if (lua_isstring(L, 3)) {
592− size_t l;
593− const char *news = lua_tolstring(L, 3, &l);
594− size_t i;
595− for (i=0; i<l; i++) {
596− if (news[i] != L_ESC)
589+static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
590+ const char *e) {
591+ size_t l, i;
592+ const char *news = lua_tolstring(ms->L, 3, &l);
593+ for (i = 0; i < l; i++) {
594+ if (news[i] != L_ESC)
595+ luaL_addchar(b, news[i]);
596+ else {
597+ i++; /* skip ESC */
598+ if (!isdigit(uchar(news[i])))
597599 luaL_addchar(b, news[i]);
600+ else if (news[i] == '0')
601+ luaL_addlstring(b, s, e - s);
598602 else {
599− i++; /* skip ESC */
600− if (!isdigit(uchar(news[i])))
601− luaL_addchar(b, news[i]);
602− else {
603− if (news[i] == '0')
604− lua_pushlstring(L, s, e - s); /* add whole match */
605− else {
606− int level = check_capture(ms, news[i]);
607− push_onecapture(ms, level);
608− }
609− luaL_addvalue(b); /* add capture to accumulated result */
610− }
603+ push_onecapture(ms, news[i] - '1', s, e);
604+ luaL_addvalue(b); /* add capture to accumulated result */
611605 }
612606 }
613607 }
614− else { /* is a function */
615− int n;
616− lua_pushvalue(L, 3);
617− n = push_captures(ms, s, e);
618− lua_call(L, n, 1);
619− if (lua_isstring(L, -1))
620− luaL_addvalue(b); /* add return to accumulated result */
621− else
622− lua_pop(L, 1); /* function result is not a string: pop it */
608+}
609+
610+
611+static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
612+ const char *e) {
613+ lua_State *L = ms->L;
614+ switch (lua_type(L, 3)) {
615+ case LUA_TNUMBER:
616+ case LUA_TSTRING: {
617+ add_s(ms, b, s, e);
618+ return;
619+ }
620+ case LUA_TFUNCTION: {
621+ int n;
622+ lua_pushvalue(L, 3);
623+ n = push_captures(ms, s, e);
624+ lua_call(L, n, 1);
625+ break;
626+ }
627+ case LUA_TTABLE: {
628+ push_onecapture(ms, 0, s, e);
629+ lua_gettable(L, 3);
630+ break;
631+ }
632+ default: {
633+ luaL_argerror(L, 3, "string/function/table expected");
634+ return;
635+ }
636+ }
637+ if (!lua_toboolean(L, -1)) { /* nil or false? */
638+ lua_pop(L, 1);
639+ lua_pushlstring(L, s, e - s); /* keep original text */
623640 }
641+ else if (!lua_isstring(L, -1))
642+ luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
643+ luaL_addvalue(b); /* add result to accumulator */
624644 }
625645
626646
@@ -633,9 +653,6 @@ static int str_gsub (lua_State *L) { · 6 unmodified lines
633653 int n = 0;
634654 MatchState ms;
635655 luaL_Buffer b;
636− luaL_argcheck(L,
637− lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)),
638− 3, "string or function expected");
639656 luaL_buffinit(L, &b);
640657 ms.L = L;
641658 ms.src_init = src;
@@ -646,7 +663,7 @@ static int str_gsub (lua_State *L) { · 4 unmodified lines
646663 e = match(&ms, src, p);
647664 if (e) {
648665 n++;
649− add_s(&ms, &b, src, e);
666+ add_value(&ms, &b, src, e);
650667 }
651668 if (e && e>src) /* non empty match? */
652669 src = e; /* skip it */
src/ltable.c+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.26 2005/07/11 14:01:37 roberto Exp $
2+** $Id: ltable.c,v 2.27 2005/10/24 17:37:52 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -120,7 +120,7 @@ static int arrayindex (const TValue *key) { · 114 unmodified lines
120120 lua_Number n = nvalue(key);
121121 int k;
122122 lua_number2int(k, n);
123− if (luai_numeq(L, cast(lua_Number, k), nvalue(key)))
123+ if (luai_numeq(cast(lua_Number, k), nvalue(key)))
124124 return k;
125125 }
126126 return -1; /* `key' did not match some condition */
@@ -437,7 +437,7 @@ const TValue *luaH_getnum (Table *t, int key) { · 310 unmodified lines
437437 lua_Number nk = cast(lua_Number, key);
438438 Node *n = hashnum(t, nk);
439439 do { /* check whether `key' is somewhere in the chain */
440− if (ttisnumber(gkey(n)) && luai_numeq(L, nvalue(gkey(n)), nk))
440+ if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
441441 return gval(n); /* that's it */
442442 else n = gnext(n);
443443 } while (n);
@@ -471,7 +471,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 27 unmodified lines
471471 int k;
472472 lua_Number n = nvalue(key);
473473 lua_number2int(k, n);
474− if (luai_numeq(L, cast(lua_Number, k), nvalue(key))) /* index is int? */
474+ if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */
475475 return luaH_getnum(t, k); /* use specialized version */
476476 /* else go through */
477477 }
@@ -495,7 +495,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 17 unmodified lines
495495 return cast(TValue *, p);
496496 else {
497497 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
498− else if (ttisnumber(key) && !luai_numeq(L, nvalue(key), nvalue(key)))
498+ else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key)))
499499 luaG_runerror(L, "table index is NaN");
500500 return newkey(L, t, key);
501501 }
src/ltablib.c+40−18
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltablib.c,v 1.35 2005/08/26 17:36:32 roberto Exp $
2+** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $
33 ** Library for Table Manipulation
44 ** See Copyright Notice in lua.h
55 */
@@ -40,9 +40,7 @@ static int foreach (lua_State *L) { · 34 unmodified lines
4040 luaL_checktype(L, 1, LUA_TTABLE);
4141 luaL_checktype(L, 2, LUA_TFUNCTION);
4242 lua_pushnil(L); /* first key */
43− for (;;) {
44− if (lua_next(L, 1) == 0)
45− return 0;
43+ while (lua_next(L, 1)) {
4644 lua_pushvalue(L, 2); /* function */
4745 lua_pushvalue(L, -3); /* key */
4846 lua_pushvalue(L, -3); /* value */
@@ -51,6 +49,23 @@ static int foreach (lua_State *L) { · 2 unmodified lines
5149 return 1;
5250 lua_pop(L, 2); /* remove value and result */
5351 }
52+ return 0;
53+}
54+
55+
56+static int maxn (lua_State *L) {
57+ lua_Number max = 0;
58+ luaL_checktype(L, 1, LUA_TTABLE);
59+ lua_pushnil(L); /* first key */
60+ while (lua_next(L, 1)) {
61+ lua_pop(L, 1); /* remove value */
62+ if (lua_type(L, -1) == LUA_TNUMBER) {
63+ lua_Number v = lua_tonumber(L, -1);
64+ if (v > max) max = v;
65+ }
66+ }
67+ lua_pushnumber(L, max);
68+ return 1;
5469 }
5570
5671
@@ -75,16 +90,23 @@ static int setn (lua_State *L) { · 18 unmodified lines
7590 static int tinsert (lua_State *L) {
7691 int e = aux_getn(L, 1) + 1; /* first empty element */
7792 int pos; /* where to insert new element */
78− if (lua_isnone(L, 3)) /* called with only 2 arguments */
79− pos = e; /* insert new element at the end */
80− else {
81− int i;
82− pos = luaL_checkint(L, 2); /* 2nd argument is the position */
83− if (pos > e) e = pos; /* `grow' array if necessary */
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] */
93+ switch (lua_gettop(L)) {
94+ case 2: { /* called with only 2 arguments */
95+ pos = e; /* insert new element at the end */
96+ break;
97+ }
98+ case 3: {
99+ int i;
100+ pos = luaL_checkint(L, 2); /* 2nd argument is the position */
101+ if (pos > e) e = pos; /* `grow' array if necessary */
102+ for (i = e; i > pos; i--) { /* move up elements */
103+ lua_rawgeti(L, 1, i-1);
104+ lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
105+ }
106+ break;
107+ }
108+ default: {
109+ return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
88110 }
89111 }
90112 luaL_setn(L, 1, e); /* new size */
@@ -112,12 +134,11 @@ static int tremove (lua_State *L) { · 21 unmodified lines
112134 static int tconcat (lua_State *L) {
113135 luaL_Buffer b;
114136 size_t lsep;
137+ int i, last;
115138 const char *sep = luaL_optlstring(L, 2, "", &lsep);
116− int i = luaL_optint(L, 3, 1);
117− int last = luaL_optint(L, 4, -2);
118139 luaL_checktype(L, 1, LUA_TTABLE);
119− if (last == -2)
120− last = luaL_getn(L, 1);
140+ i = luaL_optint(L, 3, 1);
141+ last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));
121142 luaL_buffinit(L, &b);
122143 for (; i <= last; i++) {
123144 lua_rawgeti(L, 1, i);
@@ -241,6 +262,7 @@ static const luaL_Reg tab_funcs[] = { · 117 unmodified lines
241262 {"foreach", foreach},
242263 {"foreachi", foreachi},
243264 {"getn", getn},
265+ {"maxn", maxn},
244266 {"insert", tinsert},
245267 {"remove", tremove},
246268 {"setn", setn},
src/lua.c+96−90
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.150 2005/09/06 17:19:33 roberto Exp $
2+** $Id: lua.c,v 1.154 2005/10/24 17:38:47 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -43,12 +43,13 @@ static void print_usage (void) { · 37 unmodified lines
4343 fprintf(stderr,
4444 "usage: %s [options] [script [args]].\n"
4545 "Available options are:\n"
46− " - execute stdin as a file\n"
4746 " -e stat execute string " LUA_QL("stat") "\n"
48− " -i enter interactive mode after executing " LUA_QL("script") "\n"
4947 " -l name require library " LUA_QL("name") "\n"
48+ " -i enter interactive mode after executing " LUA_QL("script") "\n"
5049 " -v show version information\n"
51− " -- stop handling options\n" ,
50+ " -- stop handling options\n"
51+ " - execute stdin and stop handling options\n"
52+ ,
5253 progname);
5354 fflush(stderr);
5455 }
@@ -99,6 +100,8 @@ static int docall (lua_State *L, int narg, int clear) { · 44 unmodified lines
99100 status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
100101 signal(SIGINT, SIG_DFL);
101102 lua_remove(L, base); /* remove traceback function */
103+ /* force a complete garbage collection in case of errors */
104+ if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
102105 return status;
103106 }
104107
@@ -108,9 +111,12 @@ static void print_version (void) { · 3 unmodified lines
108111 }
109112
110113
111−static int getargs (lua_State *L, int argc, char **argv, int n) {
112− int narg = argc - (n + 1); /* number of arguments to the script */
114+static int getargs (lua_State *L, char **argv, int n) {
115+ int narg;
113116 int i;
117+ int argc = 0;
118+ while (argv[argc]) argc++; /* count total number of arguments */
119+ narg = argc - (n + 1); /* number of arguments to the script */
114120 luaL_checkstack(L, narg + 3, "too many arguments to script");
115121 for (i=n+1; i < argc; i++)
116122 lua_pushstring(L, argv[i]);
@@ -229,86 +235,71 @@ static void dotty (lua_State *L) { · 112 unmodified lines
229235 }
230236
231237
232−#define clearinteractive(i) (*i &= 2)
238+static int handle_script (lua_State *L, char **argv, int n) {
239+ int status;
240+ const char *fname;
241+ int narg = getargs(L, argv, n); /* collect arguments */
242+ lua_setglobal(L, "arg");
243+ fname = argv[n];
244+ if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
245+ fname = NULL; /* stdin */
246+ status = luaL_loadfile(L, fname);
247+ lua_insert(L, -(narg+1));
248+ if (status == 0)
249+ status = docall(L, narg, 0);
250+ else
251+ lua_pop(L, narg);
252+ return report(L, status);
253+}
233254
234−static int handle_argv (lua_State *L, int argc, char **argv, int *interactive) {
235− if (argv[1] == NULL) { /* no arguments? */
236− *interactive = 0;
237− if (lua_stdin_is_tty())
238− dotty(L);
239− else
240− dofile(L, NULL); /* executes stdin as a file */
241− }
242− else { /* other arguments; loop over them */
243− int i;
244− for (i = 1; argv[i] != NULL; i++) {
245− if (argv[i][0] != '-') break; /* not an option? */
246− switch (argv[i][1]) { /* option */
247− case '-': { /* `--' */
248− if (argv[i][2] != '\0') {
249− print_usage();
250− return 1;
251− }
252− i++; /* skip this argument */
253− goto endloop; /* stop handling arguments */
254− }
255− case '\0': {
256− clearinteractive(interactive);
257− dofile(L, NULL); /* executes stdin as a file */
258− break;
259− }
260− case 'i': {
261− *interactive = 2; /* force interactive mode after arguments */
262− break;
263− }
264− case 'v': {
265− clearinteractive(interactive);
266− print_version();
267− break;
268− }
269− case 'e': {
270− const char *chunk = argv[i] + 2;
271− clearinteractive(interactive);
272− if (*chunk == '\0') chunk = argv[++i];
273− if (chunk == NULL) {
274− print_usage();
275− return 1;
276− }
277− if (dostring(L, chunk, "=(command line)") != 0)
278− return 1;
279− break;
280− }
281− case 'l': {
282− const char *filename = argv[i] + 2;
283− if (*filename == '\0') filename = argv[++i];
284− if (filename == NULL) {
285− print_usage();
286− return 1;
287− }
288− if (dolibrary(L, filename))
289− return 1; /* stop if file fails */
290− break;
255+
256+static int collectargs (char **argv, int *pi, int *pv, int *pe) {
257+ int i;
258+ for (i = 1; argv[i] != NULL; i++) {
259+ if (argv[i][0] != '-') /* not an option? */
260+ return i;
261+ switch (argv[i][1]) { /* option */
262+ case '-': return (argv[i+1] != NULL ? i+1 : 0);
263+ case '\0': return i;
264+ case 'i': *pi = 1; break;
265+ case 'v': *pv = 1; break;
266+ case 'e': *pe = 1; /* go through */
267+ case 'l':
268+ if (argv[i][2] == '\0') {
269+ i++;
270+ if (argv[i] == NULL) return -1;
291271 }
292− default: {
293− clearinteractive(interactive);
294− print_usage();
272+ break;
273+ default: return -1; /* invalid option */
274+ }
275+ }
276+ return 0;
277+}
278+
279+
280+static int runargs (lua_State *L, char **argv, int n) {
281+ int i;
282+ for (i = 1; i < n; i++) {
283+ if (argv[i] == NULL) continue;
284+ lua_assert(argv[i][0] == '-');
285+ switch (argv[i][1]) { /* option */
286+ case 'e': {
287+ const char *chunk = argv[i] + 2;
288+ if (*chunk == '\0') chunk = argv[++i];
289+ lua_assert(chunk != NULL);
290+ if (dostring(L, chunk, "=(command line)") != 0)
295291 return 1;
296− }
292+ break;
297293 }
298− } endloop:
299− if (argv[i] != NULL) {
300− int status;
301− const char *filename = argv[i];
302− int narg = getargs(L, argc, argv, i); /* collect arguments */
303− lua_setglobal(L, "arg");
304− clearinteractive(interactive);
305− status = luaL_loadfile(L, filename);
306− lua_insert(L, -(narg+1));
307− if (status == 0)
308− status = docall(L, narg, 0);
309− else
310− lua_pop(L, narg);
311− return report(L, status);
294+ case 'l': {
295+ const char *filename = argv[i] + 2;
296+ if (*filename == '\0') filename = argv[++i];
297+ lua_assert(filename != NULL);
298+ if (dolibrary(L, filename))
299+ return 1; /* stop if file fails */
300+ break;
301+ }
302+ default: break;
312303 }
313304 }
314305 return 0;
@@ -334,17 +325,32 @@ struct Smain { · 19 unmodified lines
334325
335326 static int pmain (lua_State *L) {
336327 struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
337− int status;
338− int interactive = 1;
339− if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
328+ char **argv = s->argv;
329+ int script;
330+ int has_i = 0, has_v = 0, has_e = 0;
340331 globalL = L;
332+ if (argv[0] && argv[0][0]) progname = argv[0];
341333 luaL_openlibs(L); /* open libraries */
342− status = handle_luainit(L);
343− if (status == 0) {
344− status = handle_argv(L, s->argc, s->argv, &interactive);
345− if (status == 0 && interactive) dotty(L);
334+ s->status = handle_luainit(L);
335+ if (s->status != 0) return 0;
336+ script = collectargs(argv, &has_i, &has_v, &has_e);
337+ if (script < 0) { /* invalid args? */
338+ print_usage();
339+ s->status = 1;
340+ return 0;
341+ }
342+ if (has_v) print_version();
343+ s->status = runargs(L, argv, (script > 0) ? script : s->argc);
344+ if (s->status != 0) return 0;
345+ if (script)
346+ s->status = handle_script(L, argv, script);
347+ if (s->status != 0) return 0;
348+ if (has_i)
349+ dotty(L);
350+ else if (script == 0 && !has_e && !has_v) {
351+ if (lua_stdin_is_tty()) dotty(L);
352+ else dofile(L, NULL); /* executes stdin as a file */
346353 }
347− s->status = status;
348354 return 0;
349355 }
350356
src/lua.h+7−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.212 2005/08/25 20:02:08 roberto Exp $
2+** $Id: lua.h,v 1.214 2005/10/20 11:35:50 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -16,7 +16,7 @@ · 10 unmodified lines
1616 #include "luaconf.h"
1717
1818
19−#define LUA_VERSION "Lua 5.1 (alpha)"
19+#define LUA_VERSION "Lua 5.1 (beta)"
2020 #define LUA_VERSION_NUM 501
2121 #define LUA_COPYRIGHT "Copyright (C) 1994-2005 Lua.org, PUC-Rio"
2222 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@@ -221,9 +221,10 @@ LUA_API int (lua_status) (lua_State *L); · 198 unmodified lines
221221 #define LUA_GCRESTART 1
222222 #define LUA_GCCOLLECT 2
223223 #define LUA_GCCOUNT 3
224−#define LUA_GCSTEP 4
225−#define LUA_GCSETPAUSE 5
226−#define LUA_GCSETSTEPMUL 6
224+#define LUA_GCCOUNTB 4
225+#define LUA_GCSTEP 5
226+#define LUA_GCSETPAUSE 6
227+#define LUA_GCSETSTEPMUL 7
227228
228229 LUA_API int (lua_gc) (lua_State *L, int what, int data);
229230
@@ -239,6 +240,7 @@ LUA_API int (lua_next) (lua_State *L, int idx); · 9 unmodified lines
239240 LUA_API void (lua_concat) (lua_State *L, int n);
240241
241242 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
243+LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
242244
243245
244246
src/luac.c+7−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luac.c,v 1.51 2005/06/02 13:39:23 lhf Exp $
2+** $Id: luac.c,v 1.52 2005/11/11 14:03:13 lhf Exp $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -23,13 +23,8 @@ · 17 unmodified lines
2323 #include "lstring.h"
2424 #include "lundump.h"
2525
26−#ifndef PROGNAME
2726 #define PROGNAME "luac" /* default program name */
28−#endif
29−
30−#ifndef OUTPUT
31−#define OUTPUT "luac.out" /* default output file */
32−#endif
27+#define OUTPUT PROGNAME ".out" /* default output file */
3328
3429 static int listing=0; /* list bytecodes? */
3530 static int dumping=1; /* dump bytecodes? */
@@ -152,15 +147,15 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 116 unmodified lines
152147 }
153148
154149 struct Smain {
155− int argc;
156− char **argv;
150+ int argc;
151+ char** argv;
157152 };
158153
159−static int pmain(lua_State *L)
154+static int pmain(lua_State* L)
160155 {
161− struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
156+ struct Smain* s = (struct Smain*)lua_touserdata(L, 1);
162157 int argc=s->argc;
163− char **argv=s->argv;
158+ char** argv=s->argv;
164159 Proto* f;
165160 int i;
166161 if (!lua_checkstack(L,argc)) fatal("too many input files");
src/luaconf.h+95−73
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.65 2005/09/09 18:24:42 roberto Exp $
2+** $Id: luaconf.h,v 1.74 2005/11/16 16:24:28 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -19,8 +19,6 @@ · 13 unmodified lines
1919 */
2020
2121
22−
23−
2422 /*
2523 @@ LUA_ANSI controls the use of non-ansi features.
2624 ** CHANGE it (define it) if you want Lua to avoid the use of any
@@ -30,6 +28,31 @@ · 3 unmodified lines
3028 #define LUA_ANSI
3129 #endif
3230
31+#if defined(LUA_USE_LINUX)
32+#define LUA_USE_POSIX
33+#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
34+#define LUA_USE_READLINE /* needs some extra libraries */
35+#endif
36+
37+#if defined(LUA_USE_MACOSX)
38+#define LUA_USE_POSIX
39+#define LUA_DL_DYLD /* does not need extra library */
40+#endif
41+
42+
43+
44+/*
45+@@ LUA_USE_POSIX includes all functionallity listed as X/Open System
46+@* Interfaces Extension (XSI).
47+** CHANGE it (define it) if your system is XSI compatible.
48+*/
49+#if defined(LUA_USE_POSIX)
50+#define LUA_USE_MKSTEMP
51+#define LUA_USE_ISATTY
52+#define LUA_USE_POPEN
53+#define LUA_USE_ULONGJMP
54+#endif
55+
3356
3457 /*
3558 @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@@ -92,7 +115,7 @@ · 56 unmodified lines
92115 #define LUA_PATHSEP ";"
93116 #define LUA_PATH_MARK "?"
94117 #define LUA_EXECDIR "!"
95−#define LUA_IGMARK ":"
118+#define LUA_IGMARK "-"
96119
97120
98121 /*
@@ -141,10 +164,12 @@ · 42 unmodified lines
141164 #if defined(luaall_c)
142165 #define LUAI_FUNC static
143166 #define LUAI_DATA /* empty */
167+
144168 #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
145169 defined(__ELF__)
146170 #define LUAI_FUNC __attribute__((visibility("hidden"))) extern
147171 #define LUAI_DATA LUAI_FUNC
172+
148173 #else
149174 #define LUAI_FUNC extern
150175 #define LUAI_DATA extern
@@ -189,7 +214,7 @@ · 38 unmodified lines
189214 ** CHANGE it if you have a better definition for non-POSIX/non-Windows
190215 ** systems.
191216 */
192−#if !defined(LUA_ANSI) && defined(_POSIX_C_SOURCE)
217+#if defined(LUA_USE_ISATTY)
193218 #include <unistd.h>
194219 #define lua_stdin_is_tty() isatty(0)
195220 #elif !defined(LUA_ANSI) && defined(_WIN32)
@@ -239,17 +264,17 @@ · 43 unmodified lines
239264 #include <stdio.h>
240265 #include <readline/readline.h>
241266 #include <readline/history.h>
242−#define lua_readline(L,b,p) (((b)=readline(p)) != NULL)
267+#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
243268 #define lua_saveline(L,idx) \
244269 if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
245270 add_history(lua_tostring(L, idx)); /* add it to history */
246−#define lua_freeline(L,b) free(b)
271+#define lua_freeline(L,b) ((void)L, free(b))
247272 #else
248273 #define lua_readline(L,b,p) \
249− (fputs(p, stdout), fflush(stdout), /* show prompt */ \
274+ ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
250275 fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
251−#define lua_saveline(L,idx) ((void)0)
252−#define lua_freeline(L,b) ((void)0)
276+#define lua_saveline(L,idx) { (void)L; (void)idx; }
277+#define lua_freeline(L,b) { (void)L; (void)b; }
253278 #endif
254279
255280 #endif
@@ -315,13 +340,6 @@ · 59 unmodified lines
315340 */
316341 #define LUA_COMPAT_LSTR 1
317342
318−/*
319−@@ LUA_COMPAT_FIND controls compatibility with old 'string.find' behavior.
320−** CHANGE it to undefined as soon as your programs use 'string.find' only
321−** to find patterns.
322−*/
323−#define LUA_COMPAT_FIND
324−
325343 /*
326344 @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
327345 ** CHANGE it to undefined as soon as you rename 'string.gfind' to
@@ -329,7 +347,6 @@ · 1 unmodified line
329347 */
330348 #define LUA_COMPAT_GFIND
331349
332−
333350 /*
334351 @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
335352 @* behavior.
@@ -349,10 +366,10 @@ · 13 unmodified lines
349366 */
350367 #if defined(LUA_USE_APICHECK)
351368 #include <assert.h>
352−#define luai_apicheck(L,o) assert(o)
369+#define luai_apicheck(L,o) { (void)L; assert(o); }
353370 #else
354371 /* (By default lua_assert is empty, so luai_apicheck is also empty.) */
355−#define luai_apicheck(L,o) lua_assert(o)
372+#define luai_apicheck(L,o) { (void)L; lua_assert(o); }
356373 #endif
357374
358375
@@ -464,31 +481,6 @@ · 105 unmodified lines
464481
465482
466483
467−/*
468−@@ lua_number2int is a macro to convert lua_Number to int.
469−@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
470−** CHANGE them if you know a faster way to convert a lua_Number to
471−** int (with any rounding method and without throwing errors) in your
472−** system. In Pentium machines, a naive typecast from double to int
473−** in C is extremely slow, so any alternative is worth trying.
474−*/
475−
476−/* On a Pentium, resort to a trick */
477−#if !defined(LUA_ANSI) && !defined(__SSE2__) && \
478− (defined(__i386) || defined (_M_IX86))
479−union luai_Cast { double l_d; long l_l; };
480−#define lua_number2int(i,d) \
481− { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
482−#define lua_number2integer(i,n) lua_number2int(i, n)
483−
484−/* this option always works, but may be slow */
485−#else
486−#define lua_number2int(i,d) ((i)=(int)(d))
487−#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
488−
489−#endif
490−
491−
492484
493485 /*
494486 ** {==================================================================
@@ -525,16 +517,44 @@ union luai_Cast { double l_d; long l_l; }; · 30 unmodified lines
525517 /*
526518 @@ The luai_num* macros define the primitive operations over numbers.
527519 */
528−#define luai_numadd(L,a,b) ((a)+(b))
529−#define luai_numsub(L,a,b) ((a)-(b))
530−#define luai_nummul(L,a,b) ((a)*(b))
531−#define luai_numdiv(L,a,b) ((a)/(b))
532−#define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))
533−#define luai_numpow(L,a,b) pow(a,b)
534−#define luai_numunm(L,a) (-(a))
535−#define luai_numeq(L,a,b) ((a)==(b))
536−#define luai_numlt(L,a,b) ((a)<(b))
537−#define luai_numle(L,a,b) ((a)<=(b))
520+#if defined(LUA_CORE)
521+#include <math.h>
522+#define luai_numadd(a,b) ((a)+(b))
523+#define luai_numsub(a,b) ((a)-(b))
524+#define luai_nummul(a,b) ((a)*(b))
525+#define luai_numdiv(a,b) ((a)/(b))
526+#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
527+#define luai_numpow(a,b) (pow(a,b))
528+#define luai_numunm(a) (-(a))
529+#define luai_numeq(a,b) ((a)==(b))
530+#define luai_numlt(a,b) ((a)<(b))
531+#define luai_numle(a,b) ((a)<=(b))
532+#endif
533+
534+
535+/*
536+@@ lua_number2int is a macro to convert lua_Number to int.
537+@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
538+** CHANGE them if you know a faster way to convert a lua_Number to
539+** int (with any rounding method and without throwing errors) in your
540+** system. In Pentium machines, a naive typecast from double to int
541+** in C is extremely slow, so any alternative is worth trying.
542+*/
543+
544+/* On a Pentium, resort to a trick */
545+#if !defined(LUA_ANSI) && !defined(__SSE2__) && \
546+ (defined(__i386) || defined (_M_IX86) || defined(__i386__))
547+union luai_Cast { double l_d; long l_l; };
548+#define lua_number2int(i,d) \
549+ { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
550+#define lua_number2integer(i,n) lua_number2int(i, n)
551+
552+/* this option always works, but may be slow */
553+#else
554+#define lua_number2int(i,d) ((i)=(int)(d))
555+#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
556+
557+#endif
538558
539559 /* }================================================================== */
540560
@@ -597,7 +617,7 @@ union luai_Cast { double l_d; long l_l; }; · 56 unmodified lines
597617 */
598618 #if defined(loslib_c) || defined(luaall_c)
599619
600−#if !defined(LUA_ANSI) && defined(_POSIX_C_SOURCE)
620+#if defined(LUA_USE_MKSTEMP)
601621 #include <unistd.h>
602622 #define LUA_TMPNAMBUFSIZE 32
603623 #define lua_tmpnam(b,e) { \
@@ -605,6 +625,7 @@ union luai_Cast { double l_d; long l_l; }; · 1 unmodified line
605625 e = mkstemp(b); \
606626 if (e != -1) close(e); \
607627 e = (e == -1); }
628+
608629 #else
609630 #define LUA_TMPNAMBUFSIZE L_tmpnam
610631 #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
@@ -618,21 +639,21 @@ union luai_Cast { double l_d; long l_l; }; · 7 unmodified lines
618639 @* the file streams.
619640 ** CHANGE it if you have a way to implement it in your system.
620641 */
621−#if !defined(LUA_ANSI) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 2
642+#if defined(LUA_USE_POPEN)
622643
623−#define lua_popen(L,c,m) popen(c,m)
624−#define lua_pclose(L,file) (pclose(file) != -1)
644+#define lua_popen(L,c,m) ((void)L, popen(c,m))
645+#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
625646
626647 #elif !defined(LUA_ANSI) && defined(_WIN32)
627648
628−#define lua_popen(L,c,m) _popen(c,m)
629−#define lua_pclose(L,file) (_pclose(file) != -1)
649+#define lua_popen(L,c,m) ((void)L, _popen(c,m))
650+#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
630651
631652 #else
632653
633654 #define lua_popen(L,c,m) \
634655 ((void)c, (void)m, luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
635−#define lua_pclose(L,file) ((void)file, 0)
656+#define lua_pclose(L,file) ((void)L, (void)file, 0)
636657
637658 #endif
638659
@@ -647,16 +668,15 @@ union luai_Cast { double l_d; long l_l; }; · 8 unmodified lines
647668 ** automatically. (When you change the makefile to add -ldl, you must
648669 ** also add -DLUA_USE_DLOPEN.)
649670 ** If you do not want any kind of dynamic library, undefine all these
650−** options (or just remove these definitions).
671+** options.
672+** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
651673 */
652−#if !defined(LUA_ANSI)
653−#if defined(_WIN32)
654−#define LUA_DL_DLL
655−#elif defined(__APPLE__) && defined(__MACH__)
656−#define LUA_DL_DYLD
657−#elif defined(LUA_USE_DLOPEN)
674+#if defined(LUA_USE_DLOPEN)
658675 #define LUA_DL_DLOPEN
659676 #endif
677+
678+#if !defined(LUA_ANSI) && defined(_WIN32)
679+#define LUA_DL_DLL
660680 #endif
661681
662682
@@ -674,10 +694,12 @@ union luai_Cast { double l_d; long l_l; }; · 11 unmodified lines
674694 ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
675695 ** extra when a thread is created/deleted/resumed/yielded.
676696 */
677−#define luai_userstateopen(L) ((void)0)
678−#define luai_userstatefree(L) ((void)0)
679−#define luai_userstateresume(L,n) ((void)0)
680−#define luai_userstateyield(L,n) ((void)0)
697+#define luai_userstateopen(L) ((void)L)
698+#define luai_userstateclose(L) ((void)L)
699+#define luai_userstatethread(L,L1) ((void)L)
700+#define luai_userstatefree(L) ((void)L)
701+#define luai_userstateresume(L,n) ((void)L)
702+#define luai_userstateyield(L,n) ((void)L)
681703
682704
683705
src/lundump.c+41−108
@@ -1,6 +1,6 @@
11 /*
2−** $Id: lundump.c,v 1.58 2005/09/02 01:54:47 lhf Exp $
3−** load pre-compiled Lua chunks
2+** $Id: lundump.c,v 1.59 2005/11/11 14:03:13 lhf Exp $
3+** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
66
@@ -15,42 +15,34 @@ · 8 unmodified lines
1515 #include "ldo.h"
1616 #include "lfunc.h"
1717 #include "lmem.h"
18−#include "lopcodes.h"
18+#include "lobject.h"
1919 #include "lstring.h"
2020 #include "lundump.h"
2121 #include "lzio.h"
2222
23−#ifdef LUAC_TRUST_BINARIES
24−#define IF(c,s)
25−#else
26−#define IF(c,s) if (c) error(S,s)
27−#endif
28−
2923 typedef struct {
3024 lua_State* L;
3125 ZIO* Z;
3226 Mbuffer* b;
3327 const char* name;
34−#ifdef LUAC_SWAP_ON_LOAD
35− int swap;
36−#endif
3728 } LoadState;
3829
39−#ifdef LUAC_SWAP_ON_LOAD
40−static void LoadMem (LoadState* S, void* b, int n, size_t size);
30+#ifdef LUAC_TRUST_BINARIES
31+#define IF(c,s)
4132 #else
42−#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
43−#endif
44−
45−#define LoadByte(S) (lu_byte)LoadChar(S)
46−#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
47−#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
33+#define IF(c,s) if (c) error(S,s)
4834
4935 static void error(LoadState* S, const char* why)
5036 {
51− luaO_pushfstring(S->L,"%s: %s",S->name,why);
37+ luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
5238 luaD_throw(S->L,LUA_ERRSYNTAX);
5339 }
40+#endif
41+
42+#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
43+#define LoadByte(S) (lu_byte)LoadChar(S)
44+#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
45+#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
5446
5547 static void LoadBlock(LoadState* S, void* b, size_t size)
5648 {
@@ -102,39 +94,6 @@ static void LoadCode(LoadState* S, Proto* f) · 45 unmodified lines
10294 LoadVector(S,f->code,n,sizeof(Instruction));
10395 }
10496
105−static void LoadLocals(LoadState* S, Proto* f)
106−{
107− int i,n;
108− n=LoadInt(S);
109− f->locvars=luaM_newvector(S->L,n,LocVar);
110− f->sizelocvars=n;
111− for (i=0; i<n; i++) f->locvars[i].varname=NULL;
112− for (i=0; i<n; i++)
113− {
114− f->locvars[i].varname=LoadString(S);
115− f->locvars[i].startpc=LoadInt(S);
116− f->locvars[i].endpc=LoadInt(S);
117− }
118−}
119−
120−static void LoadLines(LoadState* S, Proto* f)
121−{
122− int n=LoadInt(S);
123− f->lineinfo=luaM_newvector(S->L,n,int);
124− f->sizelineinfo=n;
125− LoadVector(S,f->lineinfo,n,sizeof(int));
126−}
127−
128−static void LoadUpvalues(LoadState* S, Proto* f)
129−{
130− int i,n;
131− n=LoadInt(S);
132− f->upvalues=luaM_newvector(S->L,n,TString*);
133− f->sizeupvalues=n;
134− for (i=0; i<n; i++) f->upvalues[i]=NULL;
135− for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
136−}
137−
13897 static Proto* LoadFunction(LoadState* S, TString* p);
13998
14099 static void LoadConstants(LoadState* S, Proto* f)
@@ -174,6 +133,30 @@ static void LoadConstants(LoadState* S, Proto* f) · 33 unmodified lines
174133 for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
175134 }
176135
136+static void LoadDebug(LoadState* S, Proto* f)
137+{
138+ int i,n;
139+ n=LoadInt(S);
140+ f->lineinfo=luaM_newvector(S->L,n,int);
141+ f->sizelineinfo=n;
142+ LoadVector(S,f->lineinfo,n,sizeof(int));
143+ n=LoadInt(S);
144+ f->locvars=luaM_newvector(S->L,n,LocVar);
145+ f->sizelocvars=n;
146+ for (i=0; i<n; i++) f->locvars[i].varname=NULL;
147+ for (i=0; i<n; i++)
148+ {
149+ f->locvars[i].varname=LoadString(S);
150+ f->locvars[i].startpc=LoadInt(S);
151+ f->locvars[i].endpc=LoadInt(S);
152+ }
153+ n=LoadInt(S);
154+ f->upvalues=luaM_newvector(S->L,n,TString*);
155+ f->sizeupvalues=n;
156+ for (i=0; i<n; i++) f->upvalues[i]=NULL;
157+ for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
158+}
159+
177160 static Proto* LoadFunction(LoadState* S, TString* p)
178161 {
179162 Proto* f=luaF_newproto(S->L);
@@ -185,11 +168,9 @@ static Proto* LoadFunction(LoadState* S, TString* p) · 5 unmodified lines
185168 f->numparams=LoadByte(S);
186169 f->is_vararg=LoadByte(S);
187170 f->maxstacksize=LoadByte(S);
188− LoadLines(S,f);
189− LoadLocals(S,f);
190− LoadUpvalues(S,f);
191− LoadConstants(S,f);
192171 LoadCode(S,f);
172+ LoadConstants(S,f);
173+ LoadDebug(S,f);
193174 IF (!luaG_checkcode(f), "bad code");
194175 S->L->top--;
195176 return f;
@@ -201,9 +182,6 @@ static void LoadHeader(LoadState* S) · 5 unmodified lines
201182 char s[LUAC_HEADERSIZE];
202183 luaU_header(h);
203184 LoadBlock(S,s,LUAC_HEADERSIZE);
204−#ifdef LUAC_SWAP_ON_LOAD
205− S->swap=(s[6]!=h[6]); s[6]=h[6];
206−#endif
207185 IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
208186 }
209187
@@ -236,55 +214,10 @@ void luaU_header (char* h) · 26 unmodified lines
236214 h+=sizeof(LUA_SIGNATURE)-1;
237215 *h++=(char)LUAC_VERSION;
238216 *h++=(char)LUAC_FORMAT;
239− *h++=(char)*(char*)&x;
217+ *h++=(char)*(char*)&x; /* endianness */
240218 *h++=(char)sizeof(int);
241219 *h++=(char)sizeof(size_t);
242220 *h++=(char)sizeof(Instruction);
243221 *h++=(char)sizeof(lua_Number);
244− *h++=(char)(((lua_Number)0.5)==0);
245−}
246−
247−#ifdef LUAC_SWAP_ON_LOAD
248−static void LoadMem (LoadState* S, void* b, int n, size_t size)
249−{
250− LoadBlock(S,b,n*size);
251− if (S->swap)
252− {
253− char* p=(char*) b;
254− char c;
255− switch (size)
256− {
257− case 1:
258− break;
259− case 2:
260− while (n--)
261− {
262− c=p[0]; p[0]=p[1]; p[1]=c;
263− p+=2;
264− }
265− break;
266− case 4:
267− while (n--)
268− {
269− c=p[0]; p[0]=p[3]; p[3]=c;
270− c=p[1]; p[1]=p[2]; p[2]=c;
271− p+=4;
272− }
273− break;
274− case 8:
275− while (n--)
276− {
277− c=p[0]; p[0]=p[7]; p[7]=c;
278− c=p[1]; p[1]=p[6]; p[6]=c;
279− c=p[2]; p[2]=p[5]; p[5]=c;
280− c=p[3]; p[3]=p[4]; p[4]=c;
281− p+=8;
282− }
283− break;
284− default:
285− IF(1, "bad size");
286− break;
287− }
288− }
222+ *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
289223 }
290−#endif
src/lundump.h+4−30
@@ -1,6 +1,6 @@
11 /*
2−** $Id: lundump.h,v 1.38 2005/09/02 01:54:47 lhf Exp $
3−** load pre-compiled Lua chunks
2+** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $
3+** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
66
@@ -10,12 +10,6 @@ · 3 unmodified lines
1010 #include "lobject.h"
1111 #include "lzio.h"
1212
13−/* make it work with Lua 5.0 */
14−#ifndef LUA_VERSION_NUM
15−#define LUAI_FUNC
16−#define lua_Writer lua_Chunkwriter
17−#endif
18−
1913 /* load one chunk; from lundump.c */
2014 LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
2115
@@ -25,8 +19,10 @@ LUAI_FUNC void luaU_header (char* h); · 3 unmodified lines
2519 /* dump one chunk; from ldump.c */
2620 LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
2721
22+#ifdef luac_c
2823 /* print one chunk; from print.c */
2924 LUAI_FUNC void luaU_print (const Proto* f, int full);
25+#endif
3026
3127 /* for header of binary files -- this is Lua 5.1 */
3228 #define LUAC_VERSION 0x51
@@ -37,26 +33,4 @@ LUAI_FUNC void luaU_print (const Proto* f, int full); · 4 unmodified lines
3733 /* size of header of binary files */
3834 #define LUAC_HEADERSIZE 12
3935
40−/* make it work with Lua 5.0 */
41−#ifndef LUA_VERSION_NUM
42−#define LUA_SIGNATURE "\033Lua"
43−#define TValue TObject
44−#define rawtsvalue tsvalue
45−#define linedefined lineDefined
46−#define lastlinedefined lineDefined
47−#define setptvalue2s(L,t,f)
48−#undef setsvalue2n
49−#define setsvalue2n(L,x,y) setsvalue(x,y)
50−#define LUA_QL(x) "'" x "'"
51−#define LUA_QS LUA_QL("%s")
52−#undef LUAC_VERSION
53−#define LUAC_VERSION 0x50
54−#ifdef lapi_c
55−#define luaU_dump(L,f,w,d) (luaU_dump)(L,f,w,d,0)
56−#endif
57−#ifdef ldo_c
58−#define luaU_undump(L,z,b) (luaU_undump)(L,z,b,z->name)
59−#endif
60−#endif
61−
6236 #endif
src/lvm.c+43−75
@@ -1,11 +1,10 @@
11 /*
2−** $Id: lvm.c,v 2.55 2005/09/09 18:23:35 roberto Exp $
2+** $Id: lvm.c,v 2.59 2005/11/01 16:08:45 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
66
77
8−#include <math.h>
98 #include <stdio.h>
109 #include <stdlib.h>
1110 #include <string.h>
@@ -66,7 +65,6 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 54 unmodified lines
6665 if (L->hookcount == 0) {
6766 resethookcount(L);
6867 luaD_callhook(L, LUA_HOOKCOUNT, -1);
69− return;
7068 }
7169 }
7270 if (mask & LUA_MASKLINE) {
@@ -226,7 +224,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 153 unmodified lines
226224 if (ttype(l) != ttype(r))
227225 return luaG_ordererror(L, l, r);
228226 else if (ttisnumber(l))
229− return luai_numlt(L, nvalue(l), nvalue(r));
227+ return luai_numlt(nvalue(l), nvalue(r));
230228 else if (ttisstring(l))
231229 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
232230 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
@@ -240,7 +238,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { · 7 unmodified lines
240238 if (ttype(l) != ttype(r))
241239 return luaG_ordererror(L, l, r);
242240 else if (ttisnumber(l))
243− return luai_numle(L, nvalue(l), nvalue(r));
241+ return luai_numle(nvalue(l), nvalue(r));
244242 else if (ttisstring(l))
245243 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
246244 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
@@ -256,7 +254,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { · 9 unmodified lines
256254 lua_assert(ttype(t1) == ttype(t2));
257255 switch (ttype(t1)) {
258256 case LUA_TNIL: return 1;
259− case LUA_TNUMBER: return luai_numeq(L, nvalue(t1), nvalue(t2));
257+ case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
260258 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
261259 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
262260 case LUA_TUSERDATA: {
@@ -319,13 +317,13 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, · 56 unmodified lines
319317 (c = luaV_tonumber(rc, &tempc)) != NULL) {
320318 lua_Number nb = nvalue(b), nc = nvalue(c);
321319 switch (op) {
322− case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break;
323− case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break;
324− case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break;
325− case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break;
326− case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break;
327− case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break;
328− case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break;
320+ case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
321+ case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
322+ case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
323+ case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
324+ case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
325+ case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
326+ case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
329327 default: lua_assert(0); break;
330328 }
331329 }
@@ -358,6 +356,19 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, · 26 unmodified lines
358356 #define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }
359357
360358
359+#define arith_op(op,tm) { \
360+ TValue *rb = RKB(i); \
361+ TValue *rc = RKC(i); \
362+ if (ttisnumber(rb) && ttisnumber(rc)) { \
363+ lua_Number nb = nvalue(rb), nc = nvalue(rc); \
364+ setnvalue(ra, op(nb, nc)); \
365+ } \
366+ else \
367+ Protect(Arith(L, ra, rb, rc, tm)); \
368+ }
369+
370+
371+
361372 void luaV_execute (lua_State *L, int nexeccalls) {
362373 LClosure *cl;
363374 StkId base;
@@ -455,76 +466,34 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 91 unmodified lines
455466 continue;
456467 }
457468 case OP_ADD: {
458− TValue *rb = RKB(i);
459− TValue *rc = RKC(i);
460− if (ttisnumber(rb) && ttisnumber(rc)) {
461− lua_Number nb = nvalue(rb), nc = nvalue(rc);
462− setnvalue(ra, luai_numadd(L, nb, nc));
463− }
464− else
465− Protect(Arith(L, ra, rb, rc, TM_ADD));
469+ arith_op(luai_numadd, TM_ADD);
466470 continue;
467471 }
468472 case OP_SUB: {
469− TValue *rb = RKB(i);
470− TValue *rc = RKC(i);
471− if (ttisnumber(rb) && ttisnumber(rc)) {
472− lua_Number nb = nvalue(rb), nc = nvalue(rc);
473− setnvalue(ra, luai_numsub(L, nb, nc));
474− }
475− else
476− Protect(Arith(L, ra, rb, rc, TM_SUB));
473+ arith_op(luai_numsub, TM_SUB);
477474 continue;
478475 }
479476 case OP_MUL: {
480− TValue *rb = RKB(i);
481− TValue *rc = RKC(i);
482− if (ttisnumber(rb) && ttisnumber(rc)) {
483− lua_Number nb = nvalue(rb), nc = nvalue(rc);
484− setnvalue(ra, luai_nummul(L, nb, nc));
485− }
486− else
487− Protect(Arith(L, ra, rb, rc, TM_MUL));
477+ arith_op(luai_nummul, TM_MUL);
488478 continue;
489479 }
490480 case OP_DIV: {
491− TValue *rb = RKB(i);
492− TValue *rc = RKC(i);
493− if (ttisnumber(rb) && ttisnumber(rc)) {
494− lua_Number nb = nvalue(rb), nc = nvalue(rc);
495− setnvalue(ra, luai_numdiv(L, nb, nc));
496− }
497− else
498− Protect(Arith(L, ra, rb, rc, TM_DIV));
481+ arith_op(luai_numdiv, TM_DIV);
499482 continue;
500483 }
501484 case OP_MOD: {
502− TValue *rb = RKB(i);
503− TValue *rc = RKC(i);
504− if (ttisnumber(rb) && ttisnumber(rc)) {
505− lua_Number nb = nvalue(rb), nc = nvalue(rc);
506− setnvalue(ra, luai_nummod(L, nb, nc));
507− }
508− else
509− Protect(Arith(L, ra, rb, rc, TM_MOD));
485+ arith_op(luai_nummod, TM_MOD);
510486 continue;
511487 }
512488 case OP_POW: {
513− TValue *rb = RKB(i);
514− TValue *rc = RKC(i);
515− if (ttisnumber(rb) && ttisnumber(rc)) {
516− lua_Number nb = nvalue(rb), nc = nvalue(rc);
517− setnvalue(ra, luai_numpow(L, nb, nc));
518− }
519− else
520− Protect(Arith(L, ra, rb, rc, TM_POW));
489+ arith_op(luai_numpow, TM_POW);
521490 continue;
522491 }
523492 case OP_UNM: {
524493 TValue *rb = RB(i);
525494 if (ttisnumber(rb)) {
526495 lua_Number nb = nvalue(rb);
527− setnvalue(ra, luai_numunm(L, nb));
496+ setnvalue(ra, luai_numunm(nb));
528497 }
529498 else {
530499 Protect(Arith(L, ra, rb, rb, TM_UNM));
@@ -594,18 +563,18 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 63 unmodified lines
594563 continue;
595564 }
596565 case OP_TEST: {
597− if (l_isfalse(ra) == GETARG_C(i)) pc++;
598− else
599− dojump(L, pc, GETARG_sBx(*pc) + 1);
566+ if (l_isfalse(ra) != GETARG_C(i))
567+ dojump(L, pc, GETARG_sBx(*pc));
568+ pc++;
600569 continue;
601570 }
602571 case OP_TESTSET: {
603572 TValue *rb = RB(i);
604− if (l_isfalse(rb) == GETARG_C(i)) pc++;
605− else {
573+ if (l_isfalse(rb) != GETARG_C(i)) {
606574 setobjs2s(L, ra, rb);
607− dojump(L, pc, GETARG_sBx(*pc) + 1);
575+ dojump(L, pc, GETARG_sBx(*pc));
608576 }
577+ pc++;
609578 continue;
610579 }
611580 case OP_CALL: {
@@ -678,9 +647,9 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 66 unmodified lines
678647 }
679648 case OP_FORLOOP: {
680649 lua_Number step = nvalue(ra+2);
681− lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */
650+ lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
682651 lua_Number limit = nvalue(ra+1);
683− if (step > 0 ? luai_numle(L, idx, limit) : luai_numle(L, limit, idx)) {
652+ if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) {
684653 dojump(L, pc, GETARG_sBx(i)); /* jump back */
685654 setnvalue(ra, idx); /* update internal index... */
686655 setnvalue(ra+3, idx); /* ...and external index */
@@ -698,7 +667,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 11 unmodified lines
698667 luaG_runerror(L, LUA_QL("for") " limit must be a number");
699668 else if (!tonumber(pstep, ra+2))
700669 luaG_runerror(L, LUA_QL("for") " step must be a number");
701− setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));
670+ setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
702671 dojump(L, pc, GETARG_sBx(i));
703672 continue;
704673 }
@@ -711,12 +680,11 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 6 unmodified lines
711680 Protect(luaD_call(L, cb, GETARG_C(i)));
712681 L->top = L->ci->top;
713682 cb = RA(i) + 3; /* previous call may change the stack */
714− if (ttisnil(cb)) /* break loop? */
715− pc++; /* skip jump (break loop) */
716− else {
683+ if (!ttisnil(cb)) { /* continue loop? */
717684 setobjs2s(L, cb-1, cb); /* save control variable */
718− dojump(L, pc, GETARG_sBx(*pc) + 1); /* jump back */
685+ dojump(L, pc, GETARG_sBx(*pc)); /* jump back */
719686 }
687+ pc++;
720688 continue;
721689 }
722690 case OP_SETLIST: {
src/print.c+6−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.52 2005/06/08 14:40:44 lhf Exp $
2+** $Id: print.c,v 1.53 2005/11/11 14:03:13 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -7,6 +7,7 @@ · 1 unmodified line
77 #include <ctype.h>
88 #include <stdio.h>
99
10+#define luac_c
1011 #define LUA_CORE
1112
1213 #include "ldebug.h"
@@ -14,6 +15,8 @@ · 1 unmodified line
1415 #include "lopcodes.h"
1516 #include "lundump.h"
1617
18+#define PrintFunction luaU_print
19+
1720 #define Sizeof(x) ((int)sizeof(x))
1821 #define VOID(p) ((const void*)(p))
1922
@@ -203,7 +206,7 @@ static void PrintUpvalues(const Proto* f) · 183 unmodified lines
203206 }
204207 }
205208
206−void luaU_print(const Proto* f, int full)
209+void PrintFunction(const Proto* f, int full)
207210 {
208211 int i,n=f->sizep;
209212 PrintHeader(f);
@@ -214,5 +217,5 @@ void luaU_print(const Proto* f, int full) · 4 unmodified lines
214217 PrintLocals(f);
215218 PrintUpvalues(f);
216219 }
217− for (i=0; i<n; i++) luaU_print(f->p[i],full);
220+ for (i=0; i<n; i++) PrintFunction(f->p[i],full);
218221 }

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