History

Lua 5.1-rc1

Lua Team committed 20 years ago

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

Unified · Split

46 files
  1. COPYRIGHT +1 −1
  2. HISTORY +1 −1
  3. INSTALL +36 −21
  4. MANIFEST +107 −107
  5. Makefile +12 −22
  6. README +1 −1
  7. doc/contents.html +143 −128
  8. doc/lua.1 +17 −20
  9. doc/lua.html +24 −27
  10. doc/luac.1 +21 −13
  11. doc/luac.html +29 −21
  12. doc/manual.html +973 −849
  13. src/Makefile +42 −9
  14. src/lapi.c +13 −14
  15. src/lauxlib.c +13 −5
  16. src/lauxlib.h +2 −2
  17. src/lbaselib.c +3 −3
  18. src/lcode.c +6 −6
  19. src/ldblib.c +3 −3
  20. src/ldebug.c +4 −4
  21. src/ldo.c +8 −9
  22. src/lfunc.c +3 −3
  23. src/lgc.c +8 −9
  24. src/linit.c +2 −2
  25. src/liolib.c +4 −4
  26. src/llex.c +46 −6
  27. src/llex.h +4 −2
  28. src/llimits.h +18 −5
  29. src/lmem.c +1 −17
  30. src/loadlib.c +38 −27
  31. src/lobject.c +6 −6
  32. src/lobject.h +9 −5
  33. src/lopcodes.h +2 −2
  34. src/loslib.c +24 −24
  35. src/lparser.c +31 −49
  36. src/lstring.c +2 −2
  37. src/lstrlib.c +38 −21
  38. src/ltable.c +53 −39
  39. src/ltable.h +8 −7
  40. src/ltm.c +3 −3
  41. src/lua.c +9 −5
  42. src/lua.h +4 −4
  43. src/luaconf.h +31 −13
  44. src/lualib.h +7 −1
  45. src/lvm.c +7 −7
  46. src/print.c +5 −2
COPYRIGHT+1−1
@@ -9,7 +9,7 @@ For details and rationale, see http://www.lua.org/license.html . · 8 unmodified lines
99
1010 ===============================================================================
1111
12−Copyright (C) 1994-2005 Lua.org, PUC-Rio.
12+Copyright (C) 1994-2006 Lua.org, PUC-Rio.
1313
1414 Permission is hereby granted, free of charge, to any person obtaining a copy
1515 of this software and associated documentation files (the "Software"), to deal
HISTORY+1−1
@@ -1,4 +1,4 @@
1−This is Lua 5.1 (beta).
1+This is Lua 5.1.
22
33 * Changes from version 5.0 to 5.1
44 -------------------------------
INSTALL+36−21
@@ -1,17 +1,27 @@
1−This is Lua 5.1 (beta).
1+This is Lua 5.1.
22
3−* Installation
3+* Building Lua
44 ------------
5− Building Lua on a Unix system should be very easy: simply doing "make"
6− should work. This will build Lua in the src directory.
5+ Lua is built in the src directory, but the build process can be
6+ controlled from the top-level Makefile.
77
8− There are also special make targets for ansi, linux, bsd, mingw.
8+ Building Lua on Unix systems should be very easy. First do "make" and
9+ see if your platform is listed. If so, just do "make xxx", where xxx
10+ is your platform name. The platforms currently supported are:
11+ ansi bsd generic linux macosx mingw posix
912
10− See below for customization instructions.
13+ See below for customization instructions and for instructions on how
14+ to build with other Windows compilers.
1115
12− If you want to install Lua in an official place in your system, then
13− do "make install". The official place and the way to install files are
14− defined in Makefile. You must have the right permissions to install files.
16+ If you want to check that Lua has been built correctly, do "make test"
17+ after building Lua. Also, have a look at the example programs in test.
18+
19+* Installing Lua
20+ --------------
21+ Once you have built Lua, you may want to install it in an official
22+ place in your system. In this case, do "make install". The official
23+ place and the way to install files are defined in Makefile. You must
24+ have the right permissions to install files.
1525
1626 If you want to install Lua locally, then do "make local". This will
1727 create directories bin, include, lib, man, and install Lua there as
@@ -25,8 +35,11 @@ This is Lua 5.1 (beta). · 7 unmodified lines
2535 These are the only directories you need for development.
2636
2737 There are man pages for lua and luac, in both nroff and html, and a
28− reference manual in html in ./doc, some sample code in ./test, and some
29− useful stuff in ./etc. You don't need these directories for development.
38+ reference manual in html in doc, some sample code in test, and some
39+ useful stuff in etc. You don't need these directories for development.
40+
41+ If you want to install Lua locally, but in some other directory, do
42+ "make install INSTALL_TOP=xxx", where xxx is your chosen directory.
3043
3144 See below for instructions for Windows and other systems.
3245
@@ -44,14 +57,16 @@ This is Lua 5.1 (beta). · 11 unmodified lines
4457 to edit src/luaconf.h. The edited file will be the one installed, and
4558 it will be used by any Lua clients that you build, to ensure consistency.
4659
47− We strongly recommend that you enable dynamic loading. See src/luaconf.h
48− and also src/Makefile.
60+ We strongly recommend that you enable dynamic loading. This is done
61+ automatically for all platforms listed above that have this feature
62+ (and also Windows). See src/luaconf.h and also src/Makefile.
4963
50−* Installation on Windows and other systems
64+* Building Lua on Windows and other systems
5165 -----------------------------------------
52− The instructions for building Lua on other systems depend on the compiler
53− you use. You'll need to create projects (or whatever your compiler uses)
54− for building the library, the interpreter, and the compiler, as follows:
66+ If you're not using the usual Unix tools, then the instructions for
67+ building Lua depend on the compiler you use. You'll need to create
68+ projects (or whatever your compiler uses) for building the library,
69+ the interpreter, and the compiler, as follows:
5570
5671 library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
5772 lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
@@ -63,8 +78,11 @@ This is Lua 5.1 (beta). · 5 unmodified lines
6378
6479 compiler: library, luac.c print.c
6580
81+ If you use Visual Studio .NET, you can use etc/luavs.bat
82+ in its "Command Prompt".
83+
6684 If all you want is to build the Lua interpreter, you may put all .c files
67− in a single project, except for luac.c and print.c. Or use etc/all.c.
85+ in a single project, except for luac.c and print.c. Or just use etc/all.c.
6886
6987 To use Lua as a library in your own programs, you'll need to know how to
7088 create and use libraries with your compiler.
@@ -72,7 +90,4 @@ This is Lua 5.1 (beta). · 1 unmodified line
7290 As mentioned above, you may edit luaconf.h to select some features before
7391 building Lua.
7492
75− If you use Visual Studio .NET, you can use etc/luavs.bat
76− in its "Command Prompt".
77−
7893 (end of INSTALL)
MANIFEST+107−107
@@ -1,108 +1,108 @@
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
1+MANIFEST contents of Lua 5.1 distribution on Wed Jan 11 22:50:45 BRST 2006
2+lua-5.1
3+lua-5.1/COPYRIGHT
4+lua-5.1/doc
5+lua-5.1/doc/contents.html
6+lua-5.1/doc/logo.gif
7+lua-5.1/doc/lua.1
8+lua-5.1/doc/luac.1
9+lua-5.1/doc/luac.html
10+lua-5.1/doc/lua.css
11+lua-5.1/doc/lua.html
12+lua-5.1/doc/manual.html
13+lua-5.1/doc/readme.html
14+lua-5.1/etc
15+lua-5.1/etc/all.c
16+lua-5.1/etc/lua.hpp
17+lua-5.1/etc/lua.ico
18+lua-5.1/etc/lua.pc
19+lua-5.1/etc/luavs.bat
20+lua-5.1/etc/Makefile
21+lua-5.1/etc/min.c
22+lua-5.1/etc/noparser.c
23+lua-5.1/etc/README
24+lua-5.1/etc/strict.lua
25+lua-5.1/HISTORY
26+lua-5.1/INSTALL
27+lua-5.1/Makefile
28+lua-5.1/MANIFEST
29+lua-5.1/README
30+lua-5.1/src
31+lua-5.1/src/lapi.c
32+lua-5.1/src/lapi.h
33+lua-5.1/src/lauxlib.c
34+lua-5.1/src/lauxlib.h
35+lua-5.1/src/lbaselib.c
36+lua-5.1/src/lcode.c
37+lua-5.1/src/lcode.h
38+lua-5.1/src/ldblib.c
39+lua-5.1/src/ldebug.c
40+lua-5.1/src/ldebug.h
41+lua-5.1/src/ldo.c
42+lua-5.1/src/ldo.h
43+lua-5.1/src/ldump.c
44+lua-5.1/src/lfunc.c
45+lua-5.1/src/lfunc.h
46+lua-5.1/src/lgc.c
47+lua-5.1/src/lgc.h
48+lua-5.1/src/linit.c
49+lua-5.1/src/liolib.c
50+lua-5.1/src/llex.c
51+lua-5.1/src/llex.h
52+lua-5.1/src/llimits.h
53+lua-5.1/src/lmathlib.c
54+lua-5.1/src/lmem.c
55+lua-5.1/src/lmem.h
56+lua-5.1/src/loadlib.c
57+lua-5.1/src/lobject.c
58+lua-5.1/src/lobject.h
59+lua-5.1/src/lopcodes.c
60+lua-5.1/src/lopcodes.h
61+lua-5.1/src/loslib.c
62+lua-5.1/src/lparser.c
63+lua-5.1/src/lparser.h
64+lua-5.1/src/lstate.c
65+lua-5.1/src/lstate.h
66+lua-5.1/src/lstring.c
67+lua-5.1/src/lstring.h
68+lua-5.1/src/lstrlib.c
69+lua-5.1/src/ltable.c
70+lua-5.1/src/ltable.h
71+lua-5.1/src/ltablib.c
72+lua-5.1/src/ltm.c
73+lua-5.1/src/ltm.h
74+lua-5.1/src/lua.c
75+lua-5.1/src/luac.c
76+lua-5.1/src/luaconf.h
77+lua-5.1/src/lua.h
78+lua-5.1/src/lualib.h
79+lua-5.1/src/lundump.c
80+lua-5.1/src/lundump.h
81+lua-5.1/src/lvm.c
82+lua-5.1/src/lvm.h
83+lua-5.1/src/lzio.c
84+lua-5.1/src/lzio.h
85+lua-5.1/src/Makefile
86+lua-5.1/src/print.c
87+lua-5.1/test
88+lua-5.1/test/bisect.lua
89+lua-5.1/test/cf.lua
90+lua-5.1/test/echo.lua
91+lua-5.1/test/env.lua
92+lua-5.1/test/factorial.lua
93+lua-5.1/test/fibfor.lua
94+lua-5.1/test/fib.lua
95+lua-5.1/test/globals.lua
96+lua-5.1/test/hello.lua
97+lua-5.1/test/life.lua
98+lua-5.1/test/luac.lua
99+lua-5.1/test/printf.lua
100+lua-5.1/test/README
101+lua-5.1/test/readonly.lua
102+lua-5.1/test/sieve.lua
103+lua-5.1/test/sort.lua
104+lua-5.1/test/table.lua
105+lua-5.1/test/trace-calls.lua
106+lua-5.1/test/trace-globals.lua
107+lua-5.1/test/xd.lua
108108 END OF MANIFEST
Makefile+12−22
@@ -4,6 +4,9 @@ · 3 unmodified lines
44
55 # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
66
7+# Your platform. See PLATS for possible values.
8+PLAT= none
9+
710 # Where to install. The installation starts in the src directory, so take care
811 # if INSTALL_TOP is not an absolute path. (Man pages are installed from the
912 # doc directory.)
@@ -24,6 +27,9 @@ INSTALL_DATA= cp · 14 unmodified lines
2427
2528 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
2629
30+# Convenience platforms targets.
31+PLATS= ansi bsd generic linux macosx mingw posix
32+
2733 # What to install.
2834 TO_BIN= lua luac
2935 TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
@@ -33,7 +39,9 @@ TO_MAN= lua.1 luac.1 · 3 unmodified lines
3339 # Lua version. Currently used only for messages.
3440 V= 5.1
3541
36−all clean:
42+all: $(PLAT)
43+
44+$(PLATS) clean:
3745 cd src; $(MAKE) $@
3846
3947 test: all
@@ -49,27 +57,8 @@ install: all · 9 unmodified lines
4957 local:
5058 $(MAKE) install INSTALL_TOP=.. INSTALL_EXEC="cp -p" INSTALL_DATA="cp -p"
5159
52−# convenience targets for usual platforms
53−
54−ansi:
55− cd src; $(MAKE) MYCFLAGS=-DLUA_ANSI
56−
57−linux:
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
65−
66−bsd:
67− cd src; $(MAKE) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
68−
69−mingw:
70− cd src; $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
71− "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \
72− "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
60+none:
61+ @echo "Please choose a platform: $(PLATS)"
7362
7463 # echo config parameters
7564 echo:
@@ -80,6 +69,7 @@ echo: · 4 unmodified lines
8069 @echo ""
8170 @echo "These are the parameters currently set in Makefile to install Lua $V:"
8271 @echo ""
72+ @echo "PLAT = $(PLAT)"
8373 @echo "INSTALL_TOP = $(INSTALL_TOP)"
8474 @echo "INSTALL_BIN = $(INSTALL_BIN)"
8575 @echo "INSTALL_INC = $(INSTALL_INC)"
README+1−1
@@ -1,4 +1,4 @@
1−This is Lua 5.1 (beta).
1+This is Lua 5.1.
22 See HISTORY for a summary of changes since the last released version.
33
44 * What is Lua?
doc/contents.html+143−128
@@ -14,12 +14,14 @@ Lua 5.1 Reference Manual · 13 unmodified lines
1414
1515 <SMALL>
1616 <A HREF="http://www.lua.org/copyright.html">Copyright</A>
17−&copy; 2005 Lua.org, PUC-Rio. All rights reserved.
17+&copy; 2006 Lua.org, PUC-Rio. All rights reserved.
1818 </SMALL>
1919 <HR>
2020
21+<H2>Contents</H2>
2122 <UL>
22−<LI><A HREF="#words">Word index</A>
23+<LI><A HREF="#quick">Quick index</A>
24+<P>
2325 <LI><A HREF="manual.html">Top</A>
2426 <LI><A HREF="manual.html#1">1 - Introduction</A>
2527 <LI><A HREF="manual.html#2">2 - The Language</A>
@@ -82,20 +84,23 @@ Lua 5.1 Reference Manual · 56 unmodified lines
8284 <UL>
8385 <LI><A HREF="manual.html#5.1">5.1 - Basic Functions</A>
8486 <LI><A HREF="manual.html#5.2">5.2 - Coroutine Manipulation</A>
85−<LI><A HREF="manual.html#5.3">5.3 - Packages and Modules</A>
87+<LI><A HREF="manual.html#5.3">5.3 - Modules</A>
8688 <LI><A HREF="manual.html#5.4">5.4 - String Manipulation</A>
8789 <LI><A HREF="manual.html#5.5">5.5 - Table Manipulation</A>
8890 <LI><A HREF="manual.html#5.6">5.6 - Mathematical Functions</A>
8991 <LI><A HREF="manual.html#5.7">5.7 - Input and Output Facilities</A>
9092 <LI><A HREF="manual.html#5.8">5.8 - Operating System Facilities</A>
91−<LI><A HREF="manual.html#5.9">5.9 - The Reflexive Debug Interface</A>
93+<LI><A HREF="manual.html#5.9">5.9 - The Debug Library</A>
9294 </UL>
9395 <LI><A HREF="manual.html#6">6 - Lua Stand-alone</A>
9496 <LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>
9597 </UL>
9698
97−<H3><A NAME="words">Word index</A></H3>
98−
99+<H2><A NAME="quick">Quick index</A></H2>
100+<TABLE>
101+<TR VALIGN="top">
102+<TD WIDTH="35%">
103+<H3><A NAME="functions">Functions</A></H3>
99104 <A HREF="manual.html#pdf-_G">_G</A><BR>
100105 <A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
101106 <A HREF="manual.html#pdf-assert">assert</A><BR>
@@ -146,52 +151,83 @@ Lua 5.1 Reference Manual · 44 unmodified lines
146151 <A HREF="manual.html#pdf-load">load</A><BR>
147152 <A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
148153 <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>
154+<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
155+<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
156+<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
157+<A HREF="manual.html#pdf-math.atan">math.atan</A><BR>
158+<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR>
159+<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR>
160+<A HREF="manual.html#pdf-math.cos">math.cos</A><BR>
161+<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR>
162+<A HREF="manual.html#pdf-math.def">math.def</A><BR>
163+<A HREF="manual.html#pdf-math.exp">math.exp</A><BR>
164+<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>
165+<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>
166+<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
167+<A HREF="manual.html#pdf-math.log">math.log</A><BR>
168+<A HREF="manual.html#pdf-math.log10">math.log10</A><BR>
169+<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>
170+<A HREF="manual.html#pdf-math.sin">math.sin</A><BR>
171+<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR>
172+<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>
173+<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>
174+<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
175+<A HREF="manual.html#pdf-module">module</A><BR>
176+<A HREF="manual.html#pdf-next">next</A><BR>
177+<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
178+<A HREF="manual.html#pdf-os.date">os.date</A><BR>
179+<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
180+<A HREF="manual.html#pdf-os.execute">os.execute</A><BR>
181+<A HREF="manual.html#pdf-os.exit">os.exit</A><BR>
182+<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR>
183+<A HREF="manual.html#pdf-os.remove">os.remove</A><BR>
184+<A HREF="manual.html#pdf-os.rename">os.rename</A><BR>
185+<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR>
186+<A HREF="manual.html#pdf-os.time">os.time</A><BR>
187+<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>
188+<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
189+<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
190+<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>
191+<A HREF="manual.html#pdf-package.path">package.path</A><BR>
192+<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
193+<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>
194+<A HREF="manual.html#pdf-pairs">pairs</A><BR>
195+<A HREF="manual.html#pdf-pcall">pcall</A><BR>
196+<A HREF="manual.html#pdf-print">print</A><BR>
197+<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
198+<A HREF="manual.html#pdf-rawget">rawget</A><BR>
199+<A HREF="manual.html#pdf-rawset">rawset</A><BR>
200+<A HREF="manual.html#pdf-require">require</A><BR>
201+<A HREF="manual.html#pdf-select">select</A><BR>
202+<A HREF="manual.html#pdf-setfenv">setfenv</A><BR>
203+<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>
204+<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
205+<A HREF="manual.html#pdf-string.char">string.char</A><BR>
206+<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
207+<A HREF="manual.html#pdf-string.find">string.find</A><BR>
208+<A HREF="manual.html#pdf-string.format">string.format</A><BR>
209+<A HREF="manual.html#pdf-string.gmatch">string.gmatch</A><BR>
210+<A HREF="manual.html#pdf-string.gsub">string.gsub</A><BR>
211+<A HREF="manual.html#pdf-string.len">string.len</A><BR>
212+<A HREF="manual.html#pdf-string.lower">string.lower</A><BR>
213+<A HREF="manual.html#pdf-string.match">string.match</A><BR>
214+<A HREF="manual.html#pdf-string.rep">string.rep</A><BR>
215+<A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR>
216+<A HREF="manual.html#pdf-string.sub">string.sub</A><BR>
217+<A HREF="manual.html#pdf-string.upper">string.upper</A><BR>
218+<A HREF="manual.html#pdf-table.concat">table.concat</A><BR>
219+<A HREF="manual.html#pdf-table.insert">table.insert</A><BR>
220+<A HREF="manual.html#pdf-table.maxn">table.maxn</A><BR>
221+<A HREF="manual.html#pdf-table.remove">table.remove</A><BR>
222+<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
223+<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
224+<A HREF="manual.html#pdf-tostring">tostring</A><BR>
225+<A HREF="manual.html#pdf-type">type</A><BR>
226+<A HREF="manual.html#pdf-unpack">unpack</A><BR>
227+<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
228+</TD>
229+<TD>
230+<H3>API</H3>
195231 <A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
196232 <A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
197233 <A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
@@ -256,6 +292,7 @@ Lua 5.1 Reference Manual · 58 unmodified lines
256292 <A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR>
257293 <A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR>
258294 <A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR>
295+<A HREF="manual.html#lua_pushthread">lua_pushthread</A><BR>
259296 <A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR>
260297 <A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR>
261298 <A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR>
@@ -275,6 +312,7 @@ Lua 5.1 Reference Manual · 13 unmodified lines
275312 <A HREF="manual.html#lua_settable">lua_settable</A><BR>
276313 <A HREF="manual.html#lua_settop">lua_settop</A><BR>
277314 <A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>
315+<A HREF="manual.html#lua_status">lua_status</A><BR>
278316 <A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>
279317 <A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>
280318 <A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>
@@ -285,89 +323,66 @@ Lua 5.1 Reference Manual · 4 unmodified lines
285323 <A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
286324 <A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
287325 <A HREF="manual.html#lua_type">lua_type</A><BR>
326+<A HREF="manual.html#lua_typename">lua_typename</A><BR>
288327 <A HREF="manual.html#lua_xmove">lua_xmove</A><BR>
289328 <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>
329+</TD>
330+<TD>
331+<H3>Auxiliary library</H3>
332+<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
333+<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
334+<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>
335+<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR>
336+<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR>
337+<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR>
338+<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR>
339+<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR>
340+<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR>
341+<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR>
342+<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>
343+<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>
344+<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
345+<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>
346+<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>
347+<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>
348+<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>
349+<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR>
350+<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR>
351+<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
352+<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
353+<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
354+<A HREF="manual.html#luaL_error">luaL_error</A><BR>
355+<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
356+<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
357+<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>
358+<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
359+<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
360+<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
361+<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
362+<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
363+<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
364+<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
365+<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>
366+<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
367+<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
368+<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
369+<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
370+<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
371+<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
372+<A HREF="manual.html#luaL_register">luaL_register</A><BR>
373+<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
374+<A HREF="manual.html#luaL_typerror">luaL_typerror</A><BR>
375+<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
376+<A HREF="manual.html#luaL_where">luaL_where</A><BR>
377+</TD>
378+</TR>
379+</TABLE>
365380 <P>
366381
367382 <HR>
368383 <SMALL>
369384 Last update:
370−Tue Nov 1 15:40:46 BRST 2005
385+Tue Jan 10 10:10:22 BRST 2006
371386 </SMALL>
372387
373388 </BODY>
doc/lua.1+17−20
@@ -1,5 +1,5 @@
1−.\" $Id: lua.man,v 1.9 2005/09/02 16:29:34 lhf Exp $
2−.TH LUA 1 "$Date: 2005/09/02 16:29:34 $"
1+.\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $
2+.TH LUA 1 "$Date: 2006/01/06 16:03:34 $"
33 .SH NAME
44 lua \- Lua interpreter
55 .SH SYNOPSIS
@@ -45,9 +45,9 @@ The arguments in · 39 unmodified lines
4545 .B arg
4646 start at 0,
4747 which contains the string
48−.RI ` script '.
48+.RI ' script '.
4949 The index of the last argument is stored in
50−.BR "arg.n" .
50+.BR arg.n .
5151 The arguments given in the command line before
5252 .IR script ,
5353 including the name of the interpreter,
@@ -63,17 +63,17 @@ if it is defined. · 9 unmodified lines
6363 If the value of
6464 .B LUA_INIT
6565 is of the form
66−.RI `@ filename ',
66+.RI '@ filename ',
6767 then
6868 .I filename
6969 is executed.
7070 Otherwise, the string is assumed to be a Lua statement and is executed.
7171 .LP
7272 Options start with
73−.B \-
73+.B '\-'
7474 and are described below.
7575 You can use
76−.B "\--"
76+.B "'\--'"
7777 to signal the end of options.
7878 .LP
7979 If no arguments are given,
@@ -96,11 +96,11 @@ a syntax error is found. · 16 unmodified lines
9696 So, one way to interrupt the reading of an incomplete statement is
9797 to force a syntax error:
9898 adding a
99−.B `;'
99+.B ';'
100100 in the middle of a statement is a sure way of forcing a syntax error
101101 (except inside multiline strings and comments; these must be closed explicitly).
102102 If a line starts with
103−.BR `=' ,
103+.BR '=' ,
104104 then
105105 .B lua
106106 displays the values of all the expressions in the remainder of the
@@ -115,11 +115,10 @@ So, · 8 unmodified lines
115115 to change the prompts,
116116 set the corresponding variable to a string of your choice.
117117 You can do that after calling the interpreter
118−or on the command line with
119−.BR "_PROMPT" "=\'lua: \'" ,
120−for example.
121−(Note the need for quotes, because the string contains a space.)
122−The default prompts are ``> '' and ``>> ''.
118+or on the command line
119+(but in this case you have to be careful with quotes
120+if the prompt string contains a space; otherwise you may confuse the shell.)
121+The default prompts are "> " and ">> ".
123122 .SH OPTIONS
124123 .TP
125124 .B \-
@@ -141,14 +140,12 @@ enter interactive mode after · 15 unmodified lines
141140 .I script
142141 is executed.
143142 .TP
144−.BI \-l " module"
143+.BI \-l " name"
145144 call
146−.BI require( module )
145+.BI require(' name ')
147146 before executing
148−.IR script.
149−Typically used to load libraries
150−(hence the letter
151−.IR l ).
147+.IR script .
148+Typically used to load libraries.
152149 .TP
153150 .B \-v
154151 show version information.
doc/lua.html+24−27
@@ -1,4 +1,4 @@
1−<!-- $Id: lua.man,v 1.9 2005/09/02 16:29:34 lhf Exp $ -->
1+<!-- $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -->
22 <HTML>
33 <HEAD>
44 <TITLE>LUA man page</TITLE>
@@ -7,9 +7,9 @@ · 2 unmodified lines
77
88 <BODY BGCOLOR="#FFFFFF">
99
10−<H1>NAME</H1>
10+<H2>NAME</H2>
1111 lua - Lua interpreter
12−<H1>SYNOPSIS</H1>
12+<H2>SYNOPSIS</H2>
1313 <B>lua</B>
1414 [
1515 <I>options</I>
@@ -20,7 +20,7 @@ lua - Lua interpreter · 4 unmodified lines
2020 <I>args</I>
2121 ]
2222 ]
23−<H1>DESCRIPTION</H1>
23+<H2>DESCRIPTION</H2>
2424 <B>lua</B>
2525 is the stand-alone Lua interpreter.
2626 It loads and executes Lua programs,
@@ -52,9 +52,9 @@ The arguments in · 25 unmodified lines
5252 <B>arg</B>
5353 start at 0,
5454 which contains the string
55−`<I>script</I>'.
55+'<I>script</I>'.
5656 The index of the last argument is stored in
57−<B>"arg.n"</B>.
57+<B>arg.n</B>.
5858 The arguments given in the command line before
5959 <I>script</I>,
6060 including the name of the interpreter,
@@ -70,17 +70,17 @@ if it is defined. · 9 unmodified lines
7070 If the value of
7171 <B>LUA_INIT</B>
7272 is of the form
73−`@<I>filename</I>',
73+'@<I>filename</I>',
7474 then
7575 <I>filename</I>
7676 is executed.
7777 Otherwise, the string is assumed to be a Lua statement and is executed.
7878 <P>
7979 Options start with
80−<B>-</B>
80+<B>'-'</B>
8181 and are described below.
8282 You can use
83−<B>"--"</B>
83+<B>'--'</B>
8484 to signal the end of options.
8585 <P>
8686 If no arguments are given,
@@ -103,11 +103,11 @@ a syntax error is found. · 16 unmodified lines
103103 So, one way to interrupt the reading of an incomplete statement is
104104 to force a syntax error:
105105 adding a
106−<B>`;' </B>
106+<B>';'</B>
107107 in the middle of a statement is a sure way of forcing a syntax error
108108 (except inside multiline strings and comments; these must be closed explicitly).
109109 If a line starts with
110−<B>`='</B>,
110+<B>'='</B>,
111111 then
112112 <B>lua</B>
113113 displays the values of all the expressions in the remainder of the
@@ -122,12 +122,11 @@ So, · 8 unmodified lines
122122 to change the prompts,
123123 set the corresponding variable to a string of your choice.
124124 You can do that after calling the interpreter
125−or on the command line with
126−<B>"_PROMPT" "=\'lua: \'"</B>,
127−for example.
128−(Note the need for quotes, because the string contains a space.)
129−The default prompts are ``&gt; '' and ``&gt;&gt; ''.
130−<H1>OPTIONS</H1>
125+or on the command line
126+(but in this case you have to be careful with quotes
127+if the prompt string contains a space; otherwise you may confuse the shell.)
128+The default prompts are "&gt; " and "&gt;&gt; ".
129+<H2>OPTIONS</H2>
131130 <P>
132131 <B>-</B>
133132 load and execute the standard input as a file,
@@ -135,7 +134,7 @@ that is, · 1 unmodified line
135134 not interactively,
136135 even when the standard input is a terminal.
137136 <P>
138−<B>-e "</B><I>stat"</I>
137+<B>-e </B><I>stat</I>
139138 execute statement
140139 <I>stat</I>.
141140 You need to quote
@@ -148,24 +147,22 @@ enter interactive mode after · 6 unmodified lines
148147 <I>script</I>
149148 is executed.
150149 <P>
151−<B>-l "</B><I>module"</I>
150+<B>-l </B><I>name</I>
152151 call
153−<B>require( module</B><I>)</I>
152+<B>require(' name</B><I>')</I>
154153 before executing
155−<I></I>script.
156−Typically used to load libraries
157−(hence the letter
158−<I>l</I>).
154+<I>script</I>.
155+Typically used to load libraries.
159156 <P>
160157 <B>-v</B>
161158 show version information.
162−<H1>SEE ALSO</H1>
159+<H2>SEE ALSO</H2>
163160 <B>luac</B>(1)
164161 <BR>
165162 <A HREF="http://www.lua.org/">http://www.lua.org/</A>
166−<H1>DIAGNOSTICS</H1>
163+<H2>DIAGNOSTICS</H2>
167164 Error messages should be self explanatory.
168−<H1>AUTHORS</H1>
165+<H2>AUTHORS</H2>
169166 R. Ierusalimschy,
170167 L. H. de Figueiredo,
171168 and
doc/luac.1+21−13
@@ -1,5 +1,5 @@
1−.\" $Id: luac.man,v 1.26 2005/09/02 16:29:34 lhf Exp $
2−.TH LUAC 1 "$Date: 2005/09/02 16:29:34 $"
1+.\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $
2+.TH LUAC 1 "$Date: 2006/01/06 16:03:34 $"
33 .SH NAME
44 luac \- Lua compiler
55 .SH SYNOPSIS
@@ -17,7 +17,7 @@ into binary files that can be latter loaded and executed. · 11 unmodified lines
1717 .LP
1818 The main advantages of precompiling chunks are:
1919 faster loading,
20−protecting source code from user changes,
20+protecting source code from accidental user changes,
2121 and
2222 off-line syntax checking.
2323 .LP
@@ -26,6 +26,13 @@ because in Lua chunks are always compiled into bytecodes before being executed. · 2 unmodified lines
2626 .B luac
2727 simply allows those bytecodes to be saved in a file for later execution.
2828 .LP
29+Pre-compiled chunks are not necessarily smaller than the corresponding source.
30+The main goal in pre-compiling is faster loading.
31+.LP
32+The binary files created by
33+.B luac
34+are portable only among architectures with the same word size and byte order.
35+.LP
2936 .B luac
3037 produces a single output file containing the bytecodes
3138 for all source files given.
@@ -36,10 +43,6 @@ but you can change this with the · 4 unmodified lines
3643 .B \-o
3744 option.
3845 .LP
39−The binary files created by
40−.B luac
41−are portable only among architectures with the same word size and byte order.
42−.LP
4346 In the command line,
4447 you can mix
4548 text files containing Lua source and
@@ -49,14 +52,14 @@ even from different (but compatible) platforms, · 3 unmodified lines
4952 into a single precompiled chunk.
5053 .LP
5154 You can use
52−.B "\-"
55+.B "'\-'"
5356 to indicate the standard input as a source file
5457 and
55−.B "\--"
58+.B "'\--'"
5659 to signal the end of options
5760 (that is,
5861 all remaining arguments will be treated as files even if they start with
59−.BR "\-" ).
62+.BR "'\-'" ).
6063 .LP
6164 The internal format of the binary files produced by
6265 .B luac
@@ -81,6 +84,10 @@ output to · 18 unmodified lines
8184 .IR file ,
8285 instead of the default
8386 .BR luac.out .
87+(You can use
88+.B "'\-'"
89+for standard output,
90+but not on platforms that open standard output in text mode.)
8491 The output file may be a source file because
8592 all files are loaded before the output file is written.
8693 Be careful not to overwrite precious files.
@@ -105,9 +112,10 @@ No messages are displayed if the file passes the integrity test. · 18 unmodified lines
105112 .B \-s
106113 strip debug information before writing the output file.
107114 This saves some space in very large chunks,
108−but if errors occur when running these chunks,
109−then the error messages may not contain the full information they usually do
110−(line numbers and names of locals are lost).
115+but if errors occur when running a stripped chunk,
116+then the error messages may not contain the full information they usually do.
117+For instance,
118+line numbers and names of local variables are lost.
111119 .TP
112120 .B \-v
113121 show version information.
doc/luac.html+29−21
@@ -1,4 +1,4 @@
1−<!-- $Id: luac.man,v 1.26 2005/09/02 16:29:34 lhf Exp $ -->
1+<!-- $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ -->
22 <HTML>
33 <HEAD>
44 <TITLE>LUAC man page</TITLE>
@@ -7,16 +7,16 @@ · 2 unmodified lines
77
88 <BODY BGCOLOR="#FFFFFF">
99
10−<H1>NAME</H1>
10+<H2>NAME</H2>
1111 luac - Lua compiler
12−<H1>SYNOPSIS</H1>
12+<H2>SYNOPSIS</H2>
1313 <B>luac</B>
1414 [
1515 <I>options</I>
1616 ] [
1717 <I>filenames</I>
1818 ]
19−<H1>DESCRIPTION</H1>
19+<H2>DESCRIPTION</H2>
2020 <B>luac</B>
2121 is the Lua compiler.
2222 It translates programs written in the Lua programming language
@@ -24,7 +24,7 @@ into binary files that can be latter loaded and executed. · 1 unmodified line
2424 <P>
2525 The main advantages of precompiling chunks are:
2626 faster loading,
27−protecting source code from user changes,
27+protecting source code from accidental user changes,
2828 and
2929 off-line syntax checking.
3030 <P>
@@ -33,6 +33,13 @@ because in Lua chunks are always compiled into bytecodes before being executed. · 2 unmodified lines
3333 <B>luac</B>
3434 simply allows those bytecodes to be saved in a file for later execution.
3535 <P>
36+Pre-compiled chunks are not necessarily smaller than the corresponding source.
37+The main goal in pre-compiling is faster loading.
38+<P>
39+The binary files created by
40+<B>luac</B>
41+are portable only among architectures with the same word size and byte order.
42+<P>
3643 <B>luac</B>
3744 produces a single output file containing the bytecodes
3845 for all source files given.
@@ -43,10 +50,6 @@ but you can change this with the · 4 unmodified lines
4350 <B>-o</B>
4451 option.
4552 <P>
46−The binary files created by
47−<B>luac</B>
48−are portable only among architectures with the same word size and byte order.
49−<P>
5053 In the command line,
5154 you can mix
5255 text files containing Lua source and
@@ -56,14 +59,14 @@ even from different (but compatible) platforms, · 3 unmodified lines
5659 into a single precompiled chunk.
5760 <P>
5861 You can use
59−<B>"-"</B>
62+<B>'-'</B>
6063 to indicate the standard input as a source file
6164 and
62−<B>"--"</B>
65+<B>'--'</B>
6366 to signal the end of options
6467 (that is,
6568 all remaining arguments will be treated as files even if they start with
66−<B>"-"</B>).
69+<B>'-'</B>).
6770 <P>
6871 The internal format of the binary files produced by
6972 <B>luac</B>
@@ -71,7 +74,7 @@ is likely to change when a new version of Lua is released. · 1 unmodified line
7174 So,
7275 save the source files of all Lua programs that you precompile.
7376 <P>
74−<H1>OPTIONS</H1>
77+<H2>OPTIONS</H2>
7578 Options must be separate.
7679 <P>
7780 <B>-l</B>
@@ -83,11 +86,15 @@ loads · 5 unmodified lines
8386 <B>luac.out</B>
8487 and lists its contents.
8588 <P>
86−<B>-o "</B><I>file"</I>
89+<B>-o </B><I>file</I>
8790 output to
8891 <I>file</I>,
8992 instead of the default
9093 <B>luac.out</B>.
94+(You can use
95+<B>'-'</B>
96+for standard output,
97+but not on platforms that open standard output in text mode.)
9198 The output file may be a source file because
9299 all files are loaded before the output file is written.
93100 Be careful not to overwrite precious files.
@@ -112,23 +119,24 @@ No messages are displayed if the file passes the integrity test. · 18 unmodified lines
112119 <B>-s</B>
113120 strip debug information before writing the output file.
114121 This saves some space in very large chunks,
115−but if errors occur when running these chunks,
116−then the error messages may not contain the full information they usually do
117−(line numbers and names of locals are lost).
122+but if errors occur when running a stripped chunk,
123+then the error messages may not contain the full information they usually do.
124+For instance,
125+line numbers and names of local variables are lost.
118126 <P>
119127 <B>-v</B>
120128 show version information.
121−<H1>FILES</H1>
129+<H2>FILES</H2>
122130 <P>
123131 <B>luac.out</B>
124132 default output file
125−<H1>SEE ALSO</H1>
133+<H2>SEE ALSO</H2>
126134 <B>lua</B>(1)
127135 <BR>
128136 <A HREF="http://www.lua.org/">http://www.lua.org/</A>
129−<H1>DIAGNOSTICS</H1>
137+<H2>DIAGNOSTICS</H2>
130138 Error messages should be self explanatory.
131−<H1>AUTHORS</H1>
139+<H2>AUTHORS</H2>
132140 L. H. de Figueiredo,
133141 R. Ierusalimschy and
134142 W. Celes
doc/manual.html+973−849
@@ -8,9 +8,9 @@ · 7 unmodified lines
88
99 <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
@@ -18,16 +18,15 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line
1818 <p>
1919 <small>
2020 <a href="http://www.lua.org/copyright.html">Copyright</a>
21−&copy; 2005 Lua.org, PUC-Rio. All rights reserved.
21+&copy; 2006 Lua.org, PUC-Rio. All rights reserved.
2222 </small>
23−<hr/>
23+<hr />
2424
2525 <p>
2626 <p>
2727 <!-- ====================================================================== -->
2828
2929
30−
3130 <a name="1"></a><h1>1 - Introduction</h1>
3231
3332 <p>Lua is an extension programming language designed to support
@@ -36,7 +35,7 @@ facilities. · 2 unmodified lines
3635 It also offers good support for object-oriented programming,
3736 functional programming, and data-driven programming.
3837 Lua is intended to be used as a powerful, light-weight
39−configuration language for any program that needs one.
38+scripting language for any program that needs one.
4039 Lua is implemented as a library, written in <em>clean</em> C
4140 (that is, in the common subset of ANSI C and C++).
4241
@@ -49,42 +48,21 @@ and can register C functions to be called by Lua code. · 6 unmodified lines
4948 Through the use of C functions, Lua can be augmented to cope with
5049 a wide range of different domains,
5150 thus creating customized programming languages sharing a syntactical framework.
52−
53−<p>The Lua distribution includes a stand-alone embedding program,
54−<code>lua</code>, that uses the Lua library to offer a complete Lua interpreter.
51+The Lua distribution includes a sample host program called <code>lua</code>,
52+which uses the Lua library to offer a complete, stand-alone Lua interpreter.
5553
5654 <p>Lua is free software,
5755 and is provided as usual with no guarantees,
58−as stated in its copyright notice.
56+as stated in its license.
5957 The implementation described in this manual is available
6058 at Lua's official web site, <code>www.lua.org</code>.
6159
6260 <p>Like any other reference manual,
6361 this document is dry in places.
6462 For a discussion of the decisions behind the design of Lua,
65−see the papers below,
66−which are available at Lua's web site.
67−<ul>
68−<li>
69−R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
70−Lua---an extensible extension language.
71−<em>Software: Practice &#038; Experience</em> <b>26</b>:6 (1996) 635--652.
72−<li>
73−L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
74−The design and implementation of a language for extending applications.
75−<em>Proceedings of XXI Brazilian Seminar on Software and Hardware</em>
76−(1994) 273--283.
77−<li>
78−L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
79−Lua: an extensible embedded language.
80−<em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26--33.
81−<li>
82−R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
83−The evolution of an extension language: a history of Lua,
84−<em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14--B-28.
85−</ul>
86−
87−<p>Lua means "moon" in Portuguese and is pronounced LOO-ah.
63+see the technical papers available at Lua's web site.
64+For a detailed introduction to programming in Lua,
65+see Roberto's book, <em>Programming in Lua</em>.
8866
8967 <p>
9068 <a name="language"></a><a name="2"></a><h1>2 - The Language</h1>
@@ -96,7 +74,7 @@ which tokens are valid, · 5 unmodified lines
9674 how they can be combined,
9775 and what their combinations mean.
9876
99−<p>The language constructs will be explained using the usual extended BNF,
77+<p>The language constructs will be explained using the usual extended BNF notation,
10078 in which
10179 {<em>a</em>} means 0 or more <em>a</em>'s, and
10280 [<em>a</em>] means an optional <em>a</em>.
@@ -104,16 +82,20 @@ Non-terminals are shown in <em>italics</em>, · 1 unmodified line
10482 keywords are shown in <b>bold</b>,
10583 and other terminal symbols are shown in <code>typewriter</code> font,
10684 enclosed in single quotes.
85+The complete syntax of Lua can be found at the end of this manual.
10786
10887 <p><a name="lexical"></a><a name="2.1"></a><h2>2.1 - Lexical Conventions</h2>
10988
110−<p><em>Names</em> in Lua can be any string of letters,
89+<p><em>Names</em>
90+(also called <em>identifiers</em>)
91+in Lua can be any string of letters,
11192 digits, and underscores,
11293 not beginning with a digit.
11394 This coincides with the definition of names in most languages.
11495 (The definition of letter depends on the current locale:
11596 any character considered alphabetic by the current locale
11697 can be used in an identifier.)
98+Identifiers are used to name variables and table fields.
11799
118100 <p>The following <em>keywords</em> are reserved
119101 and cannot be used as names:
@@ -130,7 +112,7 @@ and cannot be used as names: · 10 unmodified lines
130112 are two different, valid names.
131113 As a convention, names starting with an underscore followed by
132114 uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>)
133−are reserved for internal variables used by Lua.
115+are reserved for internal global variables used by Lua.
134116
135117 <p>The following strings denote other tokens:
136118 <pre>
@@ -152,8 +134,8 @@ and can contain the following C-like escape sequences: · 15 unmodified lines
152134 <li><b><code>\t</code></b> --- horizontal tab
153135 <li><b><code>\v</code></b> --- vertical tab
154136 <li><b><code>\\</code></b> --- backslash
155−<li><b><code>\"</code></b> --- quotation mark
156−<li><b><code>\'</code></b> --- apostrophe
137+<li><b><code>\"</code></b> --- quotation mark (double quote)
138+<li><b><code>\'</code></b> --- apostrophe (single quote)
157139 </ul>
158140 Moreover, a `<code>\</code><em>newline</em>&acute;
159141 (that is, a backslash followed by a real newline)
@@ -161,38 +143,51 @@ results in a newline in the string. · 1 unmodified line
161143 A character in a string may also be specified by its numerical value
162144 using the escape sequence `<code>\</code><em>ddd</em>&acute;,
163145 where <em>ddd</em> is a sequence of up to three decimal digits.
146+(Note that if a numerical escape is to be followed by a digit,
147+it must be expressed using exactly three digits.)
164148 Strings in Lua may contain any 8-bit value, including embedded zeros,
165149 which can be specified as `<code>\0</code>&acute;.
166150
151+<p>To put a double (single) quote, a newline, a backslash,
152+or an embedded zero
153+inside a literal string enclosed by double (single) quotes
154+you must use an escape sequence.
155+Any other character may be directly inserted into the literal.
156+(Some control characters may cause problems for the file system,
157+but Lua has no problem with them.)
158+
167159 <p>Literal strings can also be defined using a long format
168−enclosed by <em>l-brackets</em> (long brackets).
169−We define an <em>opening l-bracket of level <em>n</em></em> as an opening
160+enclosed by <em>long brackets</em>.
161+We define an <em>opening long bracket of level <em>n</em></em> as an opening
170162 square bracket followed by <em>n</em> equal signs followed by another
171163 opening square bracket.
172−So, an opening l-bracket of level 0 is written as <code>[[</code>,
173−an opening l-bracket of level 1 is written as <code>[=[</code>,
164+So, an opening long bracket of level 0 is written as <code>[[</code>,
165+an opening long bracket of level 1 is written as <code>[=[</code>,
174166 and so on.
175−A <em>closing l-bracket</em> is defined similarly;
176−for instance, a closing l-bracket of level 4 is written as <code>]====]</code>.
177−A long string starts with an opening l-bracket of any level and
178−ends at the first closing l-bracket of the same level.
167+A <em>closing long bracket</em> is defined similarly;
168+for instance, a closing long bracket of level 4 is written as <code>]====]</code>.
169+A long string starts with an opening long bracket of any level and
170+ends at the first closing long bracket of the same level.
179171 Literals in this bracketed form may run for several lines,
180172 do not interpret any escape sequences,
181−and ignore l-brackets of any other level.
173+and ignore long brackets of any other level.
174+They may contain anything except a closing bracket of the proper level
175+or embedded zeros.
182176
183177 <p>For convenience,
184−when the opening l-bracket is immediately followed by a newline,
178+when the opening long bracket is immediately followed by a newline,
185179 the newline is not included in the string.
186180 As an example, in a system using ASCII
187181 (in which `<code>a</code>&acute; is coded as 97,
188182 newline is coded as 10, and `<code>1</code>&acute; is coded as 49),
189183 the four literals below denote the same string:
190184 <pre>
191− (1) "alo\n123\""
192− (2) '\97lo\10\04923"'
193− (3) [[alo
185+ (1) 'alo\n123"'
186+ (2) "alo\n123\""
187+ (3) '\97lo\10\04923"'
188+ (4) [[alo
194189 123"]]
195− (4) [==[
190+ (5) [==[
196191 alo
197192 123"]==]
198193 </pre>
@@ -204,13 +199,14 @@ Examples of valid numerical constants are · 5 unmodified lines
204199 3 3.0 3.1416 314.16e-2 0.31416E1
205200 </pre>
206201
207−<p><em>Comments</em> start anywhere outside a string with a
208−double hyphen (<code>--</code>).
209−If the text immediately after <code>--</code> is not an opening l-bracket,
202+<p><em>Comments</em> start with a double hyphen (<code>--</code>)
203+anywhere outside a string.
204+If the text immediately after <code>--</code> is not an opening long bracket,
210205 the comment is a <em>short comment</em>,
211206 which runs until the end of the line.
212207 Otherwise, it is a <em>long comment</em>,
213−which runs until the corresponding closing l-bracket.
208+which runs until the corresponding closing long bracket.
209+Long comments are frequently used to disable code temporarily.
214210
215211 <p><a name="TypesSec"></a><a name="2.2"></a><h2>2.2 - Values and Types</h2>
216212
@@ -220,15 +216,19 @@ variables do not have types; only values do. · 3 unmodified lines
220216 There are no type definitions in the language.
221217 All values carry their own type.
222218
219+<p>All values in Lua are <em>first-class values</em>.
220+That means that all values can be stored in variables,
221+passed as arguments to other functions, and returned as results.
222+
223223 <p>There are eight basic types in Lua:
224224 <em>nil</em>, <em>boolean</em>, <em>number</em>,
225225 <em>string</em>, <em>function</em>, <em>userdata</em>,
226226 <em>thread</em>, and <em>table</em>.
227227 <em>Nil</em> is the type of the value <b>nil</b>,
228228 whose main property is to be different from any other value;
229−usually it represents the absence of a useful value.
229+it usually represents the absence of a useful value.
230230 <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;
231+Both <b>nil</b> and <b>false</b> make a condition false;
232232 any other value makes it true.
233233 <em>Number</em> represents real (double-precision floating-point) numbers.
234234 (It is easy to build Lua interpreters that use other
@@ -239,12 +239,9 @@ See file <code>luaconf.h</code>.) · 4 unmodified lines
239239
240240 Lua is 8-bit clean:
241241 Strings may contain any 8-bit character,
242−including embedded zeros (<code>'\0'</code>) (see <a href="#lexical">2.1</a>).
242+including embedded zeros (`<code>\0</code>&acute;) (see <a href="#lexical">2.1</a>).
243243
244−<p>Functions are <em>first-class values</em> in Lua.
245−That means that functions can be stored in variables,
246−passed as arguments to other functions, and returned as results.
247−Lua can call (and manipulate) functions written in Lua and
244+<p>Lua can call (and manipulate) functions written in Lua and
248245 functions written in C
249246 (see <a href="#functioncall">2.5.8</a>).
250247
@@ -262,12 +259,14 @@ This guarantees the integrity of data owned by the host program. · 11 unmodified lines
262259
263260 <p>The type <em>thread</em> represents independent threads of execution
264261 and it is used to implement coroutines (see <a href="#coroutine">2.11</a>).
262+Do not confuse Lua threads with operating-system threads.
263+Lua supports coroutines on all systems,
264+even those that do not support threads.
265265
266266 <p>The type <em>table</em> implements associative arrays,
267267 that is, arrays that can be indexed not only with numbers,
268268 but with any value (except <b>nil</b>).
269−Moreover,
270−tables can be <em>heterogeneous</em>,
269+Tables can be <em>heterogeneous</em>;
271270 that is, they can contain values of all types (except <b>nil</b>).
272271 Tables are the sole data structuring mechanism in Lua;
273272 they may be used to represent ordinary arrays,
@@ -281,11 +280,11 @@ There are several convenient ways to create tables in Lua · 7 unmodified lines
281280 <p>Like indices,
282281 the value of a table field can be of any type (except <b>nil</b>).
283282 In particular,
284−because functions are first class values,
283+because functions are first-class values,
285284 table fields may contain functions.
286285 Thus tables may also carry <em>methods</em> (see <a href="#func-def">2.5.9</a>).
287286
288−<p>Tables, functions, and userdata values are <em>objects</em>:
287+<p>Strings, tables, functions, and userdata values are <em>objects</em>:
289288 variables do not actually <em>contain</em> these values,
290289 only <em>references</em> to them.
291290 Assignment, parameter passing, and function returns
@@ -300,7 +299,7 @@ of a given value. · 8 unmodified lines
300299 <p>Lua provides automatic conversion between
301300 string and number values at run time.
302301 Any arithmetic operation applied to a string tries to convert
303−that string to a number, following the usual rules.
302+that string to a number, following the usual conversion rules.
304303 Conversely, whenever a number is used where a string is expected,
305304 the number is converted to a string, in a reasonable format.
306305 For complete control of how numbers are converted to strings,
@@ -315,12 +314,14 @@ There are three kinds of variables in Lua: · 8 unmodified lines
315314 global variables, local variables, and table fields.
316315
317316 <p>A single name can denote a global variable or a local variable
318−(or a formal parameter of a function,
319−which is a particular form of local variable):
317+(or a function formal parameter,
318+which is a particular kind of local variable):
320319 <pre>
321320 var ::= Name
322321 </pre>
323−Variables are assumed to be global unless explicitly declared local
322+Name denotes identifiers, as defined in (see <a href="#lexical">2.1</a>).
323+
324+<p>Variables are assumed to be global unless explicitly declared local
324325 (see <a href="#localvar">2.4.7</a>).
325326 Local variables are <em>lexically scoped</em>:
326327 Local variables can be freely accessed by functions
@@ -334,12 +335,12 @@ defined inside their scope (see <a href="#visibility">2.6</a>). · 7 unmodified lines
334335 </pre>
335336 The first expression (<em>prefixexp</em>) should result in a table value;
336337 the second expression (<em>exp</em>)
337−identifies a specific entry inside that table.
338+identifies a specific entry in that table.
338339 The expression denoting the table to be indexed has a restricted syntax;
339340 see <a href="#expressions">2.5</a> for details.
340341
341−<p>The syntax <code>var.NAME</code> is just syntactic sugar for
342−<code>var["NAME"]</code>:
342+<p>The syntax <code>var.Name</code> is just syntactic sugar for
343+<code>var["Name"]</code> and is used to denote table fields:
343344 <pre>
344345 var ::= prefixexp `<b>.</b>&acute; Name
345346 </pre>
@@ -361,8 +362,10 @@ so that all global variables in that function · 15 unmodified lines
361362 will refer to that environment table.
362363 When a function is created,
363364 it inherits the environment from the function that created it.
364−To replace or get the environment table of a Lua function,
365−you call <a href="#pdf-setfenv"><code>setfenv</code></a> or <a href="#pdf-getfenv"><code>getfenv</code></a>.
365+To get the environment table of a Lua function,
366+you call <a href="#pdf-setfenv"><code>setfenv</code></a>.
367+To replace it,
368+you call <a href="#pdf-setfenv"><code>setfenv</code></a>.
366369 (You can only manipulate the environment of C functions
367370 through the debug library; (see <a href="#libdebug">5.9</a>).)
368371
@@ -384,7 +387,7 @@ We use them here only for explanatory purposes.) · 15 unmodified lines
384387 <p>Lua supports an almost conventional set of statements,
385388 similar to those in Pascal or C.
386389 This set includes
387−assignment, control structures, procedure calls,
390+assignment, control structures, function calls,
388391 table constructors, and variable declarations.
389392
390393 <p><a name="chunks"></a><a name="2.4.1"></a><h3>2.4.1 - Chunks</h3>
@@ -396,6 +399,7 @@ Each statement can be optionally followed by a semicolon: · 5 unmodified lines
396399 <pre>
397400 chunk ::= {stat [`<b>;</b>&acute;]}
398401 </pre>
402+There are no empty statements and thus `<code>;;</code>&acute; is not legal.
399403
400404 <p>Lua handles a chunk as the body of an anonymous function
401405 with a variable number of arguments
@@ -404,7 +408,7 @@ As such, chunks can define local variables, · 2 unmodified lines
404408 receive arguments, and return values.
405409
406410 <p>A chunk may be stored in a file or in a string inside the host program.
407−When a chunk is executed, first it is pre-compiled into opcodes for
411+When a chunk is executed, first it is pre-compiled into instructions for
408412 a virtual machine,
409413 and then the compiled code is executed
410414 by an interpreter for the virtual machine.
@@ -417,7 +421,7 @@ Lua automatically detects the file type and acts accordingly. · 6 unmodified lines
417421
418422 <p><a name="2.4.2"></a><h3>2.4.2 - Blocks</h3>
419423 A block is a list of statements;
420−syntactically, a block is equal to a chunk:
424+syntactically, a block is the same as a chunk:
421425 <pre>
422426 block ::= chunk
423427 </pre>
@@ -455,7 +459,7 @@ the excess values are thrown away. · 31 unmodified lines
455459 If there are fewer values than needed,
456460 the list is extended with as many <b>nil</b>'s as needed.
457461 If the list of expressions ends with a function call,
458−then all values returned by that function call enter in the list of values,
462+then all values returned by that call enter in the list of values,
459463 before the adjustment
460464 (except when the call is enclosed in parentheses; see <a href="#expressions">2.5</a>).
461465
@@ -509,7 +513,7 @@ familiar syntax: · 47 unmodified lines
509513 </pre>
510514 Lua also has a <b>for</b> statement, in two flavors (see <a href="#for">2.4.5</a>).
511515
512−<p>The condition expression <em>exp</em> of a
516+<p>The condition expression of a
513517 control structure may return any value.
514518 Both <b>false</b> and <b>nil</b> are considered false.
515519 All values different from <b>nil</b> and <b>false</b> are considered true
@@ -518,11 +522,11 @@ All values different from <b>nil</b> and <b>false</b> are considered true · 2 unmodified lines
518522 <p>In the <b>repeat</b>--<b>until</b> loop,
519523 the inner block does not end at the <b>until</b> keyword,
520524 but only after the condition.
521−That means the condition can refer to local variables
522−declared inside the loop.
525+So, the condition can refer to local variables
526+declared inside the loop block.
523527
524528 <p>The <b>return</b> statement is used to return values
525−from a function or from a chunk.
529+from a function or a chunk (which is just a function).
526530
527531 Functions and chunks may return more than one value,
528532 so the syntax for the <b>return</b> statement is
@@ -530,7 +534,7 @@ so the syntax for the <b>return</b> statement is · 1 unmodified line
530534 stat ::= <b>return</b> [explist1]
531535 </pre>
532536
533−<p>The <b>break</b> statement can be used to terminate the execution of a
537+<p>The <b>break</b> statement is used to terminate the execution of a
534538 <b>while</b>, <b>repeat</b>, or <b>for</b> loop,
535539 skipping to the next statement after the loop:
536540
@@ -539,7 +543,7 @@ skipping to the next statement after the loop: · 2 unmodified lines
539543 </pre>
540544 A <b>break</b> ends the innermost enclosing loop.
541545
542−<p>For syntactic reasons, <b>return</b> and <b>break</b>
546+<p>The <b>return</b> and <b>break</b>
543547 statements can only be written as the <em>last</em> statement of a block.
544548 If it is really necessary to <b>return</b> or <b>break</b> in the
545549 middle of a block,
@@ -599,11 +603,12 @@ then assign it to another variable before breaking or exiting the loop. · 53 unmodified lines
599603
600604 <p>The generic <b>for</b> statement works over functions,
601605 called <em>iterators</em>.
602−For each iteration, it calls its iterator function to produce a new value,
603−stopping when the new value is <b>nil</b>.
606+On each iteration, the iterator function is called to produce a new value,
607+stopping when this new value is <b>nil</b>.
604608 The generic <b>for</b> loop has the following syntax:
605609 <pre>
606− stat ::= <b>for</b> Name {`<b>,</b>&acute; Name} <b>in</b> explist1 <b>do</b> block <b>end</b>
610+ stat ::= <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b>
611+ namelist ::= Name {`<b>,</b>&acute; Name}
607612 </pre>
608613 A <b>for</b> statement like
609614 <pre>
@@ -649,14 +654,13 @@ Local variables may be declared anywhere inside a block. · 39 unmodified lines
649654 The declaration may include an initial assignment:
650655 <pre>
651656 stat ::= <b>local</b> namelist [`<b>=</b>&acute; explist1]
652− namelist ::= Name {`<b>,</b>&acute; Name}
653657 </pre>
654658 If present, an initial assignment has the same semantics
655659 of a multiple assignment (see <a href="#assignment">2.4.3</a>).
656660 Otherwise, all variables are initialized with <b>nil</b>.
657661
658662 <p>A chunk is also a block (see <a href="#chunks">2.4.1</a>),
659−so local variables can be declared in a chunk outside any explicit block.
663+and so local variables can be declared in a chunk outside any explicit block.
660664 The scope of such local variables extends until the end of the chunk.
661665
662666 <p>The visibility rules for local variables are explained in <a href="#visibility">2.6</a>.
@@ -669,7 +673,7 @@ The basic expressions in Lua are the following: · 6 unmodified lines
669673 exp ::= prefixexp
670674 exp ::= <b>nil</b> | <b>false</b> | <b>true</b>
671675 exp ::= Number
672− exp ::= Literal
676+ exp ::= String
673677 exp ::= function
674678 exp ::= tableconstructor
675679 exp ::= `<b>...</b>&acute;
@@ -684,7 +688,7 @@ function definitions are explained in <a href="#func-def">2.5.9</a>; · 8 unmodified lines
684688 function calls are explained in <a href="#functioncall">2.5.8</a>;
685689 table constructors are explained in <a href="#tableconstructor">2.5.7</a>.
686690 Vararg expressions,
687−denoted by three dots (...), can only be used inside
691+denoted by three dots (`<code>...</code>&acute;), can only be used inside
688692 vararg functions;
689693 they are explained in <a href="#func-def">2.5.9</a>.
690694
@@ -738,18 +742,18 @@ or <b>nil</b> if <code>f</code> does not return any values.) · 47 unmodified lines
738742 Lua supports the usual arithmetic operators:
739743 the binary <code>+</code> (addition),
740744 <code>-</code> (subtraction), <code>*</code> (multiplication),
741−<code>/</code> (division), <code>%</code> (modulus), and <code>^</code> (exponentiation);
745+<code>/</code> (division), <code>%</code> (modulo), and <code>^</code> (exponentiation);
742746 and unary <code>-</code> (negation).
743747 If the operands are numbers, or strings that can be converted to
744748 numbers (see <a href="#coercion">2.2.1</a>),
745749 then all operations have the usual meaning.
746750 Exponentiation works for any exponent.
747−For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>.
751+For instance, <code>x^(-0.5)</code> computes the inverse of the square root of <code>x</code>.
748752 Modulus is defined as
749753 <pre>
750− a % b == a - math.floor(a/b)*b
754+ a % b == a - math.floor(a/b)*b
751755 </pre>
752−That is, it is the remaining of a division that rounds
756+That is, it is the remainder of a division that rounds
753757 the quotient towards minus infinity.
754758
755759 <p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3>
@@ -766,11 +770,12 @@ Numbers and strings are compared in the usual way. · 10 unmodified lines
766770 Objects (tables, userdata, threads, and functions)
767771 are compared by <em>reference</em>:
768772 Two objects are considered equal only if they are the <em>same</em> object.
769−Every time you create a new object (a table, userdata, or function),
773+Every time you create a new object
774+(a table, userdata, thread, or function),
770775 this new object is different from any previously existing object.
771776
772777 <p>You can change the way that Lua compares tables and userdata
773−using the "eq" metamethod (see <a href="#metatable">2.8</a>).
778+by using the "eq" metamethod (see <a href="#metatable">2.8</a>).
774779
775780 <p>The conversion rules of <a href="#coercion">2.2.1</a>
776781 <em>do not</em> apply to equality comparisons.
@@ -799,27 +804,29 @@ all logical operators consider both <b>false</b> and <b>nil</b> as false · 22 unmodified lines
799804 and anything else as true.
800805
801806
802−<p>The operator <b>not</b> always returns <b>false</b> or <b>true</b>.
803−
804−<p>The conjunction operator <b>and</b> returns its first argument
807+<p>The negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.
808+The conjunction operator <b>and</b> returns its first argument
805809 if this value is <b>false</b> or <b>nil</b>;
806810 otherwise, <b>and</b> returns its second argument.
807811 The disjunction operator <b>or</b> returns its first argument
808812 if this value is different from <b>nil</b> and <b>false</b>;
809813 otherwise, <b>or</b> returns its second argument.
810−Both <b>and</b> and <b>or</b> use short-cut evaluation,
814+Both <b>and</b> and <b>or</b> use short-cut evaluation;
811815 that is,
812816 the second operand is evaluated only if necessary.
813−For example,
817+Here are some examples:
814818 <pre>
815− 10 or error() -> 10
816− nil or "a" -> "a"
817− nil and 10 -> nil
818− false and error() -> false
819− false and nil -> false
820− false or nil -> nil
821− 10 and 20 -> 20
819+ 10 or 20 --> 10
820+ 10 or error() --> 10
821+ nil or "a" --> "a"
822+ nil and 10 --> nil
823+ false and error() --> false
824+ false and nil --> false
825+ false or nil --> nil
826+ 10 and 20 --> 20
822827 </pre>
828+(Here and in the sequel,
829+`<code>--></code>&acute; indicates the result of the preceding expression.)
823830
824831 <p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3>
825832 The string concatenation operator in Lua is
@@ -830,21 +837,22 @@ Otherwise, the "concat" metamethod is called (see <a href="#metatable">2.8</a>). · 4 unmodified lines
830837
831838 <p><a name="len-op"></a><a name="2.5.5"></a><h3>2.5.5 - The Length Operator</h3>
832839
833−<p>The length operator is denoted by the prefix <code>#</code>.
840+<p>The length operator is denoted by the unary operator <code>#</code>.
834841 The length of a string is its number of bytes
835842 (that is, the usual meaning of string length when each
836843 character is one byte).
837−The length of a table <code>t</code> is defined to be any
844+
845+<p>The length of a table <code>t</code> is defined to be any
838846 integer index <code>n</code>
839847 such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;
840848 moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> may be zero.
841−
842−<p>For a regular array, with non-nil values from 1 to a given <code>n</code>,
849+For a regular array, with non-nil values from 1 to a given <code>n</code>,
843850 its length is exactly that <code>n</code>,
844851 the index of its last value.
845852 If the array has "holes"
846853 (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
854+then <code>#t</code> may be any of the indices that
855+directly precedes a <b>nil</b> value
848856 (that is, it may consider any such <b>nil</b> value as the end of
849857 the array).
850858
@@ -861,7 +869,8 @@ from lower to higher priority: · 10 unmodified lines
861869 not # - (unary)
862870 ^
863871 </pre>
864−You can use parentheses to change the precedences of an expression.
872+As usual,
873+you can use parentheses to change the precedences of an expression.
865874 The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)
866875 operators are right associative.
867876 All other binary operators are left associative.
@@ -889,20 +898,20 @@ starting with 1. · 21 unmodified lines
889898 Fields in the other formats do not affect this counting.
890899 For example,
891900 <pre>
892− a = {[f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45}
901+ a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
893902 </pre>
894903 is equivalent to
895904 <pre>
896905 do
897− local temp = {}
898− temp[f(1)] = g
899− temp[1] = "x" -- 1st exp
900− temp[2] = "y" -- 2nd exp
901− temp.x = 1 -- temp["x"] = 1
902− temp[3] = f(x) -- 3rd exp
903− temp[30] = 23
904− temp[4] = 45 -- 4th exp
905− a = temp
906+ local t = {}
907+ t[f(1)] = g
908+ t[1] = "x" -- 1st exp
909+ t[2] = "y" -- 2nd exp
910+ t.x = 1 -- t["x"] = 1
911+ t[3] = f(x) -- 3rd exp
912+ t[30] = 23
913+ t[4] = 45 -- 4th exp
914+ a = t
906915 end
907916 </pre>
908917
@@ -927,7 +936,7 @@ first <em>prefixexp</em> and <em>args</em> are evaluated. · 18 unmodified lines
927936 If the value of <em>prefixexp</em> has type <em>function</em>,
928937 then that function is called
929938 with the given arguments.
930−Otherwise, its "call" metamethod is called,
939+Otherwise, the <em>prefixexp</em> "call" metamethod is called,
931940 having as first parameter the value of <em>prefixexp</em>,
932941 followed by the original call arguments
933942 (see <a href="#metatable">2.8</a>).
@@ -945,16 +954,14 @@ except that <code>v</code> is evaluated only once. · 11 unmodified lines
945954 <pre>
946955 args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute;
947956 args ::= tableconstructor
948− args ::= Literal
957+ args ::= String
949958 </pre>
950959 All argument expressions are evaluated before the call.
951−A call of the form <code>f{...}</code> is syntactic sugar for
952−<code>f({...})</code>, that is,
953−the argument list is a single new table.
960+A call of the form <code>f{...}</code> is syntactic sugar for <code>f({...})</code>;
961+that is, the argument list is a single new table.
954962 A call of the form <code>f'...'</code>
955−(or <code>f"..."</code> or <code>f[[...]]</code>) is syntactic sugar for
956−<code>f('...')</code>, that is,
957−the argument list is a single literal string.
963+(or <code>f"..."</code> or <code>f[[...]]</code>) is syntactic sugar for <code>f('...')</code>;
964+that is, the argument list is a single literal string.
958965
959966 <p>As an exception to the free-format syntax of Lua,
960967 you cannot put a line break before the `<code>(</code>&acute; in a function call.
@@ -964,7 +971,7 @@ If you write · 3 unmodified lines
964971 a = f
965972 (g).x(a)
966973 </pre>
967−Lua would read that as <code>a = f(g).x(a)</code>.
974+Lua would see that as a single statement, <code>a = f(g).x(a)</code>.
968975 So, if you want two statements, you must add a semi-colon between them.
969976 If you actually want to call <code>f</code>,
970977 you must remove the line break before <code>(g)</code>.
@@ -981,15 +988,15 @@ However, a tail call erases any debug information about the · 10 unmodified lines
981988 calling function.
982989 Note that a tail call only happens with a particular syntax,
983990 where the <b>return</b> has one single function call as argument;
984−this syntax makes the calling function returns exactly
991+this syntax makes the calling function return exactly
985992 the returns of the called function.
986−So, all the following examples are not tail calls:
993+So, none of the following examples are tail calls:
987994 <pre>
988− return (f(x)) -- results adjusted to 1
989− return 2 * f(x)
990− return x, f(x) -- additional results
991− f(x); return -- results discarded
992− return x or f(x) -- results adjusted to 1
995+ return (f(x)) -- results adjusted to 1
996+ return 2 * f(x)
997+ return x, f(x) -- additional results
998+ f(x); return -- results discarded
999+ return x or f(x) -- results adjusted to 1
9931000 </pre>
9941001
9951002 <p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3>
@@ -1030,6 +1037,12 @@ translates to · 34 unmodified lines
10301037 <pre>
10311038 local f; f = function () ... end
10321039 </pre>
1040+<em>not</em> this:
1041+<pre>
1042+ local f = function () ... end
1043+</pre>
1044+(This only makes a difference when the body of the function
1045+contains references to <code>f</code>.)
10331046
10341047 <p>A function definition is an executable expression,
10351048 whose value has type <em>function</em>.
@@ -1084,10 +1097,10 @@ to the vararg expression: · 48 unmodified lines
10841097 f(r(), 10) a=1, b=10
10851098 f(r()) a=1, b=2
10861099
1087− g(3) a=3, b=nil, ... -> (nothing)
1088− g(3, 4) a=3, b=4, ... -> (nothing)
1089− g(3, 4, 5, 8) a=3, b=4, ... -> 5 8
1090− g(5, r()) a=5, b=1, ... -> 2 3
1100+ g(3) a=3, b=nil, ... --> (nothing)
1101+ g(3, 4) a=3, b=4, ... --> (nothing)
1102+ g(3, 4, 5, 8) a=3, b=4, ... --> 5 8
1103+ g(5, r()) a=5, b=1, ... --> 2 3
10911104 </pre>
10921105
10931106 <p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>).
@@ -1114,36 +1127,29 @@ is syntactic sugar for · 20 unmodified lines
11141127 The scope of variables begins at the first statement <em>after</em>
11151128 their declaration and lasts until the end of the innermost block that
11161129 includes the declaration.
1117−For instance:
1118−<pre>
1119− x = 10 -- global variable
1120− do -- new block
1121− local x = x -- new `x', with value 10
1122− print(x) --> 10
1123− x = x+1
1124− do -- another block
1125− local x = x+1 -- another `x'
1126− print(x) --> 12
1127− end
1128− print(x) --> 11
1129− end
1130− print(x) --> 10 (the global one)
1130+Consider the following example:
1131+<pre>
1132+ x = 10 -- global variable
1133+ do -- new block
1134+ local x = x -- new `x', with value 10
1135+ print(x) --> 10
1136+ x = x+1
1137+ do -- another block
1138+ local x = x+1 -- another `x'
1139+ print(x) --> 12
1140+ end
1141+ print(x) --> 11
1142+ end
1143+ print(x) --> 10 (the global one)
11311144 </pre>
1132−Notice that, in a declaration like <code>local x = x</code>,
1145+
1146+<p>Notice that, in a declaration like <code>local x = x</code>,
11331147 the new <code>x</code> being declared is not in scope yet,
11341148 and so the second <code>x</code> refers to the outside variable.
11351149
11361150 <p>Because of the lexical scoping rules,
11371151 local variables can be freely accessed by functions
11381152 defined inside their scope.
1139−For instance:
1140−<pre>
1141− local counter = 0
1142− function inc (x)
1143− counter = counter + x
1144− return counter
1145− end
1146−</pre>
11471153 A local variable used by an inner function is called
11481154 an <em>upvalue</em>, or <em>external local variable</em>,
11491155 inside the inner function.
@@ -1152,12 +1158,12 @@ inside the inner function. · 2 unmodified lines
11521158 defines new local variables.
11531159 Consider the following example:
11541160 <pre>
1155− a = {}
1156− local x = 20
1157− for i=1,10 do
1158− local y = 0
1159− a[i] = function () y=y+1; return x+y end
1160− end
1161+ a = {}
1162+ local x = 20
1163+ for i=1,10 do
1164+ local y = 0
1165+ a[i] = function () y=y+1; return x+y end
1166+ end
11611167 </pre>
11621168 The loop creates ten closures
11631169 (that is, ten instances of the anonymous function).
@@ -1166,13 +1172,13 @@ while all of them share the same <code>x</code>. · 2 unmodified lines
11661172
11671173 <p><a name="error"></a><a name="2.7"></a><h2>2.7 - Error Handling</h2>
11681174
1169−<p>Because Lua is an extension language,
1175+<p>Because Lua is an embedded extension language,
11701176 all Lua actions start from C code in the host program
11711177 calling a function from the Lua library (see <a href="#lua_pcall"></a>).
11721178 Whenever an error occurs during Lua compilation or execution,
11731179 control returns to C,
11741180 which can take appropriate measures
1175−(such as print an error message).
1181+(such as printing an error message).
11761182
11771183 <p>Lua code can explicitly generate an error by calling the
11781184 <a href="#pdf-error"><code>error</code></a> function.
@@ -1215,7 +1221,7 @@ So, there is one single metatable for all numbers, · 36 unmodified lines
12151221 and for all strings, etc.
12161222
12171223 <p>A metatable may control how an object behaves in arithmetic operations,
1218−order comparisons, concatenation, and indexing.
1224+order comparisons, concatenation, length operation, and indexing.
12191225 A metatable can also define a function to be called when a userdata
12201226 is garbage collected.
12211227 For each of those operations Lua associates a specific key
@@ -1228,7 +1234,7 @@ controls how Lua will perform the operation. · 6 unmodified lines
12281234 <p>Metatables control the operations listed next.
12291235 Each operation is identified by its corresponding name.
12301236 The key for each operation is a string with its name prefixed by
1231−two underscores;
1237+two underscores, `<code>__</code>&acute;;
12321238 for instance, the key for operation "add" is the
12331239 string <code>"__add"</code>.
12341240 The semantics of these operations is better explained by a Lua function
@@ -1243,11 +1249,11 @@ are described in <a href="#predefined">5.1</a>. · 8 unmodified lines
12431249 In particular, to retrieve the metamethod of a given object,
12441250 we use the expression
12451251 <pre>
1246− metatable(obj)[event]
1252+ metatable(obj)[event]
12471253 </pre>
12481254 This should be read as
12491255 <pre>
1250− rawget(metatable(obj) or {}, event)
1256+ rawget(getmetatable(obj) or {}, event)
12511257 </pre>
12521258 That is, the access to a metamethod does not invoke other metamethods,
12531259 and the access to objects with no metatables does not fail
@@ -1522,11 +1528,11 @@ called when Lua calls a value. · 268 unmodified lines
15221528 <p>Besides metatables,
15231529 objects of types thread, function, and userdata
15241530 have another table associated with them,
1525−called <em>environment</em>.
1531+called their <em>environment</em>.
15261532 Like metatables, environments are regular tables and
15271533 multiple objects can share the same environment.
15281534
1529−<p>Environments associated with userdata has no meaning for Lua.
1535+<p>Environments associated with userdata have no meaning for Lua.
15301536 It is only a feature for programmers to associate a table to
15311537 a userdata.
15321538
@@ -1557,10 +1563,10 @@ use the C API. · 24 unmodified lines
15571563
15581564 <p><a name="GC"></a><a name="2.10"></a><h2>2.10 - Garbage Collection</h2>
15591565
1560−<p>Lua does automatic memory management.
1566+<p>Lua performs automatic memory management.
15611567 That means that
15621568 you do not have to worry about allocating memory for new objects
1563−and freeing it when the objects are no longer needed.
1569+not about freeing it when the objects are no longer needed.
15641570 Lua manages memory automatically by running
15651571 a <em>garbage collector</em> from time to time
15661572 to collect all <em>dead objects</em>
@@ -1568,9 +1574,12 @@ to collect all <em>dead objects</em> · 1 unmodified line
15681574 All objects in Lua are subject to automatic management:
15691575 tables, userdata, functions, threads, and strings.
15701576
1571−<p>Lua 5.1 implements an incremental mark-and-sweep collector.
1572−It uses two numbers to control its garbage-collection cycles.
1573−One number, the <em>garbage-collector pause</em>,
1577+<p>Lua implements an incremental mark-and-sweep collector.
1578+It uses two numbers to control its garbage-collection cycles:
1579+the <em>garbage-collector pause</em> and
1580+the <em>garbage-collector multiplier</em>.
1581+
1582+<p>The garbage-collector pause
15741583 controls how long the collector waits before starting a new cycle.
15751584 Larger values make the collector less aggressive.
15761585 Values smaller than 1 mean the collector will not wait to
@@ -1578,7 +1587,7 @@ start a new cycle. · 1 unmodified line
15781587 A value of 2 means that the collector waits more or less to double
15791588 the total memory in use before starting a new cycle.
15801589
1581−<p>The other number, the <em>garbage-collector multiplier</em>,
1590+<p>The garbage-collector multiplier
15821591 controls the relative speed of the collector relative to
15831592 memory allocation.
15841593 Larger values make the collector more aggressive but also increases
@@ -1605,7 +1614,7 @@ with external resource management · 20 unmodified lines
16051614 (such as closing files, network or database connections,
16061615 or freeing your own memory).
16071616
1608−<p>Free userdata with a field <code>__gc</code> in their metatables are not
1617+<p>Garbage userdata with a field <code>__gc</code> in their metatables are not
16091618 collected immediately by the garbage collector.
16101619 Instead, Lua puts them in a list.
16111620 After the collection,
@@ -1676,8 +1685,8 @@ passing as its first argument · 64 unmodified lines
16761685 the thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
16771686 the coroutine starts its execution,
16781687 at the first line of its main function.
1679−Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are given as
1680−parameters for the coroutine main function.
1688+Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are passed on
1689+to the coroutine main function.
16811690 After the coroutine starts running,
16821691 it runs until it terminates or <em>yields</em>.
16831692
@@ -1703,43 +1712,39 @@ it continues its execution from the point where it yielded, · 19 unmodified lines
17031712 with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra
17041713 arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
17051714
1706−<p>The <code>coroutine.wrap</code> function creates a coroutine
1707−like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1715+<p>The <code>coroutine.wrap</code> function creates a coroutine,
1716+just like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
17081717 but instead of returning the coroutine itself,
17091718 it returns a function that, when called, resumes the coroutine.
17101719 Any arguments passed to that function
1711−go as extra arguments to resume.
1712−The function returns all the values returned by resume,
1720+go as extra arguments to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1721+<code>coroutine.wrap</code> returns all the values returned by <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
17131722 except the first one (the boolean error code).
17141723 Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1715−this function does not catch errors;
1724+<code>coroutine.wrap</code> does not catch errors;
17161725 any error is propagated to the caller.
17171726
17181727 <p>As an example,
17191728 consider the next code:
17201729 <pre>
1721−function foo1 (a)
1730+function foo (a)
17221731 print("foo", a)
17231732 return coroutine.yield(2*a)
17241733 end
17251734
17261735 co = coroutine.create(function (a,b)
17271736 print("co-body", a, b)
1728− local r = foo1(a+1)
1737+ local r = foo(a+1)
17291738 print("co-body", r)
17301739 local r, s = coroutine.yield(a+b, a-b)
17311740 print("co-body", r, s)
17321741 return b, "end"
17331742 end)
17341743
1735−a, b = coroutine.resume(co, 1, 10)
1736−print("main", a, b)
1737−a, b, c = coroutine.resume(co, "r")
1738−print("main", a, b, c)
1739−a, b, c = coroutine.resume(co, "x", "y")
1740−print("main", a, b, c)
1741−a, b = coroutine.resume(co, "x", "y")
1742−print("main", a, b)
1744+print("main", coroutine.resume(co, 1, 10))
1745+print("main", coroutine.resume(co, "r"))
1746+print("main", coroutine.resume(co, "x", "y"))
1747+print("main", coroutine.resume(co, "x", "y"))
17431748 </pre>
17441749 When you run it, it produces the following output:
17451750 <pre>
@@ -1767,10 +1772,10 @@ are declared in the header file <code>lua.h</code>. · 21 unmodified lines
17671772 any facility in the API may be provided as a macro instead.
17681773 All such macros use each of its arguments exactly once
17691774 (except for the first argument, which is always a Lua state),
1770−and so do not generate hidden side-effects.
1775+and so do not generate any hidden side-effects.
17711776
1772−<p>Like in most C libraries,
1773−the Lua API functions do not check their arguments.
1777+<p>As in most C libraries,
1778+the Lua API functions do not check their arguments for validity or consistency.
17741779 However, you can change this behavior by compiling Lua
17751780 with a proper definition for the macro <code>luai_apicheck</code>,
17761781 in file <code>luaconf.h</code>.
@@ -1784,7 +1789,7 @@ Each element in this stack represents a Lua value · 7 unmodified lines
17841789 <p>Whenever Lua calls C, the called function gets a new stack,
17851790 which is independent of previous stacks and of stacks of
17861791 C functions that are still active.
1787−That stack initially contains any arguments to the C function,
1792+That stack initially contains any arguments to the C function
17881793 and it is where the C function pushes its results
17891794 to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
17901795
@@ -1794,7 +1799,7 @@ Instead, they can refer to any element in the stack · 3 unmodified lines
17941799 by using an <em>index</em>:
17951800 A positive index represents an <em>absolute</em> stack position
17961801 (starting at 1);
1797−a negative index represents an <em>offset</em> from the top of the stack.
1802+a negative index represents an <em>offset</em> relative to the top of the stack.
17981803 More specifically, if the stack has <em>n</em> elements,
17991804 then index 1 represents the first element
18001805 (that is, the element that was pushed onto the stack first)
@@ -1811,6 +1816,8 @@ if it lies between 1 and the stack top · 10 unmodified lines
18111816 <p><a name="3.2"></a><h2>3.2 - Stack Size</h2>
18121817
18131818 <p>When you interact with Lua API,
1819+you are responsible for ensuring consistency.
1820+In particular,
18141821 <em>you are responsible for controlling stack overflow</em>.
18151822 You can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a>
18161823 to grow the stack size.
@@ -1828,7 +1835,7 @@ Such indices are called <em>acceptable indices</em>. · 11 unmodified lines
18281835 More formally, we define an <em>acceptable index</em>
18291836 as follows:
18301837 <pre>
1831− (index &#060; 0 &#038;&#038; abs(index) &#060;= top) || (index > 0 &#038;&#038; index &#060;= stackspace)
1838+ (index &#060; 0 &#038;&#038; abs(index) &#060;= top) || (index > 0 &#038;&#038; index &#060;= stackspace)
18321839 </pre>
18331840 Note that 0 is never an acceptable index.
18341841
@@ -1837,8 +1844,8 @@ Note that 0 is never an acceptable index. · 2 unmodified lines
18371844 <p>Unless otherwise noted,
18381845 any function that accepts valid indices can also be called with
18391846 <em>pseudo-indices</em>,
1840−which represent some Lua values that are accessible to the C code
1841−but are not in the stack.
1847+which represent some Lua values that are accessible to C code
1848+but which are not in the stack.
18421849 Pseudo-indices are used to access the thread environment,
18431850 the function environment,
18441851 the registry,
@@ -1861,11 +1868,12 @@ For instance, to access the value of a global variable, do · 16 unmodified lines
18611868 <p>When a C function is created,
18621869 it is possible to associate some values with it,
18631870 thus creating a <em>C closure</em>;
1864−these values are then accessible to the function whenever it is called
1871+these values are called <em>upvalues</em> and are
1872+accessible to the function whenever it is called
18651873 (see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>).
18661874
18671875 <p>Whenever a C function is called,
1868−its associated values are located at specific pseudo-indices.
1876+its upvalues are located at specific pseudo-indices.
18691877 Those pseudo-indices are produced by the macro
18701878 <code>lua_upvalueindex</code>.
18711879 The first value associated with a function is at position
@@ -1877,13 +1885,14 @@ produces an acceptable (but invalid) index. · 5 unmodified lines
18771885
18781886 <p><a name="registry"></a><a name="3.5"></a><h2>3.5 - Registry</h2>
18791887
1880−<p>Lua provides a registry,
1888+<p>Lua provides a <em>registry</em>,
18811889 a pre-defined table that can be used by any C code to
18821890 store whatever Lua value it needs to store.
18831891 This table is always located at pseudo-index
18841892 <code>LUA_REGISTRYINDEX</code>.
18851893 Any C library can store data into this table,
1886−as long as it chooses keys different from other libraries.
1894+but it should take care to choose keys different from those used
1895+by other libraries, to avoid collisions.
18871896 Typically, you should use as key a string containing your library name
18881897 or a light userdata with the address of a C object in your code.
18891898
@@ -1894,9 +1903,13 @@ and therefore should not be used by other purposes. · 4 unmodified lines
18941903 <p><a name="3.6"></a><h2>3.6 - Error Handling in C</h2>
18951904
18961905 <p>Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
1906+(You can also choose to use exceptions if you use C++;
1907+See file <code>luaconf.h</code>.)
18971908 When Lua faces any error
1898−(such as memory allocation errors, type errors, syntax errors)
1899−it <em>raises</em> an error, that is, it does a long jump.
1909+(such as memory allocation errors, type errors, syntax errors,
1910+and runtime errors)
1911+it <em>raises</em> an error;
1912+that is, it does a long jump.
19001913 A <em>protected environment</em> uses <code>setjmp</code>
19011914 to set a recover point;
19021915 any error jumps to the most recent active recover point.
@@ -1909,7 +1922,7 @@ so they never raise an error: · 6 unmodified lines
19091922 <a href="#lua_newstate"><code>lua_newstate</code></a>, <a href="#lua_close"><code>lua_close</code></a>, <a href="#lua_load"><code>lua_load</code></a>,
19101923 <a href="#lua_pcall"><code>lua_pcall</code></a>, and <a href="#lua_cpcall"><code>lua_cpcall</code></a>.
19111924
1912−<p>Inside a C function you can raise an error calling <a href="#lua_error"><code>lua_error</code></a>.
1925+<p>Inside a C function you can raise an error by calling <a href="#lua_error"><code>lua_error</code></a>.
19131926
19141927 <p><a name="3.7"></a><h2>3.7 - Functions and Types</h2>
19151928
@@ -1917,7 +1930,7 @@ so they never raise an error: · 1 unmodified line
19171930 alphabetical order.
19181931
19191932 <p><a name="lua_Alloc"></a>
1920−<hr/><h3><code>lua_Alloc</code></h3>
1933+<hr /><h3><code>lua_Alloc</code></h3>
19211934 <pre>
19221935 typedef void * (*lua_Alloc) (void *ud,
19231936 void *ptr,
@@ -1927,12 +1940,12 @@ alphabetical order. · 3 unmodified lines
19271940 </pre>
19281941
19291942
1930−<p>The allocator function used by Lua states.
1943+<p>The type of the memory allocation function used by Lua states.
19311944 The allocator function must provide a
19321945 functionality similar to <code>realloc</code>,
19331946 but not exactly the same.
1934−Its arguments are <code>ud</code>,
1935−the opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;
1947+Its arguments are
1948+<code>ud</code>, an opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;
19361949 <code>ptr</code>, a pointer to the block being allocated/reallocated/freed;
19371950 <code>osize</code>, the original size of the block;
19381951 <code>nsize</code>, the new size of the block.
@@ -1943,30 +1956,30 @@ it should free the block pointed by <code>ptr</code>. · 4 unmodified lines
19431956 When <code>nsize</code> is not zero, the allocator returns <code>NULL</code>
19441957 if and only if it cannot fill the request.
19451958 When <code>nsize</code> is not zero and <code>osize</code> is zero,
1946−the allocator behaves like <code>malloc</code>.
1959+the allocator should behave like <code>malloc</code>.
19471960 When <code>nsize</code> and <code>osize</code> are not zero,
19481961 the allocator behaves like <code>realloc</code>.
19491962 Lua assumes that the allocator never fails when
19501963 <code>osize >= nsize</code>.
19511964
1952−<p>A simple implementation for the allocator function
1953−could be like this:
1965+<p>Here is a simple implementation for the allocator function.
1966+It is used in the auxiliary library by <a href="#lua_newstate"><code>lua_newstate</code></a>.
19541967 <pre>
19551968 static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
19561969 (void)ud; /* not used */
19571970 (void)osize; /* not used */
19581971 if (nsize == 0) {
1959− free(ptr); /* ANSI ensures that free(NULL) has no effect */
1972+ free(ptr); /* ANSI requires that free(NULL) has no effect */
19601973 return NULL;
19611974 }
19621975 else
1963− /* ANSI ensures that realloc(NULL, size) == malloc(size) */
1976+ /* ANSI requires that realloc(NULL, size) == malloc(size) */
19641977 return realloc(ptr, nsize);
19651978 }
19661979 </pre>
19671980
19681981 <p><a name="lua_atpanic"></a>
1969−<hr/><h3><code>lua_atpanic</code></h3>
1982+<hr /><h3><code>lua_atpanic</code></h3>
19701983 <pre>
19711984 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
19721985 </pre>
@@ -1976,14 +1989,15 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { · 3 unmodified lines
19761989
19771990 <p>If an error happens outside any protected environment,
19781991 Lua calls a <em>panic function</em>
1979−and then calls <code>exit(EXIT_FAILURE)</code>.
1980−Your new panic function may avoid the application exit by
1992+and then calls <code>exit(EXIT_FAILURE)</code>,
1993+thus exiting the host application.
1994+Your panic function may avoid this exit by
19811995 never returning (e.g., doing a long jump).
19821996
19831997 <p>The panic function can access the error message at the top of the stack.
19841998
19851999 <p><a name="lua_call"></a>
1986−<hr/><h3><code>lua_call</code></h3>
2000+<hr /><h3><code>lua_call</code></h3>
19872001 <pre>
19882002 void lua_call (lua_State *L, int nargs, int nresults);
19892003 </pre>
@@ -1994,18 +2008,20 @@ never returning (e.g., doing a long jump). · 4 unmodified lines
19942008 <p>To call a function you must use the following protocol:
19952009 First, the function to be called is pushed onto the stack;
19962010 then, the arguments to the function are pushed
1997−in direct order, that is, the first argument is pushed first.
2011+in direct order;
2012+that is, the first argument is pushed first.
19982013 Finally you call <a href="#lua_call"><code>lua_call</code></a>;
19992014 <code>nargs</code> is the number of arguments that you pushed onto the stack.
2000−All arguments and the function value are popped from the stack,
2001−and the function results are pushed.
2002−The number of results are adjusted to <code>nresults</code>,
2015+All arguments and the function value are popped from the stack
2016+when the function is called.
2017+The function results are pushed onto the stack when the function returns.
2018+The number of results is adjusted to <code>nresults</code>,
20032019 unless <code>nresults</code> is <code>LUA_MULTRET</code>.
20042020 In that case, <em>all</em> results from the function are pushed.
20052021 Lua takes care that the returned values fit into the stack space.
20062022 The function results are pushed onto the stack in direct order
20072023 (the first result is pushed first),
2008−so that after the call the last result is on the top.
2024+so that after the call the last result is on the top of the stack.
20092025
20102026 <p>Any error inside the called function is propagated upwards
20112027 (with a <code>longjmp</code>).
@@ -2017,21 +2033,21 @@ equivalent to this Lua code: · 5 unmodified lines
20172033 </pre>
20182034 Here it is in C:
20192035 <pre>
2020− lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */
20212036 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
20222037 lua_pushstring(L, "how"); /* 1st argument */
2023− lua_getfield(L, -3, "x"); /* push result of t.x (2nd arg) */
2038+ lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
2039+ lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
2040+ lua_remove(L, -2); /* remove `t' from the stack */
20242041 lua_pushinteger(L, 14); /* 3rd argument */
20252042 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */
20262043 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */
2027− lua_pop(L, 1); /* remove `t' from the stack */
20282044 </pre>
20292045 Note that the code above is "balanced":
20302046 at its end, the stack is back to its original configuration.
20312047 This is considered good programming practice.
20322048
20332049 <p><a name="lua_CFunction"></a>
2034−<hr/><h3><code>lua_CFunction</code></h3>
2050+<hr /><h3><code>lua_CFunction</code></h3>
20352051 <pre>
20362052 typedef int (*lua_CFunction) (lua_State *L);
20372053 </pre>
@@ -2040,17 +2056,19 @@ This is considered good programming practice. · 2 unmodified lines
20402056 <p>Type for C functions.
20412057
20422058 <p>In order to communicate properly with Lua,
2043−a C function must follow the following protocol,
2059+a C function must use the following protocol,
20442060 which defines the way parameters and results are passed:
20452061 A C function receives its arguments from Lua in its stack
20462062 in direct order (the first argument is pushed first).
20472063 So, when the function starts,
2048−its first argument (if any) is at index 1.
2064+<a href="#lua_gettop(L)"><code>lua_gettop(L)</code></a> returns the number of arguments received by the function.
2065+The first argument (if any) is at index 1
2066+and its last argument is at index <a href="#lua_gettop(L)"><code>lua_gettop(L)</code></a>.
20492067 To return values to Lua, a C function just pushes them onto the stack,
20502068 in direct order (the first result is pushed first),
20512069 and returns the number of results.
20522070 Any other value in the stack below the results will be properly
2053−discharged by Lua.
2071+discarded by Lua.
20542072 Like a Lua function, a C function called by Lua can also return
20552073 many results.
20562074
@@ -2075,20 +2093,20 @@ of numerical arguments and returns their average and sum: · 18 unmodified lines
20752093 </pre>
20762094
20772095 <p><a name="lua_checkstack"></a>
2078−<hr/><h3><code>lua_checkstack</code></h3>
2096+<hr /><h3><code>lua_checkstack</code></h3>
20792097 <pre>
20802098 int lua_checkstack (lua_State *L, int extra);
20812099 </pre>
20822100
20832101
2084−<p>Grows the stack size to <code>top + extra</code> elements;
2102+<p>Ensures that there are at least <code>extra</code> free stack slots in the stack.
20852103 it returns false if it cannot grow the stack to that size.
20862104 This function never shrinks the stack;
20872105 if the stack is already larger than the new size,
20882106 it is left unchanged.
20892107
20902108 <p><a name="lua_close"></a>
2091−<hr/><h3><code>lua_close</code></h3>
2109+<hr /><h3><code>lua_close</code></h3>
20922110 <pre>
20932111 void lua_close (lua_State *L);
20942112 </pre>
@@ -2105,7 +2123,7 @@ might need to release states as soon as they are not needed, · 10 unmodified lines
21052123 to avoid growing too large.
21062124
21072125 <p><a name="lua_concat"></a>
2108−<hr/><h3><code>lua_concat</code></h3>
2126+<hr /><h3><code>lua_concat</code></h3>
21092127 <pre>
21102128 void lua_concat (lua_State *L, int n);
21112129 </pre>
@@ -2120,7 +2138,7 @@ Concatenation is done following the usual semantics of Lua · 8 unmodified lines
21202138 (see <a href="#concat">2.5.4</a>).
21212139
21222140 <p><a name="lua_cpcall"></a>
2123−<hr/><h3><code>lua_cpcall</code></h3>
2141+<hr /><h3><code>lua_cpcall</code></h3>
21242142 <pre>
21252143 int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
21262144 </pre>
@@ -2133,10 +2151,10 @@ In case of errors, · 6 unmodified lines
21332151 <a href="#lua_cpcall"><code>lua_cpcall</code></a> returns the same error codes as <a href="#lua_pcall"><code>lua_pcall</code></a>,
21342152 plus the error object on the top of the stack;
21352153 otherwise, it returns zero, and does not change the stack.
2136−Any value returned by <code>func</code> is discarded.
2154+All values returned by <code>func</code> are discarded.
21372155
21382156 <p><a name="lua_createtable"></a>
2139−<hr/><h3><code>lua_createtable</code></h3>
2157+<hr /><h3><code>lua_createtable</code></h3>
21402158 <pre>
21412159 void lua_createtable (lua_State *L, int narr, int nrec);
21422160 </pre>
@@ -2144,25 +2162,26 @@ Any value returned by <code>func</code> is discarded. · 1 unmodified line
21442162
21452163 <p>Creates a new empty table and pushes it onto the stack.
21462164 The new table has space pre-allocated
2147−for <code>narr</code> array elements plus <code>nrec</code> non-array elements.
2165+for <code>narr</code> array elements and <code>nrec</code> non-array elements.
21482166 This pre-allocation is useful when you know exactly how many elements
21492167 the table will have.
21502168 Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
21512169
21522170 <p><a name="lua_dump"></a>
2153−<hr/><h3><code>lua_dump</code></h3>
2171+<hr /><h3><code>lua_dump</code></h3>
21542172 <pre>
21552173 int lua_dump (lua_State *L, lua_Writer writer, void *data);
21562174 </pre>
21572175
21582176
21592177 <p>Dumps a function as a binary chunk.
2160−This function receives a Lua function on the top of the stack
2178+Receives a Lua function on the top of the stack
21612179 and produces a binary chunk that,
21622180 if loaded again,
21632181 results in a function equivalent to the one dumped.
21642182 As it produces parts of the chunk,
21652183 <a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua_Writer"><code>lua_Writer</code></a>)
2184+with the given <code>data</code>
21662185 to write them.
21672186
21682187 <p>The value returned is the error code returned by the last
@@ -2172,7 +2191,7 @@ call to the writer; · 3 unmodified lines
21722191 <p>This function does not pop the function from the stack.
21732192
21742193 <p><a name="lua_equal"></a>
2175−<hr/><h3><code>lua_equal</code></h3>
2194+<hr /><h3><code>lua_equal</code></h3>
21762195 <pre>
21772196 int lua_equal (lua_State *L, int index1, int index2);
21782197 </pre>
@@ -2183,23 +2202,24 @@ call to the writer; · 4 unmodified lines
21832202 following the semantics of the Lua <code>==</code> operator
21842203 (that is, may call metamethods).
21852204 Otherwise returns 0.
2186−Also returns 0 if any of the indices are non valid.
2205+Also returns 0 if any of the indices is non valid.
21872206
21882207 <p><a name="lua_error"></a>
2189−<hr/><h3><code>lua_error</code></h3>
2208+<hr /><h3><code>lua_error</code></h3>
21902209 <pre>
21912210 int lua_error (lua_State *L);
21922211 </pre>
21932212
21942213
21952214 <p>Generates a Lua error.
2196−The error message (which actually can be any type of object)
2215+The error message (which can actually be a Lua value of any type)
21972216 must be on the stack top.
21982217 This function does a long jump,
21992218 and therefore never returns.
2219+(see <a href="#pdf-luaL_error"><code>luaL_error</code></a>).
22002220
22012221 <p><a name="lua_gc"></a>
2202−<hr/><h3><code>lua_gc</code></h3>
2222+<hr /><h3><code>lua_gc</code></h3>
22032223 <pre>
22042224 int lua_gc (lua_State *L, int what, int data);
22052225 </pre>
@@ -2227,28 +2247,28 @@ you must tune experimentally the value of <code>data</code>. · 21 unmodified lines
22272247 The function returns 1 if that step finished a
22282248 garbage-collection cycle.
22292249 <li> <code>LUA_GCSETPAUSE</code>---
2230−sets <em><code>data</code>/100</em> as the new value
2250+sets <code>data</code>/100 as the new value
22312251 for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>).
22322252 The function returns the previous value of the pause.
22332253 <li> <code>LUA_GCSETSTEPMUL</code>---
2234−sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of
2254+sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of
22352255 the collector (see <a href="#GC">2.10</a>).
22362256 The function returns the previous value of the step multiplier.
22372257 </ul>
22382258
22392259 <p><a name="lua_getallocf"></a>
2240−<hr/><h3><code>lua_getallocf</code></h3>
2260+<hr /><h3><code>lua_getallocf</code></h3>
22412261 <pre>
22422262 lua_Alloc lua_getallocf (lua_State *L, void **ud);
22432263 </pre>
22442264
22452265
2246−<p>Returns the allocator function of a given state.
2247−If <code>ud</code> is not <code>NULL</code> Lua stores in <code>*ud</code> the
2266+<p>Returns the memory allocator function of a given state.
2267+If <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the
22482268 opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.
22492269
22502270 <p><a name="lua_getfenv"></a>
2251−<hr/><h3><code>lua_getfenv</code></h3>
2271+<hr /><h3><code>lua_getfenv</code></h3>
22522272 <pre>
22532273 void lua_getfenv (lua_State *L, int index);
22542274 </pre>
@@ -2258,7 +2278,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 3 unmodified lines
22582278 the value at the given index.
22592279
22602280 <p><a name="lua_getfield"></a>
2261−<hr/><h3><code>lua_getfield</code></h3>
2281+<hr /><h3><code>lua_getfield</code></h3>
22622282 <pre>
22632283 void lua_getfield (lua_State *L, int index, const char *k);
22642284 </pre>
@@ -2270,7 +2290,7 @@ As in Lua, this function may trigger a metamethod · 5 unmodified lines
22702290 for the "index" event (see <a href="#metatable">2.8</a>).
22712291
22722292 <p><a name="lua_getmetatable"></a>
2273−<hr/><h3><code>lua_getmetatable</code></h3>
2293+<hr /><h3><code>lua_getmetatable</code></h3>
22742294 <pre>
22752295 int lua_getmetatable (lua_State *L, int index);
22762296 </pre>
@@ -2283,7 +2303,7 @@ or if the value does not have a metatable, · 6 unmodified lines
22832303 returns 0 and pushes nothing on the stack.
22842304
22852305 <p><a name="lua_gettable"></a>
2286−<hr/><h3><code>lua_gettable</code></h3>
2306+<hr /><h3><code>lua_gettable</code></h3>
22872307 <pre>
22882308 void lua_gettable (lua_State *L, int index);
22892309 </pre>
@@ -2299,7 +2319,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
22992319 for the "index" event (see <a href="#metatable">2.8</a>).
23002320
23012321 <p><a name="lua_gettop"></a>
2302−<hr/><h3><code>lua_gettop</code></h3>
2322+<hr /><h3><code>lua_gettop</code></h3>
23032323 <pre>
23042324 int lua_gettop (lua_State *L);
23052325 </pre>
@@ -2311,7 +2331,7 @@ that result is equal to the number of elements in the stack · 5 unmodified lines
23112331 (and so 0 means an empty stack).
23122332
23132333 <p><a name="lua_insert"></a>
2314−<hr/><h3><code>lua_insert</code></h3>
2334+<hr /><h3><code>lua_insert</code></h3>
23152335 <pre>
23162336 void lua_insert (lua_State *L, int index);
23172337 </pre>
@@ -2323,7 +2343,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
23232343 because a pseudo-index is not an actual stack position.
23242344
23252345 <p><a name="lua_Integer"></a>
2326−<hr/><h3><code>lua_Integer</code></h3>
2346+<hr /><h3><code>lua_Integer</code></h3>
23272347 <pre>
23282348 typedef ptrdiff_t lua_Integer;
23292349 </pre>
@@ -2332,11 +2352,11 @@ because a pseudo-index is not an actual stack position. · 2 unmodified lines
23322352 <p>The type used by the Lua API to represent integral values.
23332353
23342354 <p>By default it is a <code>ptrdiff_t</code>,
2335−which is usually the largest type the machine handles
2355+which is usually the largest integral type the machine handles
23362356 "comfortably".
23372357
23382358 <p><a name="lua_isboolean"></a>
2339−<hr/><h3><code>lua_isboolean</code></h3>
2359+<hr /><h3><code>lua_isboolean</code></h3>
23402360 <pre>
23412361 int lua_isboolean (lua_State *L, int index);
23422362 </pre>
@@ -2346,7 +2366,7 @@ which is usually the largest type the machine handles · 3 unmodified lines
23462366 and 0 otherwise.
23472367
23482368 <p><a name="lua_iscfunction"></a>
2349−<hr/><h3><code>lua_iscfunction</code></h3>
2369+<hr /><h3><code>lua_iscfunction</code></h3>
23502370 <pre>
23512371 int lua_iscfunction (lua_State *L, int index);
23522372 </pre>
@@ -2356,7 +2376,7 @@ and 0 otherwise. · 3 unmodified lines
23562376 and 0 otherwise.
23572377
23582378 <p><a name="lua_isfunction"></a>
2359−<hr/><h3><code>lua_isfunction</code></h3>
2379+<hr /><h3><code>lua_isfunction</code></h3>
23602380 <pre>
23612381 int lua_isfunction (lua_State *L, int index);
23622382 </pre>
@@ -2366,7 +2386,7 @@ and 0 otherwise. · 3 unmodified lines
23662386 (either C or Lua), and 0 otherwise.
23672387
23682388 <p><a name="lua_islightuserdata"></a>
2369−<hr/><h3><code>lua_islightuserdata</code></h3>
2389+<hr /><h3><code>lua_islightuserdata</code></h3>
23702390 <pre>
23712391 int lua_islightuserdata (lua_State *L, int index);
23722392 </pre>
@@ -2376,7 +2396,7 @@ and 0 otherwise. · 3 unmodified lines
23762396 and 0 otherwise.
23772397
23782398 <p><a name="lua_isnil"></a>
2379−<hr/><h3><code>lua_isnil</code></h3>
2399+<hr /><h3><code>lua_isnil</code></h3>
23802400 <pre>
23812401 int lua_isnil (lua_State *L, int index);
23822402 </pre>
@@ -2386,7 +2406,7 @@ and 0 otherwise. · 3 unmodified lines
23862406 and 0 otherwise.
23872407
23882408 <p><a name="lua_isnumber"></a>
2389−<hr/><h3><code>lua_isnumber</code></h3>
2409+<hr /><h3><code>lua_isnumber</code></h3>
23902410 <pre>
23912411 int lua_isnumber (lua_State *L, int index);
23922412 </pre>
@@ -2397,7 +2417,7 @@ or a string convertible to a number, · 4 unmodified lines
23972417 and 0 otherwise.
23982418
23992419 <p><a name="lua_isstring"></a>
2400−<hr/><h3><code>lua_isstring</code></h3>
2420+<hr /><h3><code>lua_isstring</code></h3>
24012421 <pre>
24022422 int lua_isstring (lua_State *L, int index);
24032423 </pre>
@@ -2408,7 +2428,7 @@ or a number (which is always convertible to a string), · 4 unmodified lines
24082428 and 0 otherwise.
24092429
24102430 <p><a name="lua_istable"></a>
2411−<hr/><h3><code>lua_istable</code></h3>
2431+<hr /><h3><code>lua_istable</code></h3>
24122432 <pre>
24132433 int lua_istable (lua_State *L, int index);
24142434 </pre>
@@ -2418,7 +2438,7 @@ and 0 otherwise. · 3 unmodified lines
24182438 and 0 otherwise.
24192439
24202440 <p><a name="lua_isthread"></a>
2421−<hr/><h3><code>lua_isthread</code></h3>
2441+<hr /><h3><code>lua_isthread</code></h3>
24222442 <pre>
24232443 int lua_isthread (lua_State *L, int index);
24242444 </pre>
@@ -2428,7 +2448,7 @@ and 0 otherwise. · 3 unmodified lines
24282448 and 0 otherwise.
24292449
24302450 <p><a name="lua_isuserdata"></a>
2431−<hr/><h3><code>lua_isuserdata</code></h3>
2451+<hr /><h3><code>lua_isuserdata</code></h3>
24322452 <pre>
24332453 int lua_isuserdata (lua_State *L, int index);
24342454 </pre>
@@ -2438,21 +2458,21 @@ and 0 otherwise. · 3 unmodified lines
24382458 (either full or light), and 0 otherwise.
24392459
24402460 <p><a name="lua_lessthan"></a>
2441−<hr/><h3><code>lua_lessthan</code></h3>
2461+<hr /><h3><code>lua_lessthan</code></h3>
24422462 <pre>
24432463 int lua_lessthan (lua_State *L, int index1, int index2);
24442464 </pre>
24452465
24462466
2447−<p>Returns 1 if the value in acceptable index <code>index1</code> is smaller
2448−than the value in acceptable index <code>index2</code>,
2467+<p>Returns 1 if the value at acceptable index <code>index1</code> is smaller
2468+than the value at acceptable index <code>index2</code>,
24492469 following the semantics of the Lua <code>&#060;</code> operator
24502470 (that is, may call metamethods).
24512471 Otherwise returns 0.
2452−Also returns 0 if any of the indices are non valid.
2472+Also returns 0 if any of the indices is non valid.
24532473
24542474 <p><a name="lua_load"></a>
2455−<hr/><h3><code>lua_load</code></h3>
2475+<hr /><h3><code>lua_load</code></h3>
24562476 <pre>
24572477 int lua_load (lua_State *L, lua_Reader reader, void *data,
24582478 const char *chunkname);
@@ -2481,11 +2501,11 @@ and loads it accordingly (see program <code>luac</code>). · 22 unmodified lines
24812501 (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
24822502 The <code>data</code> argument is an opaque value passed to the reader function.
24832503
2484−<p>The <code>chunkname</code> argument gives the chunk name.
2485−It is used for error messages and debug information (see <a href="#debugI">3.8</a>).
2504+<p>The <code>chunkname</code> argument gives a name to the chunk,
2505+which is used for error messages and in debug information (see <a href="#debugI">3.8</a>).
24862506
24872507 <p><a name="lua_newstate"></a>
2488−<hr/><h3><code>lua_newstate</code></h3>
2508+<hr /><h3><code>lua_newstate</code></h3>
24892509 <pre>
24902510 lua_State *lua_newstate (lua_Alloc f, void *ud);
24912511 </pre>
@@ -2493,14 +2513,14 @@ It is used for error messages and debug information (see <a href="#debugI">3.8</ · 1 unmodified line
24932513
24942514 <p>Creates a new, independent state.
24952515 Returns <code>NULL</code> if cannot create the state
2496−(not enough memory).
2516+(due to lack of memory).
24972517 The argument <code>f</code> is the allocator function;
24982518 Lua does all memory allocation for that state through that function.
24992519 The second argument, <code>ud</code>, is an opaque pointer that Lua
25002520 simply passes to the allocator in every call.
25012521
25022522 <p><a name="lua_newtable"></a>
2503−<hr/><h3><code>lua_newtable</code></h3>
2523+<hr /><h3><code>lua_newtable</code></h3>
25042524 <pre>
25052525 void lua_newtable (lua_State *L);
25062526 </pre>
@@ -2510,7 +2530,7 @@ simply passes to the allocator in every call. · 3 unmodified lines
25102530 Equivalent to <code>lua_createtable(L, 0, 0)</code>.
25112531
25122532 <p><a name="lua_newthread"></a>
2513−<hr/><h3><code>lua_newthread</code></h3>
2533+<hr /><h3><code>lua_newthread</code></h3>
25142534 <pre>
25152535 lua_State *lua_newthread (lua_State *L);
25162536 </pre>
@@ -2520,14 +2540,14 @@ Equivalent to <code>lua_createtable(L, 0, 0)</code>. · 3 unmodified lines
25202540 and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread.
25212541 The new state returned by this function shares with the original state
25222542 all global objects (such as tables),
2523−but has an independent run-time stack.
2543+but has an independent execution stack.
25242544
25252545 <p>There is no explicit function to close or to destroy a thread.
25262546 Threads are subject to garbage collection,
25272547 like any Lua object.
25282548
25292549 <p><a name="lua_newuserdata"></a>
2530−<hr/><h3><code>lua_newuserdata</code></h3>
2550+<hr /><h3><code>lua_newuserdata</code></h3>
25312551 <pre>
25322552 void *lua_newuserdata (lua_State *L, size_t size);
25332553 </pre>
@@ -2544,21 +2564,22 @@ You must create it, it can have its own metatable, · 10 unmodified lines
25442564 and you can detect when it is being collected.
25452565 A full userdata is only equal to itself (under raw equality).
25462566
2547−<p>When Lua collects a full userdata,
2548−it calls the userdata's <code>gc</code> metamethod, if any,
2549−and then it frees the userdata's corresponding memory.
2567+<p>When Lua collects a full userdata with a <code>gc</code> metamethod,
2568+Lua calls the metamethod and marks the userdata as finalized.
2569+When that userdata is collected again then
2570+Lua frees its corresponding memory.
25502571
25512572 <p><a name="lua_next"></a>
2552−<hr/><h3><code>lua_next</code></h3>
2573+<hr /><h3><code>lua_next</code></h3>
25532574 <pre>
25542575 int lua_next (lua_State *L, int index);
25552576 </pre>
25562577
25572578
25582579 <p>Pops a key from the stack,
2559−and pushes a key-value pair from the table
2580+and pushes a key-value pair from the table at the given index
25602581 (the "next" pair after the given key).
2561−If there are no more elements,
2582+If there are no more elements in the table,
25622583 then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).
25632584
25642585 <p>A typical traversal looks like this:
@@ -2581,33 +2602,34 @@ the value at the given index; · 16 unmodified lines
25812602 this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
25822603
25832604 <p><a name="lua_Number"></a>
2584−<hr/><h3><code>lua_Number</code></h3>
2605+<hr /><h3><code>lua_Number</code></h3>
25852606 <pre>
25862607 typedef double lua_Number;
25872608 </pre>
25882609
25892610
25902611 <p>The type of numbers in Lua.
2612+By default, it is double, but that can be changed in <code>luaconf.h</code>.
25912613
25922614 <p>Through the configuration file you can change
25932615 Lua to operate with other type for numbers (e.g., float or long).
25942616
25952617 <p><a name="lua_objlen"></a>
2596−<hr/><h3><code>lua_objlen</code></h3>
2618+<hr /><h3><code>lua_objlen</code></h3>
25972619 <pre>
25982620 size_t lua_objlen (lua_State *L, int index);
25992621 </pre>
26002622
26012623
26022624 <p>Returns the "length" of the value at the given acceptable index:
2603−For strings, this is the string length;
2604−for tables, this is the result of the length operator (`<code>#</code>&acute;).
2625+for strings, this is the string length;
2626+for tables, this is the result of the length operator (`<code>#</code>&acute;);
26052627 for userdata, this is the size of the block of memory allocated
2606−for the userdatum.
2607−For other values, returns 0.
2628+for the userdata;
2629+for other values, it is 0.
26082630
26092631 <p><a name="lua_pcall"></a>
2610−<hr/><h3><code>lua_pcall</code></h3>
2632+<hr /><h3><code>lua_pcall</code></h3>
26112633 <pre>
26122634 lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
26132635 </pre>
@@ -2628,13 +2650,14 @@ Like <a href="#lua_call"><code>lua_call</code></a>, · 14 unmodified lines
26282650 and its arguments from the stack.
26292651
26302652 <p>If <code>errfunc</code> is 0,
2631−then the error message returned is exactly the original error message.
2653+then the error message returned on the stack
2654+is exactly the original error message.
26322655 Otherwise, <code>errfunc</code> is the stack index of an
26332656 <em>error handler function</em>.
26342657 (In the current implementation, that index cannot be a pseudo-index.)
26352658 In case of runtime errors,
26362659 that function will be called with the error message
2637−and its return value will be the message returned by <a href="#lua_pcall"><code>lua_pcall</code></a>.
2660+and its return value will be the message returned on the stack by <a href="#lua_pcall"><code>lua_pcall</code></a>.
26382661
26392662 <p>Typically, the error handler function is used to add more debug
26402663 information to the error message, such as a stack traceback.
@@ -2653,7 +2676,7 @@ error while running the error handler function. · 12 unmodified lines
26532676 </ul>
26542677
26552678 <p><a name="lua_pop"></a>
2656−<hr/><h3><code>lua_pop</code></h3>
2679+<hr /><h3><code>lua_pop</code></h3>
26572680 <pre>
26582681 void lua_pop (lua_State *L, int n);
26592682 </pre>
@@ -2662,7 +2685,7 @@ error while running the error handler function. · 2 unmodified lines
26622685 <p>Pops <code>n</code> elements from the stack.
26632686
26642687 <p><a name="lua_pushboolean"></a>
2665−<hr/><h3><code>lua_pushboolean</code></h3>
2688+<hr /><h3><code>lua_pushboolean</code></h3>
26662689 <pre>
26672690 void lua_pushboolean (lua_State *L, int b);
26682691 </pre>
@@ -2671,7 +2694,7 @@ error while running the error handler function. · 2 unmodified lines
26712694 <p>Pushes a boolean value with value <code>b</code> onto the stack.
26722695
26732696 <p><a name="lua_pushcclosure"></a>
2674−<hr/><h3><code>lua_pushcclosure</code></h3>
2697+<hr /><h3><code>lua_pushcclosure</code></h3>
26752698 <pre>
26762699 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
26772700 </pre>
@@ -2686,14 +2709,14 @@ these values are then accessible to the function whenever it is called. · 8 unmodified lines
26862709 To associate values with a C function,
26872710 first these values should be pushed onto the stack
26882711 (when there are multiple values, the first value is pushed first).
2689−Then the function <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>
2690−is used to create and push the C function onto the stack,
2712+Then <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>
2713+is called to create and push the C function onto the stack,
26912714 with the argument <code>n</code> telling how many values should be
26922715 associated with the function.
26932716 <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
26942717
26952718 <p><a name="lua_pushcfunction"></a>
2696−<hr/><h3><code>lua_pushcfunction</code></h3>
2719+<hr /><h3><code>lua_pushcfunction</code></h3>
26972720 <pre>
26982721 void lua_pushcfunction (lua_State *L, lua_CFunction f);
26992722 </pre>
@@ -2703,7 +2726,7 @@ associated with the function. · 3 unmodified lines
27032726 This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>.
27042727
27052728 <p><a name="lua_pushfstring"></a>
2706−<hr/><h3><code>lua_pushfstring</code></h3>
2729+<hr /><h3><code>lua_pushfstring</code></h3>
27072730 <pre>
27082731 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
27092732 </pre>
@@ -2711,15 +2734,15 @@ This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>. · 1 unmodified line
27112734
27122735 <p>Pushes onto the stack a formatted string
27132736 and returns a pointer to that string.
2714−It is similar to the C function <code>sprintf</code>
2715−but with some important differences:
2737+It is similar to the C function <code>sprintf</code>,
2738+but has some important differences:
27162739 <ul>
27172740 <li> You do not have to allocate the space for the result:
27182741 The result is a Lua string and Lua takes care of memory allocation
27192742 (and deallocation, through garbage collection).
27202743 <li> The conversion specifiers are quite restricted.
27212744 There are no flags, widths, or precisions.
2722−The conversion specifiers can be simply
2745+The conversion specifiers can only be
27232746 `<code>%%</code>&acute; (inserts a `<code>%</code>&acute; in the string),
27242747 `<code>%s</code>&acute; (inserts a zero-terminated string, with no size restrictions),
27252748 `<code>%f</code>&acute; (inserts a <a href="#lua_Number"><code>lua_Number</code></a>),
@@ -2729,7 +2752,7 @@ The conversion specifiers can be simply · 3 unmodified lines
27292752 </ul>
27302753
27312754 <p><a name="lua_pushinteger"></a>
2732−<hr/><h3><code>lua_pushinteger</code></h3>
2755+<hr /><h3><code>lua_pushinteger</code></h3>
27332756 <pre>
27342757 void lua_pushinteger (lua_State *L, lua_Integer n);
27352758 </pre>
@@ -2738,7 +2761,7 @@ The conversion specifiers can be simply · 2 unmodified lines
27382761 <p>Pushes a number with value <code>n</code> onto the stack.
27392762
27402763 <p><a name="lua_pushlightuserdata"></a>
2741−<hr/><h3><code>lua_pushlightuserdata</code></h3>
2764+<hr /><h3><code>lua_pushlightuserdata</code></h3>
27422765 <pre>
27432766 void lua_pushlightuserdata (lua_State *L, void *p);
27442767 </pre>
@@ -2755,7 +2778,7 @@ A light userdata is equal to "any" · 10 unmodified lines
27552778 light userdata with the same C address.
27562779
27572780 <p><a name="lua_pushlstring"></a>
2758−<hr/><h3><code>lua_pushlstring</code></h3>
2781+<hr /><h3><code>lua_pushlstring</code></h3>
27592782 <pre>
27602783 void lua_pushlstring (lua_State *L, const char *s, size_t len);
27612784 </pre>
@@ -2766,9 +2789,10 @@ onto the stack. · 4 unmodified lines
27662789 Lua makes (or reuses) an internal copy of the given string,
27672790 so the memory at <code>s</code> can be freed or reused immediately after
27682791 the function returns.
2792+The string can contain embedded zeros.
27692793
27702794 <p><a name="lua_pushnil"></a>
2771−<hr/><h3><code>lua_pushnil</code></h3>
2795+<hr /><h3><code>lua_pushnil</code></h3>
27722796 <pre>
27732797 void lua_pushnil (lua_State *L);
27742798 </pre>
@@ -2777,7 +2801,7 @@ the function returns. · 2 unmodified lines
27772801 <p>Pushes a nil value onto the stack.
27782802
27792803 <p><a name="lua_pushnumber"></a>
2780−<hr/><h3><code>lua_pushnumber</code></h3>
2804+<hr /><h3><code>lua_pushnumber</code></h3>
27812805 <pre>
27822806 void lua_pushnumber (lua_State *L, lua_Number n);
27832807 </pre>
@@ -2786,7 +2810,7 @@ the function returns. · 2 unmodified lines
27862810 <p>Pushes a number with value <code>n</code> onto the stack.
27872811
27882812 <p><a name="lua_pushstring"></a>
2789−<hr/><h3><code>lua_pushstring</code></h3>
2813+<hr /><h3><code>lua_pushstring</code></h3>
27902814 <pre>
27912815 void lua_pushstring (lua_State *L, const char *s);
27922816 </pre>
@@ -2797,9 +2821,20 @@ onto the stack. · 4 unmodified lines
27972821 Lua makes (or reuses) an internal copy of the given string,
27982822 so the memory at <code>s</code> can be freed or reused immediately after
27992823 the function returns.
2824+The string cannot embedded zeros;
2825+it is assumed to end at the first zero.
2826+
2827+<p><a name="lua_pushthread"></a>
2828+<hr /><h3><code>lua_pushthread</code></h3>
2829+<pre>
2830+ void lua_pushthread (lua_State *L);
2831+</pre>
2832+
2833+
2834+<p>Pushes the thread represented by <code>L</code> onto the stack.
28002835
28012836 <p><a name="lua_pushvalue"></a>
2802−<hr/><h3><code>lua_pushvalue</code></h3>
2837+<hr /><h3><code>lua_pushvalue</code></h3>
28032838 <pre>
28042839 void lua_pushvalue (lua_State *L, int index);
28052840 </pre>
@@ -2809,7 +2844,7 @@ the function returns. · 3 unmodified lines
28092844 onto the stack.
28102845
28112846 <p><a name="lua_pushvfstring"></a>
2812−<hr/><h3><code>lua_pushvfstring</code></h3>
2847+<hr /><h3><code>lua_pushvfstring</code></h3>
28132848 <pre>
28142849 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
28152850 </pre>
@@ -2819,7 +2854,7 @@ onto the stack. · 3 unmodified lines
28192854 instead of a variable number of arguments.
28202855
28212856 <p><a name="lua_rawequal"></a>
2822−<hr/><h3><code>lua_rawequal</code></h3>
2857+<hr /><h3><code>lua_rawequal</code></h3>
28232858 <pre>
28242859 int lua_rawequal (lua_State *L, int index1, int index2);
28252860 </pre>
@@ -2832,17 +2867,17 @@ Otherwise returns 0. · 6 unmodified lines
28322867 Also returns 0 if any of the indices are non valid.
28332868
28342869 <p><a name="lua_rawget"></a>
2835−<hr/><h3><code>lua_rawget</code></h3>
2870+<hr /><h3><code>lua_rawget</code></h3>
28362871 <pre>
28372872 void lua_rawget (lua_State *L, int index);
28382873 </pre>
28392874
28402875
2841−<p>Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but doing a raw indexing
2876+<p>Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw access
28422877 (i.e., without metamethods).
28432878
28442879 <p><a name="lua_rawgeti"></a>
2845−<hr/><h3><code>lua_rawgeti</code></h3>
2880+<hr /><h3><code>lua_rawgeti</code></h3>
28462881 <pre>
28472882 void lua_rawgeti (lua_State *L, int index, int n);
28482883 </pre>
@@ -2850,36 +2885,36 @@ Also returns 0 if any of the indices are non valid. · 1 unmodified line
28502885
28512886 <p>Pushes onto the stack the value <code>t[n]</code>,
28522887 where <code>t</code> is the value at the given valid index <code>index</code>.
2853−The access is raw,
2888+The access is raw;
28542889 that is, it does not invoke metamethods.
28552890
28562891 <p><a name="lua_rawset"></a>
2857−<hr/><h3><code>lua_rawset</code></h3>
2892+<hr /><h3><code>lua_rawset</code></h3>
28582893 <pre>
28592894 void lua_rawset (lua_State *L, int index);
28602895 </pre>
28612896
28622897
2863−<p>Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but doing a raw assignment
2898+<p>Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw assignment
28642899 (i.e., without metamethods).
28652900
28662901 <p><a name="lua_rawseti"></a>
2867−<hr/><h3><code>lua_rawseti</code></h3>
2902+<hr /><h3><code>lua_rawseti</code></h3>
28682903 <pre>
28692904 void lua_rawseti (lua_State *L, int index, int n);
28702905 </pre>
28712906
28722907
2873−<p>Does the equivalent to <code>t[n] = v</code>,
2908+<p>Does the equivalent of <code>t[n] = v</code>,
28742909 where <code>t</code> is the value at the given valid index <code>index</code>
28752910 and <code>v</code> is the value at the top of the stack,
28762911
28772912 <p>This function pops the value from the stack.
2878−The assignment is raw,
2913+The assignment is raw;
28792914 that is, it does not invoke metamethods.
28802915
28812916 <p><a name="lua_Reader"></a>
2882−<hr/><h3><code>lua_Reader</code></h3>
2917+<hr /><h3><code>lua_Reader</code></h3>
28832918 <pre>
28842919 typedef const char * (*lua_Reader)
28852920 (lua_State *L, void *data, size_t *size);
@@ -2894,11 +2929,12 @@ passing along its <code>data</code> parameter. · 8 unmodified lines
28942929 The reader must return a pointer to a block of memory
28952930 with a new piece of the chunk
28962931 and set <code>size</code> to the block size.
2897−To signal the end of the chunk, the reader returns <code>NULL</code>.
2932+The block must exist until the reader function is called again.
2933+To signal the end of the chunk, the reader must return <code>NULL</code>.
28982934 The reader function may return pieces of any size greater than zero.
28992935
29002936 <p><a name="lua_remove"></a>
2901−<hr/><h3><code>lua_remove</code></h3>
2937+<hr /><h3><code>lua_remove</code></h3>
29022938 <pre>
29032939 void lua_remove (lua_State *L, int index);
29042940 </pre>
@@ -2910,7 +2946,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
29102946 because a pseudo-index is not an actual stack position.
29112947
29122948 <p><a name="lua_replace"></a>
2913−<hr/><h3><code>lua_replace</code></h3>
2949+<hr /><h3><code>lua_replace</code></h3>
29142950 <pre>
29152951 void lua_replace (lua_State *L, int index);
29162952 </pre>
@@ -2921,7 +2957,7 @@ without shifting any element · 4 unmodified lines
29212957 (therefore replacing the value at the given position).
29222958
29232959 <p><a name="lua_resume"></a>
2924−<hr/><h3><code>lua_resume</code></h3>
2960+<hr /><h3><code>lua_resume</code></h3>
29252961 <pre>
29262962 int lua_resume (lua_State *L, int narg);
29272963 </pre>
@@ -2931,7 +2967,7 @@ without shifting any element · 3 unmodified lines
29312967
29322968 <p>To start a coroutine, you first create a new thread
29332969 (see <a href="#lua_newthread"><code>lua_newthread</code></a>);
2934−then you push on its stack the body function plus any eventual arguments;
2970+then you push on its stack the main function plus any eventual arguments;
29352971 then you call <a href="#lua_resume"><code>lua_resume</code></a>,
29362972 with <code>narg</code> being the number of arguments.
29372973 This call returns when the coroutine suspends or finishes its execution.
@@ -2944,14 +2980,14 @@ without errors, · 6 unmodified lines
29442980 or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
29452981 In case of errors,
29462982 the stack is not unwound,
2947−so you can use the debug API over it;
2983+so you can use the debug API over it.
29482984 The error message is on the top of the stack.
29492985 To restart a coroutine, you put on its stack only the values to
29502986 be passed as results from <code>yield</code>,
29512987 and then call <a href="#lua_resume"><code>lua_resume</code></a>.
29522988
29532989 <p><a name="lua_setallocf"></a>
2954−<hr/><h3><code>lua_setallocf</code></h3>
2990+<hr /><h3><code>lua_setallocf</code></h3>
29552991 <pre>
29562992 void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
29572993 </pre>
@@ -2961,7 +2997,7 @@ and then call <a href="#lua_resume"><code>lua_resume</code></a>. · 3 unmodified lines
29612997 with user data <code>ud</code>.
29622998
29632999 <p><a name="lua_setfenv"></a>
2964−<hr/><h3><code>lua_setfenv</code></h3>
3000+<hr /><h3><code>lua_setfenv</code></h3>
29653001 <pre>
29663002 int lua_setfenv (lua_State *L, int index);
29673003 </pre>
@@ -2971,10 +3007,11 @@ with user data <code>ud</code>. · 3 unmodified lines
29713007 the new environment for the value at the given index.
29723008 If the value at the given index is
29733009 neither a function nor a thread nor a userdata,
2974−<a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0 (false).
3010+<a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0.
3011+Otherwise it returns 1.
29753012
29763013 <p><a name="lua_setfield"></a>
2977−<hr/><h3><code>lua_setfield</code></h3>
3014+<hr /><h3><code>lua_setfield</code></h3>
29783015 <pre>
29793016 void lua_setfield (lua_State *L, int index, const char *k);
29803017 </pre>
@@ -2989,7 +3026,7 @@ As in Lua, this function may trigger a metamethod · 8 unmodified lines
29893026 for the "newindex" event (see <a href="#metatable">2.8</a>).
29903027
29913028 <p><a name="lua_setmetatable"></a>
2992−<hr/><h3><code>lua_setmetatable</code></h3>
3029+<hr /><h3><code>lua_setmetatable</code></h3>
29933030 <pre>
29943031 int lua_setmetatable (lua_State *L, int index);
29953032 </pre>
@@ -3000,7 +3037,7 @@ sets it as the new metatable for the value at the given · 4 unmodified lines
30003037 acceptable index.
30013038
30023039 <p><a name="lua_settable"></a>
3003−<hr/><h3><code>lua_settable</code></h3>
3040+<hr /><h3><code>lua_settable</code></h3>
30043041 <pre>
30053042 void lua_settable (lua_State *L, int index);
30063043 </pre>
@@ -3016,7 +3053,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
30163053 for the "newindex" event (see <a href="#metatable">2.8</a>).
30173054
30183055 <p><a name="lua_settop"></a>
3019−<hr/><h3><code>lua_settop</code></h3>
3056+<hr /><h3><code>lua_settop</code></h3>
30203057 <pre>
30213058 void lua_settop (lua_State *L, int index);
30223059 </pre>
@@ -3029,7 +3066,7 @@ then the new elements are filled with <b>nil</b>. · 6 unmodified lines
30293066 If <code>index</code> is 0, then all stack elements are removed.
30303067
30313068 <p><a name="lua_State"></a>
3032−<hr/><h3><code>lua_State</code></h3>
3069+<hr /><h3><code>lua_State</code></h3>
30333070 <pre>
30343071 typedef struct lua_State lua_State;
30353072 </pre>
@@ -3044,8 +3081,21 @@ All information about a state is kept in this structure. · 8 unmodified lines
30443081 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
30453082 which creates a Lua state from scratch.
30463083
3084+<p><a name="lua_status"></a>
3085+<hr /><h3><code>lua_status</code></h3>
3086+<pre>
3087+ int lua_status (lua_State *L);
3088+</pre>
3089+
3090+
3091+<p>Returns the status of the thread <code>L</code>.
3092+
3093+<p>The status can by 0 for a normal thread,
3094+an error code if the thread finished its execution with an error,
3095+or <code>LUA_YIELD</code> if the thread is suspended.
3096+
30473097 <p><a name="lua_toboolean"></a>
3048−<hr/><h3><code>lua_toboolean</code></h3>
3098+<hr /><h3><code>lua_toboolean</code></h3>
30493099 <pre>
30503100 int lua_toboolean (lua_State *L, int index);
30513101 </pre>
@@ -3058,11 +3108,11 @@ Like all tests in Lua, · 6 unmodified lines
30583108 different from <b>false</b> and <b>nil</b>;
30593109 otherwise it returns 0.
30603110 It also returns 0 when called with a non-valid index.
3061−(If you want to accept only real boolean values,
3111+(If you want to accept only actual boolean values,
30623112 use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
30633113
30643114 <p><a name="lua_tocfunction"></a>
3065−<hr/><h3><code>lua_tocfunction</code></h3>
3115+<hr /><h3><code>lua_tocfunction</code></h3>
30663116 <pre>
30673117 lua_CFunction lua_tocfunction (lua_State *L, int index);
30683118 </pre>
@@ -3073,7 +3123,7 @@ That value must be a C function; · 4 unmodified lines
30733123 otherwise, returns <code>NULL</code>.
30743124
30753125 <p><a name="lua_tointeger"></a>
3076−<hr/><h3><code>lua_tointeger</code></h3>
3126+<hr /><h3><code>lua_tointeger</code></h3>
30773127 <pre>
30783128 lua_Integer lua_tointeger (lua_State *L, int idx);
30793129 </pre>
@@ -3089,7 +3139,7 @@ otherwise, <a href="#lua_tointeger"><code>lua_tointeger</code></a> returns 0. · 9 unmodified lines
30893139 it is truncated in some non-specified way.
30903140
30913141 <p><a name="lua_tolstring"></a>
3092−<hr/><h3><code>lua_tolstring</code></h3>
3142+<hr /><h3><code>lua_tolstring</code></h3>
30933143 <pre>
30943144 const char *lua_tolstring (lua_State *L, int index, size_t *len);
30953145 </pre>
@@ -3105,11 +3155,11 @@ If the value is a number, · 9 unmodified lines
31053155 then <a href="#lua_tolstring"><code>lua_tolstring</code></a> also
31063156 <em>changes the actual value in the stack to a string</em>.
31073157 (This change confuses <a href="#lua_next"><code>lua_next</code></a>
3108−when <a href="#lua_tolstring"><code>lua_tolstring</code></a> is applied to keys.)
3158+when <a href="#lua_tolstring"><code>lua_tolstring</code></a> is applied to keys during a table traversal.)
31093159
31103160 <p><a href="#lua_tolstring"><code>lua_tolstring</code></a> returns a fully aligned pointer
31113161 to a string inside the Lua state.
3112−This string always has a zero (<code>'\0'</code>)
3162+This string always has a zero (`<code>\0</code>&acute;)
31133163 after its last character (as in C),
31143164 but may contain other zeros in its body.
31153165 Because Lua has garbage collection,
@@ -3117,7 +3167,7 @@ there is no guarantee that the pointer returned by <a href="#lua_tolstring"><cod · 1 unmodified line
31173167 will be valid after the corresponding value is removed from the stack.
31183168
31193169 <p><a name="lua_tonumber"></a>
3120−<hr/><h3><code>lua_tonumber</code></h3>
3170+<hr /><h3><code>lua_tonumber</code></h3>
31213171 <pre>
31223172 lua_Number lua_tonumber (lua_State *L, int index);
31233173 </pre>
@@ -3130,23 +3180,23 @@ The Lua value must be a number or a string convertible to number · 6 unmodified lines
31303180 otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0.
31313181
31323182 <p><a name="lua_topointer"></a>
3133−<hr/><h3><code>lua_topointer</code></h3>
3183+<hr /><h3><code>lua_topointer</code></h3>
31343184 <pre>
31353185 const void *lua_topointer (lua_State *L, int index);
31363186 </pre>
31373187
31383188
31393189 <p>Converts the value at the given acceptable index to a generic
3140−C pointer (<code>void *</code>).
3190+C pointer (<code>void*</code>).
31413191 The value may be a userdata, a table, a thread, or a function;
31423192 otherwise, <a href="#lua_topointer"><code>lua_topointer</code></a> returns <code>NULL</code>.
31433193 Lua ensures that different objects return different pointers.
31443194 There is no direct way to convert the pointer back to its original value.
31453195
3146−<p>Typically this function is used for debug information.
3196+<p>Typically this function is used only for debug information.
31473197
31483198 <p><a name="lua_tostring"></a>
3149−<hr/><h3><code>lua_tostring</code></h3>
3199+<hr /><h3><code>lua_tostring</code></h3>
31503200 <pre>
31513201 const char *lua_tostring (lua_State *L, int index);
31523202 </pre>
@@ -3155,19 +3205,19 @@ There is no direct way to convert the pointer back to its original value. · 2 unmodified lines
31553205 <p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.
31563206
31573207 <p><a name="lua_tothread"></a>
3158−<hr/><h3><code>lua_tothread</code></h3>
3208+<hr /><h3><code>lua_tothread</code></h3>
31593209 <pre>
31603210 lua_State *lua_tothread (lua_State *L, int index);
31613211 </pre>
31623212
31633213
31643214 <p>Converts the value at the given acceptable index to a Lua thread
3165−(represented as <code>lua_State *</code>).
3215+(represented as <code>lua_State*</code>).
31663216 This value must be a thread;
31673217 otherwise, the function returns <code>NULL</code>.
31683218
31693219 <p><a name="lua_touserdata"></a>
3170−<hr/><h3><code>lua_touserdata</code></h3>
3220+<hr /><h3><code>lua_touserdata</code></h3>
31713221 <pre>
31723222 void *lua_touserdata (lua_State *L, int index);
31733223 </pre>
@@ -3180,7 +3230,7 @@ returns its pointer. · 6 unmodified lines
31803230 Otherwise, returns <code>NULL</code>.
31813231
31823232 <p><a name="lua_type"></a>
3183−<hr/><h3><code>lua_type</code></h3>
3233+<hr /><h3><code>lua_type</code></h3>
31843234 <pre>
31853235 int lua_type (lua_State *L, int index);
31863236 </pre>
@@ -3199,10 +3249,21 @@ defined in <code>lua.h</code>: · 12 unmodified lines
31993249 <code>LUA_TFUNCTION</code>,
32003250 <code>LUA_TUSERDATA</code>,
32013251 <code>LUA_TTHREAD</code>,
3252+and
32023253 <code>LUA_TLIGHTUSERDATA</code>.
32033254
3255+<p><a name="lua_typename"></a>
3256+<hr /><h3><code>lua_typename</code></h3>
3257+<pre>
3258+ const char *lua_typename (lua_State *L, int tp);
3259+</pre>
3260+
3261+
3262+<p>Returns the name of the type encoded by the value <code>tp</code>,
3263+which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>.
3264+
32043265 <p><a name="lua_Writer"></a>
3205−<hr/><h3><code>lua_Writer</code></h3>
3266+<hr /><h3><code>lua_Writer</code></h3>
32063267 <pre>
32073268 typedef int (*lua_Writer)
32083269 (lua_State *L, const void* p, size_t sz, void* ud);
@@ -3223,19 +3284,19 @@ any other value means an error and stops <a href="#lua_dump"><code>lua_dump</cod · 14 unmodified lines
32233284 calling the writer again.
32243285
32253286 <p><a name="lua_xmove"></a>
3226−<hr/><h3><code>lua_xmove</code></h3>
3287+<hr /><h3><code>lua_xmove</code></h3>
32273288 <pre>
32283289 void lua_xmove (lua_State *from, lua_State *to, int n);
32293290 </pre>
32303291
32313292
3232−<p>Exchange values between different threads of the same global state.
3293+<p>Exchange values between different threads of the <em>same</em> global state.
32333294
32343295 <p>This function pops <code>n</code> values from the stack <code>from</code>,
32353296 and pushes them into the stack <code>to</code>.
32363297
32373298 <p><a name="lua_yield"></a>
3238−<hr/><h3><code>lua_yield</code></h3>
3299+<hr /><h3><code>lua_yield</code></h3>
32393300 <pre>
32403301 int lua_yield (lua_State *L, int nresults);
32413302 </pre>
@@ -3243,7 +3304,7 @@ and pushes them into the stack <code>to</code>. · 1 unmodified line
32433304
32443305 <p>Yields a coroutine.
32453306
3246−<p>This function can only be called as the
3307+<p>This function should only be called as the
32473308 return expression of a C function, as follows:
32483309 <pre>
32493310 return lua_yield (L, nresults);
@@ -3265,20 +3326,19 @@ kinds of debuggers, profilers, and other tools · 15 unmodified lines
32653326 that need "inside information" from the interpreter.
32663327
32673328 <p><a name="lua_Debug"></a>
3268−<hr/><h3><code>lua_Debug</code></h3>
3329+<hr /><h3><code>lua_Debug</code></h3>
32693330 <pre>
32703331 typedef struct lua_Debug {
32713332 int event;
3272− const char *name; /* (n) */
3273− const char *namewhat; /* (n) */
3274− const char *what; /* (S) */
3275− const char *source; /* (S) */
3276− int currentline; /* (l) */
3277− int nups; /* (u) number of upvalues */
3278− int linedefined; /* (S) */
3279− int lastlinedefined; /* (S) */
3333+ const char *name; /* (n) */
3334+ const char *namewhat; /* (n) */
3335+ const char *what; /* (S) */
3336+ const char *source; /* (S) */
3337+ int currentline; /* (l) */
3338+ int nups; /* (u) number of upvalues */
3339+ int linedefined; /* (S) */
3340+ int lastlinedefined; /* (S) */
32803341 char short_src[LUA_IDSIZE]; /* (S) */
3281−
32823342 /* private part */
32833343 ...
32843344 } lua_Debug;
@@ -3295,36 +3355,37 @@ call <a href="#lua_getinfo"><code>lua_getinfo</code></a>. · 10 unmodified lines
32953355
32963356 <p>The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:
32973357 <ul>
3298−<li><b><code>source</code></b>
3358+<li><b><code>source</code></b> ---
32993359 If the function was defined in a string,
33003360 then <code>source</code> is that string.
33013361 If the function was defined in a file,
33023362 then <code>source</code> starts with a `<code>@</code>&acute; followed by the file name.
33033363
3304−<p><li><b><code>short_src</code></b>
3305−A "printable" version of <code>source</code>, to be used in error messages.
3364+<p><li><b><code>short_src</code></b> ---
3365+a "printable" version of <code>source</code>, to be used in error messages.
33063366
3307−<p><li><b><code>linedefined</code></b>
3367+<p><li><b><code>linedefined</code></b> ---
33083368 the line number where the definition of the function starts.
33093369
3310−<p><li><b><code>lastlinedefined</code></b>
3370+<p><li><b><code>lastlinedefined</code></b> ---
33113371 the line number where the definition of the function ends.
33123372
3313−<p><li><b><code>what</code></b> the string <code>"Lua"</code> if this is a Lua function,
3314−<code>"C"</code> if this is a C function,
3315−<code>"main"</code> if this is the main part of a chunk,
3316−and <code>"tail"</code> if this was a function that did a tail call.
3373+<p><li><b><code>what</code></b> ---
3374+the string <code>"Lua"</code> if the function is a Lua function,
3375+<code>"C"</code> if it is a C function,
3376+<code>"main"</code> if it is the main part of a chunk,
3377+and <code>"tail"</code> if it was a function that did a tail call.
33173378 In the latter case,
3318−Lua has no other information about this function.
3379+Lua has no other information about the function.
33193380
3320−<p><li><b><code>currentline</code></b>
3381+<p><li><b><code>currentline</code></b> ---
33213382 the current line where the given function is executing.
33223383 When no line information is available,
33233384 <code>currentline</code> is set to <em>-1</em>.
33243385
3325−<p><li><b><code>name</code></b>
3386+<p><li><b><code>name</code></b> ---
33263387 a reasonable name for the given function.
3327−Because functions in Lua are first class values,
3388+Because functions in Lua are first-class values,
33283389 they do not have a fixed name:
33293390 Some functions may be the value of multiple global variables,
33303391 while others may be stored only in a table field.
@@ -3333,21 +3394,21 @@ called to find a suitable name. · 2 unmodified lines
33333394 If it cannot find a name,
33343395 then <code>name</code> is set to <code>NULL</code>.
33353396
3336−<p><li><b><code>namewhat</code></b>
3337−Explains the <code>name</code> field.
3397+<p><li><b><code>namewhat</code></b> ---
3398+explains the <code>name</code> field.
33383399 The value of <code>namewhat</code> can be
33393400 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
33403401 <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
33413402 according to how the function was called.
33423403 (Lua uses the empty string when no other option seems to apply.)
33433404
3344−<p><li><b><code>nups</code></b>
3345−The number of upvalues of the function.
3405+<p><li><b><code>nups</code></b> ---
3406+the number of upvalues of the function.
33463407
33473408 <p></ul>
33483409
33493410 <p><a name="lua_gethook"></a>
3350−<hr/><h3><code>lua_gethook</code></h3>
3411+<hr /><h3><code>lua_gethook</code></h3>
33513412 <pre>
33523413 lua_Hook lua_gethook (lua_State *L);
33533414 </pre>
@@ -3356,7 +3417,7 @@ The number of upvalues of the function. · 2 unmodified lines
33563417 <p>Returns the current hook function.
33573418
33583419 <p><a name="lua_gethookcount"></a>
3359−<hr/><h3><code>lua_gethookcount</code></h3>
3420+<hr /><h3><code>lua_gethookcount</code></h3>
33603421 <pre>
33613422 int lua_gethookcount (lua_State *L);
33623423 </pre>
@@ -3365,7 +3426,7 @@ The number of upvalues of the function. · 2 unmodified lines
33653426 <p>Returns the current hook count.
33663427
33673428 <p><a name="lua_gethookmask"></a>
3368−<hr/><h3><code>lua_gethookmask</code></h3>
3429+<hr /><h3><code>lua_gethookmask</code></h3>
33693430 <pre>
33703431 int lua_gethookmask (lua_State *L);
33713432 </pre>
@@ -3374,7 +3435,7 @@ The number of upvalues of the function. · 2 unmodified lines
33743435 <p>Returns the current hook mask.
33753436
33763437 <p><a name="lua_getinfo"></a>
3377−<hr/><h3><code>lua_getinfo</code></h3>
3438+<hr /><h3><code>lua_getinfo</code></h3>
33783439 <pre>
33793440 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
33803441 </pre>
@@ -3408,7 +3469,7 @@ you can write the following code: · 27 unmodified lines
34083469 </pre>
34093470
34103471 <p><a name="lua_getlocal"></a>
3411−<hr/><h3><code>lua_getlocal</code></h3>
3472+<hr /><h3><code>lua_getlocal</code></h3>
34123473 <pre>
34133474 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
34143475 </pre>
@@ -3421,7 +3482,7 @@ given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>). · 6 unmodified lines
34213482 The index <code>n</code> selects which local variable to inspect
34223483 (1 is the first parameter or active local variable, and so on,
34233484 until the last active local variable).
3424−<a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack,
3485+<a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack
34253486 and returns its name.
34263487
34273488 <p>Variable names starting with `<code>(</code>&acute; (open parentheses)
@@ -3433,7 +3494,7 @@ when the index is greater than · 5 unmodified lines
34333494 the number of active local variables.
34343495
34353496 <p><a name="lua_getstack"></a>
3436−<hr/><h3><code>lua_getstack</code></h3>
3497+<hr /><h3><code>lua_getstack</code></h3>
34373498 <pre>
34383499 int lua_getstack (lua_State *L, int level, lua_Debug *ar);
34393500 </pre>
@@ -3451,7 +3512,7 @@ when called with a level greater than the stack depth, · 11 unmodified lines
34513512 it returns 0.
34523513
34533514 <p><a name="lua_getupvalue"></a>
3454−<hr/><h3><code>lua_getupvalue</code></h3>
3515+<hr /><h3><code>lua_getupvalue</code></h3>
34553516 <pre>
34563517 const char *lua_getupvalue (lua_State *L, int funcindex, int n);
34573518 </pre>
@@ -3466,7 +3527,8 @@ pushes the upvalue's value onto the stack, · 8 unmodified lines
34663527 and returns its name.
34673528 <code>funcindex</code> points to the closure in the stack.
34683529 (Upvalues have no particular order,
3469−as they are active through the whole function.)
3530+as they are active through the whole function.
3531+So, they are numbered in an arbitrary order.)
34703532
34713533 <p>Returns <code>NULL</code> (and pushes nothing)
34723534 when the index is greater than the number of upvalues.
@@ -3474,7 +3536,7 @@ For C functions, this function uses the empty string <code>""</code> · 1 unmodified line
34743536 as a name for all upvalues.
34753537
34763538 <p><a name="lua_Hook"></a>
3477−<hr/><h3><code>lua_Hook</code></h3>
3539+<hr /><h3><code>lua_Hook</code></h3>
34783540 <pre>
34793541 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
34803542 </pre>
@@ -3502,7 +3564,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 21 unmodified lines
35023564 that execution occurs without any calls to hooks.
35033565
35043566 <p><a name="lua_sethook"></a>
3505−<hr/><h3><code>lua_sethook</code></h3>
3567+<hr /><h3><code>lua_sethook</code></h3>
35063568 <pre>
35073569 int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
35083570 </pre>
@@ -3512,7 +3574,7 @@ that execution occurs without any calls to hooks. · 3 unmodified lines
35123574
35133575 <p><code>func</code> is the hook function.
35143576 <code>mask</code> specifies on which events the hook will be called:
3515−It is formed by a disjunction of the constants
3577+It is formed by a bitwise or of the constants
35163578 <code>LUA_MASKCALL</code>,
35173579 <code>LUA_MASKRET</code>,
35183580 <code>LUA_MASKLINE</code>,
@@ -3522,9 +3584,11 @@ includes <code>LUA_MASKCOUNT</code>. · 3 unmodified lines
35223584 For each event, the hook is called as explained below:
35233585 <ul>
35243586 <li><b>The call hook</b> is called when the interpreter calls a function.
3525−The hook is called just after Lua enters the new function.
3587+The hook is called just after Lua enters the new function,
3588+before the function gets its arguments.
35263589 <li><b>The return hook</b> is called when the interpreter returns from a function.
35273590 The hook is called just before Lua leaves the function.
3591+You have no access to the values to be returned by the function.
35283592 <li><b>The line hook</b> is called when the interpreter is about to
35293593 start the execution of a new line of code,
35303594 or when it jumps back in the code (even to the same line).
@@ -3537,14 +3601,14 @@ or when it jumps back in the code (even to the same line). · 6 unmodified lines
35373601 <p>A hook is disabled by setting <code>mask</code> to zero.
35383602
35393603 <p><a name="lua_setlocal"></a>
3540−<hr/><h3><code>lua_setlocal</code></h3>
3604+<hr /><h3><code>lua_setlocal</code></h3>
35413605 <pre>
35423606 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
35433607 </pre>
35443608
35453609
35463610 <p>Sets the value of a local variable of a given activation record.
3547−Parameters <code>ar</code> and <code>n</code> are like in <a href="#lua_getlocal"><code>lua_getlocal</code></a>
3611+Parameters <code>ar</code> and <code>n</code> are as in <a href="#lua_getlocal"><code>lua_getlocal</code></a>
35483612 (see <a href="#lua_getlocal"></a>).
35493613 <a href="#lua_setlocal"><code>lua_setlocal</code></a> assigns the value at the top of the stack
35503614 to the variable and returns its name.
@@ -3555,14 +3619,14 @@ when the index is greater than · 4 unmodified lines
35553619 the number of active local variables.
35563620
35573621 <p><a name="lua_setupvalue"></a>
3558−<hr/><h3><code>lua_setupvalue</code></h3>
3622+<hr /><h3><code>lua_setupvalue</code></h3>
35593623 <pre>
35603624 const char *lua_setupvalue (lua_State *L, int funcindex, int n);
35613625 </pre>
35623626
35633627
35643628 <p>Sets the value of a closure's upvalue.
3565−Parameters <code>funcindex</code> and <code>n</code> are like in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
3629+Parameters <code>funcindex</code> and <code>n</code> are as in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
35663630 (see <a href="#lua_getupvalue"></a>).
35673631 It assigns the value at the top of the stack
35683632 to the upvalue and returns its name.
@@ -3586,17 +3650,17 @@ common tasks. · 17 unmodified lines
35863650 are defined in header file <code>lauxlib.h</code> and
35873651 have a prefix <code>luaL_</code>.
35883652
3589−<p>All functions in the auxiliary library are build on
3590−top of the basic API, so they provide nothing that cannot
3591−be done with that API.
3653+<p>All functions in the auxiliary library are built on
3654+top of the basic API,
3655+and so they provide nothing that cannot be done with that API.
35923656
35933657 <p>Several functions in the auxiliary library are used to
35943658 check C function arguments.
35953659 Their names are always <code>luaL_check*</code> or <code>luaL_opt*</code>.
3596−All those functions raise an error if the check is not satisfied.
3660+All of these functions raise an error if the check is not satisfied.
35973661 Because the error message is formatted for arguments
35983662 (e.g., <code>"bad argument #1"</code>),
3599−you should not use those functions for other stack values.
3663+you should not use these functions for other stack values.
36003664
36013665 <p><a name="4.1"></a><h2>4.1 - Functions and Types</h2>
36023666
@@ -3604,7 +3668,7 @@ you should not use those functions for other stack values. · 1 unmodified line
36043668 in alphabetical order.
36053669
36063670 <p><a name="luaL_addchar"></a>
3607−<hr/><h3><code>luaL_addchar</code></h3>
3671+<hr /><h3><code>luaL_addchar</code></h3>
36083672 <pre>
36093673 void luaL_addchar (luaL_Buffer B, char c);
36103674 </pre>
@@ -3614,7 +3678,7 @@ in alphabetical order. · 3 unmodified lines
36143678 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
36153679
36163680 <p><a name="luaL_addlstring"></a>
3617−<hr/><h3><code>luaL_addlstring</code></h3>
3681+<hr /><h3><code>luaL_addlstring</code></h3>
36183682 <pre>
36193683 void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
36203684 </pre>
@@ -3623,9 +3687,10 @@ in alphabetical order. · 2 unmodified lines
36233687 <p>Adds the string pointed by <code>s</code> with length <code>l</code> to
36243688 the buffer <code>B</code>
36253689 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3690+The string may contain embedded zeros.
36263691
36273692 <p><a name="luaL_addsize"></a>
3628−<hr/><h3><code>luaL_addsize</code></h3>
3693+<hr /><h3><code>luaL_addsize</code></h3>
36293694 <pre>
36303695 void luaL_addsize (luaL_Buffer B, size_t n);
36313696 </pre>
@@ -3636,7 +3701,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 4 unmodified lines
36363701 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
36373702
36383703 <p><a name="luaL_addstring"></a>
3639−<hr/><h3><code>luaL_addstring</code></h3>
3704+<hr /><h3><code>luaL_addstring</code></h3>
36403705 <pre>
36413706 void luaL_addstring (luaL_Buffer *B, const char *s);
36423707 </pre>
@@ -3645,9 +3710,10 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 2 unmodified lines
36453710 <p>Adds the zero-terminated string pointed by <code>s</code>
36463711 to the buffer <code>B</code>
36473712 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3713+The string may not contain embedded zeros.
36483714
36493715 <p><a name="luaL_addvalue"></a>
3650−<hr/><h3><code>luaL_addvalue</code></h3>
3716+<hr /><h3><code>luaL_addvalue</code></h3>
36513717 <pre>
36523718 void luaL_addvalue (luaL_Buffer *B);
36533719 </pre>
@@ -3663,7 +3729,7 @@ be called with an extra element on the stack, · 9 unmodified lines
36633729 which is the value to be added to the buffer.
36643730
36653731 <p><a name="luaL_argcheck"></a>
3666−<hr/><h3><code>luaL_argcheck</code></h3>
3732+<hr /><h3><code>luaL_argcheck</code></h3>
36673733 <pre>
36683734 void luaL_argcheck (lua_State *L, int cond, int numarg,
36693735 const char *extramsg);
@@ -3671,12 +3737,12 @@ which is the value to be added to the buffer. · 1 unmodified line
36713737
36723738
36733739 <p>Checks whether <code>cond</code> is true.
3674−If not, raise an error with message
3740+If not, raises an error with message
36753741 <code>"bad argument #&#060;numarg> to &#060;func> (&#060;extramsg>)"</code>,
36763742 where <code>func</code> is retrieved from the call stack.
36773743
36783744 <p><a name="luaL_argerror"></a>
3679−<hr/><h3><code>luaL_argerror</code></h3>
3745+<hr /><h3><code>luaL_argerror</code></h3>
36803746 <pre>
36813747 int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
36823748 </pre>
@@ -3686,10 +3752,12 @@ where <code>func</code> is retrieved from the call stack. · 3 unmodified lines
36863752 <code>"bad argument #&#060;numarg> to &#060;func> (&#060;extramsg>)"</code>,
36873753 where <code>func</code> is retrieved from the call stack.
36883754
3689−<p>This function never returns.
3755+<p>This function never returns,
3756+but it is an idiom to use it as <code>return luaL_argerror ...</code>
3757+in C functions.
36903758
36913759 <p><a name="luaL_Buffer"></a>
3692−<hr/><h3><code>luaL_Buffer</code></h3>
3760+<hr /><h3><code>luaL_Buffer</code></h3>
36933761 <pre>
36943762 typedef struct luaL_Buffer luaL_Buffer;
36953763 </pre>
@@ -3700,21 +3768,23 @@ where <code>func</code> is retrieved from the call stack. · 4 unmodified lines
37003768 <p>A string buffer allows C code to build Lua strings piecemeal.
37013769 Its pattern of use is as follows:
37023770 <ul>
3703−<li> Fist you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.
3704−<li> Then you initialize it with a call <code>luaL_buffinit(L, &#038;b);</code>.
3771+<li> First you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.
3772+<li> Then you initialize it with a call <code>luaL_buffinit(L, &#038;b)</code>.
37053773 <li> Then you add string pieces to the buffer calling any of
37063774 the <code>luaL_add*</code> functions.
37073775 <li> You finish calling <code>luaL_pushresult(&#038;b)</code>.
37083776 That call leaves the final string on the top of the stack.
37093777 </ul>
37103778
3711−<p>During its normal operation a string buffer uses a
3712−variable number of stack slots.
3779+<p>During its normal operation,
3780+a string buffer uses a variable number of stack slots.
37133781 So, while using a buffer, you cannot assume that you know where
3714−is the top of the stack.
3715−You can use the stack between successive calls to buffer operations,
3716−as long as that use is balanced, that is,
3717−when you call a buffer operation the stack is at the same level
3782+the top of the stack is.
3783+You can use the stack between successive calls to buffer operations
3784+as long as that use is balanced;
3785+that is,
3786+when you call a buffer operation,
3787+the stack is at the same level
37183788 it was immediately after the previous buffer operation.
37193789 (The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)
37203790 After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a> the stack is back to its
@@ -3722,7 +3792,7 @@ level when the buffer was initialized, · 1 unmodified line
37223792 plus the final string on its top.
37233793
37243794 <p><a name="luaL_buffinit"></a>
3725−<hr/><h3><code>luaL_buffinit</code></h3>
3795+<hr /><h3><code>luaL_buffinit</code></h3>
37263796 <pre>
37273797 void luaL_buffinit (lua_State *L, luaL_Buffer *B);
37283798 </pre>
@@ -3734,7 +3804,7 @@ the buffer must be declared as a variable · 5 unmodified lines
37343804 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
37353805
37363806 <p><a name="luaL_callmeta"></a>
3737−<hr/><h3><code>luaL_callmeta</code></h3>
3807+<hr /><h3><code>luaL_callmeta</code></h3>
37383808 <pre>
37393809 int luaL_callmeta (lua_State *L, int obj, const char *e);
37403810 </pre>
@@ -3744,53 +3814,54 @@ the buffer must be declared as a variable · 3 unmodified lines
37443814
37453815 <p>If the object at index <code>obj</code> has a metatable and that
37463816 metatable has a field <code>e</code>,
3747−calls that field passing the object as argument.
3748−In that case the function returns 1 and pushes on the
3817+this function calls that field and passes the object as its only argument.
3818+In that case this function returns 1 and pushes on the
37493819 stack the value returned by the call.
3750−If there is no metatable or no metamethod returns 0
3751−(without pushing any value on the stack).
3820+If there is no metatable or no metamethod,
3821+this function returns 0 (without pushing any value on the stack).
37523822
37533823 <p><a name="luaL_checkany"></a>
3754−<hr/><h3><code>luaL_checkany</code></h3>
3824+<hr /><h3><code>luaL_checkany</code></h3>
37553825 <pre>
37563826 void luaL_checkany (lua_State *L, int narg);
37573827 </pre>
37583828
37593829
3760−<p>Checks whether the function has an argument <code>narg</code>.
3830+<p>Checks whether the function has an argument
3831+of any type (including <b>nil</b>) at position <code>narg</code>.
37613832
37623833 <p><a name="luaL_checkint"></a>
3763−<hr/><h3><code>luaL_checkint</code></h3>
3834+<hr /><h3><code>luaL_checkint</code></h3>
37643835 <pre>
37653836 int luaL_checkint (lua_State *L, int narg);
37663837 </pre>
37673838
37683839
37693840 <p>Checks whether the function argument <code>narg</code> is a number
3770−and returns that number casted to an <code>int</code>.
3841+and returns that number cast to an <code>int</code>.
37713842
37723843 <p><a name="luaL_checkinteger"></a>
3773−<hr/><h3><code>luaL_checkinteger</code></h3>
3844+<hr /><h3><code>luaL_checkinteger</code></h3>
37743845 <pre>
3775− lua_Integer luaL_checkinteger (lua_State *L, int numArg);
3846+ lua_Integer luaL_checkinteger (lua_State *L, int narg);
37763847 </pre>
37773848
37783849
37793850 <p>Checks whether the function argument <code>narg</code> is a number
3780−and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
3851+and returns that number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
37813852
37823853 <p><a name="luaL_checklong"></a>
3783−<hr/><h3><code>luaL_checklong</code></h3>
3854+<hr /><h3><code>luaL_checklong</code></h3>
37843855 <pre>
37853856 long luaL_checklong (lua_State *L, int narg);
37863857 </pre>
37873858
37883859
37893860 <p>Checks whether the function argument <code>narg</code> is a number
3790−and returns that number casted to a <code>long</code>.
3861+and returns that number cast to a <code>long</code>.
37913862
37923863 <p><a name="luaL_checklstring"></a>
3793−<hr/><h3><code>luaL_checklstring</code></h3>
3864+<hr /><h3><code>luaL_checklstring</code></h3>
37943865 <pre>
37953866 const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);
37963867 </pre>
@@ -3798,11 +3869,11 @@ and returns that number casted to a <code>long</code>. · 1 unmodified line
37983869
37993870 <p>Checks whether the function argument <code>narg</code> is a string
38003871 and returns that string;
3801−if <code>l</code> is not <code>NULL</code> fills the position <code>*l</code>
3872+if <code>l</code> is not <code>NULL</code> fills <code>*l</code>
38023873 with the string's length.
38033874
38043875 <p><a name="luaL_checknumber"></a>
3805−<hr/><h3><code>luaL_checknumber</code></h3>
3876+<hr /><h3><code>luaL_checknumber</code></h3>
38063877 <pre>
38073878 lua_Number luaL_checknumber (lua_State *L, int numArg);
38083879 </pre>
@@ -3812,7 +3883,7 @@ with the string's length. · 3 unmodified lines
38123883 and returns that number.
38133884
38143885 <p><a name="luaL_checkoption"></a>
3815−<hr/><h3><code>luaL_checkoption</code></h3>
3886+<hr /><h3><code>luaL_checkoption</code></h3>
38163887 <pre>
38173888 int luaL_checkoption (lua_State *L, int narg, const char *def,
38183889 const char *const lst[]);
@@ -3830,8 +3901,12 @@ the function has no argument <code>narg</code> or if that argument is <b>nil</b> · 11 unmodified lines
38303901 Raises an error if the argument is not a string or
38313902 if the string cannot be found.
38323903
3904+<p>This is a useful function for mapping strings to C enums.
3905+The usual interfaces in Lua libraries is to use strings instead of numbers
3906+to select options.
3907+
38333908 <p><a name="luaL_checkstack"></a>
3834−<hr/><h3><code>luaL_checkstack</code></h3>
3909+<hr /><h3><code>luaL_checkstack</code></h3>
38353910 <pre>
38363911 void luaL_checkstack (lua_State *L, int sz, const char *msg);
38373912 </pre>
@@ -3842,7 +3917,7 @@ raising an error if the stack cannot grow to that size. · 4 unmodified lines
38423917 <code>msg</code> is an additional text to go into the error message.
38433918
38443919 <p><a name="luaL_checkstring"></a>
3845−<hr/><h3><code>luaL_checkstring</code></h3>
3920+<hr /><h3><code>luaL_checkstring</code></h3>
38463921 <pre>
38473922 const char *luaL_checkstring (lua_State *L, int narg);
38483923 </pre>
@@ -3852,7 +3927,7 @@ raising an error if the stack cannot grow to that size. · 3 unmodified lines
38523927 and returns that string.
38533928
38543929 <p><a name="luaL_checktype"></a>
3855−<hr/><h3><code>luaL_checktype</code></h3>
3930+<hr /><h3><code>luaL_checktype</code></h3>
38563931 <pre>
38573932 void luaL_checktype (lua_State *L, int narg, int t);
38583933 </pre>
@@ -3861,7 +3936,7 @@ and returns that string. · 2 unmodified lines
38613936 <p>Checks whether the function argument <code>narg</code> has type <code>t</code>.
38623937
38633938 <p><a name="luaL_checkudata"></a>
3864−<hr/><h3><code>luaL_checkudata</code></h3>
3939+<hr /><h3><code>luaL_checkudata</code></h3>
38653940 <pre>
38663941 void *luaL_checkudata (lua_State *L, int ud, const char *tname);
38673942 </pre>
@@ -3871,7 +3946,7 @@ and returns that string. · 3 unmodified lines
38713946 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
38723947
38733948 <p><a name="luaL_error"></a>
3874−<hr/><h3><code>luaL_error</code></h3>
3949+<hr /><h3><code>luaL_error</code></h3>
38753950 <pre>
38763951 int luaL_error (lua_State *L, const char *fmt, ...);
38773952 </pre>
@@ -3885,10 +3960,12 @@ It also adds at the beginning of the message the file name and · 7 unmodified lines
38853960 the line number where the error occurred,
38863961 if that information is available.
38873962
3888−<p>This function never returns.
3963+<p>This function never returns,
3964+but it is an idiom to use it as <code>return luaL_error ...</code>
3965+in C functions.
38893966
38903967 <p><a name="luaL_getmetafield"></a>
3891−<hr/><h3><code>luaL_getmetafield</code></h3>
3968+<hr /><h3><code>luaL_getmetafield</code></h3>
38923969 <pre>
38933970 int luaL_getmetafield (lua_State *L, int obj, const char *e);
38943971 </pre>
@@ -3898,10 +3975,10 @@ if that information is available. · 3 unmodified lines
38983975 of the object at index <code>obj</code>.
38993976 If the object does not have a metatable,
39003977 or if the metatable does not have that field,
3901−returns 0 (false) and pushes nothing.
3978+returns 0 and pushes nothing.
39023979
39033980 <p><a name="luaL_getmetatable"></a>
3904−<hr/><h3><code>luaL_getmetatable</code></h3>
3981+<hr /><h3><code>luaL_getmetatable</code></h3>
39053982 <pre>
39063983 void luaL_getmetatable (lua_State *L, const char *tname);
39073984 </pre>
@@ -3911,19 +3988,20 @@ returns 0 (false) and pushes nothing. · 3 unmodified lines
39113988 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
39123989
39133990 <p><a name="luaL_gsub"></a>
3914−<hr/><h3><code>luaL_gsub</code></h3>
3991+<hr /><h3><code>luaL_gsub</code></h3>
39153992 <pre>
39163993 const char *luaL_gsub (lua_State *L, const char *s,
39173994 const char *p, const char *r);
39183995 </pre>
39193996
39203997
3921−<p>Creates a copy of string <code>s</code> changing any occurrence of <code>p</code>
3922−by the string <code>r</code>.
3998+<p>Creates a copy of string <code>s</code> by replacing any occurrence
3999+any occurrence of the string <code>p</code>
4000+wth the string <code>r</code>.
39234001 Pushes the resulting string on the stack and returns it.
39244002
39254003 <p><a name="luaL_loadbuffer"></a>
3926−<hr/><h3><code>luaL_loadbuffer</code></h3>
4004+<hr /><h3><code>luaL_loadbuffer</code></h3>
39274005 <pre>
39284006 int luaL_loadbuffer (lua_State *L, const char *buff,
39294007 size_t sz, const char *name);
@@ -3939,7 +4017,7 @@ buffer pointed by <code>buff</code> with size <code>sz</code>. · 9 unmodified lines
39394017 used for debug information and error messages.
39404018
39414019 <p><a name="luaL_loadfile"></a>
3942−<hr/><h3><code>luaL_loadfile</code></h3>
4020+<hr /><h3><code>luaL_loadfile</code></h3>
39434021 <pre>
39444022 int luaL_loadfile (lua_State *L, const char *filename);
39454023 </pre>
@@ -3948,14 +4026,16 @@ used for debug information and error messages. · 2 unmodified lines
39484026 <p>Loads a file as a Lua chunk.
39494027 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file
39504028 named <code>filename</code>.
3951−If the file's first line starts with a <code>#</code> it is ignored.
4029+If <code>filename</code> is <code>NULL</code>,
4030+then it loads from the standard input.
4031+The first line in the file is ignored if it starts with a <code>#</code>.
39524032
39534033 <p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>,
39544034 but it has an extra error code <code>LUA_ERRFILE</code>
3955−if it cannot open the file.
4035+if it cannot open/read the file.
39564036
39574037 <p><a name="luaL_loadstring"></a>
3958−<hr/><h3><code>luaL_loadstring</code></h3>
4038+<hr /><h3><code>luaL_loadstring</code></h3>
39594039 <pre>
39604040 int luaL_loadstring (lua_State *L, const char *s);
39614041 </pre>
@@ -3968,24 +4048,24 @@ the zero-terminated string <code>s</code>. · 6 unmodified lines
39684048 <p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
39694049
39704050 <p><a name="luaL_newmetatable"></a>
3971−<hr/><h3><code>luaL_newmetatable</code></h3>
4051+<hr /><h3><code>luaL_newmetatable</code></h3>
39724052 <pre>
39734053 int luaL_newmetatable (lua_State *L, const char *tname);
39744054 </pre>
39754055
39764056
3977−<p>If the register already has the key <code>"tname"</code>,
4057+<p>If the registry already has the key <code>"tname"</code>,
39784058 returns 0.
39794059 Otherwise,
3980−creates a new table to be used as metatables for userdata,
3981−adds it to the register with key <code>"tname"</code>,
4060+creates a new table to be used as a metatable for userdata,
4061+adds it to the registry with key <code>"tname"</code>,
39824062 and returns 1.
39834063
39844064 <p>In both cases pushes on the stack the final value associated
39854065 with <code>"tname"</code> in the registry.
39864066
39874067 <p><a name="luaL_newstate"></a>
3988−<hr/><h3><code>luaL_newstate</code></h3>
4068+<hr /><h3><code>luaL_newstate</code></h3>
39894069 <pre>
39904070 lua_State *luaL_newstate (void);
39914071 </pre>
@@ -3993,7 +4073,7 @@ with <code>"tname"</code> in the registry. · 1 unmodified line
39934073
39944074 <p>Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an
39954075 allocation function based on the standard C <code>realloc</code> function
3996−and setting a panic function ((see <a href="#lua_atpanic"><code>lua_atpanic</code></a>)) that prints
4076+and setting a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
39974077 an error message to the standard error output in case of fatal
39984078 errors.
39994079
@@ -4001,46 +4081,46 @@ errors. · 1 unmodified line
40014081 or <code>NULL</code> if there is a memory allocation error.
40024082
40034083 <p><a name="luaL_optint"></a>
4004−<hr/><h3><code>luaL_optint</code></h3>
4084+<hr /><h3><code>luaL_optint</code></h3>
40054085 <pre>
40064086 int luaL_optint (lua_State *L, int narg, int d);
40074087 </pre>
40084088
40094089
40104090 <p>If the function argument <code>narg</code> is a number,
4011−returns that number casted to an <code>int</code>.
4091+returns that number cast to an <code>int</code>.
40124092 If that argument is absent or is <b>nil</b>,
40134093 returns <code>d</code>.
4014−Otherwise, raise an error.
4094+Otherwise, raises an error.
40154095
40164096 <p><a name="luaL_optinteger"></a>
4017−<hr/><h3><code>luaL_optinteger</code></h3>
4097+<hr /><h3><code>luaL_optinteger</code></h3>
40184098 <pre>
40194099 lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d);
40204100 </pre>
40214101
40224102
40234103 <p>If the function argument <code>narg</code> is a number,
4024−returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
4104+returns that number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
40254105 If that argument is absent or is <b>nil</b>,
40264106 returns <code>d</code>.
4027−Otherwise, raise an error.
4107+Otherwise, raises an error.
40284108
40294109 <p><a name="luaL_optlong"></a>
4030−<hr/><h3><code>luaL_optlong</code></h3>
4110+<hr /><h3><code>luaL_optlong</code></h3>
40314111 <pre>
40324112 long luaL_optlong (lua_State *L, int narg, long d);
40334113 </pre>
40344114
40354115
40364116 <p>If the function argument <code>narg</code> is a number,
4037−returns that number casted to a <code>long</code>.
4117+returns that number cast to a <code>long</code>.
40384118 If that argument is absent or is <b>nil</b>,
40394119 returns <code>d</code>.
4040−Otherwise, raise an error.
4120+Otherwise, raises an error.
40414121
40424122 <p><a name="luaL_optlstring"></a>
4043−<hr/><h3><code>luaL_optlstring</code></h3>
4123+<hr /><h3><code>luaL_optlstring</code></h3>
40444124 <pre>
40454125 const char *luaL_optlstring (lua_State *L, int numArg,
40464126 const char *d, size_t *l);
@@ -4051,13 +4131,13 @@ Otherwise, raise an error. · 4 unmodified lines
40514131 returns that string.
40524132 If that argument is absent or is <b>nil</b>,
40534133 returns <code>d</code>.
4054−Otherwise, raise an error.
4134+Otherwise, raises an error.
40554135
4056−<p>If <code>l</code> is not <code>NULL</code> fills the position <code>*l</code>
4057−with the results's length.
4136+<p>If <code>l</code> is not <code>NULL</code>,
4137+fills the position <code>*l</code> with the results's length.
40584138
40594139 <p><a name="luaL_optnumber"></a>
4060−<hr/><h3><code>luaL_optnumber</code></h3>
4140+<hr /><h3><code>luaL_optnumber</code></h3>
40614141 <pre>
40624142 lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d);
40634143 </pre>
@@ -4067,10 +4147,10 @@ with the results's length. · 3 unmodified lines
40674147 returns that number.
40684148 If that argument is absent or is <b>nil</b>,
40694149 returns <code>d</code>.
4070−Otherwise, raise an error.
4150+Otherwise, raises an error.
40714151
40724152 <p><a name="luaL_optstring"></a>
4073−<hr/><h3><code>luaL_optstring</code></h3>
4153+<hr /><h3><code>luaL_optstring</code></h3>
40744154 <pre>
40754155 const char *luaL_optstring (lua_State *L, int narg, const char *d);
40764156 </pre>
@@ -4080,24 +4160,24 @@ Otherwise, raise an error. · 3 unmodified lines
40804160 returns that string.
40814161 If that argument is absent or is <b>nil</b>,
40824162 returns <code>d</code>.
4083−Otherwise, raise an error.
4163+Otherwise, raises an error.
40844164
40854165 <p><a name="luaL_prepbuffer"></a>
4086−<hr/><h3><code>luaL_prepbuffer</code></h3>
4166+<hr /><h3><code>luaL_prepbuffer</code></h3>
40874167 <pre>
40884168 char *luaL_prepbuffer (luaL_Buffer *B);
40894169 </pre>
40904170
40914171
40924172 <p>Returns an address to a space of size <code>LUAL_BUFFERSIZE</code>
4093−wherein you can copy a string to be added to buffer <code>B</code>
4173+where you can copy a string to be added to buffer <code>B</code>
40944174 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
40954175 After copying the string into that space you must call
40964176 <a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add
40974177 it to the buffer.
40984178
40994179 <p><a name="luaL_pushresult"></a>
4100−<hr/><h3><code>luaL_pushresult</code></h3>
4180+<hr /><h3><code>luaL_pushresult</code></h3>
41014181 <pre>
41024182 void luaL_pushresult (luaL_Buffer *B);
41034183 </pre>
@@ -4107,7 +4187,7 @@ it to the buffer. · 3 unmodified lines
41074187 the top of the stack.
41084188
41094189 <p><a name="luaL_ref"></a>
4110−<hr/><h3><code>luaL_ref</code></h3>
4190+<hr /><h3><code>luaL_ref</code></h3>
41114191 <pre>
41124192 int luaL_ref (lua_State *L, int t);
41134193 </pre>
@@ -4118,19 +4198,19 @@ in the table at index <code>t</code>, · 4 unmodified lines
41184198 for the object at the top of the stack (and pops the object).
41194199
41204200 <p>A reference is a unique integer key.
4121−As long as you do not add integer keys into table <code>t</code>,
4201+As long as you do not manually add integer keys into table <code>t</code>,
41224202 <a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.
41234203 You can retrieve an object referred by reference <code>r</code>
4124−calling <code>lua_rawgeti(L, t, r)</code>.
4204+by calling <code>lua_rawgeti(L, t, r)</code>.
41254205 Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.
41264206
4127−<p>Whenever the object at the top of the stack is <b>nil</b>,
4207+<p>If the object at the top of the stack is <b>nil</b>,
41284208 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>.
4129−The constant <code>LUA_NOREF</code> is garanteed to be different
4209+The constant <code>LUA_NOREF</code> is guaranteed to be different
41304210 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
41314211
41324212 <p><a name="luaL_Reg"></a>
4133−<hr/><h3><code>luaL_Reg</code></h3>
4213+<hr /><h3><code>luaL_Reg</code></h3>
41344214 <pre>
41354215 typedef struct luaL_Reg {
41364216 const char *name;
@@ -4140,15 +4220,15 @@ from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>. · 3 unmodified lines
41404220 </pre>
41414221
41424222
4143−<p>Format for arrays of functions to be registered by
4223+<p>Type for arrays of functions to be registered by
41444224 <a href="#luaL_register"><code>luaL_register</code></a>.
41454225 <code>name</code> is the function name and <code>func</code> is a pointer to
41464226 the function.
41474227 Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sentinel entry
4148−wherein both <code>name</code> and <code>func</code> are <code>NULL</code>.
4228+in which both <code>name</code> and <code>func</code> are <code>NULL</code>.
41494229
41504230 <p><a name="luaL_register"></a>
4151−<hr/><h3><code>luaL_register</code></h3>
4231+<hr /><h3><code>luaL_register</code></h3>
41524232 <pre>
41534233 void luaL_register (lua_State *L, const char *libname,
41544234 const luaL_Reg *l);
@@ -4163,7 +4243,7 @@ simply registers all functions in the list <code>l</code> · 8 unmodified lines
41634243
41644244 <p>When called with a non-null <code>libname</code>,
41654245 creates a new table <code>t</code>,
4166−sets it as the value of the variable <code>libname</code>,
4246+sets it as the value of the global variable <code>libname</code>,
41674247 sets it as the value of <code>package.loaded[libname]</code>,
41684248 and registers on it all functions in the list <code>l</code>.
41694249 If there is a table in <code>package.loaded[libname]</code> or in
@@ -4174,7 +4254,7 @@ reuses that table instead of creating a new one. · 4 unmodified lines
41744254 on the top of the stack.
41754255
41764256 <p><a name="luaL_typename"></a>
4177−<hr/><h3><code>luaL_typename</code></h3>
4257+<hr /><h3><code>luaL_typename</code></h3>
41784258 <pre>
41794259 const char *luaL_typename (lua_State *L, int idx);
41804260 </pre>
@@ -4183,7 +4263,7 @@ on the top of the stack. · 2 unmodified lines
41834263 <p>Returns the name of the type of the value at index <code>idx</code>.
41844264
41854265 <p><a name="luaL_typerror"></a>
4186−<hr/><h3><code>luaL_typerror</code></h3>
4266+<hr /><h3><code>luaL_typerror</code></h3>
41874267 <pre>
41884268 int luaL_typerror (lua_State *L, int narg, const char *tname);
41894269 </pre>
@@ -4198,7 +4278,7 @@ where <code>&#060;location></code> is produced by <a href="#luaL_where"><code>lu · 8 unmodified lines
41984278 and <code>&#060;realt></code> is the type name of the actual argument.
41994279
42004280 <p><a name="luaL_unref"></a>
4201−<hr/><h3><code>luaL_unref</code></h3>
4281+<hr /><h3><code>luaL_unref</code></h3>
42024282 <pre>
42034283 void luaL_unref (lua_State *L, int t, int ref);
42044284 </pre>
@@ -4214,7 +4294,7 @@ The reference <code>ref</code> is also freed to be used again. · 9 unmodified lines
42144294 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
42154295
42164296 <p><a name="luaL_where"></a>
4217−<hr/><h3><code>luaL_where</code></h3>
4297+<hr /><h3><code>luaL_where</code></h3>
42184298 <pre>
42194299 void luaL_where (lua_State *L, int lvl);
42204300 </pre>
@@ -4224,20 +4304,21 @@ The reference <code>ref</code> is also freed to be used again. · 3 unmodified lines
42244304 of the control at level <code>lvl</code> in the call stack.
42254305 Typically this string has the format <code>&#060;chunkname>:&#060;currentline>:</code>.
42264306 Level 0 is the running function,
4227−level 1 is the function that called the running function.
4307+level 1 is the function that called the running function,
4308+etc.
42284309
42294310 <p>This function is used to build a prefix for error messages.
42304311
42314312 <p>
42324313 <a name="libraries"></a><a name="5"></a><h1>5 - Standard Libraries</h1>
42334314
4234−<p>The standard libraries provide useful functions
4315+<p>The standard Lua libraries provide useful functions
42354316 that are implemented directly through the C API.
42364317 Some of these functions provide essential services to the language
42374318 (e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable</code></a>);
42384319 others provide access to "outside" services (e.g., I/O);
42394320 and others could be implemented in Lua itself,
4240−but are quite useful or have critical performance to
4321+but are quite useful or have critical performance requirements that
42414322 deserve an implementation in C (e.g., <code>sort</code>).
42424323
42434324 <p>All libraries are implemented through the official C API
@@ -4258,9 +4339,11 @@ each library provides all its functions as fields of a global table · 14 unmodified lines
42584339 or as methods of its objects.
42594340
42604341 <p>To have access to these libraries,
4261−the C host program must first call the function
4262−<code>luaL_openlibs</code>;
4263−or else it can open them individually calling
4342+the C host program must call
4343+<code>luaL_openlibs</code>,
4344+which open all standard libraries.
4345+Alternatively,
4346+it can open them individually by calling
42644347 <code>luaopen_base</code> (for the basic library),
42654348 <code>luaopen_package</code> (for the package library),
42664349 <code>luaopen_string</code> (for the string library),
@@ -4268,86 +4351,90 @@ or else it can open them individually calling · 1 unmodified line
42684351 <code>luaopen_math</code> (for the mathematical library),
42694352 <code>luaopen_io</code> (for the I/O and the Operating System libraries),
42704353 and <code>luaopen_debug</code> (for the debug library).
4271−These functions are declared in <code>lualib.h</code>.
4354+These functions are declared in <code>lualib.h</code>
4355+and should not be called directly:
4356+you must call them like any other Lua C function,
4357+e.g., by using <code>lua_call</code>.
42724358
42734359 <p><a name="predefined"></a><a name="5.1"></a><h2>5.1 - Basic Functions</h2>
42744360
42754361 <p>The basic library provides some core functions to Lua.
42764362 If you do not include this library in your application,
4277−you should check carefully whether you need to provide some alternative
4278−implementation for some of its facilities.
4363+you should check carefully whether you need to provide
4364+implementations for some of its facilities.
42794365
4280−<p><a name="pdf-assert"></a><hr/><h3><code>assert (v [, message])</code></h3>
4366+<p><a name="pdf-assert"></a><hr /><h3><code>assert (v [, message])</code></h3>
42814367 Issues an error when
4282−the value of its argument <code>v</code> is <b>nil</b> or <b>false</b>;
4368+the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);
42834369 otherwise, returns all its arguments.
42844370 <code>message</code> is an error message;
42854371 when absent, it defaults to "assertion failed!"
42864372
4287−<p><a name="pdf-collectgarbage"></a><hr/><h3><code>collectgarbage (opt [, arg])</code></h3>
4373+<p><a name="pdf-collectgarbage"></a><hr /><h3><code>collectgarbage (opt [, arg])</code></h3>
42884374
42894375 <p>This function is a generic interface to the garbage collector.
42904376 It performs different functions according to its first argument, <code>opt</code>:
42914377 <ul>
4292−<li><b>"stop"</b> stops the garbage collector.
4293−<li><b>"restart"</b> restarts the garbage collector.
4294−<li><b>"collect"</b> performs a full garbage-collection cycle.
4295−<li><b>"count"</b> returns the total memory in use by Lua (in Kbytes).
4296−<li><b>"step"</b> performs a garbage-collection step.
4378+<li><b>"stop"</b> --- stops the garbage collector.
4379+<li><b>"restart"</b> --- restarts the garbage collector.
4380+<li><b>"collect"</b> --- performs a full garbage-collection cycle.
4381+<li><b>"count"</b> --- returns the total memory in use by Lua (in Kbytes).
4382+<li><b>"step"</b> --- performs a garbage-collection step.
42974383 The step "size" is controlled by <code>arg</code>
42984384 (larger values mean more steps) in a non-specified way.
42994385 If you want to control the step size
43004386 you must tune experimentally the value of <code>arg</code>.
43014387 Returns <b>true</b> if that step finished a collection cycle.
4302−<li><b>"steppause"</b>
4303−sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of
4388+<li><b>"steppause"</b> ---
4389+sets <code>arg</code>/100 as the new value for the <em>pause</em> of
43044390 the collector (see <a href="#GC">2.10</a>).
4305−<li><b>"setstepmul"</b>
4306−sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of
4391+<li><b>"setstepmul"</b> ---
4392+sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of
43074393 the collector (see <a href="#GC">2.10</a>).
43084394 </ul>
43094395
4310−<p><a name="pdf-dofile"></a><hr/><h3><code>dofile (filename)</code></h3>
4396+<p><a name="pdf-dofile"></a><hr /><h3><code>dofile (filename)</code></h3>
43114397 Opens the named file and executes its contents as a Lua chunk.
43124398 When called without arguments,
4313−<a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>).
4314−Returns any value returned by the chunk.
4315−In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error
4316−to its caller (that is, it does not run in protected mode).
4399+<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).
4400+Returns all values returned by the chunk.
4401+In case of errors, <code>dofile</code> propagates the error
4402+to its caller (that is, <code>dofile</code> does not run in protected mode).
43174403
4318−<p><a name="pdf-error"></a><hr/><h3><code>error (message [, level])</code></h3>
4404+<p><a name="pdf-error"></a><hr /><h3><code>error (message [, level])</code></h3>
43194405 Terminates the last protected function called
43204406 and returns <code>message</code> as the error message.
4321−Function <a href="#pdf-error"><code>error</code></a> never returns.
4407+Function <code>error</code> never returns.
43224408
4323−<p>Usually, <a href="#pdf-error"><code>error</code></a> adds some information about the error position
4409+<p>Usually, <code>error</code> adds some information about the error position
43244410 at the beginning of the message.
43254411 The <code>level</code> argument specifies how to get the error position.
43264412 With level 1 (the default), the error position is where the
4327−<a href="#pdf-error"><code>error</code></a> function was called.
4413+<code>error</code> function was called.
43284414 Level 2 points the error to where the function
4329−that called <a href="#pdf-error"><code>error</code></a> was called; and so on.
4415+that called <code>error</code> was called; and so on.
43304416 Passing a level 0 avoids the addition of error position information
43314417 to the message.
43324418
4333−<p><a name="pdf-_G"></a><hr/><h3><code>_G</code></h3>
4419+<p><a name="pdf-_G"></a><hr /><h3><code>_G</code></h3>
43344420 A global variable (not a function) that
43354421 holds the global environment (that is, <code>_G._G = _G</code>).
43364422 Lua itself does not use this variable;
4337−changing its value does not affect any environment.
4423+changing its value does not affect any environment,
4424+nor vice-versa.
43384425 (Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.)
43394426
4340−<p><a name="pdf-getfenv"></a><hr/><h3><code>getfenv (f)</code></h3>
4427+<p><a name="pdf-getfenv"></a><hr /><h3><code>getfenv (f)</code></h3>
43414428 Returns the current environment in use by the function.
4342−<code>f</code> can be a Lua function or a number,
4343−which specifies the function at that stack level:
4344−Level 1 is the function calling <a href="#pdf-getfenv"><code>getfenv</code></a>.
4429+<code>f</code> can be a Lua function or a number
4430+that specifies the function at that stack level:
4431+Level 1 is the function calling <code>getfenv</code>.
43454432 If the given function is not a Lua function,
43464433 or if <code>f</code> is 0,
4347−<a href="#pdf-getfenv"><code>getfenv</code></a> returns the global environment.
4434+<code>getfenv</code> returns the global environment.
43484435 The default for <code>f</code> is 1.
43494436
4350−<p><a name="pdf-getmetatable"></a><hr/><h3><code>getmetatable (object)</code></h3>
4437+<p><a name="pdf-getmetatable"></a><hr /><h3><code>getmetatable (object)</code></h3>
43514438
43524439 <p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
43534440 Otherwise,
@@ -4355,9 +4442,9 @@ if the object's metatable has a <code>"__metatable"</code> field, · 1 unmodified line
43554442 returns the associated value.
43564443 Otherwise, returns the metatable of the given object.
43574444
4358−<p><a name="pdf-ipairs"></a><hr/><h3><code>ipairs (t)</code></h3>
4445+<p><a name="pdf-ipairs"></a><hr /><h3><code>ipairs (t)</code></h3>
43594446
4360−<p>Returns an iterator function, the table <code>t</code>, and 0,
4447+<p>Returns three values: an iterator function, the table <code>t</code>, and 0,
43614448 so that the construction
43624449 <pre>
43634450 for i,v in ipairs(t) do ... end
@@ -4365,7 +4452,9 @@ so that the construction · 1 unmodified line
43654452 will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
43664453 up to the first integer key with a nil value in the table.
43674454
4368−<p><a name="pdf-load"></a><hr/><h3><code>load (func [, chunkname])</code></h3>
4455+<p>See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
4456+
4457+<p><a name="pdf-load"></a><hr /><h3><code>load (func [, chunkname])</code></h3>
43694458
43704459 <p>Loads a chunk using function <code>func</code> to get its pieces.
43714460 Each call to <code>func</code> must return a string that concatenates
@@ -4380,12 +4469,14 @@ The environment of the returned function is the global environment. · 8 unmodified lines
43804469 <p><code>chunkname</code> is used as the chunk name for error messages
43814470 and debug information.
43824471
4383−<p><a name="pdf-loadfile"></a><hr/><h3><code>loadfile (filename)</code></h3>
4472+<p><a name="pdf-loadfile"></a><hr /><h3><code>loadfile ([filename])</code></h3>
43844473
43854474 <p>Similar to <a href="#pdf-load"><code>load</code></a>,
4386−but gets the chunk from file <code>filename</code>.
4475+but gets the chunk from file <code>filename</code>
4476+or from the standard input,
4477+if no file name given.
43874478
4388−<p><a name="pdf-loadstring"></a><hr/><h3><code>loadstring (string [, chunkname])</code></h3>
4479+<p><a name="pdf-loadstring"></a><hr /><h3><code>loadstring (string [, chunkname])</code></h3>
43894480
43904481 <p>Similar to <a href="#pdf-load"><code>load</code></a>,
43914482 but gets the chunk from the given string.
@@ -4395,106 +4486,112 @@ but gets the chunk from the given string. · 3 unmodified lines
43954486 assert(loadstring(s))()
43964487 </pre>
43974488
4398−<p><a name="pdf-next"></a><hr/><h3><code>next (table [, index])</code></h3>
4489+<p><a name="pdf-next"></a><hr /><h3><code>next (table [, index])</code></h3>
43994490
44004491 <p>Allows a program to traverse all fields of a table.
44014492 Its first argument is a table and its second argument
44024493 is an index in this table.
4403−<a href="#pdf-next"><code>next</code></a> returns the next index of the table and the
4404−value associated with the index.
4494+<code>next</code> returns the next index of the table
4495+and its associated value.
44054496 When called with <b>nil</b> as its second argument,
4406−<a href="#pdf-next"><code>next</code></a> returns the first index
4407−of the table and its associated value.
4497+<code>next</code> returns an initial index
4498+and its associated value.
44084499 When called with the last index,
44094500 or with <b>nil</b> in an empty table,
4410−<a href="#pdf-next"><code>next</code></a> returns <b>nil</b>.
4501+<code>next</code> returns <b>nil</b>.
44114502 If the second argument is absent, then it is interpreted as <b>nil</b>.
4503+In particular,
4504+you can use <code>next(t)</code> to check whether a table is empty.
44124505
4413−<p>Lua has no declaration of fields;
4506+<p>Lua has no declaration of fields.
44144507 There is no difference between a
44154508 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.
4509+Therefore, <code>next</code> only considers fields with non-<b>nil</b> values.
44174510 The order in which the indices are enumerated is not specified,
44184511 <em>even for numeric indices</em>.
44194512 (To traverse a table in numeric order,
44204513 use a numerical <b>for</b> or the <a href="#pdf-ipairs"><code>ipairs</code></a> function.)
44214514
4422−<p>The behavior of <a href="#pdf-next"><code>next</code></a> is <em>undefined</em> if,
4515+<p>The behavior of <code>next</code> is <em>undefined</em> if,
44234516 during the traversal,
44244517 you assign any value to a non-existent field in the table.
4518+You may however modify existing fields.
4519+In particular, you may clear existing fields.
44254520
4426−<p><a name="pdf-pairs"></a><hr/><h3><code>pairs (t)</code></h3>
4521+<p><a name="pdf-pairs"></a><hr /><h3><code>pairs (t)</code></h3>
44274522
4428−<p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <b>nil</b>),
4523+<p>Returns three values: the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,
44294524 so that the construction
44304525 <pre>
44314526 for k,v in pairs(t) do ... end
44324527 </pre>
44334528 will iterate over all key--value pairs of table <code>t</code>.
44344529
4435−<p><a name="pdf-pcall"></a><hr/><h3><code>pcall (f, arg1, arg2, ...)</code></h3>
4530+<p>See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
4531+
4532+<p><a name="pdf-pcall"></a><hr /><h3><code>pcall (f, arg1, arg2, ...)</code></h3>
44364533
44374534 <p>Calls function <code>f</code> with
44384535 the given arguments in protected mode.
44394536 That means that any error inside <code>f</code> is not propagated;
4440−instead, <a href="#pdf-pcall"><code>pcall</code></a> catches the error
4537+instead, <code>pcall</code> catches the error
44414538 and returns a status code.
44424539 Its first result is the status code (a boolean),
44434540 which is true if the call succeeds without errors.
4444−In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call,
4541+In such case, <code>pcall</code> also returns all results from the call,
44454542 after this first result.
4446−In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <b>false</b> plus the error message.
4543+In case of any error, <code>pcall</code> returns <b>false</b> plus the error message.
44474544
4448−<p><a name="pdf-print"></a><hr/><h3><code>print (e1, e2, ...)</code></h3>
4545+<p><a name="pdf-print"></a><hr /><h3><code>print (e1, e2, ...)</code></h3>
44494546 Receives any number of arguments,
44504547 and prints their values in <code>stdout</code>,
44514548 using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.
4452−This function is not intended for formatted output,
4549+<code>print</code> is not intended for formatted output,
44534550 but only as a quick way to show a value,
44544551 typically for debugging.
4455−For formatted output, use <code>format</code> (see <a href="#format">5.4</a>).
4552+For formatted output, use <a href="#pdf-string.format"><code>string.format</code></a>.
44564553
4457−<p><a name="pdf-rawequal"></a><hr/><h3><code>rawequal (v1, v2)</code></h3>
4554+<p><a name="pdf-rawequal"></a><hr /><h3><code>rawequal (v1, v2)</code></h3>
44584555 Checks whether <code>v1</code> is equal to <code>v2</code>,
44594556 without invoking any metamethod.
44604557 Returns a boolean.
44614558
4462−<p><a name="pdf-rawget"></a><hr/><h3><code>rawget (table, index)</code></h3>
4559+<p><a name="pdf-rawget"></a><hr /><h3><code>rawget (table, index)</code></h3>
44634560 Gets the real value of <code>table[index]</code>,
44644561 without invoking any metamethod.
4465−<code>table</code> must be a table;
4466−<code>index</code> is any value different from <b>nil</b>.
4562+<code>table</code> must be a table and
4563+<code>index</code> any value different from <b>nil</b>.
44674564
4468−<p><a name="pdf-rawset"></a><hr/><h3><code>rawset (table, index, value)</code></h3>
4565+<p><a name="pdf-rawset"></a><hr /><h3><code>rawset (table, index, value)</code></h3>
44694566 Sets the real value of <code>table[index]</code> to <code>value</code>,
44704567 without invoking any metamethod.
44714568 <code>table</code> must be a table,
4472−<code>index</code> is any value different from <b>nil</b>,
4473−and <code>value</code> is any Lua value.
4569+<code>index</code> any value different from <b>nil</b>,
4570+and <code>value</code> any Lua value.
44744571
4475−<p><a name="pdf-select"></a><hr/><h3><code>select (index, ...)</code></h3>
4572+<p><a name="pdf-select"></a><hr /><h3><code>select (index, ...)</code></h3>
44764573
44774574 <p>If <code>index</code> is a number,
4478−returns all argument after argument number <code>index</code>.
4575+returns all arguments after argument number <code>index</code>.
44794576 Otherwise, <code>index</code> must be the string <code>"#"</code>,
44804577 and <code>select</code> returns the total number of extra arguments it received.
44814578
4482−<p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr/><h3><code>setfenv (f, table)</code></h3>
4579+<p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr /><h3><code>setfenv (f, table)</code></h3>
44834580
44844581 <p>Sets the environment to be used by the given function.
4485−<code>f</code> can be a Lua function or a number,
4486−which specifies the function at that stack level:
4487−Level 1 is the function calling <a href="#pdf-setfenv"><code>setfenv</code></a>.
4488−<a href="#pdf-setfenv"><code>setfenv</code></a> returns the given function.
4582+<code>f</code> can be a Lua function or a number
4583+that specifies the function at that stack level:
4584+Level 1 is the function calling <code>setfenv</code>.
4585+<code>setfenv</code> returns the given function.
44894586
4490−<p>As a special case, when <code>f</code> is 0 <a href="#pdf-setfenv"><code>setfenv</code></a> changes
4587+<p>As a special case, when <code>f</code> is 0 <code>setfenv</code> changes
44914588 the environment of the running thread.
4492−In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values.
4589+In this case, <code>setfenv</code> returns no values.
44934590
4494−<p><a name="pdf-setmetatable"></a><hr/><h3><code>setmetatable (table, metatable)</code></h3>
4591+<p><a name="pdf-setmetatable"></a><hr /><h3><code>setmetatable (table, metatable)</code></h3>
44954592
44964593 <p>Sets the metatable for the given table.
4497−(You cannot change the metatable of other types from Lua.)
4594+(You cannot change the metatable of other types from Lua, only from C.)
44984595 If <code>metatable</code> is <b>nil</b>,
44994596 removes the metatable of the given table.
45004597 If the original metatable has a <code>"__metatable"</code> field,
@@ -4502,10 +4599,10 @@ raises an error. · 1 unmodified line
45024599
45034600 <p>This function returns <code>table</code>.
45044601
4505−<p><a name="pdf-tonumber"></a><hr/><h3><code>tonumber (e [, base])</code></h3>
4602+<p><a name="pdf-tonumber"></a><hr /><h3><code>tonumber (e [, base])</code></h3>
45064603 Tries to convert its argument to a number.
45074604 If the argument is already a number or a string convertible
4508−to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number;
4605+to a number, then <code>tonumber</code> returns that number;
45094606 otherwise, it returns <b>nil</b>.
45104607
45114608 <p>An optional argument specifies the base to interpret the numeral.
@@ -4514,21 +4611,21 @@ In bases above 10, the letter `<code>A</code>&acute; (in either upper or lower c · 2 unmodified lines
45144611 represents 10, `<code>B</code>&acute; represents 11, and so forth,
45154612 with `<code>Z</code>&acute; representing 35.
45164613 In base 10 (the default), the number may have a decimal part,
4517−as well as an optional exponent part (see <a href="#coercion">2.2.1</a>).
4614+as well as an optional exponent part (see <a href="#lexical">2.1</a>).
45184615 In other bases, only unsigned integers are accepted.
45194616
4520−<p><a name="pdf-tostring"></a><hr/><h3><code>tostring (e)</code></h3>
4617+<p><a name="pdf-tostring"></a><hr /><h3><code>tostring (e)</code></h3>
45214618 Receives an argument of any type and
45224619 converts it to a string in a reasonable format.
45234620 For complete control of how numbers are converted,
4524−use <a href="#pdf-string.format"><code>string.format</code></a> (see <a href="#format">5.4</a>).
4621+use <a href="#pdf-string.format"><code>string.format</code></a>.
45254622
45264623 <p>If the metatable of <code>e</code> has a <code>"__tostring"</code> field,
4527−<a href="#pdf-tostring"><code>tostring</code></a> calls the corresponding value
4624+then <code>tostring</code> calls the corresponding value
45284625 with <code>e</code> as argument,
45294626 and uses the result of the call as its result.
45304627
4531−<p><a name="pdf-type"></a><hr/><h3><code>type (v)</code></h3>
4628+<p><a name="pdf-type"></a><hr /><h3><code>type (v)</code></h3>
45324629 Returns the type of its only argument, coded as a string.
45334630 The possible results of this function are
45344631 <code>"nil"</code> (a string, not the value <b>nil</b>),
@@ -4540,8 +4637,8 @@ The possible results of this function are · 5 unmodified lines
45404637 <code>"thread"</code>,
45414638 and <code>"userdata"</code>.
45424639
4543−<p><a name="pdf-unpack"></a><hr/><h3><code>unpack (list [, i [, j]])</code></h3>
4544−Returns the elements from the given list.
4640+<p><a name="pdf-unpack"></a><hr /><h3><code>unpack (list [, i [, j]])</code></h3>
4641+Returns the elements from the given table.
45454642 This function is equivalent to
45464643 <pre>
45474644 return list[i], list[i+1], ..., list[j]
@@ -4549,30 +4646,30 @@ This function is equivalent to · 1 unmodified line
45494646 except that the above code can be written only for a fixed number
45504647 of elements.
45514648 By default, <code>i</code> is 1 and <code>j</code> is the length of the list,
4552−as defined by the length operator.
4649+as defined by the length operator (see <a href="#len-op">2.5.5</a>).
45534650
4554−<p><a name="pdf-_VERSION"></a><hr/><h3><code>_VERSION</code></h3>
4651+<p><a name="pdf-_VERSION"></a><hr /><h3><code>_VERSION</code></h3>
45554652 A global variable (not a function) that
45564653 holds a string containing the current interpreter version.
45574654 The current contents of this variable is <code>"Lua 5.1"</code>.
45584655
4559−<p><a name="pdf-xpcall"></a><hr/><h3><code>xpcall (f, err)</code></h3>
4656+<p><a name="pdf-xpcall"></a><hr /><h3><code>xpcall (f, err)</code></h3>
45604657
4561−<p>This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
4658+<p>This function is similar to <code>pcall</code>,
45624659 except that you can set a new error handler.
45634660
4564−<p><a href="#pdf-xpcall"><code>xpcall</code></a> calls function <code>f</code> in protected mode,
4661+<p><code>xpcall</code> calls function <code>f</code> in protected mode,
45654662 using <code>err</code> as the error handler.
45664663 Any error inside <code>f</code> is not propagated;
4567−instead, <a href="#pdf-xpcall"><code>xpcall</code></a> catches the error,
4664+instead, <code>xpcall</code> catches the error,
45684665 calls the <code>err</code> function with the original error object,
45694666 and returns a status code.
45704667 Its first result is the status code (a boolean),
45714668 which is true if the call succeeds without errors.
4572−In such case, <a href="#pdf-xpcall"><code>xpcall</code></a> also returns all results from the call,
4669+In this case, <code>xpcall</code> also returns all results from the call,
45734670 after this first result.
45744671 In case of any error,
4575−<a href="#pdf-xpcall"><code>xpcall</code></a> returns false plus the result from <code>err</code>.
4672+<code>xpcall</code> returns <b>false</b> plus the result from <code>err</code>.
45764673
45774674 <p><a name="5.2"></a><h2>5.2 - Coroutine Manipulation</h2>
45784675
@@ -4580,22 +4677,24 @@ In case of any error, · 1 unmodified line
45804677 the basic library and come inside the table <code>coroutine</code>.
45814678 See <a href="#coroutine">2.11</a> for a general description of coroutines.
45824679
4583−<p><a name="pdf-coroutine.create"></a><hr/><h3><code>coroutine.create (f)</code></h3>
4680+<p><a name="pdf-coroutine.create"></a><hr /><h3><code>coroutine.create (f)</code></h3>
45844681
45854682 <p>Creates a new coroutine, with body <code>f</code>.
45864683 <code>f</code> must be a Lua function.
45874684 Returns this new coroutine,
45884685 an object with type <code>"thread"</code>.
45894686
4590−<p><a name="pdf-coroutine.resume"></a><hr/><h3><code>coroutine.resume (co, val1, ...)</code></h3>
4687+<p><a name="pdf-coroutine.resume"></a><hr /><h3><code>coroutine.resume (co [, val1, ..., valn])</code></h3>
45914688
45924689 <p>Starts or continues the execution of coroutine <code>co</code>.
45934690 The first time you resume a coroutine,
45944691 it starts running its body.
4595−The arguments <code>val1</code>, ... go as the arguments to the body function.
4692+The values <code>val1</code>, ..., <code>valn</code> are passed
4693+as the arguments to the body function.
45964694 If the coroutine has yielded,
45974695 <code>resume</code> restarts it;
4598−the arguments <code>val1</code>, ... go as the results from the yield.
4696+the values <code>val1</code>, ..., <code>valn</code> are passed
4697+as the results from the yield.
45994698
46004699 <p>If the coroutine runs without any errors,
46014700 <code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>
@@ -4604,12 +4703,12 @@ the arguments <code>val1</code>, ... go as the results from the yield. · 2 unmodified lines
46044703 If there is any error,
46054704 <code>resume</code> returns <b>false</b> plus the error message.
46064705
4607−<p><a name="pdf-coroutine.running"></a><hr/><h3><code>coroutine.running ()</code></h3>
4706+<p><a name="pdf-coroutine.running"></a><hr /><h3><code>coroutine.running ()</code></h3>
46084707
46094708 <p>Returns the running coroutine,
46104709 or <b>nil</b> when called by the main thread.
46114710
4612−<p><a name="pdf-coroutine.status"></a><hr/><h3><code>coroutine.status (co)</code></h3>
4711+<p><a name="pdf-coroutine.status"></a><hr /><h3><code>coroutine.status (co)</code></h3>
46134712
46144713 <p>Returns the status of coroutine <code>co</code>, as a string:
46154714 <code>"running"</code>,
@@ -4621,7 +4720,7 @@ or if it has not started running yet; · 5 unmodified lines
46214720 and <code>"dead"</code> if the coroutine has finished its body function,
46224721 or if it has stopped with an error.
46234722
4624−<p><a name="pdf-coroutine.wrap"></a><hr/><h3><code>coroutine.wrap (f)</code></h3>
4723+<p><a name="pdf-coroutine.wrap"></a><hr /><h3><code>coroutine.wrap (f)</code></h3>
46254724
46264725 <p>Creates a new coroutine, with body <code>f</code>.
46274726 <code>f</code> must be a Lua function.
@@ -4632,22 +4731,22 @@ Returns the same values returned by <code>resume</code>, · 4 unmodified lines
46324731 except the first boolean.
46334732 In case of error, propagates the error.
46344733
4635−<p><a name="pdf-coroutine.yield"></a><hr/><h3><code>coroutine.yield (val1, ...)</code></h3>
4734+<p><a name="pdf-coroutine.yield"></a><hr /><h3><code>coroutine.yield ([val1, ..., valn])</code></h3>
46364735
46374736 <p>Suspends the execution of the calling coroutine.
4638−The coroutine cannot be running neither a C function,
4737+The coroutine can be running neither a C function,
46394738 nor a metamethod, nor an iterator.
4640−Any arguments to <code>yield</code> go as extra results to <code>resume</code>.
4739+Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
46414740
4642−<p><a name="5.3"></a><h2>5.3 - Packages and Modules</h2>
4741+<p><a name="5.3"></a><h2>5.3 - Modules</h2>
46434742
46444743 <p>The package library provides basic
4645−facilities for packages and modules in Lua.
4744+facilities for loading and building modules in Lua.
46464745 It exports two of its functions directly in the global environment:
46474746 <a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.
46484747 Everything else is exported in a table <code>package</code>.
46494748
4650−<p><a name="pdf-module"></a><hr/><h3><code>module (name [, ...])</code></h3>
4749+<p><a name="pdf-module"></a><hr /><h3><code>module (name [, ...])</code></h3>
46514750
46524751 <p>Creates a module.
46534752 If there is a table in <code>package.loaded[name]</code>,
@@ -4666,51 +4765,51 @@ of the current function and the new value of <code>package.loaded[name]</code>, · 12 unmodified lines
46664765 so that <a href="#pdf-require"><code>require</code></a> returns <code>t</code>.
46674766
46684767 <p>If <code>name</code> is a compound name
4669−(that is, one with components separated by dots)
4670−<code>module</code> creates (or reuses, if they already exists)
4768+(that is, one with components separated by dots),
4769+<code>module</code> creates (or reuses, if they already exist)
46714770 tables for each component.
46724771 For instance, if <code>name</code> is <code>a.b.c</code>,
4673−<code>module</code> stores the module table in field <code>c</code> of
4772+then <code>module</code> stores the module table in field <code>c</code> of
46744773 field <code>b</code> of global <code>a</code>.
46754774
46764775 <p>This function may receive optional <em>options</em> after
46774776 the module name,
46784777 where each option is a function to be applied over the module.
46794778
4680−<p><a name="pdf-require"></a><hr/><h3><code>require (modname)</code></h3>
4779+<p><a name="pdf-require"></a><hr /><h3><code>require (modname)</code></h3>
46814780
46824781 <p>Loads the given module.
46834782 The function starts by looking into the table <code>package.loaded</code>
46844783 to determine whether <code>modname</code> is already loaded.
4685−If it is, then <a href="#pdf-require"><code>require</code></a> returns the value stored
4784+If it is, then <code>require</code> returns the value stored
46864785 at <code>package.loaded[modname]</code>.
4687−Otherwise, it tries to find a loader for that module.
4786+Otherwise, it tries to find a <em>loader</em> for that module.
46884787
46894788 <p>To find a loader,
4690−first <a href="#pdf-require"><code>require</code></a> queries <code>package.preload[modname]</code>.
4691−If it is a true value,
4789+first <code>require</code> queries <code>package.preload[modname]</code>.
4790+If it has a value,
46924791 that value (which should be a function) is the loader.
4693−Otherwise <a href="#pdf-require"><code>require</code></a> searches for a Lua loader using the
4792+Otherwise <code>require</code> searches for a Lua loader using the
46944793 path stored in <code>package.path</code>.
4695−if that also fails, it searches for a C loader using the
4794+If that also fails, it searches for a C loader using the
46964795 path stored in <code>package.cpath</code>.
46974796 If that also fails,
4698−it tries an <em>all-in-one</em> loader.
4797+it tries an <em>all-in-one</em> loader (see below).
46994798
47004799 <p>When loading a C library,
4701−<a href="#pdf-require"><code>require</code></a> first uses a dynamic link facility to link the
4800+<code>require</code> first uses a dynamic link facility to link the
47024801 application with the library.
47034802 Then it tries to find a C function inside that library to
47044803 be used as the loader.
47054804 The name of that C function is the string <code>"luaopen_"</code>
4706−concatenated with a copy of the module name wherein each dot
4805+concatenated with a copy of the module name where each dot
47074806 is replaced by an underscore.
47084807 Moreover, if the module name has a hyphen,
47094808 its prefix up to (and including) the first hyphen is removed.
47104809 For instance, if the module name is <code>a.v1-b.c</code>,
47114810 the function name will be <code>luaopen_b_c</code>.
47124811
4713−<p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a
4812+<p>If <code>require</code> finds neither a Lua library nor a
47144813 C library for a module,
47154814 it calls the <em>all-in-one loader</em>.
47164815 That loader searches the C path for a library for
@@ -4725,29 +4824,29 @@ into one single library, · 8 unmodified lines
47254824 with each submodule keeping its original open function.
47264825
47274826 <p>Once a loader is found,
4728−<a href="#pdf-require"><code>require</code></a> calls the loader with a sinle argument, <code>modname</code>.
4827+<code>require</code> calls the loader with a single argument, <code>modname</code>.
47294828 If the loader returns any value,
4730−<a href="#pdf-require"><code>require</code></a> assigns it to <code>package.loaded[modname]</code>.
4829+<code>require</code> assigns it to <code>package.loaded[modname]</code>.
47314830 If the loader returns no value and
47324831 has not assigned any value to <code>package.loaded[modname]</code>,
4733−<a href="#pdf-require"><code>require</code></a> assigns <b>true</b> to that entry.
4832+then <code>require</code> assigns <b>true</b> to that entry.
47344833 In any case, require returns the
47354834 final value of <code>package.loaded[modname]</code>.
47364835
47374836 <p>If there is any error loading or running the module,
47384837 or if it cannot find any loader for that module,
4739−then <a href="#pdf-require"><code>require</code></a> signals an error.
4838+then <code>require</code> signals an error.
47404839
4741−<p><a name="pdf-package.cpath"></a><hr/><h3><code>package.cpath</code></h3>
4840+<p><a name="pdf-package.cpath"></a><hr /><h3><code>package.cpath</code></h3>
47424841
47434842 <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader.
47444843
47454844 <p>Lua initializes the C path <code>package.cpath</code> in the same way
47464845 it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>,
47474846 using the environment variable <code>LUA_CPATH</code>
4748−(plus another compiled-defined default path).
4847+(plus another default path defined in <code>luaconf.h</code>).
47494848
4750−<p><a name="pdf-package.loaded"></a><hr/><h3><code>package.loaded</code></h3>
4849+<p><a name="pdf-package.loaded"></a><hr /><h3><code>package.loaded</code></h3>
47514850
47524851 <p>A table used by <a href="#pdf-require"><code>require</code></a> to control which
47534852 modules are already loaded.
@@ -4755,27 +4854,34 @@ When you require a module <code>modname</code> and · 1 unmodified line
47554854 <code>package.loaded[modname]</code> is not false,
47564855 <a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
47574856
4758−<p><a name="pdf-package.loadlib"></a><hr/><h3><code>package.loadlib (libname, funcname)</code></h3>
4857+<p><a name="pdf-package.loadlib"></a><hr /><h3><code>package.loadlib (libname, funcname)</code></h3>
47594858
4760−<p>Links the program with the dynamic C library <code>libname</code>.
4859+<p>Dynamically links the host program with the C library <code>libname</code>.
47614860 Inside this library, looks for a function <code>funcname</code>
47624861 and returns this function as a C function.
4862+(So, <code>funcname</code> must follow the protocol (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>)).
47634863
4764−<p><code>libname</code> must be the complete file name of the C library,
4765−including any eventual path and extension.
4864+<p>This is a low-level function.
4865+It completely bypasses the package and module system.
4866+Unlike <a href="#pdf-require"><code>require</code></a>,
4867+it does not perform any path searching or automatically adds extensions.
4868+<code>libname</code> must be the complete file name of the C library,
4869+including if necessary a path and extension.
4870+<code>funcname</code> must be the exact name exported by the C library
4871+(which may depend on the C compiler and linker used).
47664872
47674873 <p>This function is not supported by ANSI C.
47684874 As such, it is only available on some platforms
4769−(Windows, Linux, Solaris, BSD, plus other Unix systems that
4770−support the <code>dlfcn</code> standard).
4875+(Windows, Linux, Mac OS X, Solaris, BSD,
4876+plus other Unix systems that support the <code>dlfcn</code> standard).
47714877
4772−<p><a name="pdf-package.path"></a><hr/><h3><code>package.path</code></h3>
4878+<p><a name="pdf-package.path"></a><hr /><h3><code>package.path</code></h3>
47734879
47744880 <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader.
47754881
47764882 <p>At start-up, Lua initializes this variable with
47774883 the value of the environment variable <code>LUA_PATH</code> or
4778−with a compiled-defined default path,
4884+with a default path defined in <code>luaconf.h</code>,
47794885 if the environment variable is not defined.
47804886 Any <code>";;"</code> in the value of the environment variable
47814887 is replaced by the default path.
@@ -4790,21 +4896,21 @@ So, for instance, if the Lua path is · 8 unmodified lines
47904896 <pre>
47914897 "./?.lua;./?.lc;/usr/local/?/init.lua"
47924898 </pre>
4793−the search for a Lua loader for module <code>mod</code>
4899+the search for a Lua loader for module <code>foo</code>
47944900 will try to load the files
4795−<code>./mod.lua</code>, <code>./mod.lc</code>, and
4796−<code>/usr/local/mod/init.lua</code>, in that order.
4901+<code>./foo.lua</code>, <code>./foo.lc</code>, and
4902+<code>/usr/local/foo/init.lua</code>, in that order.
47974903
4798−<p><a name="pdf-package.preload"></a><hr/><h3><code>package.preload</code></h3>
4904+<p><a name="pdf-package.preload"></a><hr /><h3><code>package.preload</code></h3>
47994905
48004906 <p>A table to store loaders for specific modules
48014907 (see <a href="#pdf-require"><code>require</code></a>).
48024908
4803−<p><a name="pdf-package.seeall"></a><hr/><h3><code>package.seeall (module)</code></h3>
4909+<p><a name="pdf-package.seeall"></a><hr /><h3><code>package.seeall (module)</code></h3>
48044910
48054911 <p>Sets a metatable for <code>module</code> with
4806−its <code>__index</code> field refering to the global environment,
4807−so that this module inherits undefined values
4912+its <code>__index</code> field referring to the global environment,
4913+so that this module inherits values
48084914 from the global environment.
48094915 To be used as an option to function <a href="#pdf-module"><code>module</code></a>.
48104916
@@ -4821,12 +4927,12 @@ Thus, the last character is at position <em>-1</em>, and so on. · 10 unmodified lines
48214927 <p>The string library provides all its functions inside the table
48224928 <code>string</code>.
48234929 It also sets a metatable for strings
4824−wherein <code>__index</code> points to itself.
4825−Therefore, you can use the string function is object-oriented style.
4930+where the <code>__index</code> field points to the metatable itself.
4931+Therefore, you can use the string functions in object-oriented style.
48264932 For instance, <code>string.byte(s, i)</code>
48274933 can be written as <code>s:byte(i)</code>.
48284934
4829−<p><a name="pdf-string.byte"></a><hr/><h3><code>string.byte (s [, i [, j]])</code></h3>
4935+<p><a name="pdf-string.byte"></a><hr /><h3><code>string.byte (s [, i [, j]])</code></h3>
48304936 Returns the internal numerical codes of the characters <code>s[i]</code>,
48314937 <code>s[i+1]</code>, ..., <code>s[j]</code>.
48324938 The default value for <code>i</code> is 1;
@@ -4834,25 +4940,25 @@ the default value for <code>j</code> is <code>i</code>. · 1 unmodified line
48344940
48354941 <p>Note that numerical codes are not necessarily portable across platforms.
48364942
4837−<p><a name="pdf-string.char"></a><hr/><h3><code>string.char (i1, i2, ...)</code></h3>
4943+<p><a name="pdf-string.char"></a><hr /><h3><code>string.char (i1, i2, ...)</code></h3>
48384944 Receives 0 or more integers.
48394945 Returns a string with length equal to the number of arguments,
48404946 in which each character has the internal numerical code equal
4841−to its correspondent argument.
4947+to its corresponding argument.
48424948
48434949 <p>Note that numerical codes are not necessarily portable across platforms.
48444950
4845−<p><a name="pdf-string.dump"></a><hr/><h3><code>string.dump (function)</code></h3>
4951+<p><a name="pdf-string.dump"></a><hr /><h3><code>string.dump (function)</code></h3>
48464952
4847−<p>Returns a binary representation of the given function,
4953+<p>Returns a string containing a binary representation of the given function,
48484954 so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns
48494955 a copy of the function.
4850−<code>function</code> must be a Lua function.
4956+<code>function</code> must be a Lua function without upvalues.
48514957
4852−<p><a name="pdf-string.find"></a><hr/><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>
4853−Looks for the first <em>match</em> of
4958+<p><a name="pdf-string.find"></a><hr /><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>
4959+Looks for the first match of
48544960 <code>pattern</code> in the string <code>s</code>.
4855−If it finds one, then <code>find</code> returns the indices of <code>s</code>
4961+If it finds a match, then <code>find</code> returns the indices of <code>s</code>
48564962 where this occurrence starts and ends;
48574963 otherwise, it returns <b>nil</b>.
48584964 A third, optional numerical argument <code>init</code> specifies
@@ -4862,26 +4968,27 @@ A value of <b>true</b> as a fourth, optional argument <code>plain</code> · 3 unmodified lines
48624968 turns off the pattern matching facilities,
48634969 so the function does a plain "find substring" operation,
48644970 with no characters in <code>pattern</code> being considered "magic".
4865−Note that if <code>plain</code> is given, then <code>init</code> must be given too.
4971+Note that if <code>plain</code> is given, then <code>init</code> must be given as well.
48664972
48674973 <p>If the pattern has captures,
48684974 then in a successful match
48694975 the captured values are also returned,
48704976 after the two indices.
48714977
4872−<p><a name="format"></a><a name="pdf-string.format"></a><hr/><h3><code>string.format (formatstring, e1, e2, ...)</code></h3>
4978+<p><a name="format"></a><a name="pdf-string.format"></a><hr /><h3><code>string.format (formatstring, e1, e2, ...)</code></h3>
48734979 Returns a formatted version of its variable number of arguments
48744980 following the description given in its first argument (which must be a string).
48754981 The format string follows the same rules as the <code>printf</code> family of
48764982 standard C functions.
48774983 The only differences are that the options/modifiers
48784984 <code>*</code>, <code>l</code>, <code>L</code>, <code>n</code>, <code>p</code>,
4879−and <code>h</code> are not supported,
4880−and there is an extra option, <code>q</code>.
4985+and <code>h</code> are not supported
4986+and that there is an extra option, <code>q</code>.
48814987 The <code>q</code> option formats a string in a form suitable to be safely read
48824988 back by the Lua interpreter:
48834989 The string is written between double quotes,
4884−and all double quotes, newlines, and backslashes in the string
4990+and all double quotes, newlines, embedded zeros,
4991+and backslashes in the string
48854992 are correctly escaped when written.
48864993 For instance, the call
48874994 <pre>
@@ -4901,12 +5008,12 @@ whereas <code>q</code> and <code>s</code> expect a string. · 13 unmodified lines
49015008 <p>This function does not accept string values
49025009 containing embedded zeros.
49035010
4904−<p><a name="pdf-string.gmatch"></a><hr/><h3><code>string.gmatch (s, pat)</code></h3>
5011+<p><a name="pdf-string.gmatch"></a><hr /><h3><code>string.gmatch (s, pattern)</code></h3>
49055012 Returns an iterator function that,
49065013 each time it is called,
4907−returns the next captures from pattern <code>pat</code> over string <code>s</code>.
5014+returns the next captures from <code>pattern</code> over string <code>s</code>.
49085015
4909−<p>If <code>pat</code> specifies no captures,
5016+<p>If <code>pattern</code> specifies no captures,
49105017 then the whole match is produced in each call.
49115018
49125019 <p>As an example, the following loop
@@ -4928,11 +5035,12 @@ given string into a table: · 15 unmodified lines
49285035 end
49295036 </pre>
49305037
4931−<p><a name="pdf-string.gsub"></a><hr/><h3><code>string.gsub (s, pat, repl [, n])</code></h3>
5038+<p><a name="pdf-string.gsub"></a><hr /><h3><code>string.gsub (s, pattern, repl [, n])</code></h3>
49325039 Returns a copy of <code>s</code>
4933−in which all occurrences of the pattern <code>pat</code> have been
4934−replaced by a replacement string specified by <code>repl</code>.
4935−<code>gsub</code> also returns, as a second value,
5040+in which all occurrences of the <code>pattern</code> have been
5041+replaced by a replacement string specified by <code>repl</code>,
5042+which may be a string, a table, or a function.
5043+<code>gsub</code> also returns, as its second value,
49365044 the total number of substitutions made.
49375045
49385046 <p>If <code>repl</code> is a string, then its value is used for replacement.
@@ -4943,6 +5051,11 @@ stands for the value of the <em>n</em>-th captured substring (see below). · 4 unmodified lines
49435051 The sequence <code>%0</code> stands for the whole match.
49445052 The sequence <code>%%</code> stands for a single <code>%</code>.
49455053
5054+<p>If <code>repl</code> is a table, then the table is queried for every match,
5055+using the first capture as the key;
5056+if the pattern specifies no captures,
5057+then the whole match is used as the key.
5058+
49465059 <p>If <code>repl</code> is a function, then this function is called every time a
49475060 match occurs, with all captured substrings passed as arguments,
49485061 in order;
@@ -4951,9 +5064,10 @@ then the whole match is passed as a sole argument. · 2 unmodified lines
49515064 If <code>repl</code> is a table, then this table is queried with the
49525065 value of the first capture or of the whole match,
49535066 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,
5067+
5068+<p>In both cases,
5069+if the value returned by the function or by the table query
5070+is a string or a number,
49575071 then it is used as the replacement string;
49585072 otherwise, if it is <b>false</b> or <b>nil</b>,
49595073 then there is no replacement
@@ -4962,7 +5076,7 @@ then there is no replacement · 2 unmodified lines
49625076 <p>The optional last parameter <code>n</code> limits
49635077 the maximum number of substitutions to occur.
49645078 For instance, when <code>n</code> is 1 only the first occurrence of
4965−<code>pat</code> is replaced.
5079+<code>pattern</code> is replaced.
49665080
49675081 <p>Here are some examples:
49685082 <pre>
@@ -4983,24 +5097,24 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 14 unmodified lines
49835097 end)
49845098 --> x="4+5 = 9"
49855099
4986− local t = {name="lua", version="5.0"}
4987− x = string.gsub("$name_$version.tar.gz", "%$(%w+)", t)
4988− --> x="lua_5.0.tar.gz"
5100+ local t = {name="lua", version="5.1"}
5101+ x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t)
5102+ --> x="lua-5.1.tar.gz"
49895103 </pre>
49905104
4991−<p><a name="pdf-string.len"></a><hr/><h3><code>string.len (s)</code></h3>
5105+<p><a name="pdf-string.len"></a><hr /><h3><code>string.len (s)</code></h3>
49925106 Receives a string and returns its length.
49935107 The empty string <code>""</code> has length 0.
49945108 Embedded zeros are counted,
49955109 so <code>"a\000bc\000"</code> has length 5.
49965110
4997−<p><a name="pdf-string.lower"></a><hr/><h3><code>string.lower (s)</code></h3>
5111+<p><a name="pdf-string.lower"></a><hr /><h3><code>string.lower (s)</code></h3>
49985112 Receives a string and returns a copy of that string with all
49995113 uppercase letters changed to lowercase.
50005114 All other characters are left unchanged.
5001−The definition of what is an uppercase letter depends on the current locale.
5115+The definition of what an uppercase letter is depends on the current locale.
50025116
5003−<p><a name="pdf-string.match"></a><hr/><h3><code>string.match (s, pattern [, init])</code></h3>
5117+<p><a name="pdf-string.match"></a><hr /><h3><code>string.match (s, pattern [, init])</code></h3>
50045118 Looks for the first <em>match</em> of
50055119 <code>pattern</code> in the string <code>s</code>.
50065120 If it finds one, then <code>match</code> returns
@@ -5012,14 +5126,14 @@ A third, optional numerical argument <code>init</code> specifies · 5 unmodified lines
50125126 where to start the search;
50135127 its default value is 1 and may be negative.
50145128
5015−<p><a name="pdf-string.rep"></a><hr/><h3><code>string.rep (s, n)</code></h3>
5129+<p><a name="pdf-string.rep"></a><hr /><h3><code>string.rep (s, n)</code></h3>
50165130 Returns a string that is the concatenation of <code>n</code> copies of
50175131 the string <code>s</code>.
50185132
5019−<p><a name="pdf-string.reverse"></a><hr/><h3><code>string.reverse (s)</code></h3>
5133+<p><a name="pdf-string.reverse"></a><hr /><h3><code>string.reverse (s)</code></h3>
50205134 Returns a string that is the string <code>s</code> reversed.
50215135
5022−<p><a name="pdf-string.sub"></a><hr/><h3><code>string.sub (s, i [, j])</code></h3>
5136+<p><a name="pdf-string.sub"></a><hr /><h3><code>string.sub (s, i [, j])</code></h3>
50235137 Returns the substring of <code>s</code> that
50245138 starts at <code>i</code> and continues until <code>j</code>;
50255139 <code>i</code> and <code>j</code> may be negative.
@@ -5031,11 +5145,11 @@ with length <code>j</code>, · 5 unmodified lines
50315145 and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>
50325146 with length <code>i</code>.
50335147
5034−<p><a name="pdf-string.upper"></a><hr/><h3><code>string.upper (s)</code></h3>
5148+<p><a name="pdf-string.upper"></a><hr /><h3><code>string.upper (s)</code></h3>
50355149 Receives a string and returns a copy of that string with all
50365150 lowercase letters changed to uppercase.
50375151 All other characters are left unchanged.
5038−The definition of what is a lowercase letter depends on the current locale.
5152+The definition of what a lowercase letter is depends on the current locale.
50395153
50405154 <p><a name="pm"></a><h3>Patterns</h3>
50415155
@@ -5043,7 +5157,7 @@ The definition of what is a lowercase letter depends on the current locale. · 1 unmodified line
50435157 A <em>character class</em> is used to represent a set of characters.
50445158 The following combinations are allowed in describing a character class:
50455159 <ul>
5046−<li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters
5160+<li><b><em>x</em></b> (where <em>x</em> is not one of the <em>magic characters</em>
50475161 <code>^$()%.[]*+-?</code>)
50485162 --- represents the character <em>x</em> itself.
50495163 <li><b><code>.</code></b> --- (a dot) represents all characters.
@@ -5117,11 +5231,11 @@ these repetition items will always match the <em>shortest</em> possible sequence · 67 unmodified lines
51175231 a single character class followed by `<code>?</code>&acute;,
51185232 which matches 0 or 1 occurrence of a character in the class;
51195233 <li>
5120−<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;
5234+<code>%</code><em>n</em>, for <em>n</em> between 1 and 9;
51215235 such item matches a substring equal to the <em>n</em>-th captured string
51225236 (see below);
51235237 <li>
5124−<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;
5238+<code>%b</code><em>xy</em>, where <em>x</em> and <em>y</em> are two distinct characters;
51255239 such item matches strings that start with <em>x</em>, end with <em>y</em>,
51265240 and where the <em>x</em> and <em>y</em> are <em>balanced</em>.
51275241 This means that, if one reads the string from left to right,
@@ -5149,8 +5263,8 @@ Captures are numbered according to their left parentheses. · 21 unmodified lines
51495263 For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>,
51505264 the part of the string matching <code>"a*(.)%w(%s*)"</code> is
51515265 stored as the first capture (and therefore has number 1);
5152−the character matching <code>.</code> is captured with number 2,
5153−and the part matching <code>%s*</code> has number 3.
5266+the character matching <code>"."</code> is captured with number 2,
5267+and the part matching <code>"%s*"</code> has number 3.
51545268
51555269 <p>As a special case, the empty capture <code>()</code> captures
51565270 the current string position (a number).
@@ -5168,14 +5282,14 @@ represents an array or a list. · 11 unmodified lines
51685282 For those functions, when we talk about "the length" of a table
51695283 we mean the result of the length operator.
51705284
5171−<p><a name="pdf-table.concat"></a><hr/><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3>
5285+<p><a name="pdf-table.concat"></a><hr /><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3>
51725286 Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>.
51735287 The default value for <code>sep</code> is the empty string,
51745288 the default for <code>i</code> is 1,
51755289 and the default for <code>j</code> is the length of the table.
51765290 If <code>i</code> is greater than <code>j</code>, returns the empty string.
51775291
5178−<p><a name="pdf-table.insert"></a><hr/><h3><code>table.insert (table, [pos,] value)</code></h3>
5292+<p><a name="pdf-table.insert"></a><hr /><h3><code>table.insert (table, [pos,] value)</code></h3>
51795293
51805294 <p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>,
51815295 shifting up other elements to open space, if necessary.
@@ -5184,12 +5298,12 @@ where <code>n</code> is the length of the table (see <a href="#len-op">2.5.5</a> · 2 unmodified lines
51845298 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
51855299 of table <code>t</code>.
51865300
5187−<p><a name="pdf-table.maxn(table)"></a><hr/><h3><code>table.maxn(table)</code></h3>
5301+<p><a name="pdf-table.maxn"></a><hr /><h3><code>table.maxn (table)</code></h3>
51885302
51895303 <p>Returns the largest positive numerical index of the given table,
51905304 or zero if the table has no positive numerical indices.
51915305
5192−<p><a name="pdf-table.remove"></a><hr/><h3><code>table.remove (table [, pos])</code></h3>
5306+<p><a name="pdf-table.remove"></a><hr /><h3><code>table.remove (table [, pos])</code></h3>
51935307
51945308 <p>Removes from <code>table</code> the element at position <code>pos</code>,
51955309 shifting down other elements to close the space, if necessary.
@@ -5199,7 +5313,7 @@ where <code>n</code> is the length of the table, · 3 unmodified lines
51995313 so that a call <code>table.remove(t)</code> removes the last element
52005314 of table <code>t</code>.
52015315
5202−<p><a name="pdf-table.sort"></a><hr/><h3><code>table.sort (table [, comp])</code></h3>
5316+<p><a name="pdf-table.sort"></a><hr /><h3><code>table.sort (table [, comp])</code></h3>
52035317 Sorts table elements in a given order, <em>in-place</em>,
52045318 from <code>table[1]</code> to <code>table[n]</code>,
52055319 where <code>n</code> is the length of the table.
@@ -5211,7 +5325,7 @@ when the first is less than the second · 5 unmodified lines
52115325 If <code>comp</code> is not given,
52125326 then the standard Lua operator <code>&#060;</code> is used instead.
52135327
5214−<p>The sort algorithm is not stable,
5328+<p>The sort algorithm is not stable;
52155329 that is, elements considered equal by the given order
52165330 may have their relative positions changed by the sort.
52175331
@@ -5276,7 +5390,7 @@ Equal seeds produce equal sequences of numbers. · 58 unmodified lines
52765390 <p><a name="libio"></a><a name="5.7"></a><h2>5.7 - Input and Output Facilities</h2>
52775391
52785392 <p>The I/O library provides two different styles for file manipulation.
5279−The first one uses implicit file descriptors,
5393+The first one uses implicit file descriptors;
52805394 that is, there are operations to set a default input file and a
52815395 default output file,
52825396 and all input/output operations are over those default files.
@@ -5297,16 +5411,16 @@ all I/O functions return <b>nil</b> on failure · 14 unmodified lines
52975411 (plus an error message as a second result)
52985412 and some value different from <b>nil</b> on success.
52995413
5300−<p><a name="pdf-io.close"></a><hr/><h3><code>io.close ([file])</code></h3>
5414+<p><a name="pdf-io.close"></a><hr /><h3><code>io.close ([file])</code></h3>
53015415
53025416 <p>Equivalent to <code>file:close()</code>.
53035417 Without a <code>file</code>, closes the default output file.
53045418
5305−<p><a name="pdf-io.flush"></a><hr/><h3><code>io.flush ()</code></h3>
5419+<p><a name="pdf-io.flush"></a><hr /><h3><code>io.flush ()</code></h3>
53065420
53075421 <p>Equivalent to <code>file:flush</code> over the default output file.
53085422
5309−<p><a name="pdf-io.input"></a><hr/><h3><code>io.input ([file])</code></h3>
5423+<p><a name="pdf-io.input"></a><hr /><h3><code>io.input ([file])</code></h3>
53105424
53115425 <p>When called with a file name, it opens the named file (in text mode),
53125426 and sets its handle as the default input file.
@@ -5318,7 +5432,7 @@ it returns the current default input file. · 5 unmodified lines
53185432 <p>In case of errors this function raises the error,
53195433 instead of returning an error code.
53205434
5321−<p><a name="pdf-io.lines"></a><hr/><h3><code>io.lines ([filename])</code></h3>
5435+<p><a name="pdf-io.lines"></a><hr /><h3><code>io.lines ([filename])</code></h3>
53225436
53235437 <p>Opens the given file name in read mode
53245438 and returns an iterator function that,
@@ -5333,11 +5447,11 @@ When the iterator function detects the end of file, · 8 unmodified lines
53335447 it returns <b>nil</b> (to finish the loop) and automatically closes the file.
53345448
53355449 <p>The call <code>io.lines()</code> (without a file name) is equivalent
5336−to <code>io.input():lines()</code>, that is, it iterates over the
5337−lines of the default input file.
5450+to <code>io.input():lines()</code>;
5451+that is, it iterates over the lines of the default input file.
53385452 In that case it does not close the file when the loop ends.
53395453
5340−<p><a name="pdf-io.open"></a><hr/><h3><code>io.open (filename [, mode])</code></h3>
5454+<p><a name="pdf-io.open"></a><hr /><h3><code>io.open (filename [, mode])</code></h3>
53415455
53425456 <p>This function opens a file,
53435457 in the mode specified in the string <code>mode</code>.
@@ -5346,24 +5460,24 @@ or, in case of errors, <b>nil</b> plus an error message. · 2 unmodified lines
53465460
53475461 <p>The <code>mode</code> string can be any of the following:
53485462 <ul>
5349−<li><b>"r"</b> read mode (the default);
5350−<li><b>"w"</b> write mode;
5351−<li><b>"a"</b> append mode;
5352−<li><b>"r+"</b> update mode, all previous data is preserved;
5353−<li><b>"w+"</b> update mode, all previous data is erased;
5354−<li><b>"a+"</b> append update mode, previous data is preserved,
5463+<li><b>"r"</b> --- read mode (the default);
5464+<li><b>"w"</b> --- write mode;
5465+<li><b>"a"</b> --- append mode;
5466+<li><b>"r+"</b> --- update mode, all previous data is preserved;
5467+<li><b>"w+"</b> --- update mode, all previous data is erased;
5468+<li><b>"a+"</b> --- append update mode, previous data is preserved,
53555469 writing is only allowed at the end of file.
53565470 </ul>
5357−The <code>mode</code> string may also have a <code>b</code> at the end,
5471+The <code>mode</code> string may also have a `<code>b</code>&acute; at the end,
53585472 which is needed in some systems to open the file in binary mode.
53595473 This string is exactly what is used in the
53605474 standard C function <code>fopen</code>.
53615475
5362−<p><a name="pdf-io.output"></a><hr/><h3><code>io.output ([file])</code></h3>
5476+<p><a name="pdf-io.output"></a><hr /><h3><code>io.output ([file])</code></h3>
53635477
53645478 <p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file.
53655479
5366−<p><a name="pdf-io.popen"></a><hr/><h3><code>io.popen ([prog [, mode]])</code></h3>
5480+<p><a name="pdf-io.popen"></a><hr /><h3><code>io.popen ([prog [, mode]])</code></h3>
53675481
53685482 <p>Starts program <code>prog</code> in a separated process and returns
53695483 a file handle that you can use to read data from that program
@@ -5372,40 +5486,41 @@ or to write data to that program · 2 unmodified lines
53725486 (if <code>mode</code> is <code>"w"</code>).
53735487
53745488 <p>This function is system dependent and is not available
5375−in all platforms.
5489+on all platforms.
53765490
5377−<p><a name="pdf-io.read"></a><hr/><h3><code>io.read (format1, ...)</code></h3>
5491+<p><a name="pdf-io.read"></a><hr /><h3><code>io.read (format1, ...)</code></h3>
53785492
53795493 <p>Equivalent to <code>io.input():read</code>.
53805494
5381−<p><a name="pdf-io.tmpfile"></a><hr/><h3><code>io.tmpfile ()</code></h3>
5495+<p><a name="pdf-io.tmpfile"></a><hr /><h3><code>io.tmpfile ()</code></h3>
53825496
53835497 <p>Returns a handle for a temporary file.
5384−This file is open in update mode
5498+This file is opened in update mode
53855499 and it is automatically removed when the program ends.
53865500
5387−<p><a name="pdf-io.type"></a><hr/><h3><code>io.type (obj)</code></h3>
5501+<p><a name="pdf-io.type"></a><hr /><h3><code>io.type (obj)</code></h3>
53885502
53895503 <p>Checks whether <code>obj</code> is a valid file handle.
53905504 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
53915505 <code>"closed file"</code> if <code>obj</code> is a closed file handle,
53925506 and <b>nil</b> if <code>obj</code> is not a file handle.
53935507
5394−<p><a name="pdf-io.write"></a><hr/><h3><code>io.write (value1, ...)</code></h3>
5508+<p><a name="pdf-io.write"></a><hr /><h3><code>io.write (value1, ...)</code></h3>
53955509
53965510 <p>Equivalent to <code>io.output():write</code>.
53975511
5398−<p><a name="pdf-file:close"></a><hr/><h3><code>file:close ()</code></h3>
5512+<p><a name="pdf-file:close"></a><hr /><h3><code>file:close ()</code></h3>
53995513
54005514 <p>Closes <code>file</code>.
5401−Note that files are automatically closed when garbage collected,
5515+Note that files are automatically closed when
5516+their handles are garbage collected,
54025517 but that takes an unpredictable time to happen.
54035518
5404−<p><a name="flush"></a><a name="pdf-file:flush"></a><hr/><h3><code>file:flush ()</code></h3>
5519+<p><a name="flush"></a><a name="pdf-file:flush"></a><hr /><h3><code>file:flush ()</code></h3>
54055520
54065521 <p>Saves any written data to <code>file</code>.
54075522
5408−<p><a name="pdf-file:lines"></a><hr/><h3><code>file:lines ()</code></h3>
5523+<p><a name="pdf-file:lines"></a><hr /><h3><code>file:lines ()</code></h3>
54095524
54105525 <p>Returns an iterator function that,
54115526 each time it is called,
@@ -5418,7 +5533,7 @@ will iterate over all lines of the file. · 6 unmodified lines
54185533 (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
54195534 when the loop ends.)
54205535
5421−<p><a name="pdf-file:read"></a><hr/><h3><code>file:read (format1, ...)</code></h3>
5536+<p><a name="pdf-file:read"></a><hr /><h3><code>file:read (format1, ...)</code></h3>
54225537
54235538 <p>Reads the file <code>file</code>,
54245539 according to the given formats, which specify what to read.
@@ -5445,7 +5560,7 @@ it reads nothing and returns an empty string, · 20 unmodified lines
54455560 or <b>nil</b> on end of file.
54465561 </ul>
54475562
5448−<p><a name="pdf-file:seek"></a><hr/><h3><code>file:seek ([whence] [, offset])</code></h3>
5563+<p><a name="pdf-file:seek"></a><hr /><h3><code>file:seek ([whence] [, offset])</code></h3>
54495564
54505565 <p>Sets and gets the file position,
54515566 measured from the beginning of the file,
@@ -5470,26 +5585,29 @@ beginning of the file (and returns 0); · 18 unmodified lines
54705585 and the call <code>file:seek("end")</code> sets the position to the
54715586 end of the file, and returns its size.
54725587
5473−<p><a name="pdf-file:setvbuf"></a><hr/><h3><code>file:setvbuf (mode [, size])</code></h3>
5588+<p><a name="pdf-file:setvbuf"></a><hr /><h3><code>file:setvbuf (mode [, size])</code></h3>
54745589
54755590 <p>Sets the buffering mode for an output file.
54765591 There are three available modes:
54775592 <ul>
5478−<li><b>"no"</b> no buffering; any output operation appear immediately.
5479−<li><b>"full"</b> full buffering; output operation is performed only
5480−when the buffer is full (or when you <code>flush</code> the file (see <a href="#flush">5.7</a>)).
5481−<li><b>"line"</b> line buffering; output is buffered until a newline is
5482−output or there is any input from some special files
5593+<li><b>"no"</b> ---
5594+no buffering; the result of any output operation appears immediately.
5595+<li><b>"full"</b> ---
5596+full buffering; output operation is performed only
5597+when the buffer is full (or when you explicitly <code>flush</code> the file (see <a href="#flush">5.7</a>)).
5598+<li><b>"line"</b> ---
5599+line buffering; output is buffered until a newline is output
5600+or there is any input from some special files
54835601 (such as a terminal device).
54845602 </ul>
54855603 For the last two cases, <code>sizes</code>
54865604 specifies the size of the buffer, in bytes.
54875605 The default is an appropriate size.
54885606
5489−<p><a name="pdf-file:write"></a><hr/><h3><code>file:write (value1, ...)</code></h3>
5607+<p><a name="pdf-file:write"></a><hr /><h3><code>file:write (value1, ...)</code></h3>
54905608
54915609 <p>Writes the value of each of its arguments to
5492−the filehandle <code>file</code>.
5610+the <code>file</code>.
54935611 The arguments must be strings or numbers.
54945612 To write other values,
54955613 use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.format"><code>string.format</code></a> before <code>write</code>.
@@ -5498,12 +5616,12 @@ use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.fo · 2 unmodified lines
54985616
54995617 <p>This library is implemented through table <code>os</code>.
55005618
5501−<p><a name="pdf-os.clock"></a><hr/><h3><code>os.clock ()</code></h3>
5619+<p><a name="pdf-os.clock"></a><hr /><h3><code>os.clock ()</code></h3>
55025620
5503−<p>Returns an approximation of the amount of CPU time
5504−used by the program, in seconds.
5621+<p>Returns an approximation of the amount in seconds of CPU time
5622+used by the program.
55055623
5506−<p><a name="pdf-os.date"></a><hr/><h3><code>os.date ([format [, time]])</code></h3>
5624+<p><a name="pdf-os.date"></a><hr /><h3><code>os.date ([format [, time]])</code></h3>
55075625
55085626 <p>Returns a string or a table containing date and time,
55095627 formatted according to the given string <code>format</code>.
@@ -5533,43 +5651,46 @@ formatted according to the same rules as the C function <code>strftime</code>. · 23 unmodified lines
55335651 the host system and on the current locale
55345652 (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).
55355653
5536−<p><a name="pdf-os.difftime"></a><hr/><h3><code>os.difftime (t2, t1)</code></h3>
5654+<p><a name="pdf-os.difftime"></a><hr /><h3><code>os.difftime (t2, t1)</code></h3>
55375655
55385656 <p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>.
55395657 In Posix, Windows, and some other systems,
55405658 this value is exactly <code>t2</code><em>-</em><code>t1</code>.
55415659
5542−<p><a name="pdf-os.execute"></a><hr/><h3><code>os.execute (command)</code></h3>
5660+<p><a name="pdf-os.execute"></a><hr /><h3><code>os.execute ([command])</code></h3>
55435661
55445662 <p>This function is equivalent to the C function <code>system</code>.
55455663 It passes <code>command</code> to be executed by an operating system shell.
55465664 It returns a status code, which is system-dependent.
5665+If <code>command</code> is absent, then it returns nonzero if a shell is available
5666+and zero otherwise.
55475667
5548−<p><a name="pdf-os.exit"></a><hr/><h3><code>os.exit ([code])</code></h3>
5668+<p><a name="pdf-os.exit"></a><hr /><h3><code>os.exit ([code])</code></h3>
55495669
55505670 <p>Calls the C function <code>exit</code>,
55515671 with an optional <code>code</code>,
55525672 to terminate the host program.
55535673 The default value for <code>code</code> is the success code.
55545674
5555−<p><a name="pdf-os.getenv"></a><hr/><h3><code>os.getenv (varname)</code></h3>
5675+<p><a name="pdf-os.getenv"></a><hr /><h3><code>os.getenv (varname)</code></h3>
55565676
55575677 <p>Returns the value of the process environment variable <code>varname</code>,
55585678 or <b>nil</b> if the variable is not defined.
55595679
5560−<p><a name="pdf-os.remove"></a><hr/><h3><code>os.remove (filename)</code></h3>
5680+<p><a name="pdf-os.remove"></a><hr /><h3><code>os.remove (filename)</code></h3>
55615681
5562−<p>Deletes the file with the given name.
5682+<p>Deletes the file or directory with the given name.
5683+Directories must be empty to be removed.
55635684 If this function fails, it returns <b>nil</b>,
55645685 plus a string describing the error.
55655686
5566−<p><a name="pdf-os.rename"></a><hr/><h3><code>os.rename (oldname, newname)</code></h3>
5687+<p><a name="pdf-os.rename"></a><hr /><h3><code>os.rename (oldname, newname)</code></h3>
55675688
5568−<p>Renames file named <code>oldname</code> to <code>newname</code>.
5689+<p>Renames file or directory named <code>oldname</code> to <code>newname</code>.
55695690 If this function fails, it returns <b>nil</b>,
55705691 plus a string describing the error.
55715692
5572−<p><a name="pdf-os.setlocale"></a><hr/><h3><code>os.setlocale (locale [, category])</code></h3>
5693+<p><a name="pdf-os.setlocale"></a><hr /><h3><code>os.setlocale (locale [, category])</code></h3>
55735694
55745695 <p>Sets the current locale of the program.
55755696 <code>locale</code> is a string specifying a locale;
@@ -5580,7 +5701,7 @@ the default category is <code>"all"</code>. · 4 unmodified lines
55805701 The function returns the name of the new locale,
55815702 or <b>nil</b> if the request cannot be honored.
55825703
5583−<p><a name="pdf-os.time"></a><hr/><h3><code>os.time ([table])</code></h3>
5704+<p><a name="pdf-os.time"></a><hr /><h3><code>os.time ([table])</code></h3>
55845705
55855706 <p>Returns the current time when called without arguments,
55865707 or a time representing the date and time specified by the given table.
@@ -5595,16 +5716,16 @@ In other systems, the meaning is not specified, · 8 unmodified lines
55955716 and the number returned by <code>time</code> can be used only as an argument to
55965717 <code>date</code> and <code>difftime</code>.
55975718
5598−<p><a name="pdf-os.tmpname"></a><hr/><h3><code>os.tmpname ()</code></h3>
5719+<p><a name="pdf-os.tmpname"></a><hr /><h3><code>os.tmpname ()</code></h3>
55995720
56005721 <p>Returns a string with a file name that can
56015722 be used for a temporary file.
56025723 The file must be explicitly opened before its use
5603−and removed when no longer needed.
5724+and explicitly removed when no longer needed.
56045725
5605−<p><a name="libdebug"></a><a name="5.9"></a><h2>5.9 - The Reflexive Debug Interface</h2>
5726+<p><a name="libdebug"></a><a name="5.9"></a><h2>5.9 - The Debug Library</h2>
56065727
5607−<p>The <em>debug library</em> provides
5728+<p>This library provides
56085729 the functionality of the debug interface to Lua programs.
56095730 You should exert care when using this library.
56105731 The functions provided here should be used exclusively for debugging
@@ -5614,14 +5735,15 @@ usual programming tool: · 3 unmodified lines
56145735 They can be very slow.
56155736 Moreover, several of its functions
56165737 violate some assumptions about Lua code
5617−(e.g., that local variables cannot be accessed from outside or
5738+(e.g., that variables local to a function
5739+cannot be accessed from outside or
56185740 that userdata metatables cannot be changed by Lua code)
5619−and therefore can compromise some otherwise secure code.
5741+and therefore can compromise otherwise secure code.
56205742
56215743 <p>All functions in this library are provided
5622−inside a <code>debug</code> table.
5744+inside the <code>debug</code> table.
56235745
5624−<p><a name="pdf-debug.debug"></a><hr/><h3><code>debug.debug ()</code></h3>
5746+<p><a name="pdf-debug.debug"></a><hr /><h3><code>debug.debug ()</code></h3>
56255747
56265748 <p>Enters an interactive mode with the user,
56275749 running each string that the user enters.
@@ -5631,22 +5753,22 @@ change their values, evaluate expressions, and so on. · 3 unmodified lines
56315753 A line containing only the word <code>cont</code> finishes this function,
56325754 so that the caller continues its execution.
56335755
5634−<p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested
5635−with any function, so they have no direct access to local variables.
5756+<p>Note that commands for <code>debug.debug</code> are not lexically nested
5757+within any function, and so have no direct access to local variables.
56365758
5637−<p><a name="pdf-debug.getfenv"></a><hr/><h3><code>debug.getfenv (o)</code></h3>
5759+<p><a name="pdf-debug.getfenv"></a><hr /><h3><code>debug.getfenv (o)</code></h3>
56385760 Returns the environment of object <code>o</code>.
56395761
5640−<p><a name="pdf-debug.gethook"></a><hr/><h3><code>debug.gethook ()</code></h3>
5762+<p><a name="pdf-debug.gethook"></a><hr /><h3><code>debug.gethook ()</code></h3>
56415763
56425764 <p>Returns the current hook settings, as three values:
56435765 the current hook function, the current hook mask,
56445766 and the current hook count
56455767 (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).
56465768
5647−<p><a name="pdf-debug.getinfo"></a><hr/><h3><code>debug.getinfo (function [, what])</code></h3>
5769+<p><a name="pdf-debug.getinfo"></a><hr /><h3><code>debug.getinfo (function [, what])</code></h3>
56485770
5649−<p>This function returns a table with information about a function.
5771+<p>Returns a table with information about a function.
56505772 You can give the function directly,
56515773 or you can give a number as the value of <code>function</code>,
56525774 which means the function running at level <code>function</code> of the call stack:
@@ -5664,11 +5786,11 @@ the option `<code>f</code>&acute; · 11 unmodified lines
56645786 adds a field named <code>func</code> with the function itself.
56655787
56665788 <p>For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
5667−the name of the current function, if a reasonable name can be found,
5789+a name of the current function, if a reasonable name can be found,
56685790 and <code>debug.getinfo(print)</code> returns a table with all available information
56695791 about the <a href="#pdf-print"><code>print</code></a> function.
56705792
5671−<p><a name="pdf-debug.getlocal"></a><hr/><h3><code>debug.getlocal (level, local)</code></h3>
5793+<p><a name="pdf-debug.getlocal"></a><hr /><h3><code>debug.getlocal (level, local)</code></h3>
56725794
56735795 <p>This function returns the name and the value of the local variable
56745796 with index <code>local</code> of the function at level <code>level</code> of the stack.
@@ -5683,26 +5805,26 @@ and raises an error when called with a <code>level</code> out of range. · 8 unmodified lines
56835805 represent internal variables
56845806 (loop control variables, temporaries, and C function locals).
56855807
5686−<p><a name="pdf-debug.getmetatable"></a><hr/><h3><code>debug.getmetatable (object)</code></h3>
5808+<p><a name="pdf-debug.getmetatable"></a><hr /><h3><code>debug.getmetatable (object)</code></h3>
56875809
5688−<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
5689−Otherwise, returns the metatable of the given object.
5810+<p>Returns the metatable of the given <code>object</code>
5811+or <b>nil</b> if it does not have a metatable.
56905812
5691−<p><a name="pdf-debug.getregistry"></a><hr/><h3><code>debug.getregistry ()</code></h3>
5813+<p><a name="pdf-debug.getregistry"></a><hr /><h3><code>debug.getregistry ()</code></h3>
56925814
56935815 <p>Returns the registry table (see <a href="#registry">3.5</a>).
56945816
5695−<p><a name="pdf-debug.getupvalue"></a><hr/><h3><code>debug.getupvalue (func, up)</code></h3>
5817+<p><a name="pdf-debug.getupvalue"></a><hr /><h3><code>debug.getupvalue (func, up)</code></h3>
56965818
56975819 <p>This function returns the name and the value of the upvalue
56985820 with index <code>up</code> of the function <code>func</code>.
56995821 The function returns <b>nil</b> if there is no upvalue with the given index.
57005822
5701−<p><a name="pdf-debug.setfenv"></a><hr/><h3><code>debug.setfenv (o, table)</code></h3>
5823+<p><a name="pdf-debug.setfenv"></a><hr /><h3><code>debug.setfenv (object, table)</code></h3>
57025824
5703−<p>Sets the environment of the given object.
5825+<p>Sets the environment of the given <code>object</code> to the given <code>table</code>.
57045826
5705−<p><a name="pdf-debug.sethook"></a><hr/><h3><code>debug.sethook (hook, mask [, count])</code></h3>
5827+<p><a name="pdf-debug.sethook"></a><hr /><h3><code>debug.sethook (hook, mask [, count])</code></h3>
57065828
57075829 <p>Sets the given function as a hook.
57085830 The string <code>mask</code> and the number <code>count</code> describe
@@ -5710,22 +5832,22 @@ when the hook will be called. · 1 unmodified line
57105832 The string mask may have the following characters,
57115833 with the given meaning:
57125834 <ul>
5713−<li><b><code>"c"</code></b> The hook is called every time Lua calls a function;
5714−<li><b><code>"r"</code></b> The hook is called every time Lua returns from a function;
5715−<li><b><code>"l"</code></b> The hook is called every time Lua enters a new line of code.
5835+<li><b><code>"c"</code></b> --- The hook is called every time Lua calls a function;
5836+<li><b><code>"r"</code></b> --- The hook is called every time Lua returns from a function;
5837+<li><b><code>"l"</code></b> --- The hook is called every time Lua enters a new line of code.
57165838 </ul>
57175839 With a <code>count</code> different from zero,
57185840 the hook is called after every <code>count</code> instructions.
57195841
57205842 <p>When called without arguments,
5721−the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function turns off the hook.
5843+<a href="#pdf-debug.sethook"><code>debug.sethook</code></a> turns off the hook.
57225844
5723−<p>When the hook is called, its first parameter is always a string
5724−describing the event that triggered its call:
5845+<p>When the hook is called, its first parameter is a string
5846+describing the event that has triggered its call:
57255847 <code>"call"</code>, <code>"return"</code> (or <code>"tail return"</code>),
57265848 <code>"line"</code>, and <code>"count"</code>.
5727−Moreover, for line events,
5728−it also gets as its second parameter the new line number.
5849+For line events,
5850+the hook also gets the new line number as its second parameter.
57295851 Inside a hook,
57305852 you can call <code>getinfo</code> with level 2 to get more information about
57315853 the running function
@@ -5735,7 +5857,7 @@ unless the event is <code>"tail return"</code>. · 3 unmodified lines
57355857 In this case, Lua is only simulating the return,
57365858 and a call to <code>getinfo</code> will return invalid data.
57375859
5738−<p><a name="pdf-debug.setlocal"></a><hr/><h3><code>debug.setlocal (level, local, value)</code></h3>
5860+<p><a name="pdf-debug.setlocal"></a><hr /><h3><code>debug.setlocal (level, local, value)</code></h3>
57395861
57405862 <p>This function assigns the value <code>value</code> to the local variable
57415863 with index <code>local</code> of the function at level <code>level</code> of the stack.
@@ -5745,11 +5867,12 @@ and raises an error when called with a <code>level</code> out of range. · 3 unmodified lines
57455867 (You can call <code>getinfo</code> to check whether the level is valid.)
57465868 Otherwise, it returns the name of the local variable.
57475869
5748−<p><a name="pdf-debug.setmetatable"></a><hr/><h3><code>debug.setmetatable (o, metatable)</code></h3>
5870+<p><a name="pdf-debug.setmetatable"></a><hr /><h3><code>debug.setmetatable (object, table)</code></h3>
57495871
5750−<p>Sets the metatable for the given object.
5872+<p>Sets the metatable for the given <code>object</code> to the given id@{table}
5873+(which can be <b>nil</b>).
57515874
5752−<p><a name="pdf-debug.setupvalue"></a><hr/><h3><code>debug.setupvalue (func, up, value)</code></h3>
5875+<p><a name="pdf-debug.setupvalue"></a><hr /><h3><code>debug.setupvalue (func, up, value)</code></h3>
57535876
57545877 <p>This function assigns the value <code>value</code> to the upvalue
57555878 with index <code>up</code> of the function <code>func</code>.
@@ -5757,7 +5880,7 @@ The function returns <b>nil</b> if there is no upvalue · 1 unmodified line
57575880 with the given index.
57585881 Otherwise, it returns the name of the upvalue.
57595882
5760−<p><a name="pdf-debug.traceback"></a><hr/><h3><code>debug.traceback ([message])</code></h3>
5883+<p><a name="pdf-debug.traceback"></a><hr /><h3><code>debug.traceback ([message])</code></h3>
57615884
57625885 <p>Returns a string with a traceback of the call stack.
57635886 An optional <code>message</code> string is appended
@@ -5775,7 +5898,7 @@ An interpreter for Lua as a stand-alone language, · 11 unmodified lines
57755898 called simply <code>lua</code>,
57765899 is provided with the standard distribution.
57775900 The stand-alone interpreter includes
5778−all standard libraries plus the reflexive debug interface.
5901+all standard libraries, including the debug library.
57795902 Its usage is:
57805903 <pre>
57815904 lua [options] [script [args]]
@@ -5790,30 +5913,31 @@ The options are: · 8 unmodified lines
57905913 <li><b><code>-</code> </b> executes <code>stdin</code> as a file and stops handling options.
57915914 </ul>
57925915 After handling its options, <code>lua</code> runs the given <em>script</em>,
5793−passing to it the given <em>args</em>.
5916+passing to it the given <em>args</em> as string arguments.
57945917 When called without arguments,
5795−<code>lua</code> behaves as <code>lua -v -i</code> when <code>stdin</code> is a terminal,
5918+<code>lua</code> behaves as <code>lua -v -i</code>
5919+when the standard input (<code>stdin</code>) is a terminal,
57965920 and as <code>lua -</code> otherwise.
57975921
57985922 <p>Before running any argument,
57995923 the interpreter checks for an environment variable <code>LUA_INIT</code>.
58005924 If its format is @<em>filename</em>,
5801−then lua executes the file.
5802−Otherwise, lua executes the string itself.
5925+then <code>lua</code> executes the file.
5926+Otherwise, <code>lua</code> executes the string itself.
58035927
58045928 <p>All options are handled in order, except <code>-i</code>.
58055929 For instance, an invocation like
58065930 <pre>
58075931 $ lua -e'a=1' -e 'print(a)' script.lua
58085932 </pre>
5809−will first set <code>a</code> to 1, then print <code>a</code>,
5810−and finally run the file <code>script.lua</code>.
5933+will first set <code>a</code> to 1, then print the value of <code>a</code> (which is `<code>1</code>&acute;),
5934+and finally run the file <code>script.lua</code> with no arguments.
58115935 (Here <code>$</code> is the shell prompt. Your prompt may be different.)
58125936
58135937 <p>Before starting to run the script,
58145938 <code>lua</code> collects all arguments in the command line
58155939 in a global table called <code>arg</code>.
5816−The script name is stored in index 0,
5940+The script name is stored at index 0,
58175941 the first argument after the script name goes to index 1,
58185942 and so on.
58195943 Any arguments before the script name
@@ -5821,34 +5945,40 @@ Any arguments before the script name · 1 unmodified line
58215945 go to negative indices.
58225946 For instance, in the call
58235947 <pre>
5824− $ lua -la.lua b.lua t1 t2
5948+ $ lua -la b.lua t1 t2
58255949 </pre>
58265950 the interpreter first runs the file <code>a.lua</code>,
58275951 then creates a table
58285952 <pre>
5829− arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua",
5953+ arg = { [-2] = "lua", [-1] = "-la",
5954+ [0] = "b.lua",
58305955 [1] = "t1", [2] = "t2" }
58315956 </pre>
58325957 and finally runs the file <code>b.lua</code>.
58335958 The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...
58345959 as arguments;
5835−it can access those arguments with the vararg expression <code>...</code>.
5960+it can also access those arguments with the vararg expression `<code>...</code>&acute;.
58365961
58375962 <p>In interactive mode,
58385963 if you write an incomplete statement,
5839−the interpreter waits for its completion.
5964+the interpreter waits for its completion
5965+by issuing a different prompt.
58405966
5841−<p>If the global variable <code>_PROMPT</code> is defined as a string,
5967+<p>If the global variable <code>_PROMPT</code> contains a string,
58425968 then its value is used as the prompt.
5843−Therefore, the prompt can be changed directly on the command line:
5969+Similarly, if the global variable <code>_PROMPT2</code> contains a string,
5970+it its value is used as the secondary prompt
5971+(issued during incomplete statements).
5972+Therefore, both prompts can be changed directly on the command line.
5973+For instance,
58445974 <pre>
58455975 $ lua -e"_PROMPT='myprompt> '" -i
58465976 </pre>
58475977 (the outer pair of quotes is for the shell,
5848−the inner is for Lua),
5978+the inner pair is for Lua),
58495979 or in any Lua programs by assigning to <code>_PROMPT</code>.
58505980 Note the use of <code>-i</code> to enter interactive mode; otherwise,
5851−the program would end just after the assignment to <code>_PROMPT</code>.
5981+the program would just end silently right after the assignment to <code>_PROMPT</code>.
58525982
58535983 <p>To allow the use of Lua as a
58545984 script interpreter in Unix systems,
@@ -5869,17 +5999,17 @@ then · 14 unmodified lines
58695999 </pre>
58706000 is a more portable solution.)
58716001
5872−<p><hr/>
6002+<p><hr />
58736003
5874−<p><h1>Incompatibilities with Previous Version</h1>
6004+<p><h1>Incompatibilities with the Previous Version</h1>
58756005
58766006
5877−<p>Here we list the incompatibilities when moving a program
6007+<p>Here we list the incompatibilities that may be found when moving a program
58786008 from Lua 5.0 to Lua 5.1.
58796009 You can avoid most of the incompatibilities compiling Lua with
5880−appropriate options.
6010+appropriate options (see file <code>luaconf.h</code>).
58816011 However,
5882−all those compatibility options will be removed in the next version.
6012+all those compatibility options will be removed in the next version of Lua.
58836013
58846014 <p><h2>Incompatibilities with version 5.0</h2>
58856015
@@ -5888,25 +6018,21 @@ all those compatibility options will be removed in the next version. · 2 unmodified lines
58886018 <li>
58896019 The vararg system changed from the pseudo-argument <code>arg</code> with a
58906020 table with the extra arguments to the vararg expression.
5891−(Option <code>LUA_COMPAT_VARARG</code>)
6021+(Option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)
58926022
58936023 <p><li>
58946024 There was a subtle change in the scope of the implicit
5895−variables of the <b>for</b> constructor.
6025+variables of the <b>for</b> statement and for the <b>repeat</b> statement.
58966026
58976027 <p><li>
58986028 The long string/long comment syntax (<code>[[...]]</code>) does not allow nesting.
58996029 You can use the new syntax (<code>[=[...]=]</code>) in those cases.
5900−(Option <code>LUA_COMPAT_LSTR</code>)
6030+(Option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)
59016031
59026032 <p></ul>
59036033
59046034 <p><h3>Changes in the Libraries</h3>
59056035 <ul>
5906−<li>
5907−Function <a href="#pdf-string.find"><code>string.find</code></a> does not return its captures.
5908−Use <a href="#pdf-string.match"><code>string.match</code></a> for that.
5909−(Option <code>LUA_COMPAT_FIND</code>)
59106036
59116037 <p><li>
59126038 Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.
@@ -5935,10 +6061,10 @@ Function <code>math.mod</code> was renamed <a href="#pdf-math.fmod"><code>math.f · 22 unmodified lines
59356061 (Option <code>LUA_COMPAT_MOD</code>)
59366062
59376063 <p><li>
5938−There was substantial changes in function <a href="#pdf-require"><code>require</code></a> due to
6064+There were substantial changes in function <a href="#pdf-require"><code>require</code></a> due to
59396065 the new module system.
59406066 However, the new behavior is mostly compatible with the old,
5941−but it gets the path from <a href="#pdf-package.path"><code>package.path</code></a> instead
6067+but <code>require</code> gets the path from <a href="#pdf-package.path"><code>package.path</code></a> instead
59426068 of from <code>LUA_PATH</code>.
59436069
59446070 <p><li>
@@ -5952,7 +6078,7 @@ use <code>collectgarbage("count")</code> instead. · 7 unmodified lines
59526078 <ul>
59536079 <li>
59546080 Function <code>lua_open</code> was replaced by <a href="#lua_newstate"><code>lua_newstate</code></a> to
5955−allow the user to set an allocation function.
6081+allow the user to set a memory allocation function.
59566082 You can use <a href="#luaL_newstate"><code>luaL_newstate</code></a> from the standard library to
59576083 create a state with a standard allocation function
59586084 (based on <code>realloc</code>).
@@ -5973,6 +6099,11 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 14 unmodified lines
59736099 <a name="BNF"></a><h1>The Complete Syntax of Lua</h1>
59746100
59756101
6102+<p>Here is the complete syntax of Lua in extended BNF.
6103+It does not describe operator priorities nor some syntactical restrictions,
6104+such as <b>return</b> and <b>break</b> statements
6105+can only appear as the <em>last</em> statement of a block.
6106+
59766107 <p>
59776108
59786109 <p><pre>
@@ -5991,7 +6122,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 12 unmodified lines
59916122 <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> |
59926123 <b>function</b> funcname funcbody |
59936124 <b>local</b> <b>function</b> Name funcbody |
5994− <b>local</b> namelist [init]
6125+ <b>local</b> namelist [`<b>=</b>&acute; explist1]
59956126
59966127 laststat ::= <b>return</b> [explist1] | <b>break</b>
59976128
@@ -6003,18 +6134,16 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 5 unmodified lines
60036134
60046135 namelist ::= Name {`<b>,</b>&acute; Name}
60056136
6006− init ::= `<b>=</b>&acute; explist1
6007−
60086137 explist1 ::= {exp `<b>,</b>&acute;} exp
60096138
6010− exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>&acute; |
6139+ exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | `<b>...</b>&acute; |
60116140 function | prefixexp | tableconstructor | exp binop exp | unop exp
60126141
60136142 prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
60146143
60156144 functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args
60166145
6017− args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Literal
6146+ args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | String
60186147
60196148 function ::= <b>function</b> funcbody
60206149
@@ -6026,7 +6155,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 5 unmodified lines
60266155
60276156 fieldlist ::= field {fieldsep field} [fieldsep]
60286157
6029− field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | name `<b>=</b>&acute; exp | exp
6158+ field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp
60306159
60316160 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
60326161
@@ -6042,10 +6171,5 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 9 unmodified lines
60426171
60436172 <p>
60446173
6045−<HR>
6046−<SMALL>
6047−Last update:
6048−Tue Nov 1 15:20:21 BRST 2005
6049−</SMALL>
6050−
60516174 </body></html>
6175+
src/Makefile+42−9
@@ -4,6 +4,9 @@ · 3 unmodified lines
44
55 # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
66
7+# Your platform. See PLATS for possible values.
8+PLAT= none
9+
710 CC= gcc
811 CFLAGS= -O2 -Wall $(MYCFLAGS)
912 AR= ar rcu
@@ -14,12 +17,11 @@ LIBS= -lm $(MYLIBS) · 4 unmodified lines
1417 MYCFLAGS=
1518 MYLDFLAGS=
1619 MYLIBS=
17−# enable dynamic loading and line editing in Linux
18−# MYCFLAGS= -DLUA_USE_DLOPEN -DLUA_USE_READLINE
19−# MYLIBS= -Wl,-E -ldl -lreadline -lhistory -lncurses
2020
2121 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
2222
23+PLATS= ansi bsd generic linux macosx mingw posix
24+
2325 LUA_A= liblua.a
2426 CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
2527 lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
@@ -37,6 +39,8 @@ ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) · 11 unmodified lines
3739 ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
3840 ALL_A= $(LUA_A)
3941
42+default: $(PLAT)
43+
4044 all: $(ALL_T)
4145
4246 o: $(ALL_O)
@@ -60,6 +64,7 @@ depend: · 17 unmodified lines
6064 @$(CC) $(CFLAGS) -MM l*.c print.c
6165
6266 echo:
67+ @echo "PLAT = $(PLAT)"
6368 @echo "CC = $(CC)"
6469 @echo "CFLAGS = $(CFLAGS)"
6570 @echo "AR = $(AR)"
@@ -69,6 +74,34 @@ echo: · 3 unmodified lines
6974 @echo "MYLDFLAGS = $(MYLDFLAGS)"
7075 @echo "MYLIBS = $(MYLIBS)"
7176
77+# convenience targets for usual platforms
78+
79+none:
80+ @echo "Please choose a platform: $(PLATS)"
81+
82+ansi:
83+ $(MAKE) all MYCFLAGS=-DLUA_ANSI
84+
85+bsd:
86+ $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
87+
88+generic:
89+ $(MAKE) all MYCFLAGS=
90+
91+linux:
92+ $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
93+
94+macosx:
95+ $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
96+
97+mingw:
98+ $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
99+ "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \
100+ "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
101+
102+posix:
103+ $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
104+
72105 # DO NOT DELETE
73106
74107 lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
@@ -86,8 +119,8 @@ ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ · 11 unmodified lines
86119 ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
87120 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
88121 lstring.h lundump.h lvm.h
89−ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \
90− ltm.h lzio.h lmem.h lundump.h
122+ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
123+ lzio.h lmem.h lundump.h
91124 lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
92125 lstate.h ltm.h lzio.h
93126 lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
@@ -99,10 +132,11 @@ llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ · 5 unmodified lines
99132 lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
100133 lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
101134 ltm.h lzio.h lmem.h ldo.h
102−loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
135+loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \
136+ lualib.h
103137 lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
104138 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
105−lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h
139+lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
106140 loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
107141 lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
108142 lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
@@ -122,8 +156,7 @@ luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \ · 13 unmodified lines
122156 lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
123157 lundump.h
124158 lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
125− llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \
126− lundump.h
159+ llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
127160 lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
128161 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
129162 lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
src/lapi.c+13−14
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.51 2005/10/20 11:35:50 roberto Exp $
2+** $Id: lapi.c,v 2.53 2006/01/10 12:50:00 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -40,7 +40,7 @@ const char lua_ident[] = · 34 unmodified lines
4040
4141 #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
4242
43−#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject)
43+#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
4444
4545 #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
4646
@@ -50,7 +50,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 3 unmodified lines
5050 if (idx > 0) {
5151 TValue *o = L->base + (idx - 1);
5252 api_check(L, idx <= L->ci->top - L->base);
53− if (o >= L->top) return cast(TValue *, &luaO_nilobject);
53+ if (o >= L->top) return cast(TValue *, luaO_nilobject);
5454 else return o;
5555 }
5656 else if (idx > LUA_REGISTRYINDEX) {
@@ -70,7 +70,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 13 unmodified lines
7070 idx = LUA_GLOBALSINDEX - idx;
7171 return (idx <= func->c.nupvalues)
7272 ? &func->c.upvalue[idx-1]
73− : cast(TValue *, &luaO_nilobject);
73+ : cast(TValue *, luaO_nilobject);
7474 }
7575 }
7676 }
@@ -153,7 +153,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 76 unmodified lines
153153
154154
155155 LUA_API int lua_gettop (lua_State *L) {
156− return cast(int, L->top - L->base);
156+ return cast_int(L->top - L->base);
157157 }
158158
159159
@@ -234,7 +234,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 74 unmodified lines
234234
235235 LUA_API int lua_type (lua_State *L, int idx) {
236236 StkId o = index2adr(L, idx);
237− return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o);
237+ return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
238238 }
239239
240240
@@ -272,7 +272,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { · 31 unmodified lines
272272 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
273273 StkId o1 = index2adr(L, index1);
274274 StkId o2 = index2adr(L, index2);
275− return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
275+ return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
276276 : luaO_rawequalObj(o1, o2);
277277 }
278278
@@ -283,8 +283,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { · 4 unmodified lines
283283 lua_lock(L); /* may call tag method */
284284 o1 = index2adr(L, index1);
285285 o2 = index2adr(L, index2);
286− i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
287− : equalobj(L, o1, o2);
286+ i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
288287 lua_unlock(L);
289288 return i;
290289 }
@@ -296,7 +295,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 5 unmodified lines
296295 lua_lock(L); /* may call tag method */
297296 o1 = index2adr(L, index1);
298297 o2 = index2adr(L, index2);
299− i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0
298+ i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
300299 : luaV_lessthan(L, o1, o2);
301300 lua_unlock(L);
302301 return i;
@@ -430,7 +429,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { · 127 unmodified lines
430429
431430 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
432431 lua_lock(L);
433− setnvalue(L->top, cast(lua_Number, n));
432+ setnvalue(L->top, cast_num(n));
434433 api_incr_top(L);
435434 lua_unlock(L);
436435 }
@@ -910,11 +909,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 473 unmodified lines
910909 }
911910 case LUA_GCCOUNT: {
912911 /* GC values are expressed in Kbytes: #bytes/2^10 */
913− res = cast(int, g->totalbytes >> 10);
912+ res = cast_int(g->totalbytes >> 10);
914913 break;
915914 }
916915 case LUA_GCCOUNTB: {
917− res = cast(int, g->totalbytes & 0x3ff);
916+ res = cast_int(g->totalbytes & 0x3ff);
918917 break;
919918 }
920919 case LUA_GCSTEP: {
@@ -983,7 +982,7 @@ LUA_API void lua_concat (lua_State *L, int n) { · 62 unmodified lines
983982 api_checknelems(L, n);
984983 if (n >= 2) {
985984 luaC_checkGC(L);
986− luaV_concat(L, n, cast(int, L->top - L->base) - 1);
985+ luaV_concat(L, n, cast_int(L->top - L->base) - 1);
987986 L->top -= (n-1);
988987 }
989988 else if (n == 0) { /* push empty string */
src/lauxlib.c+13−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp $
2+** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -226,16 +226,24 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname, · 220 unmodified lines
226226 }
227227
228228
229+static int libsize (const luaL_Reg *l) {
230+ int size = 0;
231+ for (; l->name; l++) size++;
232+ return size;
233+}
234+
235+
229236 LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
230237 const luaL_Reg *l, int nup) {
231238 if (libname) {
239+ int size = libsize(l);
232240 /* check whether lib already exists */
233− luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
241+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size);
234242 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
235243 if (!lua_istable(L, -1)) { /* not found? */
236244 lua_pop(L, 1); /* remove previous result */
237245 /* try global variable (and create one if it does not exist) */
238− if (luaL_findtable(L, LUA_GLOBALSINDEX, libname) != NULL)
246+ if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
239247 luaL_error(L, "name conflict for module " LUA_QS, libname);
240248 lua_pushvalue(L, -1);
241249 lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
@@ -331,7 +339,7 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, · 89 unmodified lines
331339
332340
333341 LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
334− const char *fname) {
342+ const char *fname, int szhint) {
335343 const char *e;
336344 lua_pushvalue(L, idx);
337345 do {
@@ -341,7 +349,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, · 3 unmodified lines
341349 lua_rawget(L, -2);
342350 if (lua_isnil(L, -1)) { /* no such field? */
343351 lua_pop(L, 1); /* remove this nil */
344− lua_newtable(L); /* create a new table for field */
352+ lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
345353 lua_pushlstring(L, fname, e - fname);
346354 lua_pushvalue(L, -2);
347355 lua_settable(L, -4); /* set new table into field */
src/lauxlib.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.86 2005/10/21 13:47:42 roberto Exp $
2+** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -86,7 +86,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, · 80 unmodified lines
8686 const char *r);
8787
8888 LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
89− const char *fname);
89+ const char *fname, int szhint);
9090
9191
9292
src/lbaselib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.186 2005/10/21 13:47:42 roberto Exp $
2+** $Id: lbaselib.c,v 1.188 2005/12/29 15:32:11 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -201,7 +201,7 @@ static int luaB_collectgarbage (lua_State *L) { · 195 unmodified lines
201201 switch (optsnum[o]) {
202202 case LUA_GCCOUNT: {
203203 int b = lua_gc(L, LUA_GCCOUNTB, 0);
204− lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000);
204+ lua_pushnumber(L, ((lua_Number)res*1024 + b)/1024);
205205 return 1;
206206 }
207207 case LUA_GCSTEP: {
@@ -625,7 +625,7 @@ static void base_open (lua_State *L) { · 417 unmodified lines
625625 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
626626 auxopen(L, "pairs", luaB_pairs, luaB_next);
627627 /* `newproxy' needs a weaktable as upvalue */
628− lua_newtable(L); /* new table `w' */
628+ lua_createtable(L, 0, 1); /* new table `w' */
629629 lua_pushvalue(L, -1); /* `w' will be its own metatable */
630630 lua_setmetatable(L, -2);
631631 lua_pushliteral(L, "kv");
src/lcode.c+6−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.22 2005/11/16 11:55:27 roberto Exp $
2+** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -196,7 +196,7 @@ void luaK_checkstack (FuncState *fs, int n) { · 190 unmodified lines
196196 if (newstack > fs->f->maxstacksize) {
197197 if (newstack >= MAXSTACK)
198198 luaX_syntaxerror(fs->ls, "function or expression too complex");
199− fs->f->maxstacksize = cast(lu_byte, newstack);
199+ fs->f->maxstacksize = cast_byte(newstack);
200200 }
201201 }
202202
@@ -227,11 +227,11 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { · 24 unmodified lines
227227 Proto *f = fs->f;
228228 int oldsize = f->sizek;
229229 if (ttisnumber(idx)) {
230− lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v));
231− return cast(int, nvalue(idx));
230+ lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
231+ return cast_int(nvalue(idx));
232232 }
233233 else { /* constant not found; create a new entry */
234− setnvalue(idx, cast(lua_Number, fs->nk));
234+ setnvalue(idx, cast_num(fs->nk));
235235 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
236236 MAXARG_Bx, "constant table overflow");
237237 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
@@ -647,7 +647,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { · 409 unmodified lines
647647 case OP_LEN: return 0; /* no constant folding for 'len' */
648648 default: lua_assert(0); r = 0; break;
649649 }
650− if (r != r) return 0; /* do not attempt to produce NaN */
650+ if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */
651651 e1->u.nval = r;
652652 return 1;
653653 }
src/ldblib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.103 2005/11/01 16:08:32 roberto Exp $
2+** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -116,7 +116,7 @@ static int db_getinfo (lua_State *L) { · 110 unmodified lines
116116 return luaL_argerror(L, arg+1, "function or level expected");
117117 if (!lua_getinfo(L1, options, &ar))
118118 return luaL_argerror(L, arg+2, "invalid option");
119− lua_newtable(L);
119+ lua_createtable(L, 0, 2);
120120 if (strchr(options, 'S')) {
121121 settabss(L, "source", ar.source);
122122 settabss(L, "short_src", ar.short_src);
@@ -246,7 +246,7 @@ static void gethooktable (lua_State *L) { · 123 unmodified lines
246246 lua_rawget(L, LUA_REGISTRYINDEX);
247247 if (!lua_istable(L, -1)) {
248248 lua_pop(L, 1);
249− lua_newtable(L);
249+ lua_createtable(L, 0, 1);
250250 lua_pushlightuserdata(L, (void *)&KEY_HOOK);
251251 lua_pushvalue(L, -2);
252252 lua_rawset(L, LUA_REGISTRYINDEX);
src/ldebug.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp $
2+** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -61,7 +61,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { · 55 unmodified lines
6161 L->hook = func;
6262 L->basehookcount = count;
6363 resethookcount(L);
64− L->hookmask = cast(lu_byte, mask);
64+ L->hookmask = cast_byte(mask);
6565 return 1;
6666 }
6767
@@ -92,7 +92,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 24 unmodified lines
9292 }
9393 if (level == 0 && ci > L->base_ci) { /* level found? */
9494 status = 1;
95− ar->i_ci = cast(int, ci - L->base_ci);
95+ ar->i_ci = cast_int(ci - L->base_ci);
9696 }
9797 else if (level < 0) { /* level is of a lost tail call? */
9898 status = 1;
@@ -550,7 +550,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 451 unmodified lines
550550 const char *name = NULL;
551551 const char *t = luaT_typenames[ttype(o)];
552552 const char *kind = (isinstack(L->ci, o)) ?
553− getobjname(L, L->ci, cast(int, o - L->base), &name) :
553+ getobjname(L, L->ci, cast_int(o - L->base), &name) :
554554 NULL;
555555 if (kind)
556556 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
src/ldo.c+8−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp $
2+** $Id: ldo.c,v 2.37 2005/12/22 16:19:56 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -71,7 +71,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 65 unmodified lines
7171 static void restore_stack_limit (lua_State *L) {
7272 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
7373 if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */
74− int inuse = cast(int, L->ci - L->base_ci);
74+ int inuse = cast_int(L->ci - L->base_ci);
7575 if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
7676 luaD_reallocCI(L, LUAI_MAXCALLS);
7777 }
@@ -97,7 +97,7 @@ void luaD_throw (lua_State *L, int errcode) { · 19 unmodified lines
9797 LUAI_THROW(L, L->errorJmp);
9898 }
9999 else {
100− L->status = cast(lu_byte, errcode);
100+ L->status = cast_byte(errcode);
101101 if (G(L)->panic) {
102102 resetstack(L, errcode);
103103 lua_unlock(L);
@@ -189,7 +189,7 @@ void luaD_callhook (lua_State *L, int event, int line) { · 85 unmodified lines
189189 if (event == LUA_HOOKTAILRET)
190190 ar.i_ci = 0; /* tail call; no debug information about it */
191191 else
192− ar.i_ci = cast(int, L->ci - L->base_ci);
192+ ar.i_ci = cast_int(L->ci - L->base_ci);
193193 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
194194 L->ci->top = L->top + LUA_MINSTACK;
195195 lua_assert(L->ci->top <= L->stack_last);
@@ -221,8 +221,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { · 25 unmodified lines
221221 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
222222 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
223223 /* store counter in field `n' */
224− setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),
225− cast(lua_Number, nvar));
224+ setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
226225 }
227226 #endif
228227 /* move fixed parameters to final position */
@@ -282,7 +281,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 53 unmodified lines
282281 L->top = base + p->numparams;
283282 }
284283 else { /* vararg function */
285− int nargs = cast(int, L->top - func) - 1;
284+ int nargs = cast_int(L->top - func) - 1;
286285 base = adjust_varargs(L, p, nargs);
287286 func = restorestack(L, funcr); /* previous call may change the stack */
288287 }
@@ -401,7 +400,7 @@ static void resume (lua_State *L, void *ud) { · 112 unmodified lines
401400 L->base = L->ci->base;
402401 }
403402 L->status = 0;
404− luaV_execute(L, cast(int, L->ci - L->base_ci));
403+ luaV_execute(L, cast_int(L->ci - L->base_ci));
405404 }
406405
407406
@@ -427,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 19 unmodified lines
427426 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
428427 status = luaD_rawrunprotected(L, resume, L->top - nargs);
429428 if (status != 0) { /* error? */
430− L->status = cast(lu_byte, status); /* mark thread as `dead' */
429+ L->status = cast_byte(status); /* mark thread as `dead' */
431430 luaD_seterrorobj(L, status, L->top);
432431 L->ci->top = L->top;
433432 }
src/lfunc.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lfunc.c,v 2.11 2005/05/05 20:47:02 roberto Exp $
2+** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $
33 ** Auxiliary functions to manipulate prototypes and closures
44 ** See Copyright Notice in lua.h
55 */
@@ -25,7 +25,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { · 19 unmodified lines
2525 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
2626 c->c.isC = 1;
2727 c->c.env = e;
28− c->c.nupvalues = cast(lu_byte, nelems);
28+ c->c.nupvalues = cast_byte(nelems);
2929 return c;
3030 }
3131
@@ -35,7 +35,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { · 3 unmodified lines
3535 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
3636 c->l.isC = 0;
3737 c->l.env = e;
38− c->l.nupvalues = cast(lu_byte, nelems);
38+ c->l.nupvalues = cast_byte(nelems);
3939 while (nelems--) c->l.upvals[nelems] = NULL;
4040 return c;
4141 }
src/lgc.c+8−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.36 2005/08/24 17:06:36 roberto Exp $
2+** $Id: lgc.c,v 2.37 2005/12/22 16:19:56 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -29,11 +29,10 @@ · 23 unmodified lines
2929 #define GCFINALIZECOST 100
3030
3131
32−#define maskmarks \
33− cast(lu_byte, ~(bitmask(BLACKBIT)|WHITEBITS))
32+#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
3433
3534 #define makewhite(g,x) \
36− ((x)->gch.marked = ((x)->gch.marked & maskmarks) | luaC_white(g))
35+ ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
3736
3837 #define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
3938 #define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
@@ -169,8 +168,8 @@ static int traversetable (global_State *g, Table *h) { · 129 unmodified lines
169168 weakvalue = (strchr(svalue(mode), 'v') != NULL);
170169 if (weakkey || weakvalue) { /* is really weak? */
171170 h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
172− h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) |
173− (weakvalue << VALUEWEAKBIT));
171+ h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
172+ (weakvalue << VALUEWEAKBIT));
174173 h->gclist = g->weak; /* must be cleared after GC, ... */
175174 g->weak = obj2gco(h); /* ... so put in the appropriate list */
176175 }
@@ -240,8 +239,8 @@ static void traverseclosure (global_State *g, Closure *cl) { · 63 unmodified lines
240239
241240
242241 static void checkstacksizes (lua_State *L, StkId max) {
243− int ci_used = cast(int, L->ci - L->base_ci); /* number of `ci' in use */
244− int s_used = cast(int, max - L->stack); /* part of stack in use */
242+ int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
243+ int s_used = cast_int(max - L->stack); /* part of stack in use */
245244 if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
246245 return; /* do not touch the stacks */
247246 if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
@@ -544,7 +543,7 @@ static void atomic (lua_State *L) { · 296 unmodified lines
544543 propagateall(g); /* remark, to propagate `preserveness' */
545544 cleartable(g->weak); /* remove collected objects from weak tables */
546545 /* flip current white */
547− g->currentwhite = cast(lu_byte, otherwhite(g));
546+ g->currentwhite = cast_byte(otherwhite(g));
548547 g->sweepstrgc = 0;
549548 g->sweepgc = &g->rootgc;
550549 g->gcstate = GCSsweepstring;
src/linit.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: linit.c,v 1.13 2005/08/26 17:36:32 roberto Exp $
2+** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $
33 ** Initialization of libraries for lua.c
44 ** See Copyright Notice in lua.h
55 */
@@ -16,13 +16,13 @@ · 10 unmodified lines
1616
1717 static const luaL_Reg lualibs[] = {
1818 {"", luaopen_base},
19+ {LUA_LOADLIBNAME, luaopen_package},
1920 {LUA_TABLIBNAME, luaopen_table},
2021 {LUA_IOLIBNAME, luaopen_io},
2122 {LUA_OSLIBNAME, luaopen_os},
2223 {LUA_STRLIBNAME, luaopen_string},
2324 {LUA_MATHLIBNAME, luaopen_math},
2425 {LUA_DBLIBNAME, luaopen_debug},
25− {LUA_LOADLIBNAME, luaopen_package},
2626 {NULL, NULL}
2727 };
2828
src/liolib.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.69 2005/10/19 13:05:11 roberto Exp $
2+** $Id: liolib.c,v 2.70 2005/12/29 15:32:11 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -507,8 +507,8 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { · 501 unmodified lines
507507
508508 LUALIB_API int luaopen_io (lua_State *L) {
509509 createmeta(L);
510− /* create new (private) environment */
511− lua_newtable(L);
510+ /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
511+ lua_createtable(L, 2, 1);
512512 lua_replace(L, LUA_ENVIRONINDEX);
513513 /* open library */
514514 luaL_register(L, LUA_IOLIBNAME, iolib);
@@ -518,7 +518,7 @@ LUALIB_API int luaopen_io (lua_State *L) { · 3 unmodified lines
518518 createstdfile(L, stderr, 0, "stderr");
519519 /* create environment for 'popen' */
520520 lua_getfield(L, -1, "popen");
521− lua_newtable(L);
521+ lua_createtable(L, 0, 1);
522522 lua_pushcfunction(L, io_pclose);
523523 lua_setfield(L, -2, "__close");
524524 lua_setfenv(L, -2);
src/llex.c+46−6
@@ -1,11 +1,12 @@
11 /*
2−** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp $
2+** $Id: llex.c,v 2.17 2005/12/22 16:19:56 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
66
77
88 #include <ctype.h>
9+#include <locale.h>
910 #include <string.h>
1011
1112 #define llex_c
@@ -65,7 +66,7 @@ void luaX_init (lua_State *L) { · 53 unmodified lines
6566 TString *ts = luaS_new(L, luaX_tokens[i]);
6667 luaS_fix(ts); /* reserved words are never collected */
6768 lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
68− ts->tsv.reserved = cast(lu_byte, i+1); /* reserved word */
69+ ts->tsv.reserved = cast_byte(i+1); /* reserved word */
6970 }
7071 }
7172
@@ -134,6 +135,7 @@ static void inclinenumber (LexState *ls) { · 62 unmodified lines
134135
135136
136137 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
138+ ls->decpoint = '.';
137139 ls->L = L;
138140 ls->lookahead.token = TK_EOS; /* no look-ahead token */
139141 ls->z = z;
@@ -163,6 +165,27 @@ static int check_next (LexState *ls, const char *set) { · 23 unmodified lines
163165 }
164166
165167
168+static void buffreplace (LexState *ls, char from, char to) {
169+ int n = luaZ_bufflen(ls->buff);
170+ char *p = luaZ_buffer(ls->buff);
171+ while (n--)
172+ if (p[n] == from) p[n] = to;
173+}
174+
175+
176+static void trydecpoint (LexState *ls, SemInfo *seminfo) {
177+ /* format error: try to update decimal point separator */
178+ struct lconv *cv = localeconv();
179+ char old = ls->decpoint;
180+ ls->decpoint = (cv ? cv->decimal_point[0] : '.');
181+ buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
182+ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
183+ /* format error with correct decimal point: no more options */
184+ buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
185+ luaX_lexerror(ls, "malformed number", TK_NUMBER);
186+ }
187+}
188+
166189
167190 /* LUA_NUMBER */
168191 static void read_numeral (LexState *ls, SemInfo *seminfo) {
@@ -177,8 +200,9 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 8 unmodified lines
177200 }
178201 }
179202 save(ls, '\0');
180− if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))
181− luaX_lexerror(ls, "malformed number", TK_NUMBER);
203+ buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
204+ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
205+ trydecpoint(ls, seminfo); /* try to update decimal point separator */
182206 }
183207
184208
@@ -306,7 +330,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 121 unmodified lines
306330 }
307331
308332
309−int luaX_lex (LexState *ls, SemInfo *seminfo) {
333+static int llex (LexState *ls, SemInfo *seminfo) {
310334 luaZ_resetbuffer(ls->buff);
311335 for (;;) {
312336 switch (ls->current) {
@@ -419,4 +443,20 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 106 unmodified lines
419443 }
420444 }
421445
422−#undef next
446+
447+void luaX_next (LexState *ls) {
448+ ls->lastline = ls->linenumber;
449+ if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
450+ ls->t = ls->lookahead; /* use this one */
451+ ls->lookahead.token = TK_EOS; /* and discharge it */
452+ }
453+ else
454+ ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
455+}
456+
457+
458+void luaX_lookahead (LexState *ls) {
459+ lua_assert(ls->lookahead.token == TK_EOS);
460+ ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
461+}
462+
src/llex.h+4−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.h,v 1.55 2005/06/06 13:30:25 roberto Exp $
2+** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -63,6 +63,7 @@ typedef struct LexState { · 57 unmodified lines
6363 ZIO *z; /* input stream */
6464 Mbuffer *buff; /* buffer for tokens */
6565 TString *source; /* current source name */
66+ char decpoint; /* locale decimal point */
6667 } LexState;
6768
6869
@@ -70,7 +71,8 @@ LUAI_FUNC void luaX_init (lua_State *L); · 1 unmodified line
7071 LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,
7172 TString *source);
7273 LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);
73−LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo);
74+LUAI_FUNC void luaX_next (LexState *ls);
75+LUAI_FUNC void luaX_lookahead (LexState *ls);
7476 LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
7577 LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
7678 LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
src/llimits.h+18−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.67 2005/08/24 16:15:49 roberto Exp $
2+** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -15,9 +15,6 @@ · 9 unmodified lines
1515 #include "lua.h"
1616
1717
18−#define api_check luai_apicheck
19−
20−
2118 typedef LUAI_UINT32 lu_int32;
2219
2320 typedef LUAI_UMEM lu_mem;
@@ -54,7 +51,19 @@ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; · 30 unmodified lines
5451 typedef LUAI_UACNUMBER l_uacNumber;
5552
5653
57−#define check_exp(c,e) (lua_assert(c), (e))
54+/* internal assertions for in-house debugging */
55+#ifdef lua_assert
56+
57+#define check_exp(c,e) (lua_assert(c), (e))
58+#define api_check(l,e) lua_assert(e)
59+
60+#else
61+
62+#define lua_assert(c) ((void)0)
63+#define check_exp(c,e) (e)
64+#define api_check luai_apicheck
65+
66+#endif
5867
5968
6069 #ifndef UNUSED
@@ -66,6 +75,10 @@ typedef LUAI_UACNUMBER l_uacNumber; · 5 unmodified lines
6675 #define cast(t, exp) ((t)(exp))
6776 #endif
6877
78+#define cast_byte(i) cast(lu_byte, (i))
79+#define cast_num(i) cast(lua_Number, (i))
80+#define cast_int(i) cast(int, (i))
81+
6982
7083
7184 /*
src/lmem.c+1−17
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.c,v 1.69 2005/02/23 17:30:22 roberto Exp $
2+** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
@@ -81,22 +81,6 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 75 unmodified lines
8181 luaD_throw(L, LUA_ERRMEM);
8282 lua_assert((nsize == 0) == (block == NULL));
8383 g->totalbytes = (g->totalbytes - osize) + nsize;
84−#if 0
85− { /* auxiliar patch to monitor garbage collection */
86− static unsigned long total = 0; /* our "time" */
87− static lu_mem last = 0; /* last totalmem that generated an output */
88− static FILE *f = NULL; /* output file */
89− if (nsize <= osize) total += 1; /* "time" always grow */
90− else total += (nsize - osize);
91− if ((int)g->totalbytes - (int)last > 1000 ||
92− (int)g->totalbytes - (int)last < -1000) {
93− last = g->totalbytes;
94− if (f == NULL) f = fopen("trace", "w");
95− fprintf(f, "%lu %u %u %u %d\n", total, g->totalbytes, g->GCthreshold,
96− g->estimate, g->gcstate);
97− }
98− }
99−#endif
10084 return block;
10185 }
10286
src/loadlib.c+38−27
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.48 2005/10/17 18:01:51 roberto Exp $
2+** $Id: loadlib.c,v 1.51 2005/12/29 15:32:11 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -16,8 +16,9 @@ · 10 unmodified lines
1616 #define loadlib_c
1717 #define LUA_LIB
1818
19−#include "lua.h"
2019 #include "lauxlib.h"
20+#include "lobject.h"
21+#include "lua.h"
2122 #include "lualib.h"
2223
2324
@@ -236,11 +237,8 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 212 unmodified lines
236237 #define LIB_FAIL "absent"
237238
238239
239−#if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux)
240−#define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation"
241−#else
242−#define DLMSG LUA_QL("loadlib") " not supported"
243−#endif
240+#define DLMSG "dynamic libraries not enabled; check your Lua installation"
241+
244242
245243 static void ll_unloadlib (void *lib) {
246244 (void)lib; /* to avoid warnings */
@@ -362,20 +360,23 @@ static const char *findfile (lua_State *L, const char *name, · 115 unmodified lines
362360 path = lua_tostring(L, -1);
363361 if (path == NULL)
364362 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
363+ lua_pushstring(L, ""); /* error accumulator */
365364 while ((path = pushnexttemplate(L, path)) != NULL) {
366365 const char *filename;
367366 filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
368367 if (readable(filename)) /* does file exist and is readable? */
369368 return filename; /* return that file name */
370369 lua_pop(L, 2); /* remove path template and file name */
370+ luaO_pushfstring(L, "\n\tno file " LUA_QS, filename);
371+ lua_concat(L, 2);
371372 }
372373 return NULL; /* not found */
373374 }
374375
375376
376−static void loaderror (lua_State *L) {
377− luaL_error(L, "error loading module " LUA_QS " (%s)",
378− lua_tostring(L, 1), lua_tostring(L, -1));
377+static void loaderror (lua_State *L, const char *filename) {
378+ luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
379+ lua_tostring(L, 1), filename, lua_tostring(L, -1));
379380 }
380381
381382
@@ -383,9 +384,9 @@ static int loader_Lua (lua_State *L) { · 1 unmodified line
383384 const char *filename;
384385 const char *name = luaL_checkstring(L, 1);
385386 filename = findfile(L, name, "path");
386− if (filename == NULL) return 0; /* library not found in this path */
387+ if (filename == NULL) return 1; /* library not found in this path */
387388 if (luaL_loadfile(L, filename) != 0)
388− loaderror(L);
389+ loaderror(L, filename);
389390 return 1; /* library loaded successfully */
390391 }
391392
@@ -405,10 +406,10 @@ static int loader_C (lua_State *L) { · 13 unmodified lines
405406 const char *funcname;
406407 const char *name = luaL_checkstring(L, 1);
407408 const char *filename = findfile(L, name, "cpath");
408− if (filename == NULL) return 0; /* library not found in this path */
409+ if (filename == NULL) return 1; /* library not found in this path */
409410 funcname = mkfuncname(L, name);
410411 if (ll_loadfunc(L, filename, funcname) != 0)
411− loaderror(L);
412+ loaderror(L, filename);
412413 return 1; /* library loaded successfully */
413414 }
414415
@@ -422,22 +423,26 @@ static int loader_Croot (lua_State *L) { · 7 unmodified lines
422423 if (p == NULL) return 0; /* is root */
423424 lua_pushlstring(L, name, p - name);
424425 filename = findfile(L, lua_tostring(L, -1), "cpath");
425− if (filename == NULL) return 0; /* root not found */
426+ if (filename == NULL) return 1; /* root not found */
426427 funcname = mkfuncname(L, name);
427428 if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
428− if (stat == ERRFUNC) return 0; /* function not found */
429− else
430− loaderror(L); /* real error */
429+ if (stat != ERRFUNC) loaderror(L, filename); /* real error */
430+ luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
431+ name, filename);
432+ return 1; /* function not found */
431433 }
432434 return 1;
433435 }
434436
435437
436438 static int loader_preload (lua_State *L) {
439+ const char *name = luaL_checkstring(L, 1);
437440 lua_getfield(L, LUA_ENVIRONINDEX, "preload");
438441 if (!lua_istable(L, -1))
439442 luaL_error(L, LUA_QL("package.preload") " must be a table");
440− lua_getfield(L, -1, luaL_checkstring(L, 1));
443+ lua_getfield(L, -1, name);
444+ if (lua_isnil(L, -1)) /* not found? */
445+ luaO_pushfstring(L, "\n\tno field package.preload['%s']", name);
441446 return 1;
442447 }
443448
@@ -461,14 +466,20 @@ static int ll_require (lua_State *L) { · 17 unmodified lines
461466 lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
462467 if (!lua_istable(L, -1))
463468 luaL_error(L, LUA_QL("package.loaders") " must be a table");
469+ lua_pushstring(L, ""); /* error message accumulator */
464470 for (i=1; ; i++) {
465− lua_rawgeti(L, -1, i); /* get a loader */
471+ lua_rawgeti(L, -2, i); /* get a loader */
466472 if (lua_isnil(L, -1))
467− luaL_error(L, "module " LUA_QS " not found", name);
473+ luaL_error(L, "module " LUA_QS " not found:%s",
474+ name, lua_tostring(L, -2));
468475 lua_pushstring(L, name);
469476 lua_call(L, 1, 1); /* call it */
470− if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */
471− else break; /* module loaded successfully */
477+ if (lua_isfunction(L, -1)) /* did it find module? */
478+ break; /* module loaded successfully */
479+ else if (lua_isstring(L, -1)) /* loader returned error message? */
480+ lua_concat(L, 2); /* accumulate it */
481+ else
482+ lua_pop(L, 1);
472483 }
473484 lua_pushlightuserdata(L, sentinel);
474485 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
@@ -539,7 +550,7 @@ static int ll_module (lua_State *L) { · 64 unmodified lines
539550 if (!lua_istable(L, -1)) { /* not found? */
540551 lua_pop(L, 1); /* remove previous result */
541552 /* try global variable (and create one if it does not exist) */
542− if (luaL_findtable(L, LUA_GLOBALSINDEX, modname) != NULL)
553+ if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
543554 return luaL_error(L, "name conflict for module " LUA_QS, modname);
544555 lua_pushvalue(L, -1);
545556 lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
@@ -562,7 +573,7 @@ static int ll_module (lua_State *L) { · 16 unmodified lines
562573 static int ll_seeall (lua_State *L) {
563574 luaL_checktype(L, 1, LUA_TTABLE);
564575 if (!lua_getmetatable(L, 1)) {
565− lua_newtable(L); /* create new metatable */
576+ lua_createtable(L, 0, 1); /* create new metatable */
566577 lua_pushvalue(L, -1);
567578 lua_setmetatable(L, 1);
568579 }
@@ -629,7 +640,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 60 unmodified lines
629640 lua_pushvalue(L, -1);
630641 lua_replace(L, LUA_ENVIRONINDEX);
631642 /* create `loaders' table */
632− lua_newtable(L);
643+ lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
633644 /* fill it with pre-defined loaders */
634645 for (i=0; loaders[i] != NULL; i++) {
635646 lua_pushcfunction(L, loaders[i]);
@@ -643,7 +654,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 7 unmodified lines
643654 LUA_EXECDIR "\n" LUA_IGMARK);
644655 lua_setfield(L, -2, "config");
645656 /* set field `loaded' */
646− luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
657+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
647658 lua_setfield(L, -2, "loaded");
648659 /* set field `preload' */
649660 lua_newtable(L);
src/lobject.c+6−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.19 2005/10/24 17:37:52 roberto Exp $
2+** $Id: lobject.c,v 2.21 2006/01/10 12:50:00 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -24,7 +24,7 @@ · 18 unmodified lines
2424
2525
2626
27−const TValue luaO_nilobject = {{NULL}, LUA_TNIL};
27+const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
2828
2929
3030 /*
@@ -39,7 +39,7 @@ int luaO_int2fb (unsigned int x) { · 8 unmodified lines
3939 e++;
4040 }
4141 if (x < 8) return x;
42− else return ((e+1) << 3) | (cast(int, x) - 8);
42+ else return ((e+1) << 3) | (cast_int(x) - 8);
4343 }
4444
4545
@@ -129,12 +129,12 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 83 unmodified lines
129129 break;
130130 }
131131 case 'd': {
132− setnvalue(L->top, cast(lua_Number, va_arg(argp, int)));
132+ setnvalue(L->top, cast_num(va_arg(argp, int)));
133133 incr_top(L);
134134 break;
135135 }
136136 case 'f': {
137− setnvalue(L->top, cast(lua_Number, va_arg(argp, l_uacNumber)));
137+ setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
138138 incr_top(L);
139139 break;
140140 }
@@ -161,7 +161,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 20 unmodified lines
161161 fmt = e+2;
162162 }
163163 pushstr(L, fmt);
164− luaV_concat(L, n+1, cast(int, L->top - L->base) - 1);
164+ luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
165165 L->top -= n;
166166 return svalue(L->top - 1);
167167 }
src/lobject.h+9−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.18 2005/10/24 17:37:33 roberto Exp $
2+** $Id: lobject.h,v 2.19 2006/01/10 12:51:53 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -323,9 +323,12 @@ typedef union Closure { · 317 unmodified lines
323323 ** Tables
324324 */
325325
326−typedef struct TKey {
327− TValuefields;
328− struct Node *next; /* for chaining */
326+typedef union TKey {
327+ struct {
328+ TValuefields;
329+ struct Node *next; /* for chaining */
330+ } nk;
331+ TValue tvk;
329332 } TKey;
330333
331334
@@ -360,8 +363,9 @@ typedef struct Table { · 28 unmodified lines
360363 #define sizenode(t) (twoto((t)->lsizenode))
361364
362365
366+#define luaO_nilobject (&luaO_nilobject_)
363367
364−LUAI_DATA const TValue luaO_nilobject;
368+LUAI_DATA const TValue luaO_nilobject_;
365369
366370 #define ceillog2(x) (luaO_log2((x)-1) + 1)
367371
src/lopcodes.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.123 2005/10/23 17:37:55 roberto Exp $
2+** $Id: lopcodes.h,v 1.124 2005/12/02 18:42:08 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -208,7 +208,7 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ · 202 unmodified lines
208208 } OpCode;
209209
210210
211−#define NUM_OPCODES (cast(int, OP_VARARG+1))
211+#define NUM_OPCODES (cast(int, OP_VARARG) + 1)
212212
213213
214214
src/loslib.c+24−24
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 roberto Exp $
2+** $Id: loslib.c,v 1.16 2005/12/22 16:19:56 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -37,26 +37,26 @@ static int os_pushresult (lua_State *L, int i, const char *filename) { · 31 unmodified lines
3737 }
3838
3939
40−static int io_execute (lua_State *L) {
40+static int os_execute (lua_State *L) {
4141 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
4242 return 1;
4343 }
4444
4545
46−static int io_remove (lua_State *L) {
46+static int os_remove (lua_State *L) {
4747 const char *filename = luaL_checkstring(L, 1);
4848 return os_pushresult(L, remove(filename) == 0, filename);
4949 }
5050
5151
52−static int io_rename (lua_State *L) {
52+static int os_rename (lua_State *L) {
5353 const char *fromname = luaL_checkstring(L, 1);
5454 const char *toname = luaL_checkstring(L, 2);
5555 return os_pushresult(L, rename(fromname, toname) == 0, fromname);
5656 }
5757
5858
59−static int io_tmpname (lua_State *L) {
59+static int os_tmpname (lua_State *L) {
6060 char buff[LUA_TMPNAMBUFSIZE];
6161 int err;
6262 lua_tmpnam(buff, err);
@@ -67,13 +67,13 @@ static int io_tmpname (lua_State *L) { · 4 unmodified lines
6767 }
6868
6969
70−static int io_getenv (lua_State *L) {
70+static int os_getenv (lua_State *L) {
7171 lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
7272 return 1;
7373 }
7474
7575
76−static int io_clock (lua_State *L) {
76+static int os_clock (lua_State *L) {
7777 lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
7878 return 1;
7979 }
@@ -123,7 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { · 43 unmodified lines
123123 }
124124
125125
126−static int io_date (lua_State *L) {
126+static int os_date (lua_State *L) {
127127 const char *s = luaL_optstring(L, 1, "%c");
128128 time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
129129 (time_t)luaL_checknumber(L, 2);
@@ -159,7 +159,7 @@ static int io_date (lua_State *L) { · 29 unmodified lines
159159 }
160160
161161
162−static int io_time (lua_State *L) {
162+static int os_time (lua_State *L) {
163163 time_t t;
164164 if (lua_isnoneornil(L, 1)) /* called without args? */
165165 t = time(NULL); /* get current time */
@@ -179,12 +179,12 @@ static int io_time (lua_State *L) { · 13 unmodified lines
179179 if (t == (time_t)(-1))
180180 lua_pushnil(L);
181181 else
182− lua_pushnumber(L, t);
182+ lua_pushnumber(L, (lua_Number)t);
183183 return 1;
184184 }
185185
186186
187−static int io_difftime (lua_State *L) {
187+static int os_difftime (lua_State *L) {
188188 lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
189189 (time_t)(luaL_optnumber(L, 2, 0))));
190190 return 1;
@@ -193,7 +193,7 @@ static int io_difftime (lua_State *L) { · 2 unmodified lines
193193 /* }====================================================== */
194194
195195
196−static int io_setloc (lua_State *L) {
196+static int os_setlocale (lua_State *L) {
197197 static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
198198 LC_NUMERIC, LC_TIME};
199199 static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
@@ -206,23 +206,23 @@ static int io_setloc (lua_State *L) { · 6 unmodified lines
206206 }
207207
208208
209−static int io_exit (lua_State *L) {
209+static int os_exit (lua_State *L) {
210210 exit(luaL_optint(L, 1, EXIT_SUCCESS));
211211 return 0; /* to avoid warnings */
212212 }
213213
214214 static const luaL_Reg syslib[] = {
215− {"clock", io_clock},
216− {"date", io_date},
217− {"difftime", io_difftime},
218− {"execute", io_execute},
219− {"exit", io_exit},
220− {"getenv", io_getenv},
221− {"remove", io_remove},
222− {"rename", io_rename},
223− {"setlocale", io_setloc},
224− {"time", io_time},
225− {"tmpname", io_tmpname},
215+ {"clock", os_clock},
216+ {"date", os_date},
217+ {"difftime", os_difftime},
218+ {"execute", os_execute},
219+ {"exit", os_exit},
220+ {"getenv", os_getenv},
221+ {"remove", os_remove},
222+ {"rename", os_rename},
223+ {"setlocale", os_setlocale},
224+ {"time", os_time},
225+ {"tmpname", os_tmpname},
226226 {NULL, NULL}
227227 };
228228
src/lparser.c+31−49
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.38 2005/10/24 17:38:47 roberto Exp $
2+** $Id: lparser.c,v 2.40 2005/12/22 16:19:56 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -54,24 +54,6 @@ static void chunk (LexState *ls); · 48 unmodified lines
5454 static void expr (LexState *ls, expdesc *v);
5555
5656
57−
58−static void next (LexState *ls) {
59− ls->lastline = ls->linenumber;
60− if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
61− ls->t = ls->lookahead; /* use this one */
62− ls->lookahead.token = TK_EOS; /* and discharge it */
63− }
64− else
65− ls->t.token = luaX_lex(ls, &ls->t.seminfo); /* read next token */
66−}
67−
68−
69−static void lookahead (LexState *ls) {
70− lua_assert(ls->lookahead.token == TK_EOS);
71− ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo);
72−}
73−
74−
7557 static void anchor_token (LexState *ls) {
7658 if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
7759 TString *ts = ls->t.seminfo.ts;
@@ -97,7 +79,7 @@ static void errorlimit (FuncState *fs, int limit, const char *what) { · 19 unmodified lines
9779
9880 static int testnext (LexState *ls, int c) {
9981 if (ls->t.token == c) {
100− next(ls);
82+ luaX_next(ls);
10183 return 1;
10284 }
10385 else return 0;
@@ -111,7 +93,7 @@ static void check (LexState *ls, int c) { · 7 unmodified lines
11193
11294 static void checknext (LexState *ls, int c) {
11395 check(ls, c);
114− next(ls);
96+ luaX_next(ls);
11597 }
11698
11799
@@ -136,7 +118,7 @@ static TString *str_checkname (LexState *ls) { · 18 unmodified lines
136118 TString *ts;
137119 check(ls, TK_NAME);
138120 ts = ls->t.seminfo.ts;
139− next(ls);
121+ luaX_next(ls);
140122 return ts;
141123 }
142124
@@ -184,7 +166,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { · 41 unmodified lines
184166
185167 static void adjustlocalvars (LexState *ls, int nvars) {
186168 FuncState *fs = ls->fs;
187− fs->nactvar = cast(lu_byte, fs->nactvar + nvars);
169+ fs->nactvar = cast_byte(fs->nactvar + nvars);
188170 for (; nvars; nvars--) {
189171 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
190172 }
@@ -216,8 +198,8 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 25 unmodified lines
216198 f->upvalues[f->nups] = name;
217199 luaC_objbarrier(fs->L, f, name);
218200 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
219− fs->upvalues[f->nups].k = cast(lu_byte, v->k);
220− fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);
201+ fs->upvalues[f->nups].k = cast_byte(v->k);
202+ fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
221203 return f->nups++;
222204 }
223205
@@ -404,7 +386,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 180 unmodified lines
404386 luaX_setinput(L, &lexstate, z, luaS_new(L, name));
405387 open_func(&lexstate, &funcstate);
406388 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
407− next(&lexstate); /* read first token */
389+ luaX_next(&lexstate); /* read first token */
408390 chunk(&lexstate);
409391 check(&lexstate, TK_EOS);
410392 close_func(&lexstate);
@@ -426,7 +408,7 @@ static void field (LexState *ls, expdesc *v) { · 15 unmodified lines
426408 FuncState *fs = ls->fs;
427409 expdesc key;
428410 luaK_exp2anyreg(fs, v);
429− next(ls); /* skip the dot or colon */
411+ luaX_next(ls); /* skip the dot or colon */
430412 checkname(ls, &key);
431413 luaK_indexed(fs, v, &key);
432414 }
@@ -434,7 +416,7 @@ static void field (LexState *ls, expdesc *v) { · 1 unmodified line
434416
435417 static void yindex (LexState *ls, expdesc *v) {
436418 /* index -> '[' expr ']' */
437− next(ls); /* skip the '[' */
419+ luaX_next(ls); /* skip the '[' */
438420 expr(ls, v);
439421 luaK_exp2val(ls->fs, v);
440422 checknext(ls, ']');
@@ -530,7 +512,7 @@ static void constructor (LexState *ls, expdesc *t) { · 89 unmodified lines
530512 closelistfield(fs, &cc);
531513 switch(ls->t.token) {
532514 case TK_NAME: { /* may be listfields or recfields */
533− lookahead(ls);
515+ luaX_lookahead(ls);
534516 if (ls->lookahead.token != '=') /* expression? */
535517 listfield(ls, &cc);
536518 else
@@ -571,7 +553,7 @@ static void parlist (LexState *ls) { · 34 unmodified lines
571553 break;
572554 }
573555 case TK_DOTS: { /* param -> `...' */
574− next(ls);
556+ luaX_next(ls);
575557 #if defined(LUA_COMPAT_VARARG)
576558 /* use `arg' as default name */
577559 new_localvarliteral(ls, "arg", nparams++);
@@ -585,7 +567,7 @@ static void parlist (LexState *ls) { · 7 unmodified lines
585567 } while (!f->is_vararg && testnext(ls, ','));
586568 }
587569 adjustlocalvars(ls, nparams);
588− f->numparams = fs->nactvar - (f->is_vararg & VARARG_HASARG);
570+ f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
589571 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
590572 }
591573
@@ -632,7 +614,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 40 unmodified lines
632614 case '(': { /* funcargs -> `(' [ explist1 ] `)' */
633615 if (line != ls->lastline)
634616 luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
635− next(ls);
617+ luaX_next(ls);
636618 if (ls->t.token == ')') /* arg list is empty? */
637619 args.k = VVOID;
638620 else {
@@ -648,7 +630,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 9 unmodified lines
648630 }
649631 case TK_STRING: { /* funcargs -> STRING */
650632 codestring(ls, &args, ls->t.seminfo.ts);
651− next(ls); /* must use `seminfo' before `next' */
633+ luaX_next(ls); /* must use `seminfo' before `next' */
652634 break;
653635 }
654636 default: {
@@ -686,7 +668,7 @@ static void prefixexp (LexState *ls, expdesc *v) { · 31 unmodified lines
686668 switch (ls->t.token) {
687669 case '(': {
688670 int line = ls->linenumber;
689− next(ls);
671+ luaX_next(ls);
690672 expr(ls, v);
691673 check_match(ls, ')', '(', line);
692674 luaK_dischargevars(ls->fs, v);
@@ -724,7 +706,7 @@ static void primaryexp (LexState *ls, expdesc *v) { · 31 unmodified lines
724706 }
725707 case ':': { /* `:' NAME funcargs */
726708 expdesc key;
727− next(ls);
709+ luaX_next(ls);
728710 checkname(ls, &key);
729711 luaK_self(fs, v, &key);
730712 funcargs(ls, v);
@@ -779,7 +761,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 48 unmodified lines
779761 return;
780762 }
781763 case TK_FUNCTION: {
782− next(ls);
764+ luaX_next(ls);
783765 body(ls, v, 0, ls->linenumber);
784766 return;
785767 }
@@ -788,7 +770,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 2 unmodified lines
788770 return;
789771 }
790772 }
791− next(ls);
773+ luaX_next(ls);
792774 }
793775
794776
@@ -848,7 +830,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 53 unmodified lines
848830 enterlevel(ls);
849831 uop = getunopr(ls->t.token);
850832 if (uop != OPR_NOUNOPR) {
851− next(ls);
833+ luaX_next(ls);
852834 subexpr(ls, v, UNARY_PRIORITY);
853835 luaK_prefix(ls->fs, uop, v);
854836 }
@@ -858,7 +840,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 3 unmodified lines
858840 while (op != OPR_NOBINOPR && priority[op].left > limit) {
859841 expdesc v2;
860842 BinOpr nextop;
861− next(ls);
843+ luaX_next(ls);
862844 luaK_infix(ls->fs, op, v);
863845 /* read sub-expression with higher priority */
864846 nextop = subexpr(ls, &v2, priority[op].right);
@@ -1009,7 +991,7 @@ static void whilestat (LexState *ls, int line) { · 144 unmodified lines
1009991 int whileinit;
1010992 int condexit;
1011993 BlockCnt bl;
1012− next(ls); /* skip WHILE */
994+ luaX_next(ls); /* skip WHILE */
1013995 whileinit = luaK_getlabel(fs);
1014996 condexit = cond(ls);
1015997 enterblock(fs, &bl, 1);
@@ -1030,7 +1012,7 @@ static void repeatstat (LexState *ls, int line) { · 14 unmodified lines
10301012 BlockCnt bl1, bl2;
10311013 enterblock(fs, &bl1, 1); /* loop block */
10321014 enterblock(fs, &bl2, 0); /* scope block */
1033− next(ls); /* skip REPEAT */
1015+ luaX_next(ls); /* skip REPEAT */
10341016 chunk(ls);
10351017 check_match(ls, TK_UNTIL, TK_REPEAT, line);
10361018 condexit = cond(ls); /* read condition (inside scope block) */
@@ -1130,7 +1112,7 @@ static void forstat (LexState *ls, int line) { · 93 unmodified lines
11301112 TString *varname;
11311113 BlockCnt bl;
11321114 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1133− next(ls); /* skip `for' */
1115+ luaX_next(ls); /* skip `for' */
11341116 varname = str_checkname(ls); /* first variable name */
11351117 switch (ls->t.token) {
11361118 case '=': fornum(ls, varname, line); break;
@@ -1145,7 +1127,7 @@ static void forstat (LexState *ls, int line) { · 8 unmodified lines
11451127 static int test_then_block (LexState *ls) {
11461128 /* test_then_block -> [IF | ELSEIF] cond THEN block */
11471129 int condexit;
1148− next(ls); /* skip IF or ELSEIF */
1130+ luaX_next(ls); /* skip IF or ELSEIF */
11491131 condexit = cond(ls);
11501132 checknext(ls, TK_THEN);
11511133 block(ls); /* `then' part */
@@ -1167,7 +1149,7 @@ static void ifstat (LexState *ls, int line) { · 15 unmodified lines
11671149 if (ls->t.token == TK_ELSE) {
11681150 luaK_concat(fs, &escapelist, luaK_jump(fs));
11691151 luaK_patchtohere(fs, flist);
1170− next(ls); /* skip ELSE (after patch, for correct line info) */
1152+ luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
11711153 block(ls); /* `else' part */
11721154 }
11731155 else
@@ -1228,7 +1210,7 @@ static void funcstat (LexState *ls, int line) { · 54 unmodified lines
12281210 /* funcstat -> FUNCTION funcname body */
12291211 int needself;
12301212 expdesc v, b;
1231− next(ls); /* skip FUNCTION */
1213+ luaX_next(ls); /* skip FUNCTION */
12321214 needself = funcname(ls, &v);
12331215 body(ls, &b, needself, line);
12341216 luaK_storevar(ls->fs, &v, &b);
@@ -1255,7 +1237,7 @@ static void retstat (LexState *ls) { · 20 unmodified lines
12551237 FuncState *fs = ls->fs;
12561238 expdesc e;
12571239 int first, nret; /* registers with returned values */
1258− next(ls); /* skip RETURN */
1240+ luaX_next(ls); /* skip RETURN */
12591241 if (block_follow(ls->t.token) || ls->t.token == ';')
12601242 first = nret = 0; /* return no values */
12611243 else {
@@ -1295,7 +1277,7 @@ static int statement (LexState *ls) { · 33 unmodified lines
12951277 return 0;
12961278 }
12971279 case TK_DO: { /* stat -> DO block END */
1298− next(ls); /* skip DO */
1280+ luaX_next(ls); /* skip DO */
12991281 block(ls);
13001282 check_match(ls, TK_END, TK_DO, line);
13011283 return 0;
@@ -1313,7 +1295,7 @@ static int statement (LexState *ls) { · 11 unmodified lines
13131295 return 0;
13141296 }
13151297 case TK_LOCAL: { /* stat -> localstat */
1316− next(ls); /* skip LOCAL */
1298+ luaX_next(ls); /* skip LOCAL */
13171299 if (testnext(ls, TK_FUNCTION)) /* local function? */
13181300 localfunc(ls);
13191301 else
@@ -1325,7 +1307,7 @@ static int statement (LexState *ls) { · 5 unmodified lines
13251307 return 1; /* must be last statement */
13261308 }
13271309 case TK_BREAK: { /* stat -> breakstat */
1328− next(ls); /* skip BREAK */
1310+ luaX_next(ls); /* skip BREAK */
13291311 breakstat(ls);
13301312 return 1; /* must be last statement */
13311313 }
src/lstring.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp $
2+** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $
33 ** String table (keeps all strings handled by Lua)
44 ** See Copyright Notice in lua.h
55 */
@@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) { · 29 unmodified lines
3535 GCObject *next = p->gch.next; /* save next */
3636 unsigned int h = gco2ts(p)->hash;
3737 int h1 = lmod(h, newsize); /* new position */
38− lua_assert(cast(int, h%newsize) == lmod(h, newsize));
38+ lua_assert(cast_int(h%newsize) == lmod(h, newsize));
3939 p->gch.next = newhash[h1]; /* chain it */
4040 newhash[h1] = p;
4141 p = next;
src/lstrlib.c+38−21
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.127 2005/10/26 13:28:19 roberto Exp $
2+** $Id: lstrlib.c,v 1.130 2005/12/29 15:32:11 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -683,8 +683,13 @@ static int str_gsub (lua_State *L) { · 677 unmodified lines
683683
684684 /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
685685 #define MAX_ITEM 512
686−/* maximum size of each format specification (such as '%-099.99d') */
687−#define MAX_FORMAT 20
686+/* valid flags in a format specification */
687+#define FLAGS "-+ #0"
688+/*
689+** maximum size of each format specification (such as '%-099.99d')
690+** (+10 accounts for %99.99x plus margin of error)
691+*/
692+#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
688693
689694
690695 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
@@ -712,30 +717,37 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 21 unmodified lines
712717 luaL_addchar(b, '"');
713718 }
714719
715−
716−static const char *scanformat (lua_State *L, const char *strfrmt,
717− char *form, int *hasprecision) {
720+static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
718721 const char *p = strfrmt;
719− while (strchr("-+ #0", *p)) p++; /* skip flags */
722+ while (strchr(FLAGS, *p)) p++; /* skip flags */
723+ if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
724+ luaL_error(L, "invalid format (repeated flags)");
720725 if (isdigit(uchar(*p))) p++; /* skip width */
721726 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
722727 if (*p == '.') {
723728 p++;
724− *hasprecision = 1;
725729 if (isdigit(uchar(*p))) p++; /* skip precision */
726730 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
727731 }
728732 if (isdigit(uchar(*p)))
729733 luaL_error(L, "invalid format (width or precision too long)");
730− if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
731− luaL_error(L, "invalid format (too long)");
732− form[0] = L_ESC;
733− strncpy(form+1, strfrmt, p-strfrmt+1);
734− form[p-strfrmt+2] = 0;
734+ *(form++) = '%';
735+ strncpy(form, strfrmt, p - strfrmt + 1);
736+ form += p - strfrmt + 1;
737+ *form = '\0';
735738 return p;
736739 }
737740
738741
742+static void addintlen (char *form) {
743+ size_t l = strlen(form);
744+ char spec = form[l - 1];
745+ strcpy(form + l - 1, LUA_INTFRMLEN);
746+ form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
747+ form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
748+}
749+
750+
739751 static int str_format (lua_State *L) {
740752 int arg = 1;
741753 size_t sfl;
@@ -751,21 +763,26 @@ static int str_format (lua_State *L) { · 9 unmodified lines
751763 else { /* format item */
752764 char form[MAX_FORMAT]; /* to store the format (`%...') */
753765 char buff[MAX_ITEM]; /* to store the formatted item */
754− int hasprecision = 0;
755766 arg++;
756− strfrmt = scanformat(L, strfrmt, form, &hasprecision);
767+ strfrmt = scanformat(L, strfrmt, form);
757768 switch (*strfrmt++) {
758− case 'c': case 'd': case 'i': {
759− sprintf(buff, form, luaL_checkint(L, arg));
769+ case 'c': {
770+ sprintf(buff, form, (int)luaL_checknumber(L, arg));
771+ break;
772+ }
773+ case 'd': case 'i': {
774+ addintlen(form);
775+ sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
760776 break;
761777 }
762778 case 'o': case 'u': case 'x': case 'X': {
763− sprintf(buff, form, (unsigned int)(luaL_checknumber(L, arg)));
779+ addintlen(form);
780+ sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
764781 break;
765782 }
766783 case 'e': case 'E': case 'f':
767784 case 'g': case 'G': {
768− sprintf(buff, form, luaL_checknumber(L, arg));
785+ sprintf(buff, form, (double)luaL_checknumber(L, arg));
769786 break;
770787 }
771788 case 'q': {
@@ -775,7 +792,7 @@ static int str_format (lua_State *L) { · 3 unmodified lines
775792 case 's': {
776793 size_t l;
777794 const char *s = luaL_checklstring(L, arg, &l);
778− if (!hasprecision && l >= 100) {
795+ if (!strchr(form, '.') && l >= 100) {
779796 /* no precision and string is too long to be formatted;
780797 keep original string */
781798 lua_pushvalue(L, arg);
@@ -820,7 +837,7 @@ static const luaL_Reg strlib[] = { · 38 unmodified lines
820837
821838
822839 static void createmetatable (lua_State *L) {
823− lua_newtable(L); /* create metatable for strings */
840+ lua_createtable(L, 0, 1); /* create metatable for strings */
824841 lua_pushliteral(L, ""); /* dummy string */
825842 lua_pushvalue(L, -2);
826843 lua_setmetatable(L, -2); /* set string metatable */
src/ltable.c+53−39
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.27 2005/10/24 17:37:52 roberto Exp $
2+** $Id: ltable.c,v 2.31 2006/01/10 13:13:06 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -66,13 +66,15 @@ · 60 unmodified lines
6666 /*
6767 ** number of ints inside a lua_Number
6868 */
69−#define numints cast(int, sizeof(lua_Number)/sizeof(int))
69+#define numints cast_int(sizeof(lua_Number)/sizeof(int))
7070
7171
7272
73−const Node luaH_dummynode = {
73+#define dummynode (&dummynode_)
74+
75+static const Node dummynode_ = {
7476 {{NULL}, LUA_TNIL}, /* value */
75− {{NULL}, LUA_TNIL, NULL} /* key */
77+ {{{NULL}, LUA_TNIL, NULL}} /* key */
7678 };
7779
7880
@@ -95,7 +97,7 @@ static Node *hashnum (const Table *t, lua_Number n) { · 16 unmodified lines
9597 ** returns the `main' position of an element in a table (that is, the index
9698 ** of its hash value)
9799 */
98−Node *luaH_mainposition (const Table *t, const TValue *key) {
100+static Node *mainposition (const Table *t, const TValue *key) {
99101 switch (ttype(key)) {
100102 case LUA_TNUMBER:
101103 return hashnum(t, nvalue(key));
@@ -120,7 +122,7 @@ static int arrayindex (const TValue *key) { · 18 unmodified lines
120122 lua_Number n = nvalue(key);
121123 int k;
122124 lua_number2int(k, n);
123− if (luai_numeq(cast(lua_Number, k), nvalue(key)))
125+ if (luai_numeq(cast_num(k), nvalue(key)))
124126 return k;
125127 }
126128 return -1; /* `key' did not match some condition */
@@ -139,13 +141,13 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 12 unmodified lines
139141 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
140142 return i-1; /* yes; that's the index (corrected to C) */
141143 else {
142− Node *n = luaH_mainposition(t, key);
144+ Node *n = mainposition(t, key);
143145 do { /* check whether `key' is somewhere in the chain */
144146 /* key may be dead already, but it is ok to use it in `next' */
145147 if (luaO_rawequalObj(key2tval(n), key) ||
146148 (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
147149 gcvalue(gkey(n)) == gcvalue(key))) {
148− i = cast(int, n - gnode(t, 0)); /* key index in hash table */
150+ i = cast_int(n - gnode(t, 0)); /* key index in hash table */
149151 /* hash elements are numbered after array ones */
150152 return i + t->sizearray;
151153 }
@@ -161,7 +163,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { · 9 unmodified lines
161163 int i = findindex(L, t, key); /* find original element */
162164 for (i++; i < t->sizearray; i++) { /* try first array part */
163165 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
164− setnvalue(key, cast(lua_Number, i+1));
166+ setnvalue(key, cast_num(i+1));
165167 setobj2s(L, key+1, &t->array[i]);
166168 return 1;
167169 }
@@ -270,7 +272,7 @@ static void setarrayvector (lua_State *L, Table *t, int size) { · 102 unmodified lines
270272 static void setnodevector (lua_State *L, Table *t, int size) {
271273 int lsize;
272274 if (size == 0) { /* no elements to hash part? */
273− t->node = cast(Node *, &luaH_dummynode); /* use common `dummynode' */
275+ t->node = cast(Node *, dummynode); /* use common `dummynode' */
274276 lsize = 0;
275277 }
276278 else {
@@ -281,12 +283,13 @@ static void setnodevector (lua_State *L, Table *t, int size) { · 4 unmodified lines
281283 size = twoto(lsize);
282284 t->node = luaM_newvector(L, size, Node);
283285 for (i=0; i<size; i++) {
284− gnext(&t->node[i]) = NULL;
285− setnilvalue(gkey(gnode(t, i)));
286− setnilvalue(gval(gnode(t, i)));
286+ Node *n = gnode(t, i);
287+ gnext(n) = NULL;
288+ setnilvalue(gkey(n));
289+ setnilvalue(gval(n));
287290 }
288291 }
289− t->lsizenode = cast(lu_byte, lsize);
292+ t->lsizenode = cast_byte(lsize);
290293 t->lastfree = gnode(t, size); /* all positions are free */
291294 }
292295
@@ -316,13 +319,13 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) { · 23 unmodified lines
316319 if (!ttisnil(gval(old)))
317320 setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
318321 }
319− if (nold != &luaH_dummynode)
322+ if (nold != dummynode)
320323 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
321324 }
322325
323326
324327 void luaH_resizearray (lua_State *L, Table *t, int nasize) {
325− int nsize = (t->node == &luaH_dummynode) ? 0 : sizenode(t);
328+ int nsize = (t->node == dummynode) ? 0 : sizenode(t);
326329 resize(L, t, nasize, nsize);
327330 }
328331
@@ -356,12 +359,12 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 27 unmodified lines
356359 Table *t = luaM_new(L, Table);
357360 luaC_link(L, obj2gco(t), LUA_TTABLE);
358361 t->metatable = NULL;
359− t->flags = cast(lu_byte, ~0);
362+ t->flags = cast_byte(~0);
360363 /* temporary values (kept only if some malloc fails) */
361364 t->array = NULL;
362365 t->sizearray = 0;
363366 t->lsizenode = 0;
364− t->node = cast(Node *, &luaH_dummynode);
367+ t->node = cast(Node *, dummynode);
365368 setarrayvector(L, t, narray);
366369 setnodevector(L, t, nhash);
367370 return t;
@@ -369,7 +372,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 1 unmodified line
369372
370373
371374 void luaH_free (lua_State *L, Table *t) {
372− if (t->node != &luaH_dummynode)
375+ if (t->node != dummynode)
373376 luaM_freearray(L, t->node, sizenode(t), Node);
374377 luaM_freearray(L, t->array, t->sizearray, TValue);
375378 luaM_free(L, t);
@@ -394,16 +397,16 @@ static Node *getfreepos (Table *t) { · 18 unmodified lines
394397 ** position), new key goes to an empty position.
395398 */
396399 static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
397− Node *mp = luaH_mainposition(t, key);
398− if (!ttisnil(gval(mp)) || mp == &luaH_dummynode) {
400+ Node *mp = mainposition(t, key);
401+ if (!ttisnil(gval(mp)) || mp == dummynode) {
399402 Node *othern;
400403 Node *n = getfreepos(t); /* get a free place */
401404 if (n == NULL) { /* cannot find a free place? */
402405 rehash(L, t, key); /* grow table */
403406 return luaH_set(L, t, key); /* re-insert key into grown table */
404407 }
405− lua_assert(n != &luaH_dummynode);
406− othern = luaH_mainposition(t, key2tval(mp));
408+ lua_assert(n != dummynode);
409+ othern = mainposition(t, key2tval(mp));
407410 if (othern != mp) { /* is colliding node out of its main position? */
408411 /* yes; move colliding node into free position */
409412 while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
@@ -434,14 +437,14 @@ const TValue *luaH_getnum (Table *t, int key) { · 24 unmodified lines
434437 if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
435438 return &t->array[key-1];
436439 else {
437− lua_Number nk = cast(lua_Number, key);
440+ lua_Number nk = cast_num(key);
438441 Node *n = hashnum(t, nk);
439442 do { /* check whether `key' is somewhere in the chain */
440443 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
441444 return gval(n); /* that's it */
442445 else n = gnext(n);
443446 } while (n);
444− return &luaO_nilobject;
447+ return luaO_nilobject;
445448 }
446449 }
447450
@@ -456,7 +459,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 8 unmodified lines
456459 return gval(n); /* that's it */
457460 else n = gnext(n);
458461 } while (n);
459− return &luaO_nilobject;
462+ return luaO_nilobject;
460463 }
461464
462465
@@ -465,24 +468,24 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 2 unmodified lines
465468 */
466469 const TValue *luaH_get (Table *t, const TValue *key) {
467470 switch (ttype(key)) {
468− case LUA_TNIL: return &luaO_nilobject;
471+ case LUA_TNIL: return luaO_nilobject;
469472 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
470473 case LUA_TNUMBER: {
471474 int k;
472475 lua_Number n = nvalue(key);
473476 lua_number2int(k, n);
474− if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */
477+ if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
475478 return luaH_getnum(t, k); /* use specialized version */
476479 /* else go through */
477480 }
478481 default: {
479− Node *n = luaH_mainposition(t, key);
482+ Node *n = mainposition(t, key);
480483 do { /* check whether `key' is somewhere in the chain */
481484 if (luaO_rawequalObj(key2tval(n), key))
482485 return gval(n); /* that's it */
483486 else n = gnext(n);
484487 } while (n);
485− return &luaO_nilobject;
488+ return luaO_nilobject;
486489 }
487490 }
488491 }
@@ -491,11 +494,11 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 2 unmodified lines
491494 TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
492495 const TValue *p = luaH_get(t, key);
493496 t->flags = 0;
494− if (p != &luaO_nilobject)
497+ if (p != luaO_nilobject)
495498 return cast(TValue *, p);
496499 else {
497500 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
498− else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key)))
501+ else if (ttisnumber(key) && luai_numisnan(nvalue(key)))
499502 luaG_runerror(L, "table index is NaN");
500503 return newkey(L, t, key);
501504 }
@@ -504,11 +507,11 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 2 unmodified lines
504507
505508 TValue *luaH_setnum (lua_State *L, Table *t, int key) {
506509 const TValue *p = luaH_getnum(t, key);
507− if (p != &luaO_nilobject)
510+ if (p != luaO_nilobject)
508511 return cast(TValue *, p);
509512 else {
510513 TValue k;
511− setnvalue(&k, cast(lua_Number, key));
514+ setnvalue(&k, cast_num(key));
512515 return newkey(L, t, &k);
513516 }
514517 }
@@ -516,7 +519,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) { · 1 unmodified line
516519
517520 TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
518521 const TValue *p = luaH_getstr(t, key);
519− if (p != &luaO_nilobject)
522+ if (p != luaO_nilobject)
520523 return cast(TValue *, p);
521524 else {
522525 TValue k;
@@ -528,11 +531,11 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { · 5 unmodified lines
528531
529532 static int unbound_search (Table *t, unsigned int j) {
530533 unsigned int i = j; /* i is zero or a present index */
531− j = j+1;
534+ j++;
532535 /* find `i' and `j' such that i is present and j is not */
533536 while (!ttisnil(luaH_getnum(t, j))) {
534537 i = j;
535− j = i*2;
538+ j *= 2;
536539 if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
537540 /* table was built with bad purposes: resort to linear search */
538541 i = 1;
@@ -541,7 +544,7 @@ static int unbound_search (Table *t, unsigned int j) { · 2 unmodified lines
541544 }
542545 }
543546 /* now do a binary search between them */
544− while (i < j-1) {
547+ while (j - i > 1) {
545548 unsigned int m = (i+j)/2;
546549 if (ttisnil(luaH_getnum(t, m))) j = m;
547550 else i = m;
@@ -567,8 +570,19 @@ int luaH_getn (Table *t) { · 19 unmodified lines
567570 return i;
568571 }
569572 /* else must find a boundary in hash part */
570− else if (t->node == &luaH_dummynode) /* hash part is empty? */
573+ else if (t->node == dummynode) /* hash part is empty? */
571574 return j; /* that is easy... */
572575 else return unbound_search(t, j);
573576 }
574577
578+
579+
580+#if defined(LUA_DEBUG)
581+
582+Node *luaH_mainposition (const Table *t, const TValue *key) {
583+ return mainposition(t, key);
584+}
585+
586+int luaH_isdummy (Node *n) { return n == dummynode; }
587+
588+#endif
src/ltable.h+8−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.h,v 2.8 2005/06/06 13:30:25 roberto Exp $
2+** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -11,15 +11,13 @@ · 5 unmodified lines
1111
1212
1313 #define gnode(t,i) (&(t)->node[i])
14−#define gkey(n) (&(n)->i_key)
14+#define gkey(n) (&(n)->i_key.nk)
1515 #define gval(n) (&(n)->i_val)
16−#define gnext(n) ((n)->i_key.next)
16+#define gnext(n) ((n)->i_key.nk.next)
1717
18−#define key2tval(n) (cast(const TValue *, gkey(n)))
18+#define key2tval(n) (&(n)->i_key.tvk)
1919
2020
21−LUAI_DATA const Node luaH_dummynode;
22−
2321 LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
2422 LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
2523 LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
@@ -32,8 +30,11 @@ LUAI_FUNC void luaH_free (lua_State *L, Table *t); · 6 unmodified lines
3230 LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
3331 LUAI_FUNC int luaH_getn (Table *t);
3432
35−/* exported only for debugging */
33+
34+#if defined(LUA_DEBUG)
3635 LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
36+LUAI_FUNC int luaH_isdummy (Node *n);
37+#endif
3738
3839
3940 #endif
src/ltm.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltm.c,v 2.6 2005/05/20 15:53:42 roberto Exp $
2+** $Id: ltm.c,v 2.8 2006/01/10 12:50:00 roberto Exp $
33 ** Tag methods
44 ** See Copyright Notice in lua.h
55 */
@@ -51,7 +51,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { · 45 unmodified lines
5151 const TValue *tm = luaH_getstr(events, ename);
5252 lua_assert(event <= TM_EQ);
5353 if (ttisnil(tm)) { /* no tag method? */
54− events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */
54+ events->flags |= cast_byte(1u<<event); /* cache this fact */
5555 return NULL;
5656 }
5757 else return tm;
@@ -70,6 +70,6 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { · 12 unmodified lines
7070 default:
7171 mt = G(L)->mt[ttype(o)];
7272 }
73− return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);
73+ return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
7474 }
7575
src/lua.c+9−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.154 2005/10/24 17:38:47 roberto Exp $
2+** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -120,7 +120,7 @@ static int getargs (lua_State *L, char **argv, int n) { · 114 unmodified lines
120120 luaL_checkstack(L, narg + 3, "too many arguments to script");
121121 for (i=n+1; i < argc; i++)
122122 lua_pushstring(L, argv[i]);
123− lua_newtable(L);
123+ lua_createtable(L, narg, n + 1);
124124 for (i=0; i < argc; i++) {
125125 lua_pushstring(L, argv[i]);
126126 lua_rawseti(L, -2, i - n);
@@ -215,7 +215,6 @@ static void dotty (lua_State *L) { · 88 unmodified lines
215215 int status;
216216 const char *oldprogname = progname;
217217 progname = NULL;
218− print_version();
219218 while ((status = loadline(L)) != -1) {
220219 if (status == 0) status = docall(L, 0, 0);
221220 report(L, status);
@@ -261,7 +260,7 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 39 unmodified lines
261260 switch (argv[i][1]) { /* option */
262261 case '-': return (argv[i+1] != NULL ? i+1 : 0);
263262 case '\0': return i;
264− case 'i': *pi = 1; break;
263+ case 'i': *pi = 1; /* go through */
265264 case 'v': *pv = 1; break;
266265 case 'e': *pe = 1; /* go through */
267266 case 'l':
@@ -330,7 +329,9 @@ static int pmain (lua_State *L) { · 62 unmodified lines
330329 int has_i = 0, has_v = 0, has_e = 0;
331330 globalL = L;
332331 if (argv[0] && argv[0][0]) progname = argv[0];
332+ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
333333 luaL_openlibs(L); /* open libraries */
334+ lua_gc(L, LUA_GCRESTART, 0);
334335 s->status = handle_luainit(L);
335336 if (s->status != 0) return 0;
336337 script = collectargs(argv, &has_i, &has_v, &has_e);
@@ -348,7 +349,10 @@ static int pmain (lua_State *L) { · 11 unmodified lines
348349 if (has_i)
349350 dotty(L);
350351 else if (script == 0 && !has_e && !has_v) {
351− if (lua_stdin_is_tty()) dotty(L);
352+ if (lua_stdin_is_tty()) {
353+ print_version();
354+ dotty(L);
355+ }
352356 else dofile(L, NULL); /* executes stdin as a file */
353357 }
354358 return 0;
src/lua.h+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.214 2005/10/20 11:35:50 roberto Exp $
2+** $Id: lua.h,v 1.216 2006/01/10 12:50:13 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -16,9 +16,9 @@ · 10 unmodified lines
1616 #include "luaconf.h"
1717
1818
19−#define LUA_VERSION "Lua 5.1 (beta)"
19+#define LUA_VERSION "Lua 5.1"
2020 #define LUA_VERSION_NUM 501
21−#define LUA_COPYRIGHT "Copyright (C) 1994-2005 Lua.org, PUC-Rio"
21+#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
2222 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2323
2424
@@ -358,7 +358,7 @@ struct lua_Debug { · 333 unmodified lines
358358
359359
360360 /******************************************************************************
361−* Copyright (C) 1994-2005 Lua.org, PUC-Rio. All rights reserved.
361+* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.
362362 *
363363 * Permission is hereby granted, free of charge, to any person obtaining
364364 * a copy of this software and associated documentation files (the
src/luaconf.h+31−13
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.74 2005/11/16 16:24:28 roberto Exp $
2+** $Id: luaconf.h,v 1.77 2005/12/27 17:12:00 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -28,6 +28,11 @@ · 22 unmodified lines
2828 #define LUA_ANSI
2929 #endif
3030
31+
32+#if !defined(LUA_ANSI) && defined(_WIN32)
33+#define LUA_WIN
34+#endif
35+
3136 #if defined(LUA_USE_LINUX)
3237 #define LUA_USE_POSIX
3338 #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
@@ -177,13 +182,6 @@ · 143 unmodified lines
177182
178183
179184
180−/*
181−@@ lua_assert describes the internal assertions in Lua.
182−** CHANGE that only if you need to debug Lua.
183−*/
184−#define lua_assert(c) ((void)0)
185−
186−
187185 /*
188186 @@ LUA_QL describes how error messages quote program elements.
189187 ** CHANGE it if you want a different appearance.
@@ -217,7 +215,7 @@ · 27 unmodified lines
217215 #if defined(LUA_USE_ISATTY)
218216 #include <unistd.h>
219217 #define lua_stdin_is_tty() isatty(0)
220−#elif !defined(LUA_ANSI) && defined(_WIN32)
218+#elif defined(LUA_WIN)
221219 #include <io.h>
222220 #include <stdio.h>
223221 #define lua_stdin_is_tty() _isatty(_fileno(stdin))
@@ -368,8 +366,7 @@ · 144 unmodified lines
368366 #include <assert.h>
369367 #define luai_apicheck(L,o) { (void)L; assert(o); }
370368 #else
371−/* (By default lua_assert is empty, so luai_apicheck is also empty.) */
372−#define luai_apicheck(L,o) { (void)L; lua_assert(o); }
369+#define luai_apicheck(L,o) { (void)L; }
373370 #endif
374371
375372
@@ -529,6 +526,7 @@ · 153 unmodified lines
529526 #define luai_numeq(a,b) ((a)==(b))
530527 #define luai_numlt(a,b) ((a)<(b))
531528 #define luai_numle(a,b) ((a)<=(b))
529+#define luai_numisnan(a) (!luai_numeq((a), (a)))
532530 #endif
533531
534532
@@ -644,7 +642,7 @@ union luai_Cast { double l_d; long l_l; }; · 109 unmodified lines
644642 #define lua_popen(L,c,m) ((void)L, popen(c,m))
645643 #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
646644
647−#elif !defined(LUA_ANSI) && defined(_WIN32)
645+#elif defined(LUA_WIN)
648646
649647 #define lua_popen(L,c,m) ((void)L, _popen(c,m))
650648 #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
@@ -675,7 +673,7 @@ union luai_Cast { double l_d; long l_l; }; · 24 unmodified lines
675673 #define LUA_DL_DLOPEN
676674 #endif
677675
678−#if !defined(LUA_ANSI) && defined(_WIN32)
676+#if defined(LUA_WIN)
679677 #define LUA_DL_DLL
680678 #endif
681679
@@ -702,6 +700,26 @@ union luai_Cast { double l_d; long l_l; }; · 20 unmodified lines
702700 #define luai_userstateyield(L,n) ((void)L)
703701
704702
703+/*
704+@@ LUA_INTFRMLEN is the length modifier for integer conversions
705+@* in 'string.fomat'.
706+@@ LUA_INTFRM_T is the integer type correspoding to the previous length
707+@* modifier.
708+** CHANGE them if your system supports long long or does not support long.
709+*/
710+
711+#if defined(LUA_USELONGLONG)
712+
713+#define LUA_INTFRMLEN "ll"
714+#define LUA_INTFRM_T long long
715+
716+#else
717+
718+#define LUA_INTFRMLEN "l"
719+#define LUA_INTFRM_T long
720+
721+#endif
722+
705723
706724
707725 /* =================================================================== */
src/lualib.h+7−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lualib.h,v 1.35 2005/08/10 18:06:58 roberto Exp $
2+** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $
33 ** Lua standard libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -44,4 +44,10 @@ LUALIB_API int (luaopen_package) (lua_State *L); · 38 unmodified lines
4444 LUALIB_API void (luaL_openlibs) (lua_State *L);
4545
4646
47+
48+#ifndef lua_assert
49+#define lua_assert(x) ((void)0)
50+#endif
51+
52+
4753 #endif
src/lvm.c+7−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 2.59 2005/11/01 16:08:45 roberto Exp $
2+** $Id: lvm.c,v 2.61 2006/01/10 12:50:00 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -509,16 +509,16 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 503 unmodified lines
509509 const TValue *rb = RB(i);
510510 switch (ttype(rb)) {
511511 case LUA_TTABLE: {
512− setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb))));
512+ setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
513513 break;
514514 }
515515 case LUA_TSTRING: {
516− setnvalue(ra, cast(lua_Number, tsvalue(rb)->len));
516+ setnvalue(ra, cast_num(tsvalue(rb)->len));
517517 break;
518518 }
519519 default: { /* try metamethod */
520520 Protect(
521− if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN))
521+ if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
522522 luaG_typeerror(L, rb, "get length of");
523523 )
524524 }
@@ -693,10 +693,10 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 168 unmodified lines
693693 int last;
694694 Table *h;
695695 if (n == 0) {
696− n = cast(int, L->top - ra) - 1;
696+ n = cast_int(L->top - ra) - 1;
697697 L->top = L->ci->top;
698698 }
699− if (c == 0) c = cast(int, *pc++);
699+ if (c == 0) c = cast_int(*pc++);
700700 runtime_check(L, ttistable(ra));
701701 h = hvalue(ra);
702702 last = ((c-1)*LFIELDS_PER_FLUSH) + n;
@@ -737,7 +737,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 34 unmodified lines
737737 int b = GETARG_B(i) - 1;
738738 int j;
739739 CallInfo *ci = L->ci;
740− int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1;
740+ int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
741741 if (b == LUA_MULTRET) {
742742 Protect(luaD_checkstack(L, n));
743743 ra = RA(i); /* previous call may change the stack */
src/print.c+5−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.53 2005/11/11 14:03:13 lhf Exp $
2+** $Id: print.c,v 1.54 2006/01/11 22:49:27 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -36,7 +36,10 @@ static void PrintString(const Proto* f, int n) · 30 unmodified lines
3636 case '\r': printf("\\r"); break;
3737 case '\t': printf("\\t"); break;
3838 case '\v': printf("\\v"); break;
39− default: printf(isprint((unsigned char)*s) ? "%c" : "\\%03d",*s);
39+ default: if (isprint((unsigned char)*s))
40+ printf("%c",*s);
41+ else
42+ printf("\\%03u",(unsigned char)*s);
4043 }
4144 }
4245 putchar('"');