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
9 9
10===============================================================================10===============================================================================
11 11
12Copyright (C) 1994-2005 Lua.org, PUC-Rio.12Copyright (C) 1994-2006 Lua.org, PUC-Rio.
13 13
14Permission is hereby granted, free of charge, to any person obtaining a copy14Permission is hereby granted, free of charge, to any person obtaining a copy
15of this software and associated documentation files (the "Software"), to deal15of this software and associated documentation files (the "Software"), to deal
HISTORY+1−1
@@ -1,4 +1,4 @@
1This is Lua 5.1 (beta).1This is Lua 5.1.
2 2
3* Changes from version 5.0 to 5.13* Changes from version 5.0 to 5.1
4 -------------------------------4 -------------------------------
INSTALL+36−21
@@ -1,17 +1,27 @@
1This is Lua 5.1 (beta).1This is Lua 5.1.
2 2
3* Installation3* Building Lua
4 ------------4 ------------
5 Building Lua on a Unix system should be very easy: simply doing "make"5 Lua is built in the src directory, but the build process can be
6 should work. This will build Lua in the src directory.6 controlled from the top-level Makefile.
7 7
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
9 12
10 See below for customization instructions.13 See below for customization instructions and for instructions on how
14 to build with other Windows compilers.
11 15
12 If you want to install Lua in an official place in your system, then16 If you want to check that Lua has been built correctly, do "make test"
13 do "make install". The official place and the way to install files are17 after building Lua. Also, have a look at the example programs in test.
14 defined in Makefile. You must have the right permissions to install files.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.
15 25
16 If you want to install Lua locally, then do "make local". This will26 If you want to install Lua locally, then do "make local". This will
17 create directories bin, include, lib, man, and install Lua there as27 create directories bin, include, lib, man, and install Lua there as
@@ -25,8 +35,11 @@ This is Lua 5.1 (beta). · 7 unmodified lines
25 These are the only directories you need for development.35 These are the only directories you need for development.
26 36
27 There are man pages for lua and luac, in both nroff and html, and a37 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 some38 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.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.
30 43
31 See below for instructions for Windows and other systems.44 See below for instructions for Windows and other systems.
32 45
@@ -44,14 +57,16 @@ This is Lua 5.1 (beta). · 11 unmodified lines
44 to edit src/luaconf.h. The edited file will be the one installed, and57 to edit src/luaconf.h. The edited file will be the one installed, and
45 it will be used by any Lua clients that you build, to ensure consistency.58 it will be used by any Lua clients that you build, to ensure consistency.
46 59
47 We strongly recommend that you enable dynamic loading. See src/luaconf.h60 We strongly recommend that you enable dynamic loading. This is done
48 and also src/Makefile.61 automatically for all platforms listed above that have this feature
62 (and also Windows). See src/luaconf.h and also src/Makefile.
49 63
50* Installation on Windows and other systems64* Building Lua on Windows and other systems
51 -----------------------------------------65 -----------------------------------------
52 The instructions for building Lua on other systems depend on the compiler66 If you're not using the usual Unix tools, then the instructions for
53 you use. You'll need to create projects (or whatever your compiler uses)67 building Lua depend on the compiler you use. You'll need to create
54 for building the library, the interpreter, and the compiler, as follows:68 projects (or whatever your compiler uses) for building the library,
69 the interpreter, and the compiler, as follows:
55 70
56 library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c71 library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
57 lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c72 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
63 78
64 compiler: library, luac.c print.c79 compiler: library, luac.c print.c
65 80
81 If you use Visual Studio .NET, you can use etc/luavs.bat
82 in its "Command Prompt".
83
66 If all you want is to build the Lua interpreter, you may put all .c files84 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.
68 86
69 To use Lua as a library in your own programs, you'll need to know how to87 To use Lua as a library in your own programs, you'll need to know how to
70 create and use libraries with your compiler.88 create and use libraries with your compiler.
@@ -72,7 +90,4 @@ This is Lua 5.1 (beta). · 1 unmodified line
72 As mentioned above, you may edit luaconf.h to select some features before90 As mentioned above, you may edit luaconf.h to select some features before
73 building Lua.91 building Lua.
74 92
75 If you use Visual Studio .NET, you can use etc/luavs.bat
76 in its "Command Prompt".
77
78(end of INSTALL)93(end of INSTALL)
MANIFEST+107−107
@@ -1,108 +1,108 @@
1MANIFEST contents of Lua 5.1 (beta) distribution on Fri Nov 18 07:42:23 BRST 20051MANIFEST contents of Lua 5.1 distribution on Wed Jan 11 22:50:45 BRST 2006
2lua-5.1-beta2lua-5.1
3lua-5.1-beta/COPYRIGHT3lua-5.1/COPYRIGHT
4lua-5.1-beta/HISTORY4lua-5.1/doc
5lua-5.1-beta/INSTALL5lua-5.1/doc/contents.html
6lua-5.1-beta/MANIFEST6lua-5.1/doc/logo.gif
7lua-5.1-beta/Makefile7lua-5.1/doc/lua.1
8lua-5.1-beta/README8lua-5.1/doc/luac.1
9lua-5.1-beta/doc9lua-5.1/doc/luac.html
10lua-5.1-beta/doc/contents.html10lua-5.1/doc/lua.css
11lua-5.1-beta/doc/logo.gif11lua-5.1/doc/lua.html
12lua-5.1-beta/doc/lua.112lua-5.1/doc/manual.html
13lua-5.1-beta/doc/lua.css13lua-5.1/doc/readme.html
14lua-5.1-beta/doc/lua.html14lua-5.1/etc
15lua-5.1-beta/doc/luac.115lua-5.1/etc/all.c
16lua-5.1-beta/doc/luac.html16lua-5.1/etc/lua.hpp
17lua-5.1-beta/doc/manual.html17lua-5.1/etc/lua.ico
18lua-5.1-beta/doc/readme.html18lua-5.1/etc/lua.pc
19lua-5.1-beta/etc19lua-5.1/etc/luavs.bat
20lua-5.1-beta/etc/Makefile20lua-5.1/etc/Makefile
21lua-5.1-beta/etc/README21lua-5.1/etc/min.c
22lua-5.1-beta/etc/all.c22lua-5.1/etc/noparser.c
23lua-5.1-beta/etc/lua.hpp23lua-5.1/etc/README
24lua-5.1-beta/etc/lua.ico24lua-5.1/etc/strict.lua
25lua-5.1-beta/etc/lua.pc25lua-5.1/HISTORY
26lua-5.1-beta/etc/luavs.bat26lua-5.1/INSTALL
27lua-5.1-beta/etc/min.c27lua-5.1/Makefile
28lua-5.1-beta/etc/noparser.c28lua-5.1/MANIFEST
29lua-5.1-beta/etc/strict.lua29lua-5.1/README
30lua-5.1-beta/src30lua-5.1/src
31lua-5.1-beta/src/Makefile31lua-5.1/src/lapi.c
32lua-5.1-beta/src/lapi.c32lua-5.1/src/lapi.h
33lua-5.1-beta/src/lapi.h33lua-5.1/src/lauxlib.c
34lua-5.1-beta/src/lauxlib.c34lua-5.1/src/lauxlib.h
35lua-5.1-beta/src/lauxlib.h35lua-5.1/src/lbaselib.c
36lua-5.1-beta/src/lbaselib.c36lua-5.1/src/lcode.c
37lua-5.1-beta/src/lcode.c37lua-5.1/src/lcode.h
38lua-5.1-beta/src/lcode.h38lua-5.1/src/ldblib.c
39lua-5.1-beta/src/ldblib.c39lua-5.1/src/ldebug.c
40lua-5.1-beta/src/ldebug.c40lua-5.1/src/ldebug.h
41lua-5.1-beta/src/ldebug.h41lua-5.1/src/ldo.c
42lua-5.1-beta/src/ldo.c42lua-5.1/src/ldo.h
43lua-5.1-beta/src/ldo.h43lua-5.1/src/ldump.c
44lua-5.1-beta/src/ldump.c44lua-5.1/src/lfunc.c
45lua-5.1-beta/src/lfunc.c45lua-5.1/src/lfunc.h
46lua-5.1-beta/src/lfunc.h46lua-5.1/src/lgc.c
47lua-5.1-beta/src/lgc.c47lua-5.1/src/lgc.h
48lua-5.1-beta/src/lgc.h48lua-5.1/src/linit.c
49lua-5.1-beta/src/linit.c49lua-5.1/src/liolib.c
50lua-5.1-beta/src/liolib.c50lua-5.1/src/llex.c
51lua-5.1-beta/src/llex.c51lua-5.1/src/llex.h
52lua-5.1-beta/src/llex.h52lua-5.1/src/llimits.h
53lua-5.1-beta/src/llimits.h53lua-5.1/src/lmathlib.c
54lua-5.1-beta/src/lmathlib.c54lua-5.1/src/lmem.c
55lua-5.1-beta/src/lmem.c55lua-5.1/src/lmem.h
56lua-5.1-beta/src/lmem.h56lua-5.1/src/loadlib.c
57lua-5.1-beta/src/loadlib.c57lua-5.1/src/lobject.c
58lua-5.1-beta/src/lobject.c58lua-5.1/src/lobject.h
59lua-5.1-beta/src/lobject.h59lua-5.1/src/lopcodes.c
60lua-5.1-beta/src/lopcodes.c60lua-5.1/src/lopcodes.h
61lua-5.1-beta/src/lopcodes.h61lua-5.1/src/loslib.c
62lua-5.1-beta/src/loslib.c62lua-5.1/src/lparser.c
63lua-5.1-beta/src/lparser.c63lua-5.1/src/lparser.h
64lua-5.1-beta/src/lparser.h64lua-5.1/src/lstate.c
65lua-5.1-beta/src/lstate.c65lua-5.1/src/lstate.h
66lua-5.1-beta/src/lstate.h66lua-5.1/src/lstring.c
67lua-5.1-beta/src/lstring.c67lua-5.1/src/lstring.h
68lua-5.1-beta/src/lstring.h68lua-5.1/src/lstrlib.c
69lua-5.1-beta/src/lstrlib.c69lua-5.1/src/ltable.c
70lua-5.1-beta/src/ltable.c70lua-5.1/src/ltable.h
71lua-5.1-beta/src/ltable.h71lua-5.1/src/ltablib.c
72lua-5.1-beta/src/ltablib.c72lua-5.1/src/ltm.c
73lua-5.1-beta/src/ltm.c73lua-5.1/src/ltm.h
74lua-5.1-beta/src/ltm.h74lua-5.1/src/lua.c
75lua-5.1-beta/src/lua.c75lua-5.1/src/luac.c
76lua-5.1-beta/src/lua.h76lua-5.1/src/luaconf.h
77lua-5.1-beta/src/luac.c77lua-5.1/src/lua.h
78lua-5.1-beta/src/luaconf.h78lua-5.1/src/lualib.h
79lua-5.1-beta/src/lualib.h79lua-5.1/src/lundump.c
80lua-5.1-beta/src/lundump.c80lua-5.1/src/lundump.h
81lua-5.1-beta/src/lundump.h81lua-5.1/src/lvm.c
82lua-5.1-beta/src/lvm.c82lua-5.1/src/lvm.h
83lua-5.1-beta/src/lvm.h83lua-5.1/src/lzio.c
84lua-5.1-beta/src/lzio.c84lua-5.1/src/lzio.h
85lua-5.1-beta/src/lzio.h85lua-5.1/src/Makefile
86lua-5.1-beta/src/print.c86lua-5.1/src/print.c
87lua-5.1-beta/test87lua-5.1/test
88lua-5.1-beta/test/README88lua-5.1/test/bisect.lua
89lua-5.1-beta/test/bisect.lua89lua-5.1/test/cf.lua
90lua-5.1-beta/test/cf.lua90lua-5.1/test/echo.lua
91lua-5.1-beta/test/echo.lua91lua-5.1/test/env.lua
92lua-5.1-beta/test/env.lua92lua-5.1/test/factorial.lua
93lua-5.1-beta/test/factorial.lua93lua-5.1/test/fibfor.lua
94lua-5.1-beta/test/fib.lua94lua-5.1/test/fib.lua
95lua-5.1-beta/test/fibfor.lua95lua-5.1/test/globals.lua
96lua-5.1-beta/test/globals.lua96lua-5.1/test/hello.lua
97lua-5.1-beta/test/hello.lua97lua-5.1/test/life.lua
98lua-5.1-beta/test/life.lua98lua-5.1/test/luac.lua
99lua-5.1-beta/test/luac.lua99lua-5.1/test/printf.lua
100lua-5.1-beta/test/printf.lua100lua-5.1/test/README
101lua-5.1-beta/test/readonly.lua101lua-5.1/test/readonly.lua
102lua-5.1-beta/test/sieve.lua102lua-5.1/test/sieve.lua
103lua-5.1-beta/test/sort.lua103lua-5.1/test/sort.lua
104lua-5.1-beta/test/table.lua104lua-5.1/test/table.lua
105lua-5.1-beta/test/trace-calls.lua105lua-5.1/test/trace-calls.lua
106lua-5.1-beta/test/trace-globals.lua106lua-5.1/test/trace-globals.lua
107lua-5.1-beta/test/xd.lua107lua-5.1/test/xd.lua
108END OF MANIFEST108END OF MANIFEST
Makefile+12−22
@@ -4,6 +4,9 @@ · 3 unmodified lines
4 4
5# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================5# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
6 6
7# Your platform. See PLATS for possible values.
8PLAT= none
9
7# Where to install. The installation starts in the src directory, so take care10# Where to install. The installation starts in the src directory, so take care
8# if INSTALL_TOP is not an absolute path. (Man pages are installed from the11# if INSTALL_TOP is not an absolute path. (Man pages are installed from the
9# doc directory.)12# doc directory.)
@@ -24,6 +27,9 @@ INSTALL_DATA= cp · 14 unmodified lines
24 27
25# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========28# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
26 29
30# Convenience platforms targets.
31PLATS= ansi bsd generic linux macosx mingw posix
32
27# What to install.33# What to install.
28TO_BIN= lua luac34TO_BIN= lua luac
29TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp35TO_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
33# Lua version. Currently used only for messages.39# Lua version. Currently used only for messages.
34V= 5.140V= 5.1
35 41
36all clean:42all: $(PLAT)
43
44$(PLATS) clean:
37 cd src; $(MAKE) $@45 cd src; $(MAKE) $@
38 46
39test: all47test: all
@@ -49,27 +57,8 @@ install: all · 9 unmodified lines
49local:57local:
50 $(MAKE) install INSTALL_TOP=.. INSTALL_EXEC="cp -p" INSTALL_DATA="cp -p"58 $(MAKE) install INSTALL_TOP=.. INSTALL_EXEC="cp -p" INSTALL_DATA="cp -p"
51 59
52# convenience targets for usual platforms60none:
53 61 @echo "Please choose a platform: $(PLATS)"
54ansi:
55 cd src; $(MAKE) MYCFLAGS=-DLUA_ANSI
56
57linux:
58 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
59
60macosx:
61 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_MACOSX
62
63posix:
64 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_POSIX
65
66bsd:
67 cd src; $(MAKE) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
68
69mingw:
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
73 62
74# echo config parameters63# echo config parameters
75echo:64echo:
@@ -80,6 +69,7 @@ echo: · 4 unmodified lines
80 @echo ""69 @echo ""
81 @echo "These are the parameters currently set in Makefile to install Lua $V:"70 @echo "These are the parameters currently set in Makefile to install Lua $V:"
82 @echo ""71 @echo ""
72 @echo "PLAT = $(PLAT)"
83 @echo "INSTALL_TOP = $(INSTALL_TOP)"73 @echo "INSTALL_TOP = $(INSTALL_TOP)"
84 @echo "INSTALL_BIN = $(INSTALL_BIN)"74 @echo "INSTALL_BIN = $(INSTALL_BIN)"
85 @echo "INSTALL_INC = $(INSTALL_INC)"75 @echo "INSTALL_INC = $(INSTALL_INC)"
README+1−1
@@ -1,4 +1,4 @@
1This is Lua 5.1 (beta).1This is Lua 5.1.
2See HISTORY for a summary of changes since the last released version.2See HISTORY for a summary of changes since the last released version.
3 3
4* What is Lua?4* What is Lua?
doc/contents.html+143−128
@@ -14,12 +14,14 @@ Lua 5.1 Reference Manual · 13 unmodified lines
14 14
15<SMALL>15<SMALL>
16<A HREF="http://www.lua.org/copyright.html">Copyright</A>16<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.
18</SMALL>18</SMALL>
19<HR>19<HR>
20 20
21<H2>Contents</H2>
21<UL>22<UL>
22<LI><A HREF="#words">Word index</A>23<LI><A HREF="#quick">Quick index</A>
24<P>
23<LI><A HREF="manual.html">Top</A>25<LI><A HREF="manual.html">Top</A>
24<LI><A HREF="manual.html#1">1 - Introduction</A>26<LI><A HREF="manual.html#1">1 - Introduction</A>
25<LI><A HREF="manual.html#2">2 - The Language</A>27<LI><A HREF="manual.html#2">2 - The Language</A>
@@ -82,20 +84,23 @@ Lua 5.1 Reference Manual · 56 unmodified lines
82<UL>84<UL>
83<LI><A HREF="manual.html#5.1">5.1 - Basic Functions</A>85<LI><A HREF="manual.html#5.1">5.1 - Basic Functions</A>
84<LI><A HREF="manual.html#5.2">5.2 - Coroutine Manipulation</A>86<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>
86<LI><A HREF="manual.html#5.4">5.4 - String Manipulation</A>88<LI><A HREF="manual.html#5.4">5.4 - String Manipulation</A>
87<LI><A HREF="manual.html#5.5">5.5 - Table Manipulation</A>89<LI><A HREF="manual.html#5.5">5.5 - Table Manipulation</A>
88<LI><A HREF="manual.html#5.6">5.6 - Mathematical Functions</A>90<LI><A HREF="manual.html#5.6">5.6 - Mathematical Functions</A>
89<LI><A HREF="manual.html#5.7">5.7 - Input and Output Facilities</A>91<LI><A HREF="manual.html#5.7">5.7 - Input and Output Facilities</A>
90<LI><A HREF="manual.html#5.8">5.8 - Operating System Facilities</A>92<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>
92</UL>94</UL>
93<LI><A HREF="manual.html#6">6 - Lua Stand-alone</A>95<LI><A HREF="manual.html#6">6 - Lua Stand-alone</A>
94<LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>96<LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>
95</UL>97</UL>
96 98
97<H3><A NAME="words">Word index</A></H3>99<H2><A NAME="quick">Quick index</A></H2>
98 100<TABLE>
101<TR VALIGN="top">
102<TD WIDTH="35%">
103<H3><A NAME="functions">Functions</A></H3>
99<A HREF="manual.html#pdf-_G">_G</A><BR>104<A HREF="manual.html#pdf-_G">_G</A><BR>
100<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>105<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
101<A HREF="manual.html#pdf-assert">assert</A><BR>106<A HREF="manual.html#pdf-assert">assert</A><BR>
@@ -146,52 +151,83 @@ Lua 5.1 Reference Manual · 44 unmodified lines
146<A HREF="manual.html#pdf-load">load</A><BR>151<A HREF="manual.html#pdf-load">load</A><BR>
147<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>152<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
148<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>153<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
149 154<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
150<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>155<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
151<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>156<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
152<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>157<A HREF="manual.html#pdf-math.atan">math.atan</A><BR>
153<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR>158<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR>
154<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR>159<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR>
155<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR>160<A HREF="manual.html#pdf-math.cos">math.cos</A><BR>
156<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR>161<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR>
157<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR>162<A HREF="manual.html#pdf-math.def">math.def</A><BR>
158<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR>163<A HREF="manual.html#pdf-math.exp">math.exp</A><BR>
159<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR>164<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>
160<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>165<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>
161<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>166<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
162<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>167<A HREF="manual.html#pdf-math.log">math.log</A><BR>
163<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>168<A HREF="manual.html#pdf-math.log10">math.log10</A><BR>
164<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>169<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>
165<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>170<A HREF="manual.html#pdf-math.sin">math.sin</A><BR>
166<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>171<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR>
167<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR>172<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>
168<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR>173<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>
169<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>174<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
170<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>175<A HREF="manual.html#pdf-module">module</A><BR>
171<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>176<A HREF="manual.html#pdf-next">next</A><BR>
172<A HREF="manual.html#luaL_error">luaL_error</A><BR>177<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
173<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>178<A HREF="manual.html#pdf-os.date">os.date</A><BR>
174<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>179<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
175<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>180<A HREF="manual.html#pdf-os.execute">os.execute</A><BR>
176<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>181<A HREF="manual.html#pdf-os.exit">os.exit</A><BR>
177<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>182<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR>
178<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>183<A HREF="manual.html#pdf-os.remove">os.remove</A><BR>
179<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>184<A HREF="manual.html#pdf-os.rename">os.rename</A><BR>
180<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>185<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR>
181<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>186<A HREF="manual.html#pdf-os.time">os.time</A><BR>
182<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>187<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>
183<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>188<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
184<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>189<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
185<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>190<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>
186<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>191<A HREF="manual.html#pdf-package.path">package.path</A><BR>
187<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>192<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
188<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>193<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>
189<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>194<A HREF="manual.html#pdf-pairs">pairs</A><BR>
190<A HREF="manual.html#luaL_register">luaL_register</A><BR>195<A HREF="manual.html#pdf-pcall">pcall</A><BR>
191<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>196<A HREF="manual.html#pdf-print">print</A><BR>
192<A HREF="manual.html#luaL_typerror">luaL_typerror</A><BR>197<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
193<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>198<A HREF="manual.html#pdf-rawget">rawget</A><BR>
194<A HREF="manual.html#luaL_where">luaL_where</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>
195<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>231<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
196<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>232<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
197<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>233<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
@@ -256,6 +292,7 @@ Lua 5.1 Reference Manual · 58 unmodified lines
256<A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR>292<A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR>
257<A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR>293<A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR>
258<A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR>294<A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR>
295<A HREF="manual.html#lua_pushthread">lua_pushthread</A><BR>
259<A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR>296<A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR>
260<A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR>297<A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR>
261<A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR>298<A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR>
@@ -275,6 +312,7 @@ Lua 5.1 Reference Manual · 13 unmodified lines
275<A HREF="manual.html#lua_settable">lua_settable</A><BR>312<A HREF="manual.html#lua_settable">lua_settable</A><BR>
276<A HREF="manual.html#lua_settop">lua_settop</A><BR>313<A HREF="manual.html#lua_settop">lua_settop</A><BR>
277<A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>314<A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>
315<A HREF="manual.html#lua_status">lua_status</A><BR>
278<A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>316<A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>
279<A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>317<A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>
280<A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>318<A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>
@@ -285,89 +323,66 @@ Lua 5.1 Reference Manual · 4 unmodified lines
285<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>323<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
286<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>324<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
287<A HREF="manual.html#lua_type">lua_type</A><BR>325<A HREF="manual.html#lua_type">lua_type</A><BR>
326<A HREF="manual.html#lua_typename">lua_typename</A><BR>
288<A HREF="manual.html#lua_xmove">lua_xmove</A><BR>327<A HREF="manual.html#lua_xmove">lua_xmove</A><BR>
289<A HREF="manual.html#lua_yield">lua_yield</A><BR>328<A HREF="manual.html#lua_yield">lua_yield</A><BR>
290 329</TD>
291<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>330<TD>
292<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>331<H3>Auxiliary library</H3>
293<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>332<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
294<A HREF="manual.html#pdf-math.atan">math.atan</A><BR>333<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
295<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR>334<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>
296<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR>335<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR>
297<A HREF="manual.html#pdf-math.cos">math.cos</A><BR>336<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR>
298<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR>337<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR>
299<A HREF="manual.html#pdf-math.def">math.def</A><BR>338<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR>
300<A HREF="manual.html#pdf-math.exp">math.exp</A><BR>339<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR>
301<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>340<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR>
302<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>341<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR>
303<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>342<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>
304<A HREF="manual.html#pdf-math.log">math.log</A><BR>343<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>
305<A HREF="manual.html#pdf-math.log10">math.log10</A><BR>344<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
306<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>345<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>
307<A HREF="manual.html#pdf-math.sin">math.sin</A><BR>346<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>
308<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR>347<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>
309<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>348<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>
310<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>349<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR>
311<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>350<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR>
312<A HREF="manual.html#pdf-module">module</A><BR>351<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
313<A HREF="manual.html#pdf-next">next</A><BR>352<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
314<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>353<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
315<A HREF="manual.html#pdf-os.date">os.date</A><BR>354<A HREF="manual.html#luaL_error">luaL_error</A><BR>
316<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>355<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
317<A HREF="manual.html#pdf-os.execute">os.execute</A><BR>356<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
318<A HREF="manual.html#pdf-os.exit">os.exit</A><BR>357<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>
319<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR>358<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
320<A HREF="manual.html#pdf-os.remove">os.remove</A><BR>359<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
321<A HREF="manual.html#pdf-os.rename">os.rename</A><BR>360<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
322<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR>361<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
323<A HREF="manual.html#pdf-os.time">os.time</A><BR>362<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
324<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>363<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
325<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>364<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
326<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>365<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>
327<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>366<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
328<A HREF="manual.html#pdf-package.path">package.path</A><BR>367<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
329<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>368<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
330<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>369<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
331<A HREF="manual.html#pdf-pairs">pairs</A><BR>370<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
332<A HREF="manual.html#pdf-pcall">pcall</A><BR>371<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
333<A HREF="manual.html#pdf-print">print</A><BR>372<A HREF="manual.html#luaL_register">luaL_register</A><BR>
334<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>373<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
335<A HREF="manual.html#pdf-rawget">rawget</A><BR>374<A HREF="manual.html#luaL_typerror">luaL_typerror</A><BR>
336<A HREF="manual.html#pdf-rawset">rawset</A><BR>375<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
337<A HREF="manual.html#pdf-require">require</A><BR>376<A HREF="manual.html#luaL_where">luaL_where</A><BR>
338<A HREF="manual.html#pdf-select">select</A><BR>377</TD>
339<A HREF="manual.html#pdf-setfenv">setfenv</A><BR>378</TR>
340<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>379</TABLE>
341<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
342<A HREF="manual.html#pdf-string.char">string.char</A><BR>
343<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
344<A HREF="manual.html#pdf-string.find">string.find</A><BR>
345<A HREF="manual.html#pdf-string.format">string.format</A><BR>
346<A HREF="manual.html#pdf-string.gmatch">string.gmatch</A><BR>
347<A HREF="manual.html#pdf-string.gsub">string.gsub</A><BR>
348<A HREF="manual.html#pdf-string.len">string.len</A><BR>
349<A HREF="manual.html#pdf-string.lower">string.lower</A><BR>
350<A HREF="manual.html#pdf-string.match">string.match</A><BR>
351<A HREF="manual.html#pdf-string.rep">string.rep</A><BR>
352<A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR>
353<A HREF="manual.html#pdf-string.sub">string.sub</A><BR>
354<A HREF="manual.html#pdf-string.upper">string.upper</A><BR>
355<A HREF="manual.html#pdf-table.concat">table.concat</A><BR>
356<A HREF="manual.html#pdf-table.insert">table.insert</A><BR>
357<A HREF="manual.html#pdf-table.maxn(table)">table.maxn(table)</A><BR>
358<A HREF="manual.html#pdf-table.remove">table.remove</A><BR>
359<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
360<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
361<A HREF="manual.html#pdf-tostring">tostring</A><BR>
362<A HREF="manual.html#pdf-type">type</A><BR>
363<A HREF="manual.html#pdf-unpack">unpack</A><BR>
364<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
365<P>380<P>
366 381
367<HR>382<HR>
368<SMALL>383<SMALL>
369Last update:384Last update:
370Tue Nov 1 15:40:46 BRST 2005385Tue Jan 10 10:10:22 BRST 2006
371</SMALL>386</SMALL>
372 387
373</BODY>388</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 $1.\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $
2.TH LUA 1 "$Date: 2005/09/02 16:29:34 $"2.TH LUA 1 "$Date: 2006/01/06 16:03:34 $"
3.SH NAME3.SH NAME
4lua \- Lua interpreter4lua \- Lua interpreter
5.SH SYNOPSIS5.SH SYNOPSIS
@@ -45,9 +45,9 @@ The arguments in · 39 unmodified lines
45.B arg45.B arg
46start at 0,46start at 0,
47which contains the string47which contains the string
48.RI ` script '.48.RI ' script '.
49The index of the last argument is stored in49The index of the last argument is stored in
50.BR "arg.n" .50.BR arg.n .
51The arguments given in the command line before51The arguments given in the command line before
52.IR script ,52.IR script ,
53including the name of the interpreter,53including the name of the interpreter,
@@ -63,17 +63,17 @@ if it is defined. · 9 unmodified lines
63If the value of63If the value of
64.B LUA_INIT64.B LUA_INIT
65is of the form65is of the form
66.RI `@ filename ',66.RI '@ filename ',
67then67then
68.I filename68.I filename
69is executed.69is executed.
70Otherwise, the string is assumed to be a Lua statement and is executed.70Otherwise, the string is assumed to be a Lua statement and is executed.
71.LP71.LP
72Options start with72Options start with
73.B \-73.B '\-'
74and are described below.74and are described below.
75You can use75You can use
76.B "\--"76.B "'\--'"
77to signal the end of options.77to signal the end of options.
78.LP78.LP
79If no arguments are given,79If no arguments are given,
@@ -96,11 +96,11 @@ a syntax error is found. · 16 unmodified lines
96So, one way to interrupt the reading of an incomplete statement is96So, one way to interrupt the reading of an incomplete statement is
97to force a syntax error:97to force a syntax error:
98adding a98adding a
99.B `;' 99.B ';'
100in the middle of a statement is a sure way of forcing a syntax error100in the middle of a statement is a sure way of forcing a syntax error
101(except inside multiline strings and comments; these must be closed explicitly).101(except inside multiline strings and comments; these must be closed explicitly).
102If a line starts with102If a line starts with
103.BR `=' ,103.BR '=' ,
104then104then
105.B lua105.B lua
106displays the values of all the expressions in the remainder of the106displays the values of all the expressions in the remainder of the
@@ -115,11 +115,10 @@ So, · 8 unmodified lines
115to change the prompts,115to change the prompts,
116set the corresponding variable to a string of your choice.116set the corresponding variable to a string of your choice.
117You can do that after calling the interpreter117You can do that after calling the interpreter
118or on the command line with118or on the command line
119.BR "_PROMPT" "=\'lua: \'" ,119(but in this case you have to be careful with quotes
120for example.120if the prompt string contains a space; otherwise you may confuse the shell.)
121(Note the need for quotes, because the string contains a space.)121The default prompts are "> " and ">> ".
122The default prompts are ``> '' and ``>> ''.
123.SH OPTIONS122.SH OPTIONS
124.TP123.TP
125.B \-124.B \-
@@ -141,14 +140,12 @@ enter interactive mode after · 15 unmodified lines
141.I script140.I script
142is executed.141is executed.
143.TP142.TP
144.BI \-l " module"143.BI \-l " name"
145call144call
146.BI require( module )145.BI require(' name ')
147before executing146before executing
148.IR script.147.IR script .
149Typically used to load libraries148Typically used to load libraries.
150(hence the letter
151.IR l ).
152.TP149.TP
153.B \-v150.B \-v
154show version information.151show 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 $ -->
2<HTML>2<HTML>
3<HEAD>3<HEAD>
4<TITLE>LUA man page</TITLE>4<TITLE>LUA man page</TITLE>
@@ -7,9 +7,9 @@ · 2 unmodified lines
7 7
8<BODY BGCOLOR="#FFFFFF">8<BODY BGCOLOR="#FFFFFF">
9 9
10<H1>NAME</H1>10<H2>NAME</H2>
11lua - Lua interpreter11lua - Lua interpreter
12<H1>SYNOPSIS</H1>12<H2>SYNOPSIS</H2>
13<B>lua</B>13<B>lua</B>
14[14[
15<I>options</I>15<I>options</I>
@@ -20,7 +20,7 @@ lua - Lua interpreter · 4 unmodified lines
20<I>args</I>20<I>args</I>
21]21]
22]22]
23<H1>DESCRIPTION</H1>23<H2>DESCRIPTION</H2>
24<B>lua</B>24<B>lua</B>
25is the stand-alone Lua interpreter.25is the stand-alone Lua interpreter.
26It loads and executes Lua programs,26It loads and executes Lua programs,
@@ -52,9 +52,9 @@ The arguments in · 25 unmodified lines
52<B>arg</B>52<B>arg</B>
53start at 0,53start at 0,
54which contains the string54which contains the string
55`<I>script</I>'.55'<I>script</I>'.
56The index of the last argument is stored in56The index of the last argument is stored in
57<B>"arg.n"</B>.57<B>arg.n</B>.
58The arguments given in the command line before58The arguments given in the command line before
59<I>script</I>,59<I>script</I>,
60including the name of the interpreter,60including the name of the interpreter,
@@ -70,17 +70,17 @@ if it is defined. · 9 unmodified lines
70If the value of70If the value of
71<B>LUA_INIT</B>71<B>LUA_INIT</B>
72is of the form72is of the form
73`@<I>filename</I>',73'@<I>filename</I>',
74then74then
75<I>filename</I>75<I>filename</I>
76is executed.76is executed.
77Otherwise, the string is assumed to be a Lua statement and is executed.77Otherwise, the string is assumed to be a Lua statement and is executed.
78<P>78<P>
79Options start with79Options start with
80<B>-</B>80<B>'-'</B>
81and are described below.81and are described below.
82You can use82You can use
83<B>"--"</B>83<B>'--'</B>
84to signal the end of options.84to signal the end of options.
85<P>85<P>
86If no arguments are given,86If no arguments are given,
@@ -103,11 +103,11 @@ a syntax error is found. · 16 unmodified lines
103So, one way to interrupt the reading of an incomplete statement is103So, one way to interrupt the reading of an incomplete statement is
104to force a syntax error:104to force a syntax error:
105adding a105adding a
106<B>`;' </B>106<B>';'</B>
107in the middle of a statement is a sure way of forcing a syntax error107in the middle of a statement is a sure way of forcing a syntax error
108(except inside multiline strings and comments; these must be closed explicitly).108(except inside multiline strings and comments; these must be closed explicitly).
109If a line starts with109If a line starts with
110<B>`='</B>,110<B>'='</B>,
111then111then
112<B>lua</B>112<B>lua</B>
113displays the values of all the expressions in the remainder of the113displays the values of all the expressions in the remainder of the
@@ -122,12 +122,11 @@ So, · 8 unmodified lines
122to change the prompts,122to change the prompts,
123set the corresponding variable to a string of your choice.123set the corresponding variable to a string of your choice.
124You can do that after calling the interpreter124You can do that after calling the interpreter
125or on the command line with125or on the command line
126<B>"_PROMPT" "=\'lua: \'"</B>,126(but in this case you have to be careful with quotes
127for example.127if the prompt string contains a space; otherwise you may confuse the shell.)
128(Note the need for quotes, because the string contains a space.)128The default prompts are "&gt; " and "&gt;&gt; ".
129The default prompts are ``&gt; '' and ``&gt;&gt; ''.129<H2>OPTIONS</H2>
130<H1>OPTIONS</H1>
131<P>130<P>
132<B>-</B>131<B>-</B>
133load and execute the standard input as a file,132load and execute the standard input as a file,
@@ -135,7 +134,7 @@ that is, · 1 unmodified line
135not interactively,134not interactively,
136even when the standard input is a terminal.135even when the standard input is a terminal.
137<P>136<P>
138<B>-e "</B><I>stat"</I>137<B>-e </B><I>stat</I>
139execute statement138execute statement
140<I>stat</I>.139<I>stat</I>.
141You need to quote140You need to quote
@@ -148,24 +147,22 @@ enter interactive mode after · 6 unmodified lines
148<I>script</I>147<I>script</I>
149is executed.148is executed.
150<P>149<P>
151<B>-l "</B><I>module"</I>150<B>-l </B><I>name</I>
152call151call
153<B>require( module</B><I>)</I>152<B>require(' name</B><I>')</I>
154before executing153before executing
155<I></I>script.154<I>script</I>.
156Typically used to load libraries155Typically used to load libraries.
157(hence the letter
158<I>l</I>).
159<P>156<P>
160<B>-v</B>157<B>-v</B>
161show version information.158show version information.
162<H1>SEE ALSO</H1>159<H2>SEE ALSO</H2>
163<B>luac</B>(1)160<B>luac</B>(1)
164<BR>161<BR>
165<A HREF="http://www.lua.org/">http://www.lua.org/</A>162<A HREF="http://www.lua.org/">http://www.lua.org/</A>
166<H1>DIAGNOSTICS</H1>163<H2>DIAGNOSTICS</H2>
167Error messages should be self explanatory.164Error messages should be self explanatory.
168<H1>AUTHORS</H1>165<H2>AUTHORS</H2>
169R. Ierusalimschy,166R. Ierusalimschy,
170L. H. de Figueiredo,167L. H. de Figueiredo,
171and168and
doc/luac.1+21−13
@@ -1,5 +1,5 @@
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 $
2.TH LUAC 1 "$Date: 2005/09/02 16:29:34 $"2.TH LUAC 1 "$Date: 2006/01/06 16:03:34 $"
3.SH NAME3.SH NAME
4luac \- Lua compiler4luac \- Lua compiler
5.SH SYNOPSIS5.SH SYNOPSIS
@@ -17,7 +17,7 @@ into binary files that can be latter loaded and executed. · 11 unmodified lines
17.LP17.LP
18The main advantages of precompiling chunks are:18The main advantages of precompiling chunks are:
19faster loading,19faster loading,
20protecting source code from user changes,20protecting source code from accidental user changes,
21and21and
22off-line syntax checking.22off-line syntax checking.
23.LP23.LP
@@ -26,6 +26,13 @@ because in Lua chunks are always compiled into bytecodes before being executed. · 2 unmodified lines
26.B luac26.B luac
27simply allows those bytecodes to be saved in a file for later execution.27simply allows those bytecodes to be saved in a file for later execution.
28.LP28.LP
29Pre-compiled chunks are not necessarily smaller than the corresponding source.
30The main goal in pre-compiling is faster loading.
31.LP
32The binary files created by
33.B luac
34are portable only among architectures with the same word size and byte order.
35.LP
29.B luac36.B luac
30produces a single output file containing the bytecodes37produces a single output file containing the bytecodes
31for all source files given.38for all source files given.
@@ -36,10 +43,6 @@ but you can change this with the · 4 unmodified lines
36.B \-o43.B \-o
37option.44option.
38.LP45.LP
39The binary files created by
40.B luac
41are portable only among architectures with the same word size and byte order.
42.LP
43In the command line,46In the command line,
44you can mix47you can mix
45text files containing Lua source and48text files containing Lua source and
@@ -49,14 +52,14 @@ even from different (but compatible) platforms, · 3 unmodified lines
49into a single precompiled chunk.52into a single precompiled chunk.
50.LP53.LP
51You can use54You can use
52.B "\-"55.B "'\-'"
53to indicate the standard input as a source file56to indicate the standard input as a source file
54and57and
55.B "\--"58.B "'\--'"
56to signal the end of options59to signal the end of options
57(that is,60(that is,
58all remaining arguments will be treated as files even if they start with61all remaining arguments will be treated as files even if they start with
59.BR "\-" ).62.BR "'\-'" ).
60.LP63.LP
61The internal format of the binary files produced by64The internal format of the binary files produced by
62.B luac65.B luac
@@ -81,6 +84,10 @@ output to · 18 unmodified lines
81.IR file ,84.IR file ,
82instead of the default85instead of the default
83.BR luac.out .86.BR luac.out .
87(You can use
88.B "'\-'"
89for standard output,
90but not on platforms that open standard output in text mode.)
84The output file may be a source file because91The output file may be a source file because
85all files are loaded before the output file is written.92all files are loaded before the output file is written.
86Be careful not to overwrite precious files.93Be careful not to overwrite precious files.
@@ -105,9 +112,10 @@ No messages are displayed if the file passes the integrity test. · 18 unmodified lines
105.B \-s112.B \-s
106strip debug information before writing the output file.113strip debug information before writing the output file.
107This saves some space in very large chunks,114This saves some space in very large chunks,
108but if errors occur when running these chunks,115but if errors occur when running a stripped chunk,
109then the error messages may not contain the full information they usually do116then the error messages may not contain the full information they usually do.
110(line numbers and names of locals are lost).117For instance,
118line numbers and names of local variables are lost.
111.TP119.TP
112.B \-v120.B \-v
113show version information.121show 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 $ -->
2<HTML>2<HTML>
3<HEAD>3<HEAD>
4<TITLE>LUAC man page</TITLE>4<TITLE>LUAC man page</TITLE>
@@ -7,16 +7,16 @@ · 2 unmodified lines
7 7
8<BODY BGCOLOR="#FFFFFF">8<BODY BGCOLOR="#FFFFFF">
9 9
10<H1>NAME</H1>10<H2>NAME</H2>
11luac - Lua compiler11luac - Lua compiler
12<H1>SYNOPSIS</H1>12<H2>SYNOPSIS</H2>
13<B>luac</B>13<B>luac</B>
14[14[
15<I>options</I>15<I>options</I>
16] [16] [
17<I>filenames</I>17<I>filenames</I>
18]18]
19<H1>DESCRIPTION</H1>19<H2>DESCRIPTION</H2>
20<B>luac</B>20<B>luac</B>
21is the Lua compiler.21is the Lua compiler.
22It translates programs written in the Lua programming language22It 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
24<P>24<P>
25The main advantages of precompiling chunks are:25The main advantages of precompiling chunks are:
26faster loading,26faster loading,
27protecting source code from user changes,27protecting source code from accidental user changes,
28and28and
29off-line syntax checking.29off-line syntax checking.
30<P>30<P>
@@ -33,6 +33,13 @@ because in Lua chunks are always compiled into bytecodes before being executed. · 2 unmodified lines
33<B>luac</B>33<B>luac</B>
34simply allows those bytecodes to be saved in a file for later execution.34simply allows those bytecodes to be saved in a file for later execution.
35<P>35<P>
36Pre-compiled chunks are not necessarily smaller than the corresponding source.
37The main goal in pre-compiling is faster loading.
38<P>
39The binary files created by
40<B>luac</B>
41are portable only among architectures with the same word size and byte order.
42<P>
36<B>luac</B>43<B>luac</B>
37produces a single output file containing the bytecodes44produces a single output file containing the bytecodes
38for all source files given.45for all source files given.
@@ -43,10 +50,6 @@ but you can change this with the · 4 unmodified lines
43<B>-o</B>50<B>-o</B>
44option.51option.
45<P>52<P>
46The binary files created by
47<B>luac</B>
48are portable only among architectures with the same word size and byte order.
49<P>
50In the command line,53In the command line,
51you can mix54you can mix
52text files containing Lua source and55text files containing Lua source and
@@ -56,14 +59,14 @@ even from different (but compatible) platforms, · 3 unmodified lines
56into a single precompiled chunk.59into a single precompiled chunk.
57<P>60<P>
58You can use61You can use
59<B>"-"</B>62<B>'-'</B>
60to indicate the standard input as a source file63to indicate the standard input as a source file
61and64and
62<B>"--"</B>65<B>'--'</B>
63to signal the end of options66to signal the end of options
64(that is,67(that is,
65all remaining arguments will be treated as files even if they start with68all remaining arguments will be treated as files even if they start with
66<B>"-"</B>).69<B>'-'</B>).
67<P>70<P>
68The internal format of the binary files produced by71The internal format of the binary files produced by
69<B>luac</B>72<B>luac</B>
@@ -71,7 +74,7 @@ is likely to change when a new version of Lua is released. · 1 unmodified line
71So,74So,
72save the source files of all Lua programs that you precompile.75save the source files of all Lua programs that you precompile.
73<P>76<P>
74<H1>OPTIONS</H1>77<H2>OPTIONS</H2>
75Options must be separate.78Options must be separate.
76<P>79<P>
77<B>-l</B>80<B>-l</B>
@@ -83,11 +86,15 @@ loads · 5 unmodified lines
83<B>luac.out</B>86<B>luac.out</B>
84and lists its contents.87and lists its contents.
85<P>88<P>
86<B>-o "</B><I>file"</I>89<B>-o </B><I>file</I>
87output to90output to
88<I>file</I>,91<I>file</I>,
89instead of the default92instead of the default
90<B>luac.out</B>.93<B>luac.out</B>.
94(You can use
95<B>'-'</B>
96for standard output,
97but not on platforms that open standard output in text mode.)
91The output file may be a source file because98The output file may be a source file because
92all files are loaded before the output file is written.99all files are loaded before the output file is written.
93Be careful not to overwrite precious files.100Be careful not to overwrite precious files.
@@ -112,23 +119,24 @@ No messages are displayed if the file passes the integrity test. · 18 unmodified lines
112<B>-s</B>119<B>-s</B>
113strip debug information before writing the output file.120strip debug information before writing the output file.
114This saves some space in very large chunks,121This saves some space in very large chunks,
115but if errors occur when running these chunks,122but if errors occur when running a stripped chunk,
116then the error messages may not contain the full information they usually do123then the error messages may not contain the full information they usually do.
117(line numbers and names of locals are lost).124For instance,
125line numbers and names of local variables are lost.
118<P>126<P>
119<B>-v</B>127<B>-v</B>
120show version information.128show version information.
121<H1>FILES</H1>129<H2>FILES</H2>
122<P>130<P>
123<B>luac.out</B>131<B>luac.out</B>
124default output file132default output file
125<H1>SEE ALSO</H1>133<H2>SEE ALSO</H2>
126<B>lua</B>(1)134<B>lua</B>(1)
127<BR>135<BR>
128<A HREF="http://www.lua.org/">http://www.lua.org/</A>136<A HREF="http://www.lua.org/">http://www.lua.org/</A>
129<H1>DIAGNOSTICS</H1>137<H2>DIAGNOSTICS</H2>
130Error messages should be self explanatory.138Error messages should be self explanatory.
131<H1>AUTHORS</H1>139<H2>AUTHORS</H2>
132L. H. de Figueiredo,140L. H. de Figueiredo,
133R. Ierusalimschy and141R. Ierusalimschy and
134W. Celes142W. Celes
doc/manual.html+973−849
@@ -8,9 +8,9 @@ · 7 unmodified lines
8 8
9<body bgcolor="#FFFFFF">9<body bgcolor="#FFFFFF">
10 10
11<hr/>11<hr />
12<h1>12<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>
14Lua 5.1 Reference Manual14Lua 5.1 Reference Manual
15</h1>15</h1>
16 16
@@ -18,16 +18,15 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line
18<p>18<p>
19<small>19<small>
20<a href="http://www.lua.org/copyright.html">Copyright</a>20<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.
22</small>22</small>
23<hr/>23<hr />
24 24
25<p>25<p>
26<p>26<p>
27<!-- ====================================================================== -->27<!-- ====================================================================== -->
28 28
29 29
30
31<a name="1"></a><h1>1 - Introduction</h1>30<a name="1"></a><h1>1 - Introduction</h1>
32 31
33<p>Lua is an extension programming language designed to support32<p>Lua is an extension programming language designed to support
@@ -36,7 +35,7 @@ facilities. · 2 unmodified lines
36It also offers good support for object-oriented programming,35It also offers good support for object-oriented programming,
37functional programming, and data-driven programming.36functional programming, and data-driven programming.
38Lua is intended to be used as a powerful, light-weight37Lua is intended to be used as a powerful, light-weight
39configuration language for any program that needs one.38scripting language for any program that needs one.
40Lua is implemented as a library, written in <em>clean</em> C39Lua is implemented as a library, written in <em>clean</em> C
41(that is, in the common subset of ANSI C and C++).40(that is, in the common subset of ANSI C and C++).
42 41
@@ -49,42 +48,21 @@ and can register C functions to be called by Lua code. · 6 unmodified lines
49Through the use of C functions, Lua can be augmented to cope with48Through the use of C functions, Lua can be augmented to cope with
50a wide range of different domains,49a wide range of different domains,
51thus creating customized programming languages sharing a syntactical framework.50thus creating customized programming languages sharing a syntactical framework.
52 51The Lua distribution includes a sample host program called <code>lua</code>,
53<p>The Lua distribution includes a stand-alone embedding program,52which uses the Lua library to offer a complete, stand-alone Lua interpreter.
54<code>lua</code>, that uses the Lua library to offer a complete Lua interpreter.
55 53
56<p>Lua is free software,54<p>Lua is free software,
57and is provided as usual with no guarantees,55and is provided as usual with no guarantees,
58as stated in its copyright notice.56as stated in its license.
59The implementation described in this manual is available57The implementation described in this manual is available
60at Lua's official web site, <code>www.lua.org</code>.58at Lua's official web site, <code>www.lua.org</code>.
61 59
62<p>Like any other reference manual,60<p>Like any other reference manual,
63this document is dry in places.61this document is dry in places.
64For a discussion of the decisions behind the design of Lua,62For a discussion of the decisions behind the design of Lua,
65see the papers below,63see the technical papers available at Lua's web site.
66which are available at Lua's web site.64For a detailed introduction to programming in Lua,
67<ul>65see Roberto's book, <em>Programming in Lua</em>.
68<li>
69R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
70Lua---an extensible extension language.
71<em>Software: Practice &#038; Experience</em> <b>26</b>:6 (1996) 635--652.
72<li>
73L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
74The 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>
78L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
79Lua: an extensible embedded language.
80<em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26--33.
81<li>
82R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
83The 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.
88 66
89<p>67<p>
90<a name="language"></a><a name="2"></a><h1>2 - The Language</h1>68<a name="language"></a><a name="2"></a><h1>2 - The Language</h1>
@@ -96,7 +74,7 @@ which tokens are valid, · 5 unmodified lines
96how they can be combined,74how they can be combined,
97and what their combinations mean.75and what their combinations mean.
98 76
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,
100in which78in which
101{<em>a</em>} means 0 or more <em>a</em>'s, and79{<em>a</em>} means 0 or more <em>a</em>'s, and
102[<em>a</em>] means an optional <em>a</em>.80[<em>a</em>] means an optional <em>a</em>.
@@ -104,16 +82,20 @@ Non-terminals are shown in <em>italics</em>, · 1 unmodified line
104keywords are shown in <b>bold</b>,82keywords are shown in <b>bold</b>,
105and other terminal symbols are shown in <code>typewriter</code> font,83and other terminal symbols are shown in <code>typewriter</code> font,
106enclosed in single quotes.84enclosed in single quotes.
85The complete syntax of Lua can be found at the end of this manual.
107 86
108<p><a name="lexical"></a><a name="2.1"></a><h2>2.1 - Lexical Conventions</h2>87<p><a name="lexical"></a><a name="2.1"></a><h2>2.1 - Lexical Conventions</h2>
109 88
110<p><em>Names</em> in Lua can be any string of letters,89<p><em>Names</em>
90(also called <em>identifiers</em>)
91in Lua can be any string of letters,
111digits, and underscores,92digits, and underscores,
112not beginning with a digit.93not beginning with a digit.
113This coincides with the definition of names in most languages.94This coincides with the definition of names in most languages.
114(The definition of letter depends on the current locale:95(The definition of letter depends on the current locale:
115any character considered alphabetic by the current locale96any character considered alphabetic by the current locale
116can be used in an identifier.)97can be used in an identifier.)
98Identifiers are used to name variables and table fields.
117 99
118<p>The following <em>keywords</em> are reserved100<p>The following <em>keywords</em> are reserved
119and cannot be used as names:101and cannot be used as names:
@@ -130,7 +112,7 @@ and cannot be used as names: · 10 unmodified lines
130are two different, valid names.112are two different, valid names.
131As a convention, names starting with an underscore followed by113As a convention, names starting with an underscore followed by
132uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>)114uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>)
133are reserved for internal variables used by Lua.115are reserved for internal global variables used by Lua.
134 116
135<p>The following strings denote other tokens:117<p>The following strings denote other tokens:
136<pre>118<pre>
@@ -152,8 +134,8 @@ and can contain the following C-like escape sequences: · 15 unmodified lines
152<li><b><code>\t</code></b> --- horizontal tab134<li><b><code>\t</code></b> --- horizontal tab
153<li><b><code>\v</code></b> --- vertical tab135<li><b><code>\v</code></b> --- vertical tab
154<li><b><code>\\</code></b> --- backslash136<li><b><code>\\</code></b> --- backslash
155<li><b><code>\"</code></b> --- quotation mark137<li><b><code>\"</code></b> --- quotation mark (double quote)
156<li><b><code>\'</code></b> --- apostrophe138<li><b><code>\'</code></b> --- apostrophe (single quote)
157</ul>139</ul>
158Moreover, a `<code>\</code><em>newline</em>&acute;140Moreover, a `<code>\</code><em>newline</em>&acute;
159(that is, a backslash followed by a real newline)141(that is, a backslash followed by a real newline)
@@ -161,38 +143,51 @@ results in a newline in the string. · 1 unmodified line
161A character in a string may also be specified by its numerical value143A character in a string may also be specified by its numerical value
162using the escape sequence `<code>\</code><em>ddd</em>&acute;,144using the escape sequence `<code>\</code><em>ddd</em>&acute;,
163where <em>ddd</em> is a sequence of up to three decimal digits.145where <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,
147it must be expressed using exactly three digits.)
164Strings in Lua may contain any 8-bit value, including embedded zeros,148Strings in Lua may contain any 8-bit value, including embedded zeros,
165which can be specified as `<code>\0</code>&acute;.149which can be specified as `<code>\0</code>&acute;.
166 150
151<p>To put a double (single) quote, a newline, a backslash,
152or an embedded zero
153inside a literal string enclosed by double (single) quotes
154you must use an escape sequence.
155Any other character may be directly inserted into the literal.
156(Some control characters may cause problems for the file system,
157but Lua has no problem with them.)
158
167<p>Literal strings can also be defined using a long format159<p>Literal strings can also be defined using a long format
168enclosed by <em>l-brackets</em> (long brackets).160enclosed by <em>long brackets</em>.
169We define an <em>opening l-bracket of level <em>n</em></em> as an opening161We define an <em>opening long bracket of level <em>n</em></em> as an opening
170square bracket followed by <em>n</em> equal signs followed by another162square bracket followed by <em>n</em> equal signs followed by another
171opening square bracket.163opening square bracket.
172So, an opening l-bracket of level 0 is written as <code>[[</code>,164So, an opening long bracket of level 0 is written as <code>[[</code>,
173an opening l-bracket of level 1 is written as <code>[=[</code>,165an opening long bracket of level 1 is written as <code>[=[</code>,
174and so on.166and so on.
175A <em>closing l-bracket</em> is defined similarly;167A <em>closing long bracket</em> is defined similarly;
176for instance, a closing l-bracket of level 4 is written as <code>]====]</code>.168for instance, a closing long bracket of level 4 is written as <code>]====]</code>.
177A long string starts with an opening l-bracket of any level and169A long string starts with an opening long bracket of any level and
178ends at the first closing l-bracket of the same level.170ends at the first closing long bracket of the same level.
179Literals in this bracketed form may run for several lines,171Literals in this bracketed form may run for several lines,
180do not interpret any escape sequences,172do not interpret any escape sequences,
181and ignore l-brackets of any other level.173and ignore long brackets of any other level.
174They may contain anything except a closing bracket of the proper level
175or embedded zeros.
182 176
183<p>For convenience,177<p>For convenience,
184when the opening l-bracket is immediately followed by a newline,178when the opening long bracket is immediately followed by a newline,
185the newline is not included in the string.179the newline is not included in the string.
186As an example, in a system using ASCII180As an example, in a system using ASCII
187(in which `<code>a</code>&acute; is coded as 97,181(in which `<code>a</code>&acute; is coded as 97,
188newline is coded as 10, and `<code>1</code>&acute; is coded as 49),182newline is coded as 10, and `<code>1</code>&acute; is coded as 49),
189the four literals below denote the same string:183the four literals below denote the same string:
190<pre>184<pre>
191 (1) "alo\n123\""185 (1) 'alo\n123"'
192 (2) '\97lo\10\04923"'186 (2) "alo\n123\""
193 (3) [[alo187 (3) '\97lo\10\04923"'
188 (4) [[alo
194 123"]]189 123"]]
195 (4) [==[190 (5) [==[
196 alo191 alo
197 123"]==]192 123"]==]
198</pre>193</pre>
@@ -204,13 +199,14 @@ Examples of valid numerical constants are · 5 unmodified lines
204 3 3.0 3.1416 314.16e-2 0.31416E1199 3 3.0 3.1416 314.16e-2 0.31416E1
205</pre>200</pre>
206 201
207<p><em>Comments</em> start anywhere outside a string with a202<p><em>Comments</em> start with a double hyphen (<code>--</code>)
208double hyphen (<code>--</code>).203anywhere outside a string.
209If the text immediately after <code>--</code> is not an opening l-bracket,204If the text immediately after <code>--</code> is not an opening long bracket,
210the comment is a <em>short comment</em>,205the comment is a <em>short comment</em>,
211which runs until the end of the line.206which runs until the end of the line.
212Otherwise, it is a <em>long comment</em>,207Otherwise, it is a <em>long comment</em>,
213which runs until the corresponding closing l-bracket.208which runs until the corresponding closing long bracket.
209Long comments are frequently used to disable code temporarily.
214 210
215<p><a name="TypesSec"></a><a name="2.2"></a><h2>2.2 - Values and Types</h2>211<p><a name="TypesSec"></a><a name="2.2"></a><h2>2.2 - Values and Types</h2>
216 212
@@ -220,15 +216,19 @@ variables do not have types; only values do. · 3 unmodified lines
220There are no type definitions in the language.216There are no type definitions in the language.
221All values carry their own type.217All values carry their own type.
222 218
219<p>All values in Lua are <em>first-class values</em>.
220That means that all values can be stored in variables,
221passed as arguments to other functions, and returned as results.
222
223<p>There are eight basic types in Lua:223<p>There are eight basic types in Lua:
224<em>nil</em>, <em>boolean</em>, <em>number</em>,224<em>nil</em>, <em>boolean</em>, <em>number</em>,
225<em>string</em>, <em>function</em>, <em>userdata</em>,225<em>string</em>, <em>function</em>, <em>userdata</em>,
226<em>thread</em>, and <em>table</em>.226<em>thread</em>, and <em>table</em>.
227<em>Nil</em> is the type of the value <b>nil</b>,227<em>Nil</em> is the type of the value <b>nil</b>,
228whose main property is to be different from any other value;228whose main property is to be different from any other value;
229usually it represents the absence of a useful value.229it usually represents the absence of a useful value.
230<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.230<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
231In Lua, both <b>nil</b> and <b>false</b> make a condition false;231Both <b>nil</b> and <b>false</b> make a condition false;
232any other value makes it true.232any other value makes it true.
233<em>Number</em> represents real (double-precision floating-point) numbers.233<em>Number</em> represents real (double-precision floating-point) numbers.
234(It is easy to build Lua interpreters that use other234(It is easy to build Lua interpreters that use other
@@ -239,12 +239,9 @@ See file <code>luaconf.h</code>.) · 4 unmodified lines
239 239
240Lua is 8-bit clean:240Lua is 8-bit clean:
241Strings may contain any 8-bit character,241Strings may contain any 8-bit character,
242including embedded zeros (<code>'\0'</code>) (see <a href="#lexical">2.1</a>).242including embedded zeros (`<code>\0</code>&acute;) (see <a href="#lexical">2.1</a>).
243 243
244<p>Functions are <em>first-class values</em> in Lua.244<p>Lua can call (and manipulate) functions written in Lua and
245That means that functions can be stored in variables,
246passed as arguments to other functions, and returned as results.
247Lua can call (and manipulate) functions written in Lua and
248functions written in C245functions written in C
249(see <a href="#functioncall">2.5.8</a>).246(see <a href="#functioncall">2.5.8</a>).
250 247
@@ -262,12 +259,14 @@ This guarantees the integrity of data owned by the host program. · 11 unmodified lines
262 259
263<p>The type <em>thread</em> represents independent threads of execution260<p>The type <em>thread</em> represents independent threads of execution
264and it is used to implement coroutines (see <a href="#coroutine">2.11</a>).261and it is used to implement coroutines (see <a href="#coroutine">2.11</a>).
262Do not confuse Lua threads with operating-system threads.
263Lua supports coroutines on all systems,
264even those that do not support threads.
265 265
266<p>The type <em>table</em> implements associative arrays,266<p>The type <em>table</em> implements associative arrays,
267that is, arrays that can be indexed not only with numbers,267that is, arrays that can be indexed not only with numbers,
268but with any value (except <b>nil</b>).268but with any value (except <b>nil</b>).
269Moreover,269Tables can be <em>heterogeneous</em>;
270tables can be <em>heterogeneous</em>,
271that is, they can contain values of all types (except <b>nil</b>).270that is, they can contain values of all types (except <b>nil</b>).
272Tables are the sole data structuring mechanism in Lua;271Tables are the sole data structuring mechanism in Lua;
273they may be used to represent ordinary arrays,272they may be used to represent ordinary arrays,
@@ -281,11 +280,11 @@ There are several convenient ways to create tables in Lua · 7 unmodified lines
281<p>Like indices,280<p>Like indices,
282the value of a table field can be of any type (except <b>nil</b>).281the value of a table field can be of any type (except <b>nil</b>).
283In particular,282In particular,
284because functions are first class values,283because functions are first-class values,
285table fields may contain functions.284table fields may contain functions.
286Thus tables may also carry <em>methods</em> (see <a href="#func-def">2.5.9</a>).285Thus tables may also carry <em>methods</em> (see <a href="#func-def">2.5.9</a>).
287 286
288<p>Tables, functions, and userdata values are <em>objects</em>:287<p>Strings, tables, functions, and userdata values are <em>objects</em>:
289variables do not actually <em>contain</em> these values,288variables do not actually <em>contain</em> these values,
290only <em>references</em> to them.289only <em>references</em> to them.
291Assignment, parameter passing, and function returns290Assignment, parameter passing, and function returns
@@ -300,7 +299,7 @@ of a given value. · 8 unmodified lines
300<p>Lua provides automatic conversion between299<p>Lua provides automatic conversion between
301string and number values at run time.300string and number values at run time.
302Any arithmetic operation applied to a string tries to convert301Any arithmetic operation applied to a string tries to convert
303that string to a number, following the usual rules.302that string to a number, following the usual conversion rules.
304Conversely, whenever a number is used where a string is expected,303Conversely, whenever a number is used where a string is expected,
305the number is converted to a string, in a reasonable format.304the number is converted to a string, in a reasonable format.
306For complete control of how numbers are converted to strings,305For complete control of how numbers are converted to strings,
@@ -315,12 +314,14 @@ There are three kinds of variables in Lua: · 8 unmodified lines
315global variables, local variables, and table fields.314global variables, local variables, and table fields.
316 315
317<p>A single name can denote a global variable or a local variable316<p>A single name can denote a global variable or a local variable
318(or a formal parameter of a function,317(or a function formal parameter,
319which is a particular form of local variable):318which is a particular kind of local variable):
320<pre>319<pre>
321 var ::= Name320 var ::= Name
322</pre>321</pre>
323Variables are assumed to be global unless explicitly declared local322Name 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
324(see <a href="#localvar">2.4.7</a>).325(see <a href="#localvar">2.4.7</a>).
325Local variables are <em>lexically scoped</em>:326Local variables are <em>lexically scoped</em>:
326Local variables can be freely accessed by functions327Local 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
334</pre>335</pre>
335The first expression (<em>prefixexp</em>) should result in a table value;336The first expression (<em>prefixexp</em>) should result in a table value;
336the second expression (<em>exp</em>)337the second expression (<em>exp</em>)
337identifies a specific entry inside that table.338identifies a specific entry in that table.
338The expression denoting the table to be indexed has a restricted syntax;339The expression denoting the table to be indexed has a restricted syntax;
339see <a href="#expressions">2.5</a> for details.340see <a href="#expressions">2.5</a> for details.
340 341
341<p>The syntax <code>var.NAME</code> is just syntactic sugar for342<p>The syntax <code>var.Name</code> is just syntactic sugar for
342<code>var["NAME"]</code>:343<code>var["Name"]</code> and is used to denote table fields:
343<pre>344<pre>
344 var ::= prefixexp `<b>.</b>&acute; Name345 var ::= prefixexp `<b>.</b>&acute; Name
345</pre>346</pre>
@@ -361,8 +362,10 @@ so that all global variables in that function · 15 unmodified lines
361will refer to that environment table.362will refer to that environment table.
362When a function is created,363When a function is created,
363it inherits the environment from the function that created it.364it inherits the environment from the function that created it.
364To replace or get the environment table of a Lua function,365To get the environment table of a Lua function,
365you call <a href="#pdf-setfenv"><code>setfenv</code></a> or <a href="#pdf-getfenv"><code>getfenv</code></a>.366you call <a href="#pdf-setfenv"><code>setfenv</code></a>.
367To replace it,
368you call <a href="#pdf-setfenv"><code>setfenv</code></a>.
366(You can only manipulate the environment of C functions369(You can only manipulate the environment of C functions
367through the debug library; (see <a href="#libdebug">5.9</a>).)370through the debug library; (see <a href="#libdebug">5.9</a>).)
368 371
@@ -384,7 +387,7 @@ We use them here only for explanatory purposes.) · 15 unmodified lines
384<p>Lua supports an almost conventional set of statements,387<p>Lua supports an almost conventional set of statements,
385similar to those in Pascal or C.388similar to those in Pascal or C.
386This set includes389This set includes
387assignment, control structures, procedure calls,390assignment, control structures, function calls,
388table constructors, and variable declarations.391table constructors, and variable declarations.
389 392
390<p><a name="chunks"></a><a name="2.4.1"></a><h3>2.4.1 - Chunks</h3>393<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
396<pre>399<pre>
397 chunk ::= {stat [`<b>;</b>&acute;]}400 chunk ::= {stat [`<b>;</b>&acute;]}
398</pre>401</pre>
402There are no empty statements and thus `<code>;;</code>&acute; is not legal.
399 403
400<p>Lua handles a chunk as the body of an anonymous function 404<p>Lua handles a chunk as the body of an anonymous function
401with a variable number of arguments405with a variable number of arguments
@@ -404,7 +408,7 @@ As such, chunks can define local variables, · 2 unmodified lines
404receive arguments, and return values.408receive arguments, and return values.
405 409
406<p>A chunk may be stored in a file or in a string inside the host program.410<p>A chunk may be stored in a file or in a string inside the host program.
407When a chunk is executed, first it is pre-compiled into opcodes for411When a chunk is executed, first it is pre-compiled into instructions for
408a virtual machine,412a virtual machine,
409and then the compiled code is executed413and then the compiled code is executed
410by an interpreter for the virtual machine.414by an interpreter for the virtual machine.
@@ -417,7 +421,7 @@ Lua automatically detects the file type and acts accordingly. · 6 unmodified lines
417 421
418<p><a name="2.4.2"></a><h3>2.4.2 - Blocks</h3>422<p><a name="2.4.2"></a><h3>2.4.2 - Blocks</h3>
419A block is a list of statements;423A block is a list of statements;
420syntactically, a block is equal to a chunk:424syntactically, a block is the same as a chunk:
421<pre>425<pre>
422 block ::= chunk426 block ::= chunk
423</pre>427</pre>
@@ -455,7 +459,7 @@ the excess values are thrown away. · 31 unmodified lines
455If there are fewer values than needed,459If there are fewer values than needed,
456the list is extended with as many <b>nil</b>'s as needed.460the list is extended with as many <b>nil</b>'s as needed.
457If the list of expressions ends with a function call,461If the list of expressions ends with a function call,
458then all values returned by that function call enter in the list of values,462then all values returned by that call enter in the list of values,
459before the adjustment463before the adjustment
460(except when the call is enclosed in parentheses; see <a href="#expressions">2.5</a>).464(except when the call is enclosed in parentheses; see <a href="#expressions">2.5</a>).
461 465
@@ -509,7 +513,7 @@ familiar syntax: · 47 unmodified lines
509</pre>513</pre>
510Lua also has a <b>for</b> statement, in two flavors (see <a href="#for">2.4.5</a>).514Lua also has a <b>for</b> statement, in two flavors (see <a href="#for">2.4.5</a>).
511 515
512<p>The condition expression <em>exp</em> of a516<p>The condition expression of a
513control structure may return any value.517control structure may return any value.
514Both <b>false</b> and <b>nil</b> are considered false.518Both <b>false</b> and <b>nil</b> are considered false.
515All values different from <b>nil</b> and <b>false</b> are considered true519All 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
518<p>In the <b>repeat</b>--<b>until</b> loop,522<p>In the <b>repeat</b>--<b>until</b> loop,
519the inner block does not end at the <b>until</b> keyword,523the inner block does not end at the <b>until</b> keyword,
520but only after the condition.524but only after the condition.
521That means the condition can refer to local variables525So, the condition can refer to local variables
522declared inside the loop.526declared inside the loop block.
523 527
524<p>The <b>return</b> statement is used to return values528<p>The <b>return</b> statement is used to return values
525from a function or from a chunk.529from a function or a chunk (which is just a function).
526 530
527Functions and chunks may return more than one value,531Functions and chunks may return more than one value,
528so the syntax for the <b>return</b> statement is532so 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
530 stat ::= <b>return</b> [explist1]534 stat ::= <b>return</b> [explist1]
531</pre>535</pre>
532 536
533<p>The <b>break</b> statement can be used to terminate the execution of a537<p>The <b>break</b> statement is used to terminate the execution of a
534<b>while</b>, <b>repeat</b>, or <b>for</b> loop,538<b>while</b>, <b>repeat</b>, or <b>for</b> loop,
535skipping to the next statement after the loop:539skipping to the next statement after the loop:
536 540
@@ -539,7 +543,7 @@ skipping to the next statement after the loop: · 2 unmodified lines
539</pre>543</pre>
540A <b>break</b> ends the innermost enclosing loop.544A <b>break</b> ends the innermost enclosing loop.
541 545
542<p>For syntactic reasons, <b>return</b> and <b>break</b>546<p>The <b>return</b> and <b>break</b>
543statements can only be written as the <em>last</em> statement of a block.547statements can only be written as the <em>last</em> statement of a block.
544If it is really necessary to <b>return</b> or <b>break</b> in the548If it is really necessary to <b>return</b> or <b>break</b> in the
545middle of a block,549middle of a block,
@@ -599,11 +603,12 @@ then assign it to another variable before breaking or exiting the loop. · 53 unmodified lines
599 603
600<p>The generic <b>for</b> statement works over functions,604<p>The generic <b>for</b> statement works over functions,
601called <em>iterators</em>.605called <em>iterators</em>.
602For each iteration, it calls its iterator function to produce a new value,606On each iteration, the iterator function is called to produce a new value,
603stopping when the new value is <b>nil</b>.607stopping when this new value is <b>nil</b>.
604The generic <b>for</b> loop has the following syntax:608The generic <b>for</b> loop has the following syntax:
605<pre>609<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}
607</pre>612</pre>
608A <b>for</b> statement like613A <b>for</b> statement like
609<pre>614<pre>
@@ -649,14 +654,13 @@ Local variables may be declared anywhere inside a block. · 39 unmodified lines
649The declaration may include an initial assignment:654The declaration may include an initial assignment:
650<pre>655<pre>
651 stat ::= <b>local</b> namelist [`<b>=</b>&acute; explist1]656 stat ::= <b>local</b> namelist [`<b>=</b>&acute; explist1]
652 namelist ::= Name {`<b>,</b>&acute; Name}
653</pre>657</pre>
654If present, an initial assignment has the same semantics658If present, an initial assignment has the same semantics
655of a multiple assignment (see <a href="#assignment">2.4.3</a>).659of a multiple assignment (see <a href="#assignment">2.4.3</a>).
656Otherwise, all variables are initialized with <b>nil</b>.660Otherwise, all variables are initialized with <b>nil</b>.
657 661
658<p>A chunk is also a block (see <a href="#chunks">2.4.1</a>),662<p>A chunk is also a block (see <a href="#chunks">2.4.1</a>),
659so local variables can be declared in a chunk outside any explicit block.663and so local variables can be declared in a chunk outside any explicit block.
660The scope of such local variables extends until the end of the chunk.664The scope of such local variables extends until the end of the chunk.
661 665
662<p>The visibility rules for local variables are explained in <a href="#visibility">2.6</a>.666<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
669 exp ::= prefixexp673 exp ::= prefixexp
670 exp ::= <b>nil</b> | <b>false</b> | <b>true</b>674 exp ::= <b>nil</b> | <b>false</b> | <b>true</b>
671 exp ::= Number675 exp ::= Number
672 exp ::= Literal676 exp ::= String
673 exp ::= function677 exp ::= function
674 exp ::= tableconstructor678 exp ::= tableconstructor
675 exp ::= `<b>...</b>&acute;679 exp ::= `<b>...</b>&acute;
@@ -684,7 +688,7 @@ function definitions are explained in <a href="#func-def">2.5.9</a>; · 8 unmodified lines
684function calls are explained in <a href="#functioncall">2.5.8</a>;688function calls are explained in <a href="#functioncall">2.5.8</a>;
685table constructors are explained in <a href="#tableconstructor">2.5.7</a>.689table constructors are explained in <a href="#tableconstructor">2.5.7</a>.
686Vararg expressions,690Vararg expressions,
687denoted by three dots (...), can only be used inside691denoted by three dots (`<code>...</code>&acute;), can only be used inside
688vararg functions;692vararg functions;
689they are explained in <a href="#func-def">2.5.9</a>.693they are explained in <a href="#func-def">2.5.9</a>.
690 694
@@ -738,18 +742,18 @@ or <b>nil</b> if <code>f</code> does not return any values.) · 47 unmodified lines
738Lua supports the usual arithmetic operators:742Lua supports the usual arithmetic operators:
739the binary <code>+</code> (addition),743the binary <code>+</code> (addition),
740<code>-</code> (subtraction), <code>*</code> (multiplication),744<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);
742and unary <code>-</code> (negation).746and unary <code>-</code> (negation).
743If the operands are numbers, or strings that can be converted to747If the operands are numbers, or strings that can be converted to
744numbers (see <a href="#coercion">2.2.1</a>),748numbers (see <a href="#coercion">2.2.1</a>),
745then all operations have the usual meaning.749then all operations have the usual meaning.
746Exponentiation works for any exponent.750Exponentiation works for any exponent.
747For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>.751For instance, <code>x^(-0.5)</code> computes the inverse of the square root of <code>x</code>.
748Modulus is defined as752Modulus is defined as
749<pre>753<pre>
750 a % b == a - math.floor(a/b)*b754 a % b == a - math.floor(a/b)*b
751</pre>755</pre>
752That is, it is the remaining of a division that rounds756That is, it is the remainder of a division that rounds
753the quotient towards minus infinity.757the quotient towards minus infinity.
754 758
755<p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3>759<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
766Objects (tables, userdata, threads, and functions)770Objects (tables, userdata, threads, and functions)
767are compared by <em>reference</em>:771are compared by <em>reference</em>:
768Two objects are considered equal only if they are the <em>same</em> object.772Two objects are considered equal only if they are the <em>same</em> object.
769Every time you create a new object (a table, userdata, or function),773Every time you create a new object
774(a table, userdata, thread, or function),
770this new object is different from any previously existing object.775this new object is different from any previously existing object.
771 776
772<p>You can change the way that Lua compares tables and userdata 777<p>You can change the way that Lua compares tables and userdata
773using the "eq" metamethod (see <a href="#metatable">2.8</a>).778by using the "eq" metamethod (see <a href="#metatable">2.8</a>).
774 779
775<p>The conversion rules of <a href="#coercion">2.2.1</a>780<p>The conversion rules of <a href="#coercion">2.2.1</a>
776<em>do not</em> apply to equality comparisons.781<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
799and anything else as true.804and anything else as true.
800 805
801 806
802<p>The operator <b>not</b> always returns <b>false</b> or <b>true</b>.807<p>The negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.
803 808The conjunction operator <b>and</b> returns its first argument
804<p>The conjunction operator <b>and</b> returns its first argument
805if this value is <b>false</b> or <b>nil</b>;809if this value is <b>false</b> or <b>nil</b>;
806otherwise, <b>and</b> returns its second argument.810otherwise, <b>and</b> returns its second argument.
807The disjunction operator <b>or</b> returns its first argument811The disjunction operator <b>or</b> returns its first argument
808if this value is different from <b>nil</b> and <b>false</b>;812if this value is different from <b>nil</b> and <b>false</b>;
809otherwise, <b>or</b> returns its second argument.813otherwise, <b>or</b> returns its second argument.
810Both <b>and</b> and <b>or</b> use short-cut evaluation,814Both <b>and</b> and <b>or</b> use short-cut evaluation;
811that is,815that is,
812the second operand is evaluated only if necessary.816the second operand is evaluated only if necessary.
813For example,817Here are some examples:
814<pre>818<pre>
815 10 or error() -> 10819 10 or 20 --> 10
816 nil or "a" -> "a"820 10 or error() --> 10
817 nil and 10 -> nil821 nil or "a" --> "a"
818 false and error() -> false822 nil and 10 --> nil
819 false and nil -> false823 false and error() --> false
820 false or nil -> nil824 false and nil --> false
821 10 and 20 -> 20825 false or nil --> nil
826 10 and 20 --> 20
822</pre>827</pre>
828(Here and in the sequel,
829`<code>--></code>&acute; indicates the result of the preceding expression.)
823 830
824<p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3>831<p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3>
825The string concatenation operator in Lua is832The 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
830 837
831<p><a name="len-op"></a><a name="2.5.5"></a><h3>2.5.5 - The Length Operator</h3>838<p><a name="len-op"></a><a name="2.5.5"></a><h3>2.5.5 - The Length Operator</h3>
832 839
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>.
834The length of a string is its number of bytes841The length of a string is its number of bytes
835(that is, the usual meaning of string length when each842(that is, the usual meaning of string length when each
836character is one byte).843character is one byte).
837The length of a table <code>t</code> is defined to be any844
845<p>The length of a table <code>t</code> is defined to be any
838integer index <code>n</code>846integer index <code>n</code>
839such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;847such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;
840moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> may be zero.848moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> may be zero.
841 849For a regular array, with non-nil values from 1 to a given <code>n</code>,
842<p>For a regular array, with non-nil values from 1 to a given <code>n</code>,
843its length is exactly that <code>n</code>,850its length is exactly that <code>n</code>,
844the index of its last value.851the index of its last value.
845If the array has "holes"852If the array has "holes"
846(that is, <b>nil</b> values between other non-nil values),853(that is, <b>nil</b> values between other non-nil values),
847then <code>#t</code> may be any of the indices that precede a <b>nil</b> value854then <code>#t</code> may be any of the indices that
855directly precedes a <b>nil</b> value
848(that is, it may consider any such <b>nil</b> value as the end of856(that is, it may consider any such <b>nil</b> value as the end of
849the array). 857the array).
850 858
@@ -861,7 +869,8 @@ from lower to higher priority: · 10 unmodified lines
861 not # - (unary)869 not # - (unary)
862 ^870 ^
863</pre>871</pre>
864You can use parentheses to change the precedences of an expression.872As usual,
873you can use parentheses to change the precedences of an expression.
865The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)874The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)
866operators are right associative.875operators are right associative.
867All other binary operators are left associative.876All other binary operators are left associative.
@@ -889,20 +898,20 @@ starting with 1. · 21 unmodified lines
889Fields in the other formats do not affect this counting.898Fields in the other formats do not affect this counting.
890For example,899For example,
891<pre>900<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 }
893</pre>902</pre>
894is equivalent to903is equivalent to
895<pre>904<pre>
896 do905 do
897 local temp = {}906 local t = {}
898 temp[f(1)] = g907 t[f(1)] = g
899 temp[1] = "x" -- 1st exp908 t[1] = "x" -- 1st exp
900 temp[2] = "y" -- 2nd exp909 t[2] = "y" -- 2nd exp
901 temp.x = 1 -- temp["x"] = 1910 t.x = 1 -- t["x"] = 1
902 temp[3] = f(x) -- 3rd exp911 t[3] = f(x) -- 3rd exp
903 temp[30] = 23912 t[30] = 23
904 temp[4] = 45 -- 4th exp913 t[4] = 45 -- 4th exp
905 a = temp914 a = t
906 end915 end
907</pre>916</pre>
908 917
@@ -927,7 +936,7 @@ first <em>prefixexp</em> and <em>args</em> are evaluated. · 18 unmodified lines
927If the value of <em>prefixexp</em> has type <em>function</em>,936If the value of <em>prefixexp</em> has type <em>function</em>,
928then that function is called937then that function is called
929with the given arguments.938with the given arguments.
930Otherwise, its "call" metamethod is called,939Otherwise, the <em>prefixexp</em> "call" metamethod is called,
931having as first parameter the value of <em>prefixexp</em>,940having as first parameter the value of <em>prefixexp</em>,
932followed by the original call arguments941followed by the original call arguments
933(see <a href="#metatable">2.8</a>).942(see <a href="#metatable">2.8</a>).
@@ -945,16 +954,14 @@ except that <code>v</code> is evaluated only once. · 11 unmodified lines
945<pre>954<pre>
946 args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute;955 args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute;
947 args ::= tableconstructor956 args ::= tableconstructor
948 args ::= Literal957 args ::= String
949</pre>958</pre>
950All argument expressions are evaluated before the call.959All argument expressions are evaluated before the call.
951A call of the form <code>f{...}</code> is syntactic sugar for960A call of the form <code>f{...}</code> is syntactic sugar for <code>f({...})</code>;
952<code>f({...})</code>, that is,961that is, the argument list is a single new table.
953the argument list is a single new table.
954A call of the form <code>f'...'</code>962A call of the form <code>f'...'</code>
955(or <code>f"..."</code> or <code>f[[...]]</code>) is syntactic sugar for963(or <code>f"..."</code> or <code>f[[...]]</code>) is syntactic sugar for <code>f('...')</code>;
956<code>f('...')</code>, that is,964that is, the argument list is a single literal string.
957the argument list is a single literal string.
958 965
959<p>As an exception to the free-format syntax of Lua,966<p>As an exception to the free-format syntax of Lua,
960you cannot put a line break before the `<code>(</code>&acute; in a function call.967you cannot put a line break before the `<code>(</code>&acute; in a function call.
@@ -964,7 +971,7 @@ If you write · 3 unmodified lines
964 a = f971 a = f
965 (g).x(a)972 (g).x(a)
966</pre>973</pre>
967Lua would read that as <code>a = f(g).x(a)</code>.974Lua would see that as a single statement, <code>a = f(g).x(a)</code>.
968So, if you want two statements, you must add a semi-colon between them.975So, if you want two statements, you must add a semi-colon between them.
969If you actually want to call <code>f</code>,976If you actually want to call <code>f</code>,
970you must remove the line break before <code>(g)</code>.977you 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
981calling function.988calling function.
982Note that a tail call only happens with a particular syntax,989Note that a tail call only happens with a particular syntax,
983where the <b>return</b> has one single function call as argument;990where the <b>return</b> has one single function call as argument;
984this syntax makes the calling function returns exactly991this syntax makes the calling function return exactly
985the returns of the called function.992the returns of the called function.
986So, all the following examples are not tail calls:993So, none of the following examples are tail calls:
987<pre>994<pre>
988 return (f(x)) -- results adjusted to 1995 return (f(x)) -- results adjusted to 1
989 return 2 * f(x)996 return 2 * f(x)
990 return x, f(x) -- additional results997 return x, f(x) -- additional results
991 f(x); return -- results discarded998 f(x); return -- results discarded
992 return x or f(x) -- results adjusted to 1999 return x or f(x) -- results adjusted to 1
993</pre>1000</pre>
994 1001
995<p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3>1002<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
1030<pre>1037<pre>
1031 local f; f = function () ... end1038 local f; f = function () ... end
1032</pre>1039</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
1045contains references to <code>f</code>.)
1033 1046
1034<p>A function definition is an executable expression,1047<p>A function definition is an executable expression,
1035whose value has type <em>function</em>.1048whose value has type <em>function</em>.
@@ -1084,10 +1097,10 @@ to the vararg expression: · 48 unmodified lines
1084 f(r(), 10) a=1, b=101097 f(r(), 10) a=1, b=10
1085 f(r()) a=1, b=21098 f(r()) a=1, b=2
1086 1099
1087 g(3) a=3, b=nil, ... -> (nothing)1100 g(3) a=3, b=nil, ... --> (nothing)
1088 g(3, 4) a=3, b=4, ... -> (nothing)1101 g(3, 4) a=3, b=4, ... --> (nothing)
1089 g(3, 4, 5, 8) a=3, b=4, ... -> 5 81102 g(3, 4, 5, 8) a=3, b=4, ... --> 5 8
1090 g(5, r()) a=5, b=1, ... -> 2 31103 g(5, r()) a=5, b=1, ... --> 2 3
1091</pre>1104</pre>
1092 1105
1093<p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>).1106<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
1114The scope of variables begins at the first statement <em>after</em>1127The scope of variables begins at the first statement <em>after</em>
1115their declaration and lasts until the end of the innermost block that1128their declaration and lasts until the end of the innermost block that
1116includes the declaration.1129includes the declaration.
1117For instance:1130Consider the following example:
1118<pre>1131<pre>
1119 x = 10 -- global variable1132 x = 10 -- global variable
1120 do -- new block1133 do -- new block
1121 local x = x -- new `x', with value 101134 local x = x -- new `x', with value 10
1122 print(x) --> 101135 print(x) --> 10
1123 x = x+11136 x = x+1
1124 do -- another block1137 do -- another block
1125 local x = x+1 -- another `x'1138 local x = x+1 -- another `x'
1126 print(x) --> 121139 print(x) --> 12
1127 end1140 end
1128 print(x) --> 111141 print(x) --> 11
1129 end1142 end
1130 print(x) --> 10 (the global one)1143 print(x) --> 10 (the global one)
1131</pre>1144</pre>
1132Notice that, in a declaration like <code>local x = x</code>,1145
1146<p>Notice that, in a declaration like <code>local x = x</code>,
1133the new <code>x</code> being declared is not in scope yet,1147the new <code>x</code> being declared is not in scope yet,
1134and so the second <code>x</code> refers to the outside variable.1148and so the second <code>x</code> refers to the outside variable.
1135 1149
1136<p>Because of the lexical scoping rules,1150<p>Because of the lexical scoping rules,
1137local variables can be freely accessed by functions1151local variables can be freely accessed by functions
1138defined inside their scope.1152defined inside their scope.
1139For instance:
1140<pre>
1141 local counter = 0
1142 function inc (x)
1143 counter = counter + x
1144 return counter
1145 end
1146</pre>
1147A local variable used by an inner function is called1153A local variable used by an inner function is called
1148an <em>upvalue</em>, or <em>external local variable</em>,1154an <em>upvalue</em>, or <em>external local variable</em>,
1149inside the inner function.1155inside the inner function.
@@ -1152,12 +1158,12 @@ inside the inner function. · 2 unmodified lines
1152defines new local variables.1158defines new local variables.
1153Consider the following example:1159Consider the following example:
1154<pre>1160<pre>
1155 a = {}1161 a = {}
1156 local x = 201162 local x = 20
1157 for i=1,10 do1163 for i=1,10 do
1158 local y = 01164 local y = 0
1159 a[i] = function () y=y+1; return x+y end1165 a[i] = function () y=y+1; return x+y end
1160 end1166 end
1161</pre>1167</pre>
1162The loop creates ten closures1168The loop creates ten closures
1163(that is, ten instances of the anonymous function).1169(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
1166 1172
1167<p><a name="error"></a><a name="2.7"></a><h2>2.7 - Error Handling</h2>1173<p><a name="error"></a><a name="2.7"></a><h2>2.7 - Error Handling</h2>
1168 1174
1169<p>Because Lua is an extension language,1175<p>Because Lua is an embedded extension language,
1170all Lua actions start from C code in the host program1176all Lua actions start from C code in the host program
1171calling a function from the Lua library (see <a href="#lua_pcall"></a>).1177calling a function from the Lua library (see <a href="#lua_pcall"></a>).
1172Whenever an error occurs during Lua compilation or execution,1178Whenever an error occurs during Lua compilation or execution,
1173control returns to C,1179control returns to C,
1174which can take appropriate measures1180which can take appropriate measures
1175(such as print an error message).1181(such as printing an error message).
1176 1182
1177<p>Lua code can explicitly generate an error by calling the1183<p>Lua code can explicitly generate an error by calling the
1178<a href="#pdf-error"><code>error</code></a> function.1184<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
1215and for all strings, etc.1221and for all strings, etc.
1216 1222
1217<p>A metatable may control how an object behaves in arithmetic operations,1223<p>A metatable may control how an object behaves in arithmetic operations,
1218order comparisons, concatenation, and indexing.1224order comparisons, concatenation, length operation, and indexing.
1219A metatable can also define a function to be called when a userdata1225A metatable can also define a function to be called when a userdata
1220is garbage collected.1226is garbage collected.
1221For each of those operations Lua associates a specific key1227For each of those operations Lua associates a specific key
@@ -1228,7 +1234,7 @@ controls how Lua will perform the operation. · 6 unmodified lines
1228<p>Metatables control the operations listed next.1234<p>Metatables control the operations listed next.
1229Each operation is identified by its corresponding name.1235Each operation is identified by its corresponding name.
1230The key for each operation is a string with its name prefixed by1236The key for each operation is a string with its name prefixed by
1231two underscores;1237two underscores, `<code>__</code>&acute;;
1232for instance, the key for operation "add" is the1238for instance, the key for operation "add" is the
1233string <code>"__add"</code>.1239string <code>"__add"</code>.
1234The semantics of these operations is better explained by a Lua function1240The 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
1243In particular, to retrieve the metamethod of a given object,1249In particular, to retrieve the metamethod of a given object,
1244we use the expression1250we use the expression
1245<pre>1251<pre>
1246 metatable(obj)[event]1252 metatable(obj)[event]
1247</pre>1253</pre>
1248This should be read as1254This should be read as
1249<pre>1255<pre>
1250 rawget(metatable(obj) or {}, event)1256 rawget(getmetatable(obj) or {}, event)
1251</pre>1257</pre>
1252That is, the access to a metamethod does not invoke other metamethods,1258That is, the access to a metamethod does not invoke other metamethods,
1253and the access to objects with no metatables does not fail1259and the access to objects with no metatables does not fail
@@ -1522,11 +1528,11 @@ called when Lua calls a value. · 268 unmodified lines
1522<p>Besides metatables,1528<p>Besides metatables,
1523objects of types thread, function, and userdata1529objects of types thread, function, and userdata
1524have another table associated with them,1530have another table associated with them,
1525called <em>environment</em>.1531called their <em>environment</em>.
1526Like metatables, environments are regular tables and1532Like metatables, environments are regular tables and
1527multiple objects can share the same environment.1533multiple objects can share the same environment.
1528 1534
1529<p>Environments associated with userdata has no meaning for Lua.1535<p>Environments associated with userdata have no meaning for Lua.
1530It is only a feature for programmers to associate a table to1536It is only a feature for programmers to associate a table to
1531a userdata.1537a userdata.
1532 1538
@@ -1557,10 +1563,10 @@ use the C API. · 24 unmodified lines
1557 1563
1558<p><a name="GC"></a><a name="2.10"></a><h2>2.10 - Garbage Collection</h2>1564<p><a name="GC"></a><a name="2.10"></a><h2>2.10 - Garbage Collection</h2>
1559 1565
1560<p>Lua does automatic memory management.1566<p>Lua performs automatic memory management.
1561That means that1567That means that
1562you do not have to worry about allocating memory for new objects1568you do not have to worry about allocating memory for new objects
1563and freeing it when the objects are no longer needed.1569not about freeing it when the objects are no longer needed.
1564Lua manages memory automatically by running1570Lua manages memory automatically by running
1565a <em>garbage collector</em> from time to time1571a <em>garbage collector</em> from time to time
1566to collect all <em>dead objects</em>1572to collect all <em>dead objects</em>
@@ -1568,9 +1574,12 @@ to collect all <em>dead objects</em> · 1 unmodified line
1568All objects in Lua are subject to automatic management:1574All objects in Lua are subject to automatic management:
1569tables, userdata, functions, threads, and strings.1575tables, userdata, functions, threads, and strings.
1570 1576
1571<p>Lua 5.1 implements an incremental mark-and-sweep collector.1577<p>Lua implements an incremental mark-and-sweep collector.
1572It uses two numbers to control its garbage-collection cycles.1578It uses two numbers to control its garbage-collection cycles:
1573One number, the <em>garbage-collector pause</em>,1579the <em>garbage-collector pause</em> and
1580the <em>garbage-collector multiplier</em>.
1581
1582<p>The garbage-collector pause
1574controls how long the collector waits before starting a new cycle.1583controls how long the collector waits before starting a new cycle.
1575Larger values make the collector less aggressive.1584Larger values make the collector less aggressive.
1576Values smaller than 1 mean the collector will not wait to1585Values smaller than 1 mean the collector will not wait to
@@ -1578,7 +1587,7 @@ start a new cycle. · 1 unmodified line
1578A value of 2 means that the collector waits more or less to double1587A value of 2 means that the collector waits more or less to double
1579the total memory in use before starting a new cycle.1588the total memory in use before starting a new cycle.
1580 1589
1581<p>The other number, the <em>garbage-collector multiplier</em>,1590<p>The garbage-collector multiplier
1582controls the relative speed of the collector relative to1591controls the relative speed of the collector relative to
1583memory allocation.1592memory allocation.
1584Larger values make the collector more aggressive but also increases1593Larger values make the collector more aggressive but also increases
@@ -1605,7 +1614,7 @@ with external resource management · 20 unmodified lines
1605(such as closing files, network or database connections,1614(such as closing files, network or database connections,
1606or freeing your own memory).1615or freeing your own memory).
1607 1616
1608<p>Free userdata with a field <code>__gc</code> in their metatables are not1617<p>Garbage userdata with a field <code>__gc</code> in their metatables are not
1609collected immediately by the garbage collector.1618collected immediately by the garbage collector.
1610Instead, Lua puts them in a list.1619Instead, Lua puts them in a list.
1611After the collection,1620After the collection,
@@ -1676,8 +1685,8 @@ passing as its first argument · 64 unmodified lines
1676the thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,1685the thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1677the coroutine starts its execution,1686the coroutine starts its execution,
1678at the first line of its main function.1687at the first line of its main function.
1679Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are given as1688Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are passed on
1680parameters for the coroutine main function.1689to the coroutine main function.
1681After the coroutine starts running,1690After the coroutine starts running,
1682it runs until it terminates or <em>yields</em>.1691it runs until it terminates or <em>yields</em>.
1683 1692
@@ -1703,43 +1712,39 @@ it continues its execution from the point where it yielded, · 19 unmodified lines
1703with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra1712with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra
1704arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.1713arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1705 1714
1706<p>The <code>coroutine.wrap</code> function creates a coroutine1715<p>The <code>coroutine.wrap</code> function creates a coroutine,
1707like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,1716just like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1708but instead of returning the coroutine itself,1717but instead of returning the coroutine itself,
1709it returns a function that, when called, resumes the coroutine.1718it returns a function that, when called, resumes the coroutine.
1710Any arguments passed to that function1719Any arguments passed to that function
1711go as extra arguments to resume.1720go as extra arguments to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1712The function returns all the values returned by resume,1721<code>coroutine.wrap</code> returns all the values returned by <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1713except the first one (the boolean error code).1722except the first one (the boolean error code).
1714Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,1723Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1715this function does not catch errors;1724<code>coroutine.wrap</code> does not catch errors;
1716any error is propagated to the caller.1725any error is propagated to the caller.
1717 1726
1718<p>As an example,1727<p>As an example,
1719consider the next code:1728consider the next code:
1720<pre>1729<pre>
1721function foo1 (a)1730function foo (a)
1722 print("foo", a)1731 print("foo", a)
1723 return coroutine.yield(2*a)1732 return coroutine.yield(2*a)
1724end1733end
1725 1734
1726co = coroutine.create(function (a,b)1735co = coroutine.create(function (a,b)
1727 print("co-body", a, b)1736 print("co-body", a, b)
1728 local r = foo1(a+1)1737 local r = foo(a+1)
1729 print("co-body", r)1738 print("co-body", r)
1730 local r, s = coroutine.yield(a+b, a-b)1739 local r, s = coroutine.yield(a+b, a-b)
1731 print("co-body", r, s)1740 print("co-body", r, s)
1732 return b, "end"1741 return b, "end"
1733end)1742end)
1734 1743
1735a, b = coroutine.resume(co, 1, 10)1744print("main", coroutine.resume(co, 1, 10))
1736print("main", a, b)1745print("main", coroutine.resume(co, "r"))
1737a, b, c = coroutine.resume(co, "r")1746print("main", coroutine.resume(co, "x", "y"))
1738print("main", a, b, c)1747print("main", coroutine.resume(co, "x", "y"))
1739a, b, c = coroutine.resume(co, "x", "y")
1740print("main", a, b, c)
1741a, b = coroutine.resume(co, "x", "y")
1742print("main", a, b)
1743</pre>1748</pre>
1744When you run it, it produces the following output:1749When you run it, it produces the following output:
1745<pre>1750<pre>
@@ -1767,10 +1772,10 @@ are declared in the header file <code>lua.h</code>. · 21 unmodified lines
1767any facility in the API may be provided as a macro instead.1772any facility in the API may be provided as a macro instead.
1768All such macros use each of its arguments exactly once1773All such macros use each of its arguments exactly once
1769(except for the first argument, which is always a Lua state),1774(except for the first argument, which is always a Lua state),
1770and so do not generate hidden side-effects.1775and so do not generate any hidden side-effects.
1771 1776
1772<p>Like in most C libraries,1777<p>As in most C libraries,
1773the Lua API functions do not check their arguments.1778the Lua API functions do not check their arguments for validity or consistency.
1774However, you can change this behavior by compiling Lua1779However, you can change this behavior by compiling Lua
1775with a proper definition for the macro <code>luai_apicheck</code>,1780with a proper definition for the macro <code>luai_apicheck</code>,
1776in file <code>luaconf.h</code>.1781in file <code>luaconf.h</code>.
@@ -1784,7 +1789,7 @@ Each element in this stack represents a Lua value · 7 unmodified lines
1784<p>Whenever Lua calls C, the called function gets a new stack,1789<p>Whenever Lua calls C, the called function gets a new stack,
1785which is independent of previous stacks and of stacks of1790which is independent of previous stacks and of stacks of
1786C functions that are still active.1791C functions that are still active.
1787That stack initially contains any arguments to the C function,1792That stack initially contains any arguments to the C function
1788and it is where the C function pushes its results1793and it is where the C function pushes its results
1789to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).1794to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
1790 1795
@@ -1794,7 +1799,7 @@ Instead, they can refer to any element in the stack · 3 unmodified lines
1794by using an <em>index</em>:1799by using an <em>index</em>:
1795A positive index represents an <em>absolute</em> stack position1800A positive index represents an <em>absolute</em> stack position
1796(starting at 1);1801(starting at 1);
1797a negative index represents an <em>offset</em> from the top of the stack.1802a negative index represents an <em>offset</em> relative to the top of the stack.
1798More specifically, if the stack has <em>n</em> elements,1803More specifically, if the stack has <em>n</em> elements,
1799then index 1 represents the first element1804then index 1 represents the first element
1800(that is, the element that was pushed onto the stack first)1805(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
1811<p><a name="3.2"></a><h2>3.2 - Stack Size</h2>1816<p><a name="3.2"></a><h2>3.2 - Stack Size</h2>
1812 1817
1813<p>When you interact with Lua API,1818<p>When you interact with Lua API,
1819you are responsible for ensuring consistency.
1820In particular,
1814<em>you are responsible for controlling stack overflow</em>.1821<em>you are responsible for controlling stack overflow</em>.
1815You can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a>1822You can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a>
1816to grow the stack size.1823to grow the stack size.
@@ -1828,7 +1835,7 @@ Such indices are called <em>acceptable indices</em>. · 11 unmodified lines
1828More formally, we define an <em>acceptable index</em>1835More formally, we define an <em>acceptable index</em>
1829as follows:1836as follows:
1830<pre>1837<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)
1832</pre>1839</pre>
1833Note that 0 is never an acceptable index.1840Note that 0 is never an acceptable index.
1834 1841
@@ -1837,8 +1844,8 @@ Note that 0 is never an acceptable index. · 2 unmodified lines
1837<p>Unless otherwise noted,1844<p>Unless otherwise noted,
1838any function that accepts valid indices can also be called with1845any function that accepts valid indices can also be called with
1839<em>pseudo-indices</em>,1846<em>pseudo-indices</em>,
1840which represent some Lua values that are accessible to the C code1847which represent some Lua values that are accessible to C code
1841but are not in the stack.1848but which are not in the stack.
1842Pseudo-indices are used to access the thread environment,1849Pseudo-indices are used to access the thread environment,
1843the function environment,1850the function environment,
1844the registry,1851the registry,
@@ -1861,11 +1868,12 @@ For instance, to access the value of a global variable, do · 16 unmodified lines
1861<p>When a C function is created,1868<p>When a C function is created,
1862it is possible to associate some values with it,1869it is possible to associate some values with it,
1863thus creating a <em>C closure</em>;1870thus creating a <em>C closure</em>;
1864these values are then accessible to the function whenever it is called1871these values are called <em>upvalues</em> and are
1872accessible to the function whenever it is called
1865(see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>).1873(see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>).
1866 1874
1867<p>Whenever a C function is called,1875<p>Whenever a C function is called,
1868its associated values are located at specific pseudo-indices.1876its upvalues are located at specific pseudo-indices.
1869Those pseudo-indices are produced by the macro1877Those pseudo-indices are produced by the macro
1870<code>lua_upvalueindex</code>.1878<code>lua_upvalueindex</code>.
1871The first value associated with a function is at position1879The first value associated with a function is at position
@@ -1877,13 +1885,14 @@ produces an acceptable (but invalid) index. · 5 unmodified lines
1877 1885
1878<p><a name="registry"></a><a name="3.5"></a><h2>3.5 - Registry</h2>1886<p><a name="registry"></a><a name="3.5"></a><h2>3.5 - Registry</h2>
1879 1887
1880<p>Lua provides a registry,1888<p>Lua provides a <em>registry</em>,
1881a pre-defined table that can be used by any C code to1889a pre-defined table that can be used by any C code to
1882store whatever Lua value it needs to store.1890store whatever Lua value it needs to store.
1883This table is always located at pseudo-index1891This table is always located at pseudo-index
1884<code>LUA_REGISTRYINDEX</code>.1892<code>LUA_REGISTRYINDEX</code>.
1885Any C library can store data into this table,1893Any C library can store data into this table,
1886as long as it chooses keys different from other libraries.1894but it should take care to choose keys different from those used
1895by other libraries, to avoid collisions.
1887Typically, you should use as key a string containing your library name1896Typically, you should use as key a string containing your library name
1888or a light userdata with the address of a C object in your code.1897or a light userdata with the address of a C object in your code.
1889 1898
@@ -1894,9 +1903,13 @@ and therefore should not be used by other purposes. · 4 unmodified lines
1894<p><a name="3.6"></a><h2>3.6 - Error Handling in C</h2>1903<p><a name="3.6"></a><h2>3.6 - Error Handling in C</h2>
1895 1904
1896<p>Internally, Lua uses the C <code>longjmp</code> facility to handle errors.1905<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++;
1907See file <code>luaconf.h</code>.)
1897When Lua faces any error1908When Lua faces any error
1898(such as memory allocation errors, type errors, syntax errors)1909(such as memory allocation errors, type errors, syntax errors,
1899it <em>raises</em> an error, that is, it does a long jump.1910and runtime errors)
1911it <em>raises</em> an error;
1912that is, it does a long jump.
1900A <em>protected environment</em> uses <code>setjmp</code>1913A <em>protected environment</em> uses <code>setjmp</code>
1901to set a recover point;1914to set a recover point;
1902any error jumps to the most recent active recover point.1915any error jumps to the most recent active recover point.
@@ -1909,7 +1922,7 @@ so they never raise an error: · 6 unmodified lines
1909<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>,1922<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>,
1910<a href="#lua_pcall"><code>lua_pcall</code></a>, and <a href="#lua_cpcall"><code>lua_cpcall</code></a>.1923<a href="#lua_pcall"><code>lua_pcall</code></a>, and <a href="#lua_cpcall"><code>lua_cpcall</code></a>.
1911 1924
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>.
1913 1926
1914<p><a name="3.7"></a><h2>3.7 - Functions and Types</h2>1927<p><a name="3.7"></a><h2>3.7 - Functions and Types</h2>
1915 1928
@@ -1917,7 +1930,7 @@ so they never raise an error: · 1 unmodified line
1917alphabetical order.1930alphabetical order.
1918 1931
1919<p><a name="lua_Alloc"></a>1932<p><a name="lua_Alloc"></a>
1920<hr/><h3><code>lua_Alloc</code></h3>1933<hr /><h3><code>lua_Alloc</code></h3>
1921<pre>1934<pre>
1922 typedef void * (*lua_Alloc) (void *ud,1935 typedef void * (*lua_Alloc) (void *ud,
1923 void *ptr,1936 void *ptr,
@@ -1927,12 +1940,12 @@ alphabetical order. · 3 unmodified lines
1927</pre>1940</pre>
1928 1941
1929 1942
1930<p>The allocator function used by Lua states.1943<p>The type of the memory allocation function used by Lua states.
1931The allocator function must provide a1944The allocator function must provide a
1932functionality similar to <code>realloc</code>,1945functionality similar to <code>realloc</code>,
1933but not exactly the same.1946but not exactly the same.
1934Its arguments are <code>ud</code>,1947Its arguments are
1935the opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;1948<code>ud</code>, an opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;
1936<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;1949<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;
1937<code>osize</code>, the original size of the block;1950<code>osize</code>, the original size of the block;
1938<code>nsize</code>, the new size of the block.1951<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
1943When <code>nsize</code> is not zero, the allocator returns <code>NULL</code>1956When <code>nsize</code> is not zero, the allocator returns <code>NULL</code>
1944if and only if it cannot fill the request.1957if and only if it cannot fill the request.
1945When <code>nsize</code> is not zero and <code>osize</code> is zero,1958When <code>nsize</code> is not zero and <code>osize</code> is zero,
1946the allocator behaves like <code>malloc</code>.1959the allocator should behave like <code>malloc</code>.
1947When <code>nsize</code> and <code>osize</code> are not zero,1960When <code>nsize</code> and <code>osize</code> are not zero,
1948the allocator behaves like <code>realloc</code>.1961the allocator behaves like <code>realloc</code>.
1949Lua assumes that the allocator never fails when1962Lua assumes that the allocator never fails when
1950<code>osize >= nsize</code>.1963<code>osize >= nsize</code>.
1951 1964
1952<p>A simple implementation for the allocator function1965<p>Here is a simple implementation for the allocator function.
1953could be like this:1966It is used in the auxiliary library by <a href="#lua_newstate"><code>lua_newstate</code></a>.
1954<pre>1967<pre>
1955static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {1968static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
1956 (void)ud; /* not used */1969 (void)ud; /* not used */
1957 (void)osize; /* not used */1970 (void)osize; /* not used */
1958 if (nsize == 0) {1971 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 */
1960 return NULL;1973 return NULL;
1961 }1974 }
1962 else1975 else
1963 /* ANSI ensures that realloc(NULL, size) == malloc(size) */1976 /* ANSI requires that realloc(NULL, size) == malloc(size) */
1964 return realloc(ptr, nsize);1977 return realloc(ptr, nsize);
1965}1978}
1966</pre>1979</pre>
1967 1980
1968<p><a name="lua_atpanic"></a>1981<p><a name="lua_atpanic"></a>
1969<hr/><h3><code>lua_atpanic</code></h3>1982<hr /><h3><code>lua_atpanic</code></h3>
1970<pre>1983<pre>
1971 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);1984 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
1972</pre>1985</pre>
@@ -1976,14 +1989,15 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { · 3 unmodified lines
1976 1989
1977<p>If an error happens outside any protected environment,1990<p>If an error happens outside any protected environment,
1978Lua calls a <em>panic function</em>1991Lua calls a <em>panic function</em>
1979and then calls <code>exit(EXIT_FAILURE)</code>.1992and then calls <code>exit(EXIT_FAILURE)</code>,
1980Your new panic function may avoid the application exit by1993thus exiting the host application.
1994Your panic function may avoid this exit by
1981never returning (e.g., doing a long jump).1995never returning (e.g., doing a long jump).
1982 1996
1983<p>The panic function can access the error message at the top of the stack.1997<p>The panic function can access the error message at the top of the stack.
1984 1998
1985<p><a name="lua_call"></a>1999<p><a name="lua_call"></a>
1986<hr/><h3><code>lua_call</code></h3>2000<hr /><h3><code>lua_call</code></h3>
1987<pre>2001<pre>
1988 void lua_call (lua_State *L, int nargs, int nresults);2002 void lua_call (lua_State *L, int nargs, int nresults);
1989</pre>2003</pre>
@@ -1994,18 +2008,20 @@ never returning (e.g., doing a long jump). · 4 unmodified lines
1994<p>To call a function you must use the following protocol:2008<p>To call a function you must use the following protocol:
1995First, the function to be called is pushed onto the stack;2009First, the function to be called is pushed onto the stack;
1996then, the arguments to the function are pushed2010then, the arguments to the function are pushed
1997in direct order, that is, the first argument is pushed first.2011in direct order;
2012that is, the first argument is pushed first.
1998Finally you call <a href="#lua_call"><code>lua_call</code></a>;2013Finally you call <a href="#lua_call"><code>lua_call</code></a>;
1999<code>nargs</code> is the number of arguments that you pushed onto the stack.2014<code>nargs</code> is the number of arguments that you pushed onto the stack.
2000All arguments and the function value are popped from the stack,2015All arguments and the function value are popped from the stack
2001and the function results are pushed.2016when the function is called.
2002The number of results are adjusted to <code>nresults</code>,2017The function results are pushed onto the stack when the function returns.
2018The number of results is adjusted to <code>nresults</code>,
2003unless <code>nresults</code> is <code>LUA_MULTRET</code>.2019unless <code>nresults</code> is <code>LUA_MULTRET</code>.
2004In that case, <em>all</em> results from the function are pushed.2020In that case, <em>all</em> results from the function are pushed.
2005Lua takes care that the returned values fit into the stack space.2021Lua takes care that the returned values fit into the stack space.
2006The function results are pushed onto the stack in direct order2022The function results are pushed onto the stack in direct order
2007(the first result is pushed first),2023(the first result is pushed first),
2008so that after the call the last result is on the top.2024so that after the call the last result is on the top of the stack.
2009 2025
2010<p>Any error inside the called function is propagated upwards2026<p>Any error inside the called function is propagated upwards
2011(with a <code>longjmp</code>).2027(with a <code>longjmp</code>).
@@ -2017,21 +2033,21 @@ equivalent to this Lua code: · 5 unmodified lines
2017</pre>2033</pre>
2018Here it is in C:2034Here it is in C:
2019<pre>2035<pre>
2020 lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */
2021 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */2036 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
2022 lua_pushstring(L, "how"); /* 1st argument */2037 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 */
2024 lua_pushinteger(L, 14); /* 3rd argument */2041 lua_pushinteger(L, 14); /* 3rd argument */
2025 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */2042 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */
2026 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */2043 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */
2027 lua_pop(L, 1); /* remove `t' from the stack */
2028</pre>2044</pre>
2029Note that the code above is "balanced":2045Note that the code above is "balanced":
2030at its end, the stack is back to its original configuration.2046at its end, the stack is back to its original configuration.
2031This is considered good programming practice.2047This is considered good programming practice.
2032 2048
2033<p><a name="lua_CFunction"></a>2049<p><a name="lua_CFunction"></a>
2034<hr/><h3><code>lua_CFunction</code></h3>2050<hr /><h3><code>lua_CFunction</code></h3>
2035<pre>2051<pre>
2036 typedef int (*lua_CFunction) (lua_State *L);2052 typedef int (*lua_CFunction) (lua_State *L);
2037</pre>2053</pre>
@@ -2040,17 +2056,19 @@ This is considered good programming practice. · 2 unmodified lines
2040<p>Type for C functions.2056<p>Type for C functions.
2041 2057
2042<p>In order to communicate properly with Lua,2058<p>In order to communicate properly with Lua,
2043a C function must follow the following protocol,2059a C function must use the following protocol,
2044which defines the way parameters and results are passed:2060which defines the way parameters and results are passed:
2045A C function receives its arguments from Lua in its stack2061A C function receives its arguments from Lua in its stack
2046in direct order (the first argument is pushed first).2062in direct order (the first argument is pushed first).
2047So, when the function starts,2063So, when the function starts,
2048its 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.
2065The first argument (if any) is at index 1
2066and its last argument is at index <a href="#lua_gettop(L)"><code>lua_gettop(L)</code></a>.
2049To return values to Lua, a C function just pushes them onto the stack,2067To return values to Lua, a C function just pushes them onto the stack,
2050in direct order (the first result is pushed first),2068in direct order (the first result is pushed first),
2051and returns the number of results.2069and returns the number of results.
2052Any other value in the stack below the results will be properly2070Any other value in the stack below the results will be properly
2053discharged by Lua.2071discarded by Lua.
2054Like a Lua function, a C function called by Lua can also return2072Like a Lua function, a C function called by Lua can also return
2055many results.2073many results.
2056 2074
@@ -2075,20 +2093,20 @@ of numerical arguments and returns their average and sum: · 18 unmodified lines
2075</pre>2093</pre>
2076 2094
2077<p><a name="lua_checkstack"></a>2095<p><a name="lua_checkstack"></a>
2078<hr/><h3><code>lua_checkstack</code></h3>2096<hr /><h3><code>lua_checkstack</code></h3>
2079<pre>2097<pre>
2080 int lua_checkstack (lua_State *L, int extra);2098 int lua_checkstack (lua_State *L, int extra);
2081</pre>2099</pre>
2082 2100
2083 2101
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.
2085it returns false if it cannot grow the stack to that size.2103it returns false if it cannot grow the stack to that size.
2086This function never shrinks the stack;2104This function never shrinks the stack;
2087if the stack is already larger than the new size,2105if the stack is already larger than the new size,
2088it is left unchanged.2106it is left unchanged.
2089 2107
2090<p><a name="lua_close"></a>2108<p><a name="lua_close"></a>
2091<hr/><h3><code>lua_close</code></h3>2109<hr /><h3><code>lua_close</code></h3>
2092<pre>2110<pre>
2093 void lua_close (lua_State *L);2111 void lua_close (lua_State *L);
2094</pre>2112</pre>
@@ -2105,7 +2123,7 @@ might need to release states as soon as they are not needed, · 10 unmodified lines
2105to avoid growing too large.2123to avoid growing too large.
2106 2124
2107<p><a name="lua_concat"></a>2125<p><a name="lua_concat"></a>
2108<hr/><h3><code>lua_concat</code></h3>2126<hr /><h3><code>lua_concat</code></h3>
2109<pre>2127<pre>
2110 void lua_concat (lua_State *L, int n);2128 void lua_concat (lua_State *L, int n);
2111</pre>2129</pre>
@@ -2120,7 +2138,7 @@ Concatenation is done following the usual semantics of Lua · 8 unmodified lines
2120(see <a href="#concat">2.5.4</a>).2138(see <a href="#concat">2.5.4</a>).
2121 2139
2122<p><a name="lua_cpcall"></a>2140<p><a name="lua_cpcall"></a>
2123<hr/><h3><code>lua_cpcall</code></h3>2141<hr /><h3><code>lua_cpcall</code></h3>
2124<pre>2142<pre>
2125 int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);2143 int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
2126</pre>2144</pre>
@@ -2133,10 +2151,10 @@ In case of errors, · 6 unmodified lines
2133<a href="#lua_cpcall"><code>lua_cpcall</code></a> returns the same error codes as <a href="#lua_pcall"><code>lua_pcall</code></a>,2151<a href="#lua_cpcall"><code>lua_cpcall</code></a> returns the same error codes as <a href="#lua_pcall"><code>lua_pcall</code></a>,
2134plus the error object on the top of the stack;2152plus the error object on the top of the stack;
2135otherwise, it returns zero, and does not change the stack.2153otherwise, it returns zero, and does not change the stack.
2136Any value returned by <code>func</code> is discarded.2154All values returned by <code>func</code> are discarded.
2137 2155
2138<p><a name="lua_createtable"></a>2156<p><a name="lua_createtable"></a>
2139<hr/><h3><code>lua_createtable</code></h3>2157<hr /><h3><code>lua_createtable</code></h3>
2140<pre>2158<pre>
2141 void lua_createtable (lua_State *L, int narr, int nrec);2159 void lua_createtable (lua_State *L, int narr, int nrec);
2142</pre>2160</pre>
@@ -2144,25 +2162,26 @@ Any value returned by <code>func</code> is discarded. · 1 unmodified line
2144 2162
2145<p>Creates a new empty table and pushes it onto the stack.2163<p>Creates a new empty table and pushes it onto the stack.
2146The new table has space pre-allocated2164The new table has space pre-allocated
2147for <code>narr</code> array elements plus <code>nrec</code> non-array elements.2165for <code>narr</code> array elements and <code>nrec</code> non-array elements.
2148This pre-allocation is useful when you know exactly how many elements2166This pre-allocation is useful when you know exactly how many elements
2149the table will have.2167the table will have.
2150Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.2168Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
2151 2169
2152<p><a name="lua_dump"></a>2170<p><a name="lua_dump"></a>
2153<hr/><h3><code>lua_dump</code></h3>2171<hr /><h3><code>lua_dump</code></h3>
2154<pre>2172<pre>
2155 int lua_dump (lua_State *L, lua_Writer writer, void *data);2173 int lua_dump (lua_State *L, lua_Writer writer, void *data);
2156</pre>2174</pre>
2157 2175
2158 2176
2159<p>Dumps a function as a binary chunk.2177<p>Dumps a function as a binary chunk.
2160This function receives a Lua function on the top of the stack2178Receives a Lua function on the top of the stack
2161and produces a binary chunk that,2179and produces a binary chunk that,
2162if loaded again,2180if loaded again,
2163results in a function equivalent to the one dumped.2181results in a function equivalent to the one dumped.
2164As it produces parts of the chunk,2182As it produces parts of the chunk,
2165<a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua_Writer"><code>lua_Writer</code></a>)2183<a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua_Writer"><code>lua_Writer</code></a>)
2184with the given <code>data</code>
2166to write them.2185to write them.
2167 2186
2168<p>The value returned is the error code returned by the last2187<p>The value returned is the error code returned by the last
@@ -2172,7 +2191,7 @@ call to the writer; · 3 unmodified lines
2172<p>This function does not pop the function from the stack.2191<p>This function does not pop the function from the stack.
2173 2192
2174<p><a name="lua_equal"></a>2193<p><a name="lua_equal"></a>
2175<hr/><h3><code>lua_equal</code></h3>2194<hr /><h3><code>lua_equal</code></h3>
2176<pre>2195<pre>
2177 int lua_equal (lua_State *L, int index1, int index2);2196 int lua_equal (lua_State *L, int index1, int index2);
2178</pre>2197</pre>
@@ -2183,23 +2202,24 @@ call to the writer; · 4 unmodified lines
2183following the semantics of the Lua <code>==</code> operator2202following the semantics of the Lua <code>==</code> operator
2184(that is, may call metamethods).2203(that is, may call metamethods).
2185Otherwise returns 0.2204Otherwise returns 0.
2186Also returns 0 if any of the indices are non valid.2205Also returns 0 if any of the indices is non valid.
2187 2206
2188<p><a name="lua_error"></a>2207<p><a name="lua_error"></a>
2189<hr/><h3><code>lua_error</code></h3>2208<hr /><h3><code>lua_error</code></h3>
2190<pre>2209<pre>
2191 int lua_error (lua_State *L);2210 int lua_error (lua_State *L);
2192</pre>2211</pre>
2193 2212
2194 2213
2195<p>Generates a Lua error.2214<p>Generates a Lua error.
2196The error message (which actually can be any type of object)2215The error message (which can actually be a Lua value of any type)
2197must be on the stack top.2216must be on the stack top.
2198This function does a long jump,2217This function does a long jump,
2199and therefore never returns.2218and therefore never returns.
2219(see <a href="#pdf-luaL_error"><code>luaL_error</code></a>).
2200 2220
2201<p><a name="lua_gc"></a>2221<p><a name="lua_gc"></a>
2202<hr/><h3><code>lua_gc</code></h3>2222<hr /><h3><code>lua_gc</code></h3>
2203<pre>2223<pre>
2204 int lua_gc (lua_State *L, int what, int data);2224 int lua_gc (lua_State *L, int what, int data);
2205</pre>2225</pre>
@@ -2227,28 +2247,28 @@ you must tune experimentally the value of <code>data</code>. · 21 unmodified lines
2227The function returns 1 if that step finished a2247The function returns 1 if that step finished a
2228garbage-collection cycle.2248garbage-collection cycle.
2229<li> <code>LUA_GCSETPAUSE</code>---2249<li> <code>LUA_GCSETPAUSE</code>---
2230sets <em><code>data</code>/100</em> as the new value2250sets <code>data</code>/100 as the new value
2231for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>).2251for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>).
2232The function returns the previous value of the pause.2252The function returns the previous value of the pause.
2233<li> <code>LUA_GCSETSTEPMUL</code>---2253<li> <code>LUA_GCSETSTEPMUL</code>---
2234sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of2254sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of
2235the collector (see <a href="#GC">2.10</a>).2255the collector (see <a href="#GC">2.10</a>).
2236The function returns the previous value of the step multiplier.2256The function returns the previous value of the step multiplier.
2237</ul>2257</ul>
2238 2258
2239<p><a name="lua_getallocf"></a>2259<p><a name="lua_getallocf"></a>
2240<hr/><h3><code>lua_getallocf</code></h3>2260<hr /><h3><code>lua_getallocf</code></h3>
2241<pre>2261<pre>
2242 lua_Alloc lua_getallocf (lua_State *L, void **ud);2262 lua_Alloc lua_getallocf (lua_State *L, void **ud);
2243</pre>2263</pre>
2244 2264
2245 2265
2246<p>Returns the allocator function of a given state.2266<p>Returns the memory allocator function of a given state.
2247If <code>ud</code> is not <code>NULL</code> Lua stores in <code>*ud</code> the2267If <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the
2248opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.2268opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.
2249 2269
2250<p><a name="lua_getfenv"></a>2270<p><a name="lua_getfenv"></a>
2251<hr/><h3><code>lua_getfenv</code></h3>2271<hr /><h3><code>lua_getfenv</code></h3>
2252<pre>2272<pre>
2253 void lua_getfenv (lua_State *L, int index);2273 void lua_getfenv (lua_State *L, int index);
2254</pre>2274</pre>
@@ -2258,7 +2278,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 3 unmodified lines
2258the value at the given index.2278the value at the given index.
2259 2279
2260<p><a name="lua_getfield"></a>2280<p><a name="lua_getfield"></a>
2261<hr/><h3><code>lua_getfield</code></h3>2281<hr /><h3><code>lua_getfield</code></h3>
2262<pre>2282<pre>
2263 void lua_getfield (lua_State *L, int index, const char *k);2283 void lua_getfield (lua_State *L, int index, const char *k);
2264</pre>2284</pre>
@@ -2270,7 +2290,7 @@ As in Lua, this function may trigger a metamethod · 5 unmodified lines
2270for the "index" event (see <a href="#metatable">2.8</a>).2290for the "index" event (see <a href="#metatable">2.8</a>).
2271 2291
2272<p><a name="lua_getmetatable"></a>2292<p><a name="lua_getmetatable"></a>
2273<hr/><h3><code>lua_getmetatable</code></h3>2293<hr /><h3><code>lua_getmetatable</code></h3>
2274<pre>2294<pre>
2275 int lua_getmetatable (lua_State *L, int index);2295 int lua_getmetatable (lua_State *L, int index);
2276</pre>2296</pre>
@@ -2283,7 +2303,7 @@ or if the value does not have a metatable, · 6 unmodified lines
2283returns 0 and pushes nothing on the stack.2303returns 0 and pushes nothing on the stack.
2284 2304
2285<p><a name="lua_gettable"></a>2305<p><a name="lua_gettable"></a>
2286<hr/><h3><code>lua_gettable</code></h3>2306<hr /><h3><code>lua_gettable</code></h3>
2287<pre>2307<pre>
2288 void lua_gettable (lua_State *L, int index);2308 void lua_gettable (lua_State *L, int index);
2289</pre>2309</pre>
@@ -2299,7 +2319,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
2299for the "index" event (see <a href="#metatable">2.8</a>).2319for the "index" event (see <a href="#metatable">2.8</a>).
2300 2320
2301<p><a name="lua_gettop"></a>2321<p><a name="lua_gettop"></a>
2302<hr/><h3><code>lua_gettop</code></h3>2322<hr /><h3><code>lua_gettop</code></h3>
2303<pre>2323<pre>
2304 int lua_gettop (lua_State *L);2324 int lua_gettop (lua_State *L);
2305</pre>2325</pre>
@@ -2311,7 +2331,7 @@ that result is equal to the number of elements in the stack · 5 unmodified lines
2311(and so 0 means an empty stack).2331(and so 0 means an empty stack).
2312 2332
2313<p><a name="lua_insert"></a>2333<p><a name="lua_insert"></a>
2314<hr/><h3><code>lua_insert</code></h3>2334<hr /><h3><code>lua_insert</code></h3>
2315<pre>2335<pre>
2316 void lua_insert (lua_State *L, int index);2336 void lua_insert (lua_State *L, int index);
2317</pre>2337</pre>
@@ -2323,7 +2343,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
2323because a pseudo-index is not an actual stack position.2343because a pseudo-index is not an actual stack position.
2324 2344
2325<p><a name="lua_Integer"></a>2345<p><a name="lua_Integer"></a>
2326<hr/><h3><code>lua_Integer</code></h3>2346<hr /><h3><code>lua_Integer</code></h3>
2327<pre>2347<pre>
2328 typedef ptrdiff_t lua_Integer;2348 typedef ptrdiff_t lua_Integer;
2329</pre>2349</pre>
@@ -2332,11 +2352,11 @@ because a pseudo-index is not an actual stack position. · 2 unmodified lines
2332<p>The type used by the Lua API to represent integral values.2352<p>The type used by the Lua API to represent integral values.
2333 2353
2334<p>By default it is a <code>ptrdiff_t</code>,2354<p>By default it is a <code>ptrdiff_t</code>,
2335which is usually the largest type the machine handles2355which is usually the largest integral type the machine handles
2336"comfortably".2356"comfortably".
2337 2357
2338<p><a name="lua_isboolean"></a>2358<p><a name="lua_isboolean"></a>
2339<hr/><h3><code>lua_isboolean</code></h3>2359<hr /><h3><code>lua_isboolean</code></h3>
2340<pre>2360<pre>
2341 int lua_isboolean (lua_State *L, int index);2361 int lua_isboolean (lua_State *L, int index);
2342</pre>2362</pre>
@@ -2346,7 +2366,7 @@ which is usually the largest type the machine handles · 3 unmodified lines
2346and 0 otherwise.2366and 0 otherwise.
2347 2367
2348<p><a name="lua_iscfunction"></a>2368<p><a name="lua_iscfunction"></a>
2349<hr/><h3><code>lua_iscfunction</code></h3>2369<hr /><h3><code>lua_iscfunction</code></h3>
2350<pre>2370<pre>
2351 int lua_iscfunction (lua_State *L, int index);2371 int lua_iscfunction (lua_State *L, int index);
2352</pre>2372</pre>
@@ -2356,7 +2376,7 @@ and 0 otherwise. · 3 unmodified lines
2356and 0 otherwise.2376and 0 otherwise.
2357 2377
2358<p><a name="lua_isfunction"></a>2378<p><a name="lua_isfunction"></a>
2359<hr/><h3><code>lua_isfunction</code></h3>2379<hr /><h3><code>lua_isfunction</code></h3>
2360<pre>2380<pre>
2361 int lua_isfunction (lua_State *L, int index);2381 int lua_isfunction (lua_State *L, int index);
2362</pre>2382</pre>
@@ -2366,7 +2386,7 @@ and 0 otherwise. · 3 unmodified lines
2366(either C or Lua), and 0 otherwise.2386(either C or Lua), and 0 otherwise.
2367 2387
2368<p><a name="lua_islightuserdata"></a>2388<p><a name="lua_islightuserdata"></a>
2369<hr/><h3><code>lua_islightuserdata</code></h3>2389<hr /><h3><code>lua_islightuserdata</code></h3>
2370<pre>2390<pre>
2371 int lua_islightuserdata (lua_State *L, int index);2391 int lua_islightuserdata (lua_State *L, int index);
2372</pre>2392</pre>
@@ -2376,7 +2396,7 @@ and 0 otherwise. · 3 unmodified lines
2376and 0 otherwise.2396and 0 otherwise.
2377 2397
2378<p><a name="lua_isnil"></a>2398<p><a name="lua_isnil"></a>
2379<hr/><h3><code>lua_isnil</code></h3>2399<hr /><h3><code>lua_isnil</code></h3>
2380<pre>2400<pre>
2381 int lua_isnil (lua_State *L, int index);2401 int lua_isnil (lua_State *L, int index);
2382</pre>2402</pre>
@@ -2386,7 +2406,7 @@ and 0 otherwise. · 3 unmodified lines
2386and 0 otherwise.2406and 0 otherwise.
2387 2407
2388<p><a name="lua_isnumber"></a>2408<p><a name="lua_isnumber"></a>
2389<hr/><h3><code>lua_isnumber</code></h3>2409<hr /><h3><code>lua_isnumber</code></h3>
2390<pre>2410<pre>
2391 int lua_isnumber (lua_State *L, int index);2411 int lua_isnumber (lua_State *L, int index);
2392</pre>2412</pre>
@@ -2397,7 +2417,7 @@ or a string convertible to a number, · 4 unmodified lines
2397and 0 otherwise.2417and 0 otherwise.
2398 2418
2399<p><a name="lua_isstring"></a>2419<p><a name="lua_isstring"></a>
2400<hr/><h3><code>lua_isstring</code></h3>2420<hr /><h3><code>lua_isstring</code></h3>
2401<pre>2421<pre>
2402 int lua_isstring (lua_State *L, int index);2422 int lua_isstring (lua_State *L, int index);
2403</pre>2423</pre>
@@ -2408,7 +2428,7 @@ or a number (which is always convertible to a string), · 4 unmodified lines
2408and 0 otherwise.2428and 0 otherwise.
2409 2429
2410<p><a name="lua_istable"></a>2430<p><a name="lua_istable"></a>
2411<hr/><h3><code>lua_istable</code></h3>2431<hr /><h3><code>lua_istable</code></h3>
2412<pre>2432<pre>
2413 int lua_istable (lua_State *L, int index);2433 int lua_istable (lua_State *L, int index);
2414</pre>2434</pre>
@@ -2418,7 +2438,7 @@ and 0 otherwise. · 3 unmodified lines
2418and 0 otherwise.2438and 0 otherwise.
2419 2439
2420<p><a name="lua_isthread"></a>2440<p><a name="lua_isthread"></a>
2421<hr/><h3><code>lua_isthread</code></h3>2441<hr /><h3><code>lua_isthread</code></h3>
2422<pre>2442<pre>
2423 int lua_isthread (lua_State *L, int index);2443 int lua_isthread (lua_State *L, int index);
2424</pre>2444</pre>
@@ -2428,7 +2448,7 @@ and 0 otherwise. · 3 unmodified lines
2428and 0 otherwise.2448and 0 otherwise.
2429 2449
2430<p><a name="lua_isuserdata"></a>2450<p><a name="lua_isuserdata"></a>
2431<hr/><h3><code>lua_isuserdata</code></h3>2451<hr /><h3><code>lua_isuserdata</code></h3>
2432<pre>2452<pre>
2433 int lua_isuserdata (lua_State *L, int index);2453 int lua_isuserdata (lua_State *L, int index);
2434</pre>2454</pre>
@@ -2438,21 +2458,21 @@ and 0 otherwise. · 3 unmodified lines
2438(either full or light), and 0 otherwise.2458(either full or light), and 0 otherwise.
2439 2459
2440<p><a name="lua_lessthan"></a>2460<p><a name="lua_lessthan"></a>
2441<hr/><h3><code>lua_lessthan</code></h3>2461<hr /><h3><code>lua_lessthan</code></h3>
2442<pre>2462<pre>
2443 int lua_lessthan (lua_State *L, int index1, int index2);2463 int lua_lessthan (lua_State *L, int index1, int index2);
2444</pre>2464</pre>
2445 2465
2446 2466
2447<p>Returns 1 if the value in acceptable index <code>index1</code> is smaller2467<p>Returns 1 if the value at acceptable index <code>index1</code> is smaller
2448than the value in acceptable index <code>index2</code>,2468than the value at acceptable index <code>index2</code>,
2449following the semantics of the Lua <code>&#060;</code> operator2469following the semantics of the Lua <code>&#060;</code> operator
2450(that is, may call metamethods).2470(that is, may call metamethods).
2451Otherwise returns 0.2471Otherwise returns 0.
2452Also returns 0 if any of the indices are non valid.2472Also returns 0 if any of the indices is non valid.
2453 2473
2454<p><a name="lua_load"></a>2474<p><a name="lua_load"></a>
2455<hr/><h3><code>lua_load</code></h3>2475<hr /><h3><code>lua_load</code></h3>
2456<pre>2476<pre>
2457 int lua_load (lua_State *L, lua_Reader reader, void *data,2477 int lua_load (lua_State *L, lua_Reader reader, void *data,
2458 const char *chunkname);2478 const char *chunkname);
@@ -2481,11 +2501,11 @@ and loads it accordingly (see program <code>luac</code>). · 22 unmodified lines
2481(see <a href="#lua_Reader"><code>lua_Reader</code></a>).2501(see <a href="#lua_Reader"><code>lua_Reader</code></a>).
2482The <code>data</code> argument is an opaque value passed to the reader function.2502The <code>data</code> argument is an opaque value passed to the reader function.
2483 2503
2484<p>The <code>chunkname</code> argument gives the chunk name.2504<p>The <code>chunkname</code> argument gives a name to the chunk,
2485It is used for error messages and debug information (see <a href="#debugI">3.8</a>).2505which is used for error messages and in debug information (see <a href="#debugI">3.8</a>).
2486 2506
2487<p><a name="lua_newstate"></a>2507<p><a name="lua_newstate"></a>
2488<hr/><h3><code>lua_newstate</code></h3>2508<hr /><h3><code>lua_newstate</code></h3>
2489<pre>2509<pre>
2490 lua_State *lua_newstate (lua_Alloc f, void *ud);2510 lua_State *lua_newstate (lua_Alloc f, void *ud);
2491</pre>2511</pre>
@@ -2493,14 +2513,14 @@ It is used for error messages and debug information (see <a href="#debugI">3.8</ · 1 unmodified line
2493 2513
2494<p>Creates a new, independent state.2514<p>Creates a new, independent state.
2495Returns <code>NULL</code> if cannot create the state2515Returns <code>NULL</code> if cannot create the state
2496(not enough memory).2516(due to lack of memory).
2497The argument <code>f</code> is the allocator function;2517The argument <code>f</code> is the allocator function;
2498Lua does all memory allocation for that state through that function.2518Lua does all memory allocation for that state through that function.
2499The second argument, <code>ud</code>, is an opaque pointer that Lua2519The second argument, <code>ud</code>, is an opaque pointer that Lua
2500simply passes to the allocator in every call.2520simply passes to the allocator in every call.
2501 2521
2502<p><a name="lua_newtable"></a>2522<p><a name="lua_newtable"></a>
2503<hr/><h3><code>lua_newtable</code></h3>2523<hr /><h3><code>lua_newtable</code></h3>
2504<pre>2524<pre>
2505 void lua_newtable (lua_State *L);2525 void lua_newtable (lua_State *L);
2506</pre>2526</pre>
@@ -2510,7 +2530,7 @@ simply passes to the allocator in every call. · 3 unmodified lines
2510Equivalent to <code>lua_createtable(L, 0, 0)</code>.2530Equivalent to <code>lua_createtable(L, 0, 0)</code>.
2511 2531
2512<p><a name="lua_newthread"></a>2532<p><a name="lua_newthread"></a>
2513<hr/><h3><code>lua_newthread</code></h3>2533<hr /><h3><code>lua_newthread</code></h3>
2514<pre>2534<pre>
2515 lua_State *lua_newthread (lua_State *L);2535 lua_State *lua_newthread (lua_State *L);
2516</pre>2536</pre>
@@ -2520,14 +2540,14 @@ Equivalent to <code>lua_createtable(L, 0, 0)</code>. · 3 unmodified lines
2520and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread.2540and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread.
2521The new state returned by this function shares with the original state2541The new state returned by this function shares with the original state
2522all global objects (such as tables),2542all global objects (such as tables),
2523but has an independent run-time stack.2543but has an independent execution stack.
2524 2544
2525<p>There is no explicit function to close or to destroy a thread.2545<p>There is no explicit function to close or to destroy a thread.
2526Threads are subject to garbage collection,2546Threads are subject to garbage collection,
2527like any Lua object.2547like any Lua object.
2528 2548
2529<p><a name="lua_newuserdata"></a>2549<p><a name="lua_newuserdata"></a>
2530<hr/><h3><code>lua_newuserdata</code></h3>2550<hr /><h3><code>lua_newuserdata</code></h3>
2531<pre>2551<pre>
2532 void *lua_newuserdata (lua_State *L, size_t size);2552 void *lua_newuserdata (lua_State *L, size_t size);
2533</pre>2553</pre>
@@ -2544,21 +2564,22 @@ You must create it, it can have its own metatable, · 10 unmodified lines
2544and you can detect when it is being collected.2564and you can detect when it is being collected.
2545A full userdata is only equal to itself (under raw equality).2565A full userdata is only equal to itself (under raw equality).
2546 2566
2547<p>When Lua collects a full userdata,2567<p>When Lua collects a full userdata with a <code>gc</code> metamethod,
2548it calls the userdata's <code>gc</code> metamethod, if any,2568Lua calls the metamethod and marks the userdata as finalized.
2549and then it frees the userdata's corresponding memory.2569When that userdata is collected again then
2570Lua frees its corresponding memory.
2550 2571
2551<p><a name="lua_next"></a>2572<p><a name="lua_next"></a>
2552<hr/><h3><code>lua_next</code></h3>2573<hr /><h3><code>lua_next</code></h3>
2553<pre>2574<pre>
2554 int lua_next (lua_State *L, int index);2575 int lua_next (lua_State *L, int index);
2555</pre>2576</pre>
2556 2577
2557 2578
2558<p>Pops a key from the stack,2579<p>Pops a key from the stack,
2559and pushes a key-value pair from the table2580and pushes a key-value pair from the table at the given index
2560(the "next" pair after the given key).2581(the "next" pair after the given key).
2561If there are no more elements,2582If there are no more elements in the table,
2562then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).2583then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).
2563 2584
2564<p>A typical traversal looks like this:2585<p>A typical traversal looks like this:
@@ -2581,33 +2602,34 @@ the value at the given index; · 16 unmodified lines
2581this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.2602this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
2582 2603
2583<p><a name="lua_Number"></a>2604<p><a name="lua_Number"></a>
2584<hr/><h3><code>lua_Number</code></h3>2605<hr /><h3><code>lua_Number</code></h3>
2585<pre>2606<pre>
2586 typedef double lua_Number;2607 typedef double lua_Number;
2587</pre>2608</pre>
2588 2609
2589 2610
2590<p>The type of numbers in Lua.2611<p>The type of numbers in Lua.
2612By default, it is double, but that can be changed in <code>luaconf.h</code>.
2591 2613
2592<p>Through the configuration file you can change2614<p>Through the configuration file you can change
2593Lua to operate with other type for numbers (e.g., float or long).2615Lua to operate with other type for numbers (e.g., float or long).
2594 2616
2595<p><a name="lua_objlen"></a>2617<p><a name="lua_objlen"></a>
2596<hr/><h3><code>lua_objlen</code></h3>2618<hr /><h3><code>lua_objlen</code></h3>
2597<pre>2619<pre>
2598 size_t lua_objlen (lua_State *L, int index);2620 size_t lua_objlen (lua_State *L, int index);
2599</pre>2621</pre>
2600 2622
2601 2623
2602<p>Returns the "length" of the value at the given acceptable index:2624<p>Returns the "length" of the value at the given acceptable index:
2603For strings, this is the string length;2625for strings, this is the string length;
2604for tables, this is the result of the length operator (`<code>#</code>&acute;).2626for tables, this is the result of the length operator (`<code>#</code>&acute;);
2605for userdata, this is the size of the block of memory allocated2627for userdata, this is the size of the block of memory allocated
2606for the userdatum.2628for the userdata;
2607For other values, returns 0.2629for other values, it is 0.
2608 2630
2609<p><a name="lua_pcall"></a>2631<p><a name="lua_pcall"></a>
2610<hr/><h3><code>lua_pcall</code></h3>2632<hr /><h3><code>lua_pcall</code></h3>
2611<pre>2633<pre>
2612 lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);2634 lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
2613</pre>2635</pre>
@@ -2628,13 +2650,14 @@ Like <a href="#lua_call"><code>lua_call</code></a>, · 14 unmodified lines
2628and its arguments from the stack.2650and its arguments from the stack.
2629 2651
2630<p>If <code>errfunc</code> is 0,2652<p>If <code>errfunc</code> is 0,
2631then the error message returned is exactly the original error message.2653then the error message returned on the stack
2654is exactly the original error message.
2632Otherwise, <code>errfunc</code> is the stack index of an2655Otherwise, <code>errfunc</code> is the stack index of an
2633<em>error handler function</em>.2656<em>error handler function</em>.
2634(In the current implementation, that index cannot be a pseudo-index.)2657(In the current implementation, that index cannot be a pseudo-index.)
2635In case of runtime errors,2658In case of runtime errors,
2636that function will be called with the error message2659that function will be called with the error message
2637and its return value will be the message returned by <a href="#lua_pcall"><code>lua_pcall</code></a>.2660and its return value will be the message returned on the stack by <a href="#lua_pcall"><code>lua_pcall</code></a>.
2638 2661
2639<p>Typically, the error handler function is used to add more debug2662<p>Typically, the error handler function is used to add more debug
2640information to the error message, such as a stack traceback.2663information to the error message, such as a stack traceback.
@@ -2653,7 +2676,7 @@ error while running the error handler function. · 12 unmodified lines
2653</ul>2676</ul>
2654 2677
2655<p><a name="lua_pop"></a>2678<p><a name="lua_pop"></a>
2656<hr/><h3><code>lua_pop</code></h3>2679<hr /><h3><code>lua_pop</code></h3>
2657<pre>2680<pre>
2658 void lua_pop (lua_State *L, int n);2681 void lua_pop (lua_State *L, int n);
2659</pre>2682</pre>
@@ -2662,7 +2685,7 @@ error while running the error handler function. · 2 unmodified lines
2662<p>Pops <code>n</code> elements from the stack.2685<p>Pops <code>n</code> elements from the stack.
2663 2686
2664<p><a name="lua_pushboolean"></a>2687<p><a name="lua_pushboolean"></a>
2665<hr/><h3><code>lua_pushboolean</code></h3>2688<hr /><h3><code>lua_pushboolean</code></h3>
2666<pre>2689<pre>
2667 void lua_pushboolean (lua_State *L, int b);2690 void lua_pushboolean (lua_State *L, int b);
2668</pre>2691</pre>
@@ -2671,7 +2694,7 @@ error while running the error handler function. · 2 unmodified lines
2671<p>Pushes a boolean value with value <code>b</code> onto the stack.2694<p>Pushes a boolean value with value <code>b</code> onto the stack.
2672 2695
2673<p><a name="lua_pushcclosure"></a>2696<p><a name="lua_pushcclosure"></a>
2674<hr/><h3><code>lua_pushcclosure</code></h3>2697<hr /><h3><code>lua_pushcclosure</code></h3>
2675<pre>2698<pre>
2676 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);2699 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
2677</pre>2700</pre>
@@ -2686,14 +2709,14 @@ these values are then accessible to the function whenever it is called. · 8 unmodified lines
2686To associate values with a C function,2709To associate values with a C function,
2687first these values should be pushed onto the stack2710first these values should be pushed onto the stack
2688(when there are multiple values, the first value is pushed first).2711(when there are multiple values, the first value is pushed first).
2689Then the function <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>2712Then <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>
2690is used to create and push the C function onto the stack,2713is called to create and push the C function onto the stack,
2691with the argument <code>n</code> telling how many values should be2714with the argument <code>n</code> telling how many values should be
2692associated with the function.2715associated with the function.
2693<a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.2716<a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
2694 2717
2695<p><a name="lua_pushcfunction"></a>2718<p><a name="lua_pushcfunction"></a>
2696<hr/><h3><code>lua_pushcfunction</code></h3>2719<hr /><h3><code>lua_pushcfunction</code></h3>
2697<pre>2720<pre>
2698 void lua_pushcfunction (lua_State *L, lua_CFunction f);2721 void lua_pushcfunction (lua_State *L, lua_CFunction f);
2699</pre>2722</pre>
@@ -2703,7 +2726,7 @@ associated with the function. · 3 unmodified lines
2703This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>.2726This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>.
2704 2727
2705<p><a name="lua_pushfstring"></a>2728<p><a name="lua_pushfstring"></a>
2706<hr/><h3><code>lua_pushfstring</code></h3>2729<hr /><h3><code>lua_pushfstring</code></h3>
2707<pre>2730<pre>
2708 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);2731 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
2709</pre>2732</pre>
@@ -2711,15 +2734,15 @@ This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>. · 1 unmodified line
2711 2734
2712<p>Pushes onto the stack a formatted string2735<p>Pushes onto the stack a formatted string
2713and returns a pointer to that string.2736and returns a pointer to that string.
2714It is similar to the C function <code>sprintf</code>2737It is similar to the C function <code>sprintf</code>,
2715but with some important differences:2738but has some important differences:
2716<ul>2739<ul>
2717<li> You do not have to allocate the space for the result:2740<li> You do not have to allocate the space for the result:
2718The result is a Lua string and Lua takes care of memory allocation2741The result is a Lua string and Lua takes care of memory allocation
2719(and deallocation, through garbage collection).2742(and deallocation, through garbage collection).
2720<li> The conversion specifiers are quite restricted.2743<li> The conversion specifiers are quite restricted.
2721There are no flags, widths, or precisions.2744There are no flags, widths, or precisions.
2722The conversion specifiers can be simply2745The conversion specifiers can only be
2723`<code>%%</code>&acute; (inserts a `<code>%</code>&acute; in the string),2746`<code>%%</code>&acute; (inserts a `<code>%</code>&acute; in the string),
2724`<code>%s</code>&acute; (inserts a zero-terminated string, with no size restrictions),2747`<code>%s</code>&acute; (inserts a zero-terminated string, with no size restrictions),
2725`<code>%f</code>&acute; (inserts a <a href="#lua_Number"><code>lua_Number</code></a>),2748`<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
2729</ul>2752</ul>
2730 2753
2731<p><a name="lua_pushinteger"></a>2754<p><a name="lua_pushinteger"></a>
2732<hr/><h3><code>lua_pushinteger</code></h3>2755<hr /><h3><code>lua_pushinteger</code></h3>
2733<pre>2756<pre>
2734 void lua_pushinteger (lua_State *L, lua_Integer n);2757 void lua_pushinteger (lua_State *L, lua_Integer n);
2735</pre>2758</pre>
@@ -2738,7 +2761,7 @@ The conversion specifiers can be simply · 2 unmodified lines
2738<p>Pushes a number with value <code>n</code> onto the stack.2761<p>Pushes a number with value <code>n</code> onto the stack.
2739 2762
2740<p><a name="lua_pushlightuserdata"></a>2763<p><a name="lua_pushlightuserdata"></a>
2741<hr/><h3><code>lua_pushlightuserdata</code></h3>2764<hr /><h3><code>lua_pushlightuserdata</code></h3>
2742<pre>2765<pre>
2743 void lua_pushlightuserdata (lua_State *L, void *p);2766 void lua_pushlightuserdata (lua_State *L, void *p);
2744</pre>2767</pre>
@@ -2755,7 +2778,7 @@ A light userdata is equal to "any" · 10 unmodified lines
2755light userdata with the same C address.2778light userdata with the same C address.
2756 2779
2757<p><a name="lua_pushlstring"></a>2780<p><a name="lua_pushlstring"></a>
2758<hr/><h3><code>lua_pushlstring</code></h3>2781<hr /><h3><code>lua_pushlstring</code></h3>
2759<pre>2782<pre>
2760 void lua_pushlstring (lua_State *L, const char *s, size_t len);2783 void lua_pushlstring (lua_State *L, const char *s, size_t len);
2761</pre>2784</pre>
@@ -2766,9 +2789,10 @@ onto the stack. · 4 unmodified lines
2766Lua makes (or reuses) an internal copy of the given string,2789Lua makes (or reuses) an internal copy of the given string,
2767so the memory at <code>s</code> can be freed or reused immediately after2790so the memory at <code>s</code> can be freed or reused immediately after
2768the function returns.2791the function returns.
2792The string can contain embedded zeros.
2769 2793
2770<p><a name="lua_pushnil"></a>2794<p><a name="lua_pushnil"></a>
2771<hr/><h3><code>lua_pushnil</code></h3>2795<hr /><h3><code>lua_pushnil</code></h3>
2772<pre>2796<pre>
2773 void lua_pushnil (lua_State *L);2797 void lua_pushnil (lua_State *L);
2774</pre>2798</pre>
@@ -2777,7 +2801,7 @@ the function returns. · 2 unmodified lines
2777<p>Pushes a nil value onto the stack.2801<p>Pushes a nil value onto the stack.
2778 2802
2779<p><a name="lua_pushnumber"></a>2803<p><a name="lua_pushnumber"></a>
2780<hr/><h3><code>lua_pushnumber</code></h3>2804<hr /><h3><code>lua_pushnumber</code></h3>
2781<pre>2805<pre>
2782 void lua_pushnumber (lua_State *L, lua_Number n);2806 void lua_pushnumber (lua_State *L, lua_Number n);
2783</pre>2807</pre>
@@ -2786,7 +2810,7 @@ the function returns. · 2 unmodified lines
2786<p>Pushes a number with value <code>n</code> onto the stack.2810<p>Pushes a number with value <code>n</code> onto the stack.
2787 2811
2788<p><a name="lua_pushstring"></a>2812<p><a name="lua_pushstring"></a>
2789<hr/><h3><code>lua_pushstring</code></h3>2813<hr /><h3><code>lua_pushstring</code></h3>
2790<pre>2814<pre>
2791 void lua_pushstring (lua_State *L, const char *s);2815 void lua_pushstring (lua_State *L, const char *s);
2792</pre>2816</pre>
@@ -2797,9 +2821,20 @@ onto the stack. · 4 unmodified lines
2797Lua makes (or reuses) an internal copy of the given string,2821Lua makes (or reuses) an internal copy of the given string,
2798so the memory at <code>s</code> can be freed or reused immediately after2822so the memory at <code>s</code> can be freed or reused immediately after
2799the function returns.2823the function returns.
2824The string cannot embedded zeros;
2825it 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.
2800 2835
2801<p><a name="lua_pushvalue"></a>2836<p><a name="lua_pushvalue"></a>
2802<hr/><h3><code>lua_pushvalue</code></h3>2837<hr /><h3><code>lua_pushvalue</code></h3>
2803<pre>2838<pre>
2804 void lua_pushvalue (lua_State *L, int index);2839 void lua_pushvalue (lua_State *L, int index);
2805</pre>2840</pre>
@@ -2809,7 +2844,7 @@ the function returns. · 3 unmodified lines
2809onto the stack.2844onto the stack.
2810 2845
2811<p><a name="lua_pushvfstring"></a>2846<p><a name="lua_pushvfstring"></a>
2812<hr/><h3><code>lua_pushvfstring</code></h3>2847<hr /><h3><code>lua_pushvfstring</code></h3>
2813<pre>2848<pre>
2814 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);2849 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
2815</pre>2850</pre>
@@ -2819,7 +2854,7 @@ onto the stack. · 3 unmodified lines
2819instead of a variable number of arguments.2854instead of a variable number of arguments.
2820 2855
2821<p><a name="lua_rawequal"></a>2856<p><a name="lua_rawequal"></a>
2822<hr/><h3><code>lua_rawequal</code></h3>2857<hr /><h3><code>lua_rawequal</code></h3>
2823<pre>2858<pre>
2824 int lua_rawequal (lua_State *L, int index1, int index2);2859 int lua_rawequal (lua_State *L, int index1, int index2);
2825</pre>2860</pre>
@@ -2832,17 +2867,17 @@ Otherwise returns 0. · 6 unmodified lines
2832Also returns 0 if any of the indices are non valid.2867Also returns 0 if any of the indices are non valid.
2833 2868
2834<p><a name="lua_rawget"></a>2869<p><a name="lua_rawget"></a>
2835<hr/><h3><code>lua_rawget</code></h3>2870<hr /><h3><code>lua_rawget</code></h3>
2836<pre>2871<pre>
2837 void lua_rawget (lua_State *L, int index);2872 void lua_rawget (lua_State *L, int index);
2838</pre>2873</pre>
2839 2874
2840 2875
2841<p>Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but doing a raw indexing2876<p>Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw access
2842(i.e., without metamethods).2877(i.e., without metamethods).
2843 2878
2844<p><a name="lua_rawgeti"></a>2879<p><a name="lua_rawgeti"></a>
2845<hr/><h3><code>lua_rawgeti</code></h3>2880<hr /><h3><code>lua_rawgeti</code></h3>
2846<pre>2881<pre>
2847 void lua_rawgeti (lua_State *L, int index, int n);2882 void lua_rawgeti (lua_State *L, int index, int n);
2848</pre>2883</pre>
@@ -2850,36 +2885,36 @@ Also returns 0 if any of the indices are non valid. · 1 unmodified line
2850 2885
2851<p>Pushes onto the stack the value <code>t[n]</code>,2886<p>Pushes onto the stack the value <code>t[n]</code>,
2852where <code>t</code> is the value at the given valid index <code>index</code>.2887where <code>t</code> is the value at the given valid index <code>index</code>.
2853The access is raw,2888The access is raw;
2854that is, it does not invoke metamethods.2889that is, it does not invoke metamethods.
2855 2890
2856<p><a name="lua_rawset"></a>2891<p><a name="lua_rawset"></a>
2857<hr/><h3><code>lua_rawset</code></h3>2892<hr /><h3><code>lua_rawset</code></h3>
2858<pre>2893<pre>
2859 void lua_rawset (lua_State *L, int index);2894 void lua_rawset (lua_State *L, int index);
2860</pre>2895</pre>
2861 2896
2862 2897
2863<p>Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but doing a raw assignment2898<p>Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw assignment
2864(i.e., without metamethods).2899(i.e., without metamethods).
2865 2900
2866<p><a name="lua_rawseti"></a>2901<p><a name="lua_rawseti"></a>
2867<hr/><h3><code>lua_rawseti</code></h3>2902<hr /><h3><code>lua_rawseti</code></h3>
2868<pre>2903<pre>
2869 void lua_rawseti (lua_State *L, int index, int n);2904 void lua_rawseti (lua_State *L, int index, int n);
2870</pre>2905</pre>
2871 2906
2872 2907
2873<p>Does the equivalent to <code>t[n] = v</code>,2908<p>Does the equivalent of <code>t[n] = v</code>,
2874where <code>t</code> is the value at the given valid index <code>index</code>2909where <code>t</code> is the value at the given valid index <code>index</code>
2875and <code>v</code> is the value at the top of the stack,2910and <code>v</code> is the value at the top of the stack,
2876 2911
2877<p>This function pops the value from the stack.2912<p>This function pops the value from the stack.
2878The assignment is raw,2913The assignment is raw;
2879that is, it does not invoke metamethods.2914that is, it does not invoke metamethods.
2880 2915
2881<p><a name="lua_Reader"></a>2916<p><a name="lua_Reader"></a>
2882<hr/><h3><code>lua_Reader</code></h3>2917<hr /><h3><code>lua_Reader</code></h3>
2883<pre>2918<pre>
2884 typedef const char * (*lua_Reader)2919 typedef const char * (*lua_Reader)
2885 (lua_State *L, void *data, size_t *size);2920 (lua_State *L, void *data, size_t *size);
@@ -2894,11 +2929,12 @@ passing along its <code>data</code> parameter. · 8 unmodified lines
2894The reader must return a pointer to a block of memory2929The reader must return a pointer to a block of memory
2895with a new piece of the chunk2930with a new piece of the chunk
2896and set <code>size</code> to the block size.2931and set <code>size</code> to the block size.
2897To signal the end of the chunk, the reader returns <code>NULL</code>.2932The block must exist until the reader function is called again.
2933To signal the end of the chunk, the reader must return <code>NULL</code>.
2898The reader function may return pieces of any size greater than zero.2934The reader function may return pieces of any size greater than zero.
2899 2935
2900<p><a name="lua_remove"></a>2936<p><a name="lua_remove"></a>
2901<hr/><h3><code>lua_remove</code></h3>2937<hr /><h3><code>lua_remove</code></h3>
2902<pre>2938<pre>
2903 void lua_remove (lua_State *L, int index);2939 void lua_remove (lua_State *L, int index);
2904</pre>2940</pre>
@@ -2910,7 +2946,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
2910because a pseudo-index is not an actual stack position.2946because a pseudo-index is not an actual stack position.
2911 2947
2912<p><a name="lua_replace"></a>2948<p><a name="lua_replace"></a>
2913<hr/><h3><code>lua_replace</code></h3>2949<hr /><h3><code>lua_replace</code></h3>
2914<pre>2950<pre>
2915 void lua_replace (lua_State *L, int index);2951 void lua_replace (lua_State *L, int index);
2916</pre>2952</pre>
@@ -2921,7 +2957,7 @@ without shifting any element · 4 unmodified lines
2921(therefore replacing the value at the given position).2957(therefore replacing the value at the given position).
2922 2958
2923<p><a name="lua_resume"></a>2959<p><a name="lua_resume"></a>
2924<hr/><h3><code>lua_resume</code></h3>2960<hr /><h3><code>lua_resume</code></h3>
2925<pre>2961<pre>
2926 int lua_resume (lua_State *L, int narg);2962 int lua_resume (lua_State *L, int narg);
2927</pre>2963</pre>
@@ -2931,7 +2967,7 @@ without shifting any element · 3 unmodified lines
2931 2967
2932<p>To start a coroutine, you first create a new thread2968<p>To start a coroutine, you first create a new thread
2933(see <a href="#lua_newthread"><code>lua_newthread</code></a>);2969(see <a href="#lua_newthread"><code>lua_newthread</code></a>);
2934then you push on its stack the body function plus any eventual arguments;2970then you push on its stack the main function plus any eventual arguments;
2935then you call <a href="#lua_resume"><code>lua_resume</code></a>,2971then you call <a href="#lua_resume"><code>lua_resume</code></a>,
2936with <code>narg</code> being the number of arguments.2972with <code>narg</code> being the number of arguments.
2937This call returns when the coroutine suspends or finishes its execution.2973This call returns when the coroutine suspends or finishes its execution.
@@ -2944,14 +2980,14 @@ without errors, · 6 unmodified lines
2944or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>).2980or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
2945In case of errors,2981In case of errors,
2946the stack is not unwound,2982the stack is not unwound,
2947so you can use the debug API over it;2983so you can use the debug API over it.
2948The error message is on the top of the stack.2984The error message is on the top of the stack.
2949To restart a coroutine, you put on its stack only the values to2985To restart a coroutine, you put on its stack only the values to
2950be passed as results from <code>yield</code>,2986be passed as results from <code>yield</code>,
2951and then call <a href="#lua_resume"><code>lua_resume</code></a>.2987and then call <a href="#lua_resume"><code>lua_resume</code></a>.
2952 2988
2953<p><a name="lua_setallocf"></a>2989<p><a name="lua_setallocf"></a>
2954<hr/><h3><code>lua_setallocf</code></h3>2990<hr /><h3><code>lua_setallocf</code></h3>
2955<pre>2991<pre>
2956 void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);2992 void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
2957</pre>2993</pre>
@@ -2961,7 +2997,7 @@ and then call <a href="#lua_resume"><code>lua_resume</code></a>. · 3 unmodified lines
2961with user data <code>ud</code>.2997with user data <code>ud</code>.
2962 2998
2963<p><a name="lua_setfenv"></a>2999<p><a name="lua_setfenv"></a>
2964<hr/><h3><code>lua_setfenv</code></h3>3000<hr /><h3><code>lua_setfenv</code></h3>
2965<pre>3001<pre>
2966 int lua_setfenv (lua_State *L, int index);3002 int lua_setfenv (lua_State *L, int index);
2967</pre>3003</pre>
@@ -2971,10 +3007,11 @@ with user data <code>ud</code>. · 3 unmodified lines
2971the new environment for the value at the given index.3007the new environment for the value at the given index.
2972If the value at the given index is3008If the value at the given index is
2973neither a function nor a thread nor a userdata,3009neither 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.
3011Otherwise it returns 1.
2975 3012
2976<p><a name="lua_setfield"></a>3013<p><a name="lua_setfield"></a>
2977<hr/><h3><code>lua_setfield</code></h3>3014<hr /><h3><code>lua_setfield</code></h3>
2978<pre>3015<pre>
2979 void lua_setfield (lua_State *L, int index, const char *k);3016 void lua_setfield (lua_State *L, int index, const char *k);
2980</pre>3017</pre>
@@ -2989,7 +3026,7 @@ As in Lua, this function may trigger a metamethod · 8 unmodified lines
2989for the "newindex" event (see <a href="#metatable">2.8</a>).3026for the "newindex" event (see <a href="#metatable">2.8</a>).
2990 3027
2991<p><a name="lua_setmetatable"></a>3028<p><a name="lua_setmetatable"></a>
2992<hr/><h3><code>lua_setmetatable</code></h3>3029<hr /><h3><code>lua_setmetatable</code></h3>
2993<pre>3030<pre>
2994 int lua_setmetatable (lua_State *L, int index);3031 int lua_setmetatable (lua_State *L, int index);
2995</pre>3032</pre>
@@ -3000,7 +3037,7 @@ sets it as the new metatable for the value at the given · 4 unmodified lines
3000acceptable index.3037acceptable index.
3001 3038
3002<p><a name="lua_settable"></a>3039<p><a name="lua_settable"></a>
3003<hr/><h3><code>lua_settable</code></h3>3040<hr /><h3><code>lua_settable</code></h3>
3004<pre>3041<pre>
3005 void lua_settable (lua_State *L, int index);3042 void lua_settable (lua_State *L, int index);
3006</pre>3043</pre>
@@ -3016,7 +3053,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
3016for the "newindex" event (see <a href="#metatable">2.8</a>).3053for the "newindex" event (see <a href="#metatable">2.8</a>).
3017 3054
3018<p><a name="lua_settop"></a>3055<p><a name="lua_settop"></a>
3019<hr/><h3><code>lua_settop</code></h3>3056<hr /><h3><code>lua_settop</code></h3>
3020<pre>3057<pre>
3021 void lua_settop (lua_State *L, int index);3058 void lua_settop (lua_State *L, int index);
3022</pre>3059</pre>
@@ -3029,7 +3066,7 @@ then the new elements are filled with <b>nil</b>. · 6 unmodified lines
3029If <code>index</code> is 0, then all stack elements are removed.3066If <code>index</code> is 0, then all stack elements are removed.
3030 3067
3031<p><a name="lua_State"></a>3068<p><a name="lua_State"></a>
3032<hr/><h3><code>lua_State</code></h3>3069<hr /><h3><code>lua_State</code></h3>
3033<pre>3070<pre>
3034 typedef struct lua_State lua_State;3071 typedef struct lua_State lua_State;
3035</pre>3072</pre>
@@ -3044,8 +3081,21 @@ All information about a state is kept in this structure. · 8 unmodified lines
3044every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,3081every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
3045which creates a Lua state from scratch.3082which creates a Lua state from scratch.
3046 3083
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,
3094an error code if the thread finished its execution with an error,
3095or <code>LUA_YIELD</code> if the thread is suspended.
3096
3047<p><a name="lua_toboolean"></a>3097<p><a name="lua_toboolean"></a>
3048<hr/><h3><code>lua_toboolean</code></h3>3098<hr /><h3><code>lua_toboolean</code></h3>
3049<pre>3099<pre>
3050 int lua_toboolean (lua_State *L, int index);3100 int lua_toboolean (lua_State *L, int index);
3051</pre>3101</pre>
@@ -3058,11 +3108,11 @@ Like all tests in Lua, · 6 unmodified lines
3058different from <b>false</b> and <b>nil</b>;3108different from <b>false</b> and <b>nil</b>;
3059otherwise it returns 0.3109otherwise it returns 0.
3060It also returns 0 when called with a non-valid index.3110It 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,
3062use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)3112use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
3063 3113
3064<p><a name="lua_tocfunction"></a>3114<p><a name="lua_tocfunction"></a>
3065<hr/><h3><code>lua_tocfunction</code></h3>3115<hr /><h3><code>lua_tocfunction</code></h3>
3066<pre>3116<pre>
3067 lua_CFunction lua_tocfunction (lua_State *L, int index);3117 lua_CFunction lua_tocfunction (lua_State *L, int index);
3068</pre>3118</pre>
@@ -3073,7 +3123,7 @@ That value must be a C function; · 4 unmodified lines
3073otherwise, returns <code>NULL</code>.3123otherwise, returns <code>NULL</code>.
3074 3124
3075<p><a name="lua_tointeger"></a>3125<p><a name="lua_tointeger"></a>
3076<hr/><h3><code>lua_tointeger</code></h3>3126<hr /><h3><code>lua_tointeger</code></h3>
3077<pre>3127<pre>
3078 lua_Integer lua_tointeger (lua_State *L, int idx);3128 lua_Integer lua_tointeger (lua_State *L, int idx);
3079</pre>3129</pre>
@@ -3089,7 +3139,7 @@ otherwise, <a href="#lua_tointeger"><code>lua_tointeger</code></a> returns 0. · 9 unmodified lines
3089it is truncated in some non-specified way.3139it is truncated in some non-specified way.
3090 3140
3091<p><a name="lua_tolstring"></a>3141<p><a name="lua_tolstring"></a>
3092<hr/><h3><code>lua_tolstring</code></h3>3142<hr /><h3><code>lua_tolstring</code></h3>
3093<pre>3143<pre>
3094 const char *lua_tolstring (lua_State *L, int index, size_t *len);3144 const char *lua_tolstring (lua_State *L, int index, size_t *len);
3095</pre>3145</pre>
@@ -3105,11 +3155,11 @@ If the value is a number, · 9 unmodified lines
3105then <a href="#lua_tolstring"><code>lua_tolstring</code></a> also3155then <a href="#lua_tolstring"><code>lua_tolstring</code></a> also
3106<em>changes the actual value in the stack to a string</em>.3156<em>changes the actual value in the stack to a string</em>.
3107(This change confuses <a href="#lua_next"><code>lua_next</code></a>3157(This change confuses <a href="#lua_next"><code>lua_next</code></a>
3108when <a href="#lua_tolstring"><code>lua_tolstring</code></a> is applied to keys.)3158when <a href="#lua_tolstring"><code>lua_tolstring</code></a> is applied to keys during a table traversal.)
3109 3159
3110<p><a href="#lua_tolstring"><code>lua_tolstring</code></a> returns a fully aligned pointer3160<p><a href="#lua_tolstring"><code>lua_tolstring</code></a> returns a fully aligned pointer
3111to a string inside the Lua state.3161to a string inside the Lua state.
3112This string always has a zero (<code>'\0'</code>)3162This string always has a zero (`<code>\0</code>&acute;)
3113after its last character (as in C),3163after its last character (as in C),
3114but may contain other zeros in its body.3164but may contain other zeros in its body.
3115Because Lua has garbage collection,3165Because 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
3117will be valid after the corresponding value is removed from the stack.3167will be valid after the corresponding value is removed from the stack.
3118 3168
3119<p><a name="lua_tonumber"></a>3169<p><a name="lua_tonumber"></a>
3120<hr/><h3><code>lua_tonumber</code></h3>3170<hr /><h3><code>lua_tonumber</code></h3>
3121<pre>3171<pre>
3122 lua_Number lua_tonumber (lua_State *L, int index);3172 lua_Number lua_tonumber (lua_State *L, int index);
3123</pre>3173</pre>
@@ -3130,23 +3180,23 @@ The Lua value must be a number or a string convertible to number · 6 unmodified lines
3130otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0.3180otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0.
3131 3181
3132<p><a name="lua_topointer"></a>3182<p><a name="lua_topointer"></a>
3133<hr/><h3><code>lua_topointer</code></h3>3183<hr /><h3><code>lua_topointer</code></h3>
3134<pre>3184<pre>
3135 const void *lua_topointer (lua_State *L, int index);3185 const void *lua_topointer (lua_State *L, int index);
3136</pre>3186</pre>
3137 3187
3138 3188
3139<p>Converts the value at the given acceptable index to a generic3189<p>Converts the value at the given acceptable index to a generic
3140C pointer (<code>void *</code>).3190C pointer (<code>void*</code>).
3141The value may be a userdata, a table, a thread, or a function;3191The value may be a userdata, a table, a thread, or a function;
3142otherwise, <a href="#lua_topointer"><code>lua_topointer</code></a> returns <code>NULL</code>.3192otherwise, <a href="#lua_topointer"><code>lua_topointer</code></a> returns <code>NULL</code>.
3143Lua ensures that different objects return different pointers.3193Lua ensures that different objects return different pointers.
3144There is no direct way to convert the pointer back to its original value.3194There is no direct way to convert the pointer back to its original value.
3145 3195
3146<p>Typically this function is used for debug information.3196<p>Typically this function is used only for debug information.
3147 3197
3148<p><a name="lua_tostring"></a>3198<p><a name="lua_tostring"></a>
3149<hr/><h3><code>lua_tostring</code></h3>3199<hr /><h3><code>lua_tostring</code></h3>
3150<pre>3200<pre>
3151 const char *lua_tostring (lua_State *L, int index);3201 const char *lua_tostring (lua_State *L, int index);
3152</pre>3202</pre>
@@ -3155,19 +3205,19 @@ There is no direct way to convert the pointer back to its original value. · 2 unmodified lines
3155<p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.3205<p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.
3156 3206
3157<p><a name="lua_tothread"></a>3207<p><a name="lua_tothread"></a>
3158<hr/><h3><code>lua_tothread</code></h3>3208<hr /><h3><code>lua_tothread</code></h3>
3159<pre>3209<pre>
3160 lua_State *lua_tothread (lua_State *L, int index);3210 lua_State *lua_tothread (lua_State *L, int index);
3161</pre>3211</pre>
3162 3212
3163 3213
3164<p>Converts the value at the given acceptable index to a Lua thread3214<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>).
3166This value must be a thread;3216This value must be a thread;
3167otherwise, the function returns <code>NULL</code>.3217otherwise, the function returns <code>NULL</code>.
3168 3218
3169<p><a name="lua_touserdata"></a>3219<p><a name="lua_touserdata"></a>
3170<hr/><h3><code>lua_touserdata</code></h3>3220<hr /><h3><code>lua_touserdata</code></h3>
3171<pre>3221<pre>
3172 void *lua_touserdata (lua_State *L, int index);3222 void *lua_touserdata (lua_State *L, int index);
3173</pre>3223</pre>
@@ -3180,7 +3230,7 @@ returns its pointer. · 6 unmodified lines
3180Otherwise, returns <code>NULL</code>.3230Otherwise, returns <code>NULL</code>.
3181 3231
3182<p><a name="lua_type"></a>3232<p><a name="lua_type"></a>
3183<hr/><h3><code>lua_type</code></h3>3233<hr /><h3><code>lua_type</code></h3>
3184<pre>3234<pre>
3185 int lua_type (lua_State *L, int index);3235 int lua_type (lua_State *L, int index);
3186</pre>3236</pre>
@@ -3199,10 +3249,21 @@ defined in <code>lua.h</code>: · 12 unmodified lines
3199<code>LUA_TFUNCTION</code>,3249<code>LUA_TFUNCTION</code>,
3200<code>LUA_TUSERDATA</code>,3250<code>LUA_TUSERDATA</code>,
3201<code>LUA_TTHREAD</code>,3251<code>LUA_TTHREAD</code>,
3252and
3202<code>LUA_TLIGHTUSERDATA</code>.3253<code>LUA_TLIGHTUSERDATA</code>.
3203 3254
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>,
3263which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>.
3264
3204<p><a name="lua_Writer"></a>3265<p><a name="lua_Writer"></a>
3205<hr/><h3><code>lua_Writer</code></h3>3266<hr /><h3><code>lua_Writer</code></h3>
3206<pre>3267<pre>
3207 typedef int (*lua_Writer)3268 typedef int (*lua_Writer)
3208 (lua_State *L, const void* p, size_t sz, void* ud);3269 (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
3223calling the writer again.3284calling the writer again.
3224 3285
3225<p><a name="lua_xmove"></a>3286<p><a name="lua_xmove"></a>
3226<hr/><h3><code>lua_xmove</code></h3>3287<hr /><h3><code>lua_xmove</code></h3>
3227<pre>3288<pre>
3228 void lua_xmove (lua_State *from, lua_State *to, int n);3289 void lua_xmove (lua_State *from, lua_State *to, int n);
3229</pre>3290</pre>
3230 3291
3231 3292
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.
3233 3294
3234<p>This function pops <code>n</code> values from the stack <code>from</code>,3295<p>This function pops <code>n</code> values from the stack <code>from</code>,
3235and pushes them into the stack <code>to</code>.3296and pushes them into the stack <code>to</code>.
3236 3297
3237<p><a name="lua_yield"></a>3298<p><a name="lua_yield"></a>
3238<hr/><h3><code>lua_yield</code></h3>3299<hr /><h3><code>lua_yield</code></h3>
3239<pre>3300<pre>
3240 int lua_yield (lua_State *L, int nresults);3301 int lua_yield (lua_State *L, int nresults);
3241</pre>3302</pre>
@@ -3243,7 +3304,7 @@ and pushes them into the stack <code>to</code>. · 1 unmodified line
3243 3304
3244<p>Yields a coroutine.3305<p>Yields a coroutine.
3245 3306
3246<p>This function can only be called as the3307<p>This function should only be called as the
3247return expression of a C function, as follows:3308return expression of a C function, as follows:
3248<pre>3309<pre>
3249 return lua_yield (L, nresults);3310 return lua_yield (L, nresults);
@@ -3265,20 +3326,19 @@ kinds of debuggers, profilers, and other tools · 15 unmodified lines
3265that need "inside information" from the interpreter.3326that need "inside information" from the interpreter.
3266 3327
3267<p><a name="lua_Debug"></a>3328<p><a name="lua_Debug"></a>
3268<hr/><h3><code>lua_Debug</code></h3>3329<hr /><h3><code>lua_Debug</code></h3>
3269<pre>3330<pre>
3270 typedef struct lua_Debug {3331 typedef struct lua_Debug {
3271 int event;3332 int event;
3272 const char *name; /* (n) */3333 const char *name; /* (n) */
3273 const char *namewhat; /* (n) */3334 const char *namewhat; /* (n) */
3274 const char *what; /* (S) */3335 const char *what; /* (S) */
3275 const char *source; /* (S) */3336 const char *source; /* (S) */
3276 int currentline; /* (l) */3337 int currentline; /* (l) */
3277 int nups; /* (u) number of upvalues */3338 int nups; /* (u) number of upvalues */
3278 int linedefined; /* (S) */3339 int linedefined; /* (S) */
3279 int lastlinedefined; /* (S) */3340 int lastlinedefined; /* (S) */
3280 char short_src[LUA_IDSIZE]; /* (S) */3341 char short_src[LUA_IDSIZE]; /* (S) */
3281
3282 /* private part */3342 /* private part */
3283 ...3343 ...
3284 } lua_Debug;3344 } lua_Debug;
@@ -3295,36 +3355,37 @@ call <a href="#lua_getinfo"><code>lua_getinfo</code></a>. · 10 unmodified lines
3295 3355
3296<p>The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:3356<p>The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:
3297<ul>3357<ul>
3298<li><b><code>source</code></b>3358<li><b><code>source</code></b> ---
3299If the function was defined in a string,3359If the function was defined in a string,
3300then <code>source</code> is that string.3360then <code>source</code> is that string.
3301If the function was defined in a file,3361If the function was defined in a file,
3302then <code>source</code> starts with a `<code>@</code>&acute; followed by the file name.3362then <code>source</code> starts with a `<code>@</code>&acute; followed by the file name.
3303 3363
3304<p><li><b><code>short_src</code></b>3364<p><li><b><code>short_src</code></b> ---
3305A "printable" version of <code>source</code>, to be used in error messages.3365a "printable" version of <code>source</code>, to be used in error messages.
3306 3366
3307<p><li><b><code>linedefined</code></b>3367<p><li><b><code>linedefined</code></b> ---
3308the line number where the definition of the function starts.3368the line number where the definition of the function starts.
3309 3369
3310<p><li><b><code>lastlinedefined</code></b>3370<p><li><b><code>lastlinedefined</code></b> ---
3311the line number where the definition of the function ends.3371the line number where the definition of the function ends.
3312 3372
3313<p><li><b><code>what</code></b> the string <code>"Lua"</code> if this is a Lua function,3373<p><li><b><code>what</code></b> ---
3314<code>"C"</code> if this is a C function,3374the string <code>"Lua"</code> if the function is a Lua function,
3315<code>"main"</code> if this is the main part of a chunk,3375<code>"C"</code> if it is a C function,
3316and <code>"tail"</code> if this was a function that did a tail call.3376<code>"main"</code> if it is the main part of a chunk,
3377and <code>"tail"</code> if it was a function that did a tail call.
3317In the latter case,3378In the latter case,
3318Lua has no other information about this function.3379Lua has no other information about the function.
3319 3380
3320<p><li><b><code>currentline</code></b>3381<p><li><b><code>currentline</code></b> ---
3321the current line where the given function is executing.3382the current line where the given function is executing.
3322When no line information is available,3383When no line information is available,
3323<code>currentline</code> is set to <em>-1</em>.3384<code>currentline</code> is set to <em>-1</em>.
3324 3385
3325<p><li><b><code>name</code></b>3386<p><li><b><code>name</code></b> ---
3326a reasonable name for the given function.3387a reasonable name for the given function.
3327Because functions in Lua are first class values,3388Because functions in Lua are first-class values,
3328they do not have a fixed name:3389they do not have a fixed name:
3329Some functions may be the value of multiple global variables,3390Some functions may be the value of multiple global variables,
3330while others may be stored only in a table field.3391while others may be stored only in a table field.
@@ -3333,21 +3394,21 @@ called to find a suitable name. · 2 unmodified lines
3333If it cannot find a name,3394If it cannot find a name,
3334then <code>name</code> is set to <code>NULL</code>.3395then <code>name</code> is set to <code>NULL</code>.
3335 3396
3336<p><li><b><code>namewhat</code></b>3397<p><li><b><code>namewhat</code></b> ---
3337Explains the <code>name</code> field.3398explains the <code>name</code> field.
3338The value of <code>namewhat</code> can be3399The value of <code>namewhat</code> can be
3339<code>"global"</code>, <code>"local"</code>, <code>"method"</code>,3400<code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
3340<code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),3401<code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
3341according to how the function was called.3402according to how the function was called.
3342(Lua uses the empty string when no other option seems to apply.)3403(Lua uses the empty string when no other option seems to apply.)
3343 3404
3344<p><li><b><code>nups</code></b>3405<p><li><b><code>nups</code></b> ---
3345The number of upvalues of the function.3406the number of upvalues of the function.
3346 3407
3347<p></ul>3408<p></ul>
3348 3409
3349<p><a name="lua_gethook"></a>3410<p><a name="lua_gethook"></a>
3350<hr/><h3><code>lua_gethook</code></h3>3411<hr /><h3><code>lua_gethook</code></h3>
3351<pre>3412<pre>
3352 lua_Hook lua_gethook (lua_State *L);3413 lua_Hook lua_gethook (lua_State *L);
3353</pre>3414</pre>
@@ -3356,7 +3417,7 @@ The number of upvalues of the function. · 2 unmodified lines
3356<p>Returns the current hook function.3417<p>Returns the current hook function.
3357 3418
3358<p><a name="lua_gethookcount"></a>3419<p><a name="lua_gethookcount"></a>
3359<hr/><h3><code>lua_gethookcount</code></h3>3420<hr /><h3><code>lua_gethookcount</code></h3>
3360<pre>3421<pre>
3361 int lua_gethookcount (lua_State *L);3422 int lua_gethookcount (lua_State *L);
3362</pre>3423</pre>
@@ -3365,7 +3426,7 @@ The number of upvalues of the function. · 2 unmodified lines
3365<p>Returns the current hook count.3426<p>Returns the current hook count.
3366 3427
3367<p><a name="lua_gethookmask"></a>3428<p><a name="lua_gethookmask"></a>
3368<hr/><h3><code>lua_gethookmask</code></h3>3429<hr /><h3><code>lua_gethookmask</code></h3>
3369<pre>3430<pre>
3370 int lua_gethookmask (lua_State *L);3431 int lua_gethookmask (lua_State *L);
3371</pre>3432</pre>
@@ -3374,7 +3435,7 @@ The number of upvalues of the function. · 2 unmodified lines
3374<p>Returns the current hook mask.3435<p>Returns the current hook mask.
3375 3436
3376<p><a name="lua_getinfo"></a>3437<p><a name="lua_getinfo"></a>
3377<hr/><h3><code>lua_getinfo</code></h3>3438<hr /><h3><code>lua_getinfo</code></h3>
3378<pre>3439<pre>
3379 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);3440 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
3380</pre>3441</pre>
@@ -3408,7 +3469,7 @@ you can write the following code: · 27 unmodified lines
3408</pre>3469</pre>
3409 3470
3410<p><a name="lua_getlocal"></a>3471<p><a name="lua_getlocal"></a>
3411<hr/><h3><code>lua_getlocal</code></h3>3472<hr /><h3><code>lua_getlocal</code></h3>
3412<pre>3473<pre>
3413 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);3474 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
3414</pre>3475</pre>
@@ -3421,7 +3482,7 @@ given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>). · 6 unmodified lines
3421The index <code>n</code> selects which local variable to inspect3482The index <code>n</code> selects which local variable to inspect
3422(1 is the first parameter or active local variable, and so on,3483(1 is the first parameter or active local variable, and so on,
3423until the last active local variable).3484until 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
3425and returns its name.3486and returns its name.
3426 3487
3427<p>Variable names starting with `<code>(</code>&acute; (open parentheses)3488<p>Variable names starting with `<code>(</code>&acute; (open parentheses)
@@ -3433,7 +3494,7 @@ when the index is greater than · 5 unmodified lines
3433the number of active local variables.3494the number of active local variables.
3434 3495
3435<p><a name="lua_getstack"></a>3496<p><a name="lua_getstack"></a>
3436<hr/><h3><code>lua_getstack</code></h3>3497<hr /><h3><code>lua_getstack</code></h3>
3437<pre>3498<pre>
3438 int lua_getstack (lua_State *L, int level, lua_Debug *ar);3499 int lua_getstack (lua_State *L, int level, lua_Debug *ar);
3439</pre>3500</pre>
@@ -3451,7 +3512,7 @@ when called with a level greater than the stack depth, · 11 unmodified lines
3451it returns 0.3512it returns 0.
3452 3513
3453<p><a name="lua_getupvalue"></a>3514<p><a name="lua_getupvalue"></a>
3454<hr/><h3><code>lua_getupvalue</code></h3>3515<hr /><h3><code>lua_getupvalue</code></h3>
3455<pre>3516<pre>
3456 const char *lua_getupvalue (lua_State *L, int funcindex, int n);3517 const char *lua_getupvalue (lua_State *L, int funcindex, int n);
3457</pre>3518</pre>
@@ -3466,7 +3527,8 @@ pushes the upvalue's value onto the stack, · 8 unmodified lines
3466and returns its name.3527and returns its name.
3467<code>funcindex</code> points to the closure in the stack.3528<code>funcindex</code> points to the closure in the stack.
3468(Upvalues have no particular order,3529(Upvalues have no particular order,
3469as they are active through the whole function.)3530as they are active through the whole function.
3531So, they are numbered in an arbitrary order.)
3470 3532
3471<p>Returns <code>NULL</code> (and pushes nothing)3533<p>Returns <code>NULL</code> (and pushes nothing)
3472when the index is greater than the number of upvalues.3534when 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
3474as a name for all upvalues.3536as a name for all upvalues.
3475 3537
3476<p><a name="lua_Hook"></a>3538<p><a name="lua_Hook"></a>
3477<hr/><h3><code>lua_Hook</code></h3>3539<hr /><h3><code>lua_Hook</code></h3>
3478<pre>3540<pre>
3479 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);3541 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
3480</pre>3542</pre>
@@ -3502,7 +3564,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 21 unmodified lines
3502that execution occurs without any calls to hooks.3564that execution occurs without any calls to hooks.
3503 3565
3504<p><a name="lua_sethook"></a>3566<p><a name="lua_sethook"></a>
3505<hr/><h3><code>lua_sethook</code></h3>3567<hr /><h3><code>lua_sethook</code></h3>
3506<pre>3568<pre>
3507 int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);3569 int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
3508</pre>3570</pre>
@@ -3512,7 +3574,7 @@ that execution occurs without any calls to hooks. · 3 unmodified lines
3512 3574
3513<p><code>func</code> is the hook function.3575<p><code>func</code> is the hook function.
3514<code>mask</code> specifies on which events the hook will be called:3576<code>mask</code> specifies on which events the hook will be called:
3515It is formed by a disjunction of the constants3577It is formed by a bitwise or of the constants
3516<code>LUA_MASKCALL</code>,3578<code>LUA_MASKCALL</code>,
3517<code>LUA_MASKRET</code>,3579<code>LUA_MASKRET</code>,
3518<code>LUA_MASKLINE</code>,3580<code>LUA_MASKLINE</code>,
@@ -3522,9 +3584,11 @@ includes <code>LUA_MASKCOUNT</code>. · 3 unmodified lines
3522For each event, the hook is called as explained below:3584For each event, the hook is called as explained below:
3523<ul>3585<ul>
3524<li><b>The call hook</b> is called when the interpreter calls a function.3586<li><b>The call hook</b> is called when the interpreter calls a function.
3525The hook is called just after Lua enters the new function.3587The hook is called just after Lua enters the new function,
3588before the function gets its arguments.
3526<li><b>The return hook</b> is called when the interpreter returns from a function.3589<li><b>The return hook</b> is called when the interpreter returns from a function.
3527The hook is called just before Lua leaves the function.3590The hook is called just before Lua leaves the function.
3591You have no access to the values to be returned by the function.
3528<li><b>The line hook</b> is called when the interpreter is about to3592<li><b>The line hook</b> is called when the interpreter is about to
3529start the execution of a new line of code,3593start the execution of a new line of code,
3530or when it jumps back in the code (even to the same line).3594or 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
3537<p>A hook is disabled by setting <code>mask</code> to zero.3601<p>A hook is disabled by setting <code>mask</code> to zero.
3538 3602
3539<p><a name="lua_setlocal"></a>3603<p><a name="lua_setlocal"></a>
3540<hr/><h3><code>lua_setlocal</code></h3>3604<hr /><h3><code>lua_setlocal</code></h3>
3541<pre>3605<pre>
3542 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);3606 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
3543</pre>3607</pre>
3544 3608
3545 3609
3546<p>Sets the value of a local variable of a given activation record.3610<p>Sets the value of a local variable of a given activation record.
3547Parameters <code>ar</code> and <code>n</code> are like in <a href="#lua_getlocal"><code>lua_getlocal</code></a>3611Parameters <code>ar</code> and <code>n</code> are as in <a href="#lua_getlocal"><code>lua_getlocal</code></a>
3548(see <a href="#lua_getlocal"></a>).3612(see <a href="#lua_getlocal"></a>).
3549<a href="#lua_setlocal"><code>lua_setlocal</code></a> assigns the value at the top of the stack3613<a href="#lua_setlocal"><code>lua_setlocal</code></a> assigns the value at the top of the stack
3550to the variable and returns its name.3614to the variable and returns its name.
@@ -3555,14 +3619,14 @@ when the index is greater than · 4 unmodified lines
3555the number of active local variables.3619the number of active local variables.
3556 3620
3557<p><a name="lua_setupvalue"></a>3621<p><a name="lua_setupvalue"></a>
3558<hr/><h3><code>lua_setupvalue</code></h3>3622<hr /><h3><code>lua_setupvalue</code></h3>
3559<pre>3623<pre>
3560 const char *lua_setupvalue (lua_State *L, int funcindex, int n);3624 const char *lua_setupvalue (lua_State *L, int funcindex, int n);
3561</pre>3625</pre>
3562 3626
3563 3627
3564<p>Sets the value of a closure's upvalue.3628<p>Sets the value of a closure's upvalue.
3565Parameters <code>funcindex</code> and <code>n</code> are like in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>3629Parameters <code>funcindex</code> and <code>n</code> are as in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
3566(see <a href="#lua_getupvalue"></a>).3630(see <a href="#lua_getupvalue"></a>).
3567It assigns the value at the top of the stack3631It assigns the value at the top of the stack
3568to the upvalue and returns its name.3632to the upvalue and returns its name.
@@ -3586,17 +3650,17 @@ common tasks. · 17 unmodified lines
3586are defined in header file <code>lauxlib.h</code> and3650are defined in header file <code>lauxlib.h</code> and
3587have a prefix <code>luaL_</code>.3651have a prefix <code>luaL_</code>.
3588 3652
3589<p>All functions in the auxiliary library are build on3653<p>All functions in the auxiliary library are built on
3590top of the basic API, so they provide nothing that cannot3654top of the basic API,
3591be done with that API.3655and so they provide nothing that cannot be done with that API.
3592 3656
3593<p>Several functions in the auxiliary library are used to3657<p>Several functions in the auxiliary library are used to
3594check C function arguments.3658check C function arguments.
3595Their names are always <code>luaL_check*</code> or <code>luaL_opt*</code>.3659Their names are always <code>luaL_check*</code> or <code>luaL_opt*</code>.
3596All those functions raise an error if the check is not satisfied.3660All of these functions raise an error if the check is not satisfied.
3597Because the error message is formatted for arguments3661Because the error message is formatted for arguments
3598(e.g., <code>"bad argument #1"</code>),3662(e.g., <code>"bad argument #1"</code>),
3599you should not use those functions for other stack values.3663you should not use these functions for other stack values.
3600 3664
3601<p><a name="4.1"></a><h2>4.1 - Functions and Types</h2>3665<p><a name="4.1"></a><h2>4.1 - Functions and Types</h2>
3602 3666
@@ -3604,7 +3668,7 @@ you should not use those functions for other stack values. · 1 unmodified line
3604in alphabetical order.3668in alphabetical order.
3605 3669
3606<p><a name="luaL_addchar"></a>3670<p><a name="luaL_addchar"></a>
3607<hr/><h3><code>luaL_addchar</code></h3>3671<hr /><h3><code>luaL_addchar</code></h3>
3608<pre>3672<pre>
3609 void luaL_addchar (luaL_Buffer B, char c);3673 void luaL_addchar (luaL_Buffer B, char c);
3610</pre>3674</pre>
@@ -3614,7 +3678,7 @@ in alphabetical order. · 3 unmodified lines
3614(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3678(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3615 3679
3616<p><a name="luaL_addlstring"></a>3680<p><a name="luaL_addlstring"></a>
3617<hr/><h3><code>luaL_addlstring</code></h3>3681<hr /><h3><code>luaL_addlstring</code></h3>
3618<pre>3682<pre>
3619 void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);3683 void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
3620</pre>3684</pre>
@@ -3623,9 +3687,10 @@ in alphabetical order. · 2 unmodified lines
3623<p>Adds the string pointed by <code>s</code> with length <code>l</code> to3687<p>Adds the string pointed by <code>s</code> with length <code>l</code> to
3624the buffer <code>B</code>3688the buffer <code>B</code>
3625(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3689(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3690The string may contain embedded zeros.
3626 3691
3627<p><a name="luaL_addsize"></a>3692<p><a name="luaL_addsize"></a>
3628<hr/><h3><code>luaL_addsize</code></h3>3693<hr /><h3><code>luaL_addsize</code></h3>
3629<pre>3694<pre>
3630 void luaL_addsize (luaL_Buffer B, size_t n);3695 void luaL_addsize (luaL_Buffer B, size_t n);
3631</pre>3696</pre>
@@ -3636,7 +3701,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 4 unmodified lines
3636(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3701(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3637 3702
3638<p><a name="luaL_addstring"></a>3703<p><a name="luaL_addstring"></a>
3639<hr/><h3><code>luaL_addstring</code></h3>3704<hr /><h3><code>luaL_addstring</code></h3>
3640<pre>3705<pre>
3641 void luaL_addstring (luaL_Buffer *B, const char *s);3706 void luaL_addstring (luaL_Buffer *B, const char *s);
3642</pre>3707</pre>
@@ -3645,9 +3710,10 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 2 unmodified lines
3645<p>Adds the zero-terminated string pointed by <code>s</code>3710<p>Adds the zero-terminated string pointed by <code>s</code>
3646to the buffer <code>B</code>3711to the buffer <code>B</code>
3647(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3712(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3713The string may not contain embedded zeros.
3648 3714
3649<p><a name="luaL_addvalue"></a>3715<p><a name="luaL_addvalue"></a>
3650<hr/><h3><code>luaL_addvalue</code></h3>3716<hr /><h3><code>luaL_addvalue</code></h3>
3651<pre>3717<pre>
3652 void luaL_addvalue (luaL_Buffer *B);3718 void luaL_addvalue (luaL_Buffer *B);
3653</pre>3719</pre>
@@ -3663,7 +3729,7 @@ be called with an extra element on the stack, · 9 unmodified lines
3663which is the value to be added to the buffer.3729which is the value to be added to the buffer.
3664 3730
3665<p><a name="luaL_argcheck"></a>3731<p><a name="luaL_argcheck"></a>
3666<hr/><h3><code>luaL_argcheck</code></h3>3732<hr /><h3><code>luaL_argcheck</code></h3>
3667<pre>3733<pre>
3668 void luaL_argcheck (lua_State *L, int cond, int numarg,3734 void luaL_argcheck (lua_State *L, int cond, int numarg,
3669 const char *extramsg);3735 const char *extramsg);
@@ -3671,12 +3737,12 @@ which is the value to be added to the buffer. · 1 unmodified line
3671 3737
3672 3738
3673<p>Checks whether <code>cond</code> is true.3739<p>Checks whether <code>cond</code> is true.
3674If not, raise an error with message3740If not, raises an error with message
3675<code>"bad argument #&#060;numarg> to &#060;func> (&#060;extramsg>)"</code>,3741<code>"bad argument #&#060;numarg> to &#060;func> (&#060;extramsg>)"</code>,
3676where <code>func</code> is retrieved from the call stack.3742where <code>func</code> is retrieved from the call stack.
3677 3743
3678<p><a name="luaL_argerror"></a>3744<p><a name="luaL_argerror"></a>
3679<hr/><h3><code>luaL_argerror</code></h3>3745<hr /><h3><code>luaL_argerror</code></h3>
3680<pre>3746<pre>
3681 int luaL_argerror (lua_State *L, int numarg, const char *extramsg);3747 int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
3682</pre>3748</pre>
@@ -3686,10 +3752,12 @@ where <code>func</code> is retrieved from the call stack. · 3 unmodified lines
3686<code>"bad argument #&#060;numarg> to &#060;func> (&#060;extramsg>)"</code>,3752<code>"bad argument #&#060;numarg> to &#060;func> (&#060;extramsg>)"</code>,
3687where <code>func</code> is retrieved from the call stack.3753where <code>func</code> is retrieved from the call stack.
3688 3754
3689<p>This function never returns.3755<p>This function never returns,
3756but it is an idiom to use it as <code>return luaL_argerror ...</code>
3757in C functions.
3690 3758
3691<p><a name="luaL_Buffer"></a>3759<p><a name="luaL_Buffer"></a>
3692<hr/><h3><code>luaL_Buffer</code></h3>3760<hr /><h3><code>luaL_Buffer</code></h3>
3693<pre>3761<pre>
3694 typedef struct luaL_Buffer luaL_Buffer;3762 typedef struct luaL_Buffer luaL_Buffer;
3695</pre>3763</pre>
@@ -3700,21 +3768,23 @@ where <code>func</code> is retrieved from the call stack. · 4 unmodified lines
3700<p>A string buffer allows C code to build Lua strings piecemeal.3768<p>A string buffer allows C code to build Lua strings piecemeal.
3701Its pattern of use is as follows:3769Its pattern of use is as follows:
3702<ul>3770<ul>
3703<li> Fist you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.3771<li> First 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>.3772<li> Then you initialize it with a call <code>luaL_buffinit(L, &#038;b)</code>.
3705<li> Then you add string pieces to the buffer calling any of3773<li> Then you add string pieces to the buffer calling any of
3706the <code>luaL_add*</code> functions.3774the <code>luaL_add*</code> functions.
3707<li> You finish calling <code>luaL_pushresult(&#038;b)</code>.3775<li> You finish calling <code>luaL_pushresult(&#038;b)</code>.
3708That call leaves the final string on the top of the stack.3776That call leaves the final string on the top of the stack.
3709</ul>3777</ul>
3710 3778
3711<p>During its normal operation a string buffer uses a3779<p>During its normal operation,
3712variable number of stack slots.3780a string buffer uses a variable number of stack slots.
3713So, while using a buffer, you cannot assume that you know where3781So, while using a buffer, you cannot assume that you know where
3714is the top of the stack.3782the top of the stack is.
3715You can use the stack between successive calls to buffer operations,3783You can use the stack between successive calls to buffer operations
3716as long as that use is balanced, that is,3784as long as that use is balanced;
3717when you call a buffer operation the stack is at the same level3785that is,
3786when you call a buffer operation,
3787the stack is at the same level
3718it was immediately after the previous buffer operation.3788it was immediately after the previous buffer operation.
3719(The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)3789(The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)
3720After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a> the stack is back to its3790After 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
3722plus the final string on its top.3792plus the final string on its top.
3723 3793
3724<p><a name="luaL_buffinit"></a>3794<p><a name="luaL_buffinit"></a>
3725<hr/><h3><code>luaL_buffinit</code></h3>3795<hr /><h3><code>luaL_buffinit</code></h3>
3726<pre>3796<pre>
3727 void luaL_buffinit (lua_State *L, luaL_Buffer *B);3797 void luaL_buffinit (lua_State *L, luaL_Buffer *B);
3728</pre>3798</pre>
@@ -3734,7 +3804,7 @@ the buffer must be declared as a variable · 5 unmodified lines
3734(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3804(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3735 3805
3736<p><a name="luaL_callmeta"></a>3806<p><a name="luaL_callmeta"></a>
3737<hr/><h3><code>luaL_callmeta</code></h3>3807<hr /><h3><code>luaL_callmeta</code></h3>
3738<pre>3808<pre>
3739 int luaL_callmeta (lua_State *L, int obj, const char *e);3809 int luaL_callmeta (lua_State *L, int obj, const char *e);
3740</pre>3810</pre>
@@ -3744,53 +3814,54 @@ the buffer must be declared as a variable · 3 unmodified lines
3744 3814
3745<p>If the object at index <code>obj</code> has a metatable and that3815<p>If the object at index <code>obj</code> has a metatable and that
3746metatable has a field <code>e</code>,3816metatable has a field <code>e</code>,
3747calls that field passing the object as argument.3817this function calls that field and passes the object as its only argument.
3748In that case the function returns 1 and pushes on the3818In that case this function returns 1 and pushes on the
3749stack the value returned by the call.3819stack the value returned by the call.
3750If there is no metatable or no metamethod returns 03820If there is no metatable or no metamethod,
3751(without pushing any value on the stack).3821this function returns 0 (without pushing any value on the stack).
3752 3822
3753<p><a name="luaL_checkany"></a>3823<p><a name="luaL_checkany"></a>
3754<hr/><h3><code>luaL_checkany</code></h3>3824<hr /><h3><code>luaL_checkany</code></h3>
3755<pre>3825<pre>
3756 void luaL_checkany (lua_State *L, int narg);3826 void luaL_checkany (lua_State *L, int narg);
3757</pre>3827</pre>
3758 3828
3759 3829
3760<p>Checks whether the function has an argument <code>narg</code>.3830<p>Checks whether the function has an argument
3831of any type (including <b>nil</b>) at position <code>narg</code>.
3761 3832
3762<p><a name="luaL_checkint"></a>3833<p><a name="luaL_checkint"></a>
3763<hr/><h3><code>luaL_checkint</code></h3>3834<hr /><h3><code>luaL_checkint</code></h3>
3764<pre>3835<pre>
3765 int luaL_checkint (lua_State *L, int narg);3836 int luaL_checkint (lua_State *L, int narg);
3766</pre>3837</pre>
3767 3838
3768 3839
3769<p>Checks whether the function argument <code>narg</code> is a number3840<p>Checks whether the function argument <code>narg</code> is a number
3770and returns that number casted to an <code>int</code>.3841and returns that number cast to an <code>int</code>.
3771 3842
3772<p><a name="luaL_checkinteger"></a>3843<p><a name="luaL_checkinteger"></a>
3773<hr/><h3><code>luaL_checkinteger</code></h3>3844<hr /><h3><code>luaL_checkinteger</code></h3>
3774<pre>3845<pre>
3775 lua_Integer luaL_checkinteger (lua_State *L, int numArg);3846 lua_Integer luaL_checkinteger (lua_State *L, int narg);
3776</pre>3847</pre>
3777 3848
3778 3849
3779<p>Checks whether the function argument <code>narg</code> is a number3850<p>Checks whether the function argument <code>narg</code> is a number
3780and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.3851and returns that number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
3781 3852
3782<p><a name="luaL_checklong"></a>3853<p><a name="luaL_checklong"></a>
3783<hr/><h3><code>luaL_checklong</code></h3>3854<hr /><h3><code>luaL_checklong</code></h3>
3784<pre>3855<pre>
3785 long luaL_checklong (lua_State *L, int narg);3856 long luaL_checklong (lua_State *L, int narg);
3786</pre>3857</pre>
3787 3858
3788 3859
3789<p>Checks whether the function argument <code>narg</code> is a number3860<p>Checks whether the function argument <code>narg</code> is a number
3790and returns that number casted to a <code>long</code>.3861and returns that number cast to a <code>long</code>.
3791 3862
3792<p><a name="luaL_checklstring"></a>3863<p><a name="luaL_checklstring"></a>
3793<hr/><h3><code>luaL_checklstring</code></h3>3864<hr /><h3><code>luaL_checklstring</code></h3>
3794<pre>3865<pre>
3795 const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);3866 const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);
3796</pre>3867</pre>
@@ -3798,11 +3869,11 @@ and returns that number casted to a <code>long</code>. · 1 unmodified line
3798 3869
3799<p>Checks whether the function argument <code>narg</code> is a string3870<p>Checks whether the function argument <code>narg</code> is a string
3800and returns that string;3871and returns that string;
3801if <code>l</code> is not <code>NULL</code> fills the position <code>*l</code>3872if <code>l</code> is not <code>NULL</code> fills <code>*l</code>
3802with the string's length.3873with the string's length.
3803 3874
3804<p><a name="luaL_checknumber"></a>3875<p><a name="luaL_checknumber"></a>
3805<hr/><h3><code>luaL_checknumber</code></h3>3876<hr /><h3><code>luaL_checknumber</code></h3>
3806<pre>3877<pre>
3807 lua_Number luaL_checknumber (lua_State *L, int numArg);3878 lua_Number luaL_checknumber (lua_State *L, int numArg);
3808</pre>3879</pre>
@@ -3812,7 +3883,7 @@ with the string's length. · 3 unmodified lines
3812and returns that number.3883and returns that number.
3813 3884
3814<p><a name="luaL_checkoption"></a>3885<p><a name="luaL_checkoption"></a>
3815<hr/><h3><code>luaL_checkoption</code></h3>3886<hr /><h3><code>luaL_checkoption</code></h3>
3816<pre>3887<pre>
3817 int luaL_checkoption (lua_State *L, int narg, const char *def,3888 int luaL_checkoption (lua_State *L, int narg, const char *def,
3818 const char *const lst[]);3889 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
3830Raises an error if the argument is not a string or3901Raises an error if the argument is not a string or
3831if the string cannot be found.3902if the string cannot be found.
3832 3903
3904<p>This is a useful function for mapping strings to C enums.
3905The usual interfaces in Lua libraries is to use strings instead of numbers
3906to select options.
3907
3833<p><a name="luaL_checkstack"></a>3908<p><a name="luaL_checkstack"></a>
3834<hr/><h3><code>luaL_checkstack</code></h3>3909<hr /><h3><code>luaL_checkstack</code></h3>
3835<pre>3910<pre>
3836 void luaL_checkstack (lua_State *L, int sz, const char *msg);3911 void luaL_checkstack (lua_State *L, int sz, const char *msg);
3837</pre>3912</pre>
@@ -3842,7 +3917,7 @@ raising an error if the stack cannot grow to that size. · 4 unmodified lines
3842<code>msg</code> is an additional text to go into the error message.3917<code>msg</code> is an additional text to go into the error message.
3843 3918
3844<p><a name="luaL_checkstring"></a>3919<p><a name="luaL_checkstring"></a>
3845<hr/><h3><code>luaL_checkstring</code></h3>3920<hr /><h3><code>luaL_checkstring</code></h3>
3846<pre>3921<pre>
3847 const char *luaL_checkstring (lua_State *L, int narg);3922 const char *luaL_checkstring (lua_State *L, int narg);
3848</pre>3923</pre>
@@ -3852,7 +3927,7 @@ raising an error if the stack cannot grow to that size. · 3 unmodified lines
3852and returns that string.3927and returns that string.
3853 3928
3854<p><a name="luaL_checktype"></a>3929<p><a name="luaL_checktype"></a>
3855<hr/><h3><code>luaL_checktype</code></h3>3930<hr /><h3><code>luaL_checktype</code></h3>
3856<pre>3931<pre>
3857 void luaL_checktype (lua_State *L, int narg, int t);3932 void luaL_checktype (lua_State *L, int narg, int t);
3858</pre>3933</pre>
@@ -3861,7 +3936,7 @@ and returns that string. · 2 unmodified lines
3861<p>Checks whether the function argument <code>narg</code> has type <code>t</code>.3936<p>Checks whether the function argument <code>narg</code> has type <code>t</code>.
3862 3937
3863<p><a name="luaL_checkudata"></a>3938<p><a name="luaL_checkudata"></a>
3864<hr/><h3><code>luaL_checkudata</code></h3>3939<hr /><h3><code>luaL_checkudata</code></h3>
3865<pre>3940<pre>
3866 void *luaL_checkudata (lua_State *L, int ud, const char *tname);3941 void *luaL_checkudata (lua_State *L, int ud, const char *tname);
3867</pre>3942</pre>
@@ -3871,7 +3946,7 @@ and returns that string. · 3 unmodified lines
3871of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).3946of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
3872 3947
3873<p><a name="luaL_error"></a>3948<p><a name="luaL_error"></a>
3874<hr/><h3><code>luaL_error</code></h3>3949<hr /><h3><code>luaL_error</code></h3>
3875<pre>3950<pre>
3876 int luaL_error (lua_State *L, const char *fmt, ...);3951 int luaL_error (lua_State *L, const char *fmt, ...);
3877</pre>3952</pre>
@@ -3885,10 +3960,12 @@ It also adds at the beginning of the message the file name and · 7 unmodified lines
3885the line number where the error occurred,3960the line number where the error occurred,
3886if that information is available.3961if that information is available.
3887 3962
3888<p>This function never returns.3963<p>This function never returns,
3964but it is an idiom to use it as <code>return luaL_error ...</code>
3965in C functions.
3889 3966
3890<p><a name="luaL_getmetafield"></a>3967<p><a name="luaL_getmetafield"></a>
3891<hr/><h3><code>luaL_getmetafield</code></h3>3968<hr /><h3><code>luaL_getmetafield</code></h3>
3892<pre>3969<pre>
3893 int luaL_getmetafield (lua_State *L, int obj, const char *e);3970 int luaL_getmetafield (lua_State *L, int obj, const char *e);
3894</pre>3971</pre>
@@ -3898,10 +3975,10 @@ if that information is available. · 3 unmodified lines
3898of the object at index <code>obj</code>.3975of the object at index <code>obj</code>.
3899If the object does not have a metatable,3976If the object does not have a metatable,
3900or if the metatable does not have that field,3977or if the metatable does not have that field,
3901returns 0 (false) and pushes nothing.3978returns 0 and pushes nothing.
3902 3979
3903<p><a name="luaL_getmetatable"></a>3980<p><a name="luaL_getmetatable"></a>
3904<hr/><h3><code>luaL_getmetatable</code></h3>3981<hr /><h3><code>luaL_getmetatable</code></h3>
3905<pre>3982<pre>
3906 void luaL_getmetatable (lua_State *L, const char *tname);3983 void luaL_getmetatable (lua_State *L, const char *tname);
3907</pre>3984</pre>
@@ -3911,19 +3988,20 @@ returns 0 (false) and pushes nothing. · 3 unmodified lines
3911in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).3988in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
3912 3989
3913<p><a name="luaL_gsub"></a>3990<p><a name="luaL_gsub"></a>
3914<hr/><h3><code>luaL_gsub</code></h3>3991<hr /><h3><code>luaL_gsub</code></h3>
3915<pre>3992<pre>
3916 const char *luaL_gsub (lua_State *L, const char *s,3993 const char *luaL_gsub (lua_State *L, const char *s,
3917 const char *p, const char *r);3994 const char *p, const char *r);
3918</pre>3995</pre>
3919 3996
3920 3997
3921<p>Creates a copy of string <code>s</code> changing any occurrence of <code>p</code>3998<p>Creates a copy of string <code>s</code> by replacing any occurrence
3922by the string <code>r</code>.3999any occurrence of the string <code>p</code>
4000wth the string <code>r</code>.
3923Pushes the resulting string on the stack and returns it.4001Pushes the resulting string on the stack and returns it.
3924 4002
3925<p><a name="luaL_loadbuffer"></a>4003<p><a name="luaL_loadbuffer"></a>
3926<hr/><h3><code>luaL_loadbuffer</code></h3>4004<hr /><h3><code>luaL_loadbuffer</code></h3>
3927<pre>4005<pre>
3928 int luaL_loadbuffer (lua_State *L, const char *buff,4006 int luaL_loadbuffer (lua_State *L, const char *buff,
3929 size_t sz, const char *name);4007 size_t sz, const char *name);
@@ -3939,7 +4017,7 @@ buffer pointed by <code>buff</code> with size <code>sz</code>. · 9 unmodified lines
3939used for debug information and error messages.4017used for debug information and error messages.
3940 4018
3941<p><a name="luaL_loadfile"></a>4019<p><a name="luaL_loadfile"></a>
3942<hr/><h3><code>luaL_loadfile</code></h3>4020<hr /><h3><code>luaL_loadfile</code></h3>
3943<pre>4021<pre>
3944 int luaL_loadfile (lua_State *L, const char *filename);4022 int luaL_loadfile (lua_State *L, const char *filename);
3945</pre>4023</pre>
@@ -3948,14 +4026,16 @@ used for debug information and error messages. · 2 unmodified lines
3948<p>Loads a file as a Lua chunk.4026<p>Loads a file as a Lua chunk.
3949This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file4027This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file
3950named <code>filename</code>.4028named <code>filename</code>.
3951If the file's first line starts with a <code>#</code> it is ignored.4029If <code>filename</code> is <code>NULL</code>,
4030then it loads from the standard input.
4031The first line in the file is ignored if it starts with a <code>#</code>.
3952 4032
3953<p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>,4033<p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>,
3954but it has an extra error code <code>LUA_ERRFILE</code>4034but it has an extra error code <code>LUA_ERRFILE</code>
3955if it cannot open the file.4035if it cannot open/read the file.
3956 4036
3957<p><a name="luaL_loadstring"></a>4037<p><a name="luaL_loadstring"></a>
3958<hr/><h3><code>luaL_loadstring</code></h3>4038<hr /><h3><code>luaL_loadstring</code></h3>
3959<pre>4039<pre>
3960 int luaL_loadstring (lua_State *L, const char *s);4040 int luaL_loadstring (lua_State *L, const char *s);
3961</pre>4041</pre>
@@ -3968,24 +4048,24 @@ the zero-terminated string <code>s</code>. · 6 unmodified lines
3968<p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.4048<p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
3969 4049
3970<p><a name="luaL_newmetatable"></a>4050<p><a name="luaL_newmetatable"></a>
3971<hr/><h3><code>luaL_newmetatable</code></h3>4051<hr /><h3><code>luaL_newmetatable</code></h3>
3972<pre>4052<pre>
3973 int luaL_newmetatable (lua_State *L, const char *tname);4053 int luaL_newmetatable (lua_State *L, const char *tname);
3974</pre>4054</pre>
3975 4055
3976 4056
3977<p>If the register already has the key <code>"tname"</code>,4057<p>If the registry already has the key <code>"tname"</code>,
3978returns 0.4058returns 0.
3979Otherwise,4059Otherwise,
3980creates a new table to be used as metatables for userdata,4060creates a new table to be used as a metatable for userdata,
3981adds it to the register with key <code>"tname"</code>,4061adds it to the registry with key <code>"tname"</code>,
3982and returns 1.4062and returns 1.
3983 4063
3984<p>In both cases pushes on the stack the final value associated4064<p>In both cases pushes on the stack the final value associated
3985with <code>"tname"</code> in the registry.4065with <code>"tname"</code> in the registry.
3986 4066
3987<p><a name="luaL_newstate"></a>4067<p><a name="luaL_newstate"></a>
3988<hr/><h3><code>luaL_newstate</code></h3>4068<hr /><h3><code>luaL_newstate</code></h3>
3989<pre>4069<pre>
3990 lua_State *luaL_newstate (void);4070 lua_State *luaL_newstate (void);
3991</pre>4071</pre>
@@ -3993,7 +4073,7 @@ with <code>"tname"</code> in the registry. · 1 unmodified line
3993 4073
3994<p>Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an4074<p>Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an
3995allocation function based on the standard C <code>realloc</code> function4075allocation function based on the standard C <code>realloc</code> function
3996and setting a panic function ((see <a href="#lua_atpanic"><code>lua_atpanic</code></a>)) that prints4076and setting a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
3997an error message to the standard error output in case of fatal4077an error message to the standard error output in case of fatal
3998errors.4078errors.
3999 4079
@@ -4001,46 +4081,46 @@ errors. · 1 unmodified line
4001or <code>NULL</code> if there is a memory allocation error.4081or <code>NULL</code> if there is a memory allocation error.
4002 4082
4003<p><a name="luaL_optint"></a>4083<p><a name="luaL_optint"></a>
4004<hr/><h3><code>luaL_optint</code></h3>4084<hr /><h3><code>luaL_optint</code></h3>
4005<pre>4085<pre>
4006 int luaL_optint (lua_State *L, int narg, int d);4086 int luaL_optint (lua_State *L, int narg, int d);
4007</pre>4087</pre>
4008 4088
4009 4089
4010<p>If the function argument <code>narg</code> is a number,4090<p>If the function argument <code>narg</code> is a number,
4011returns that number casted to an <code>int</code>.4091returns that number cast to an <code>int</code>.
4012If that argument is absent or is <b>nil</b>,4092If that argument is absent or is <b>nil</b>,
4013returns <code>d</code>.4093returns <code>d</code>.
4014Otherwise, raise an error.4094Otherwise, raises an error.
4015 4095
4016<p><a name="luaL_optinteger"></a>4096<p><a name="luaL_optinteger"></a>
4017<hr/><h3><code>luaL_optinteger</code></h3>4097<hr /><h3><code>luaL_optinteger</code></h3>
4018<pre>4098<pre>
4019 lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d);4099 lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d);
4020</pre>4100</pre>
4021 4101
4022 4102
4023<p>If the function argument <code>narg</code> is a number,4103<p>If the function argument <code>narg</code> is a number,
4024returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.4104returns that number cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
4025If that argument is absent or is <b>nil</b>,4105If that argument is absent or is <b>nil</b>,
4026returns <code>d</code>.4106returns <code>d</code>.
4027Otherwise, raise an error.4107Otherwise, raises an error.
4028 4108
4029<p><a name="luaL_optlong"></a>4109<p><a name="luaL_optlong"></a>
4030<hr/><h3><code>luaL_optlong</code></h3>4110<hr /><h3><code>luaL_optlong</code></h3>
4031<pre>4111<pre>
4032 long luaL_optlong (lua_State *L, int narg, long d);4112 long luaL_optlong (lua_State *L, int narg, long d);
4033</pre>4113</pre>
4034 4114
4035 4115
4036<p>If the function argument <code>narg</code> is a number,4116<p>If the function argument <code>narg</code> is a number,
4037returns that number casted to a <code>long</code>.4117returns that number cast to a <code>long</code>.
4038If that argument is absent or is <b>nil</b>,4118If that argument is absent or is <b>nil</b>,
4039returns <code>d</code>.4119returns <code>d</code>.
4040Otherwise, raise an error.4120Otherwise, raises an error.
4041 4121
4042<p><a name="luaL_optlstring"></a>4122<p><a name="luaL_optlstring"></a>
4043<hr/><h3><code>luaL_optlstring</code></h3>4123<hr /><h3><code>luaL_optlstring</code></h3>
4044<pre>4124<pre>
4045 const char *luaL_optlstring (lua_State *L, int numArg,4125 const char *luaL_optlstring (lua_State *L, int numArg,
4046 const char *d, size_t *l);4126 const char *d, size_t *l);
@@ -4051,13 +4131,13 @@ Otherwise, raise an error. · 4 unmodified lines
4051returns that string.4131returns that string.
4052If that argument is absent or is <b>nil</b>,4132If that argument is absent or is <b>nil</b>,
4053returns <code>d</code>.4133returns <code>d</code>.
4054Otherwise, raise an error.4134Otherwise, raises an error.
4055 4135
4056<p>If <code>l</code> is not <code>NULL</code> fills the position <code>*l</code>4136<p>If <code>l</code> is not <code>NULL</code>,
4057with the results's length.4137fills the position <code>*l</code> with the results's length.
4058 4138
4059<p><a name="luaL_optnumber"></a>4139<p><a name="luaL_optnumber"></a>
4060<hr/><h3><code>luaL_optnumber</code></h3>4140<hr /><h3><code>luaL_optnumber</code></h3>
4061<pre>4141<pre>
4062 lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d);4142 lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d);
4063</pre>4143</pre>
@@ -4067,10 +4147,10 @@ with the results's length. · 3 unmodified lines
4067returns that number.4147returns that number.
4068If that argument is absent or is <b>nil</b>,4148If that argument is absent or is <b>nil</b>,
4069returns <code>d</code>.4149returns <code>d</code>.
4070Otherwise, raise an error.4150Otherwise, raises an error.
4071 4151
4072<p><a name="luaL_optstring"></a>4152<p><a name="luaL_optstring"></a>
4073<hr/><h3><code>luaL_optstring</code></h3>4153<hr /><h3><code>luaL_optstring</code></h3>
4074<pre>4154<pre>
4075 const char *luaL_optstring (lua_State *L, int narg, const char *d);4155 const char *luaL_optstring (lua_State *L, int narg, const char *d);
4076</pre>4156</pre>
@@ -4080,24 +4160,24 @@ Otherwise, raise an error. · 3 unmodified lines
4080returns that string.4160returns that string.
4081If that argument is absent or is <b>nil</b>,4161If that argument is absent or is <b>nil</b>,
4082returns <code>d</code>.4162returns <code>d</code>.
4083Otherwise, raise an error.4163Otherwise, raises an error.
4084 4164
4085<p><a name="luaL_prepbuffer"></a>4165<p><a name="luaL_prepbuffer"></a>
4086<hr/><h3><code>luaL_prepbuffer</code></h3>4166<hr /><h3><code>luaL_prepbuffer</code></h3>
4087<pre>4167<pre>
4088 char *luaL_prepbuffer (luaL_Buffer *B);4168 char *luaL_prepbuffer (luaL_Buffer *B);
4089</pre>4169</pre>
4090 4170
4091 4171
4092<p>Returns an address to a space of size <code>LUAL_BUFFERSIZE</code>4172<p>Returns an address to a space of size <code>LUAL_BUFFERSIZE</code>
4093wherein you can copy a string to be added to buffer <code>B</code>4173where you can copy a string to be added to buffer <code>B</code>
4094(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).4174(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
4095After copying the string into that space you must call4175After copying the string into that space you must call
4096<a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add 4176<a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add
4097it to the buffer.4177it to the buffer.
4098 4178
4099<p><a name="luaL_pushresult"></a>4179<p><a name="luaL_pushresult"></a>
4100<hr/><h3><code>luaL_pushresult</code></h3>4180<hr /><h3><code>luaL_pushresult</code></h3>
4101<pre>4181<pre>
4102 void luaL_pushresult (luaL_Buffer *B);4182 void luaL_pushresult (luaL_Buffer *B);
4103</pre>4183</pre>
@@ -4107,7 +4187,7 @@ it to the buffer. · 3 unmodified lines
4107the top of the stack.4187the top of the stack.
4108 4188
4109<p><a name="luaL_ref"></a>4189<p><a name="luaL_ref"></a>
4110<hr/><h3><code>luaL_ref</code></h3>4190<hr /><h3><code>luaL_ref</code></h3>
4111<pre>4191<pre>
4112 int luaL_ref (lua_State *L, int t);4192 int luaL_ref (lua_State *L, int t);
4113</pre>4193</pre>
@@ -4118,19 +4198,19 @@ in the table at index <code>t</code>, · 4 unmodified lines
4118for the object at the top of the stack (and pops the object).4198for the object at the top of the stack (and pops the object).
4119 4199
4120<p>A reference is a unique integer key.4200<p>A reference is a unique integer key.
4121As long as you do not add integer keys into table <code>t</code>,4201As long as you do not manually add integer keys into table <code>t</code>,
4122<a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.4202<a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.
4123You can retrieve an object referred by reference <code>r</code>4203You can retrieve an object referred by reference <code>r</code>
4124calling <code>lua_rawgeti(L, t, r)</code>.4204by calling <code>lua_rawgeti(L, t, r)</code>.
4125Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.4205Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.
4126 4206
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>,
4128<a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>.4208<a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>.
4129The constant <code>LUA_NOREF</code> is garanteed to be different4209The constant <code>LUA_NOREF</code> is guaranteed to be different
4130from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.4210from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
4131 4211
4132<p><a name="luaL_Reg"></a>4212<p><a name="luaL_Reg"></a>
4133<hr/><h3><code>luaL_Reg</code></h3>4213<hr /><h3><code>luaL_Reg</code></h3>
4134<pre>4214<pre>
4135 typedef struct luaL_Reg {4215 typedef struct luaL_Reg {
4136 const char *name;4216 const char *name;
@@ -4140,15 +4220,15 @@ from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>. · 3 unmodified lines
4140</pre>4220</pre>
4141 4221
4142 4222
4143<p>Format for arrays of functions to be registered by4223<p>Type for arrays of functions to be registered by
4144<a href="#luaL_register"><code>luaL_register</code></a>.4224<a href="#luaL_register"><code>luaL_register</code></a>.
4145<code>name</code> is the function name and <code>func</code> is a pointer to4225<code>name</code> is the function name and <code>func</code> is a pointer to
4146the function.4226the function.
4147Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sentinel entry4227Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sentinel entry
4148wherein both <code>name</code> and <code>func</code> are <code>NULL</code>.4228in which both <code>name</code> and <code>func</code> are <code>NULL</code>.
4149 4229
4150<p><a name="luaL_register"></a>4230<p><a name="luaL_register"></a>
4151<hr/><h3><code>luaL_register</code></h3>4231<hr /><h3><code>luaL_register</code></h3>
4152<pre>4232<pre>
4153 void luaL_register (lua_State *L, const char *libname,4233 void luaL_register (lua_State *L, const char *libname,
4154 const luaL_Reg *l);4234 const luaL_Reg *l);
@@ -4163,7 +4243,7 @@ simply registers all functions in the list <code>l</code> · 8 unmodified lines
4163 4243
4164<p>When called with a non-null <code>libname</code>,4244<p>When called with a non-null <code>libname</code>,
4165creates a new table <code>t</code>,4245creates a new table <code>t</code>,
4166sets it as the value of the variable <code>libname</code>,4246sets it as the value of the global variable <code>libname</code>,
4167sets it as the value of <code>package.loaded[libname]</code>,4247sets it as the value of <code>package.loaded[libname]</code>,
4168and registers on it all functions in the list <code>l</code>.4248and registers on it all functions in the list <code>l</code>.
4169If there is a table in <code>package.loaded[libname]</code> or in4249If 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
4174on the top of the stack.4254on the top of the stack.
4175 4255
4176<p><a name="luaL_typename"></a>4256<p><a name="luaL_typename"></a>
4177<hr/><h3><code>luaL_typename</code></h3>4257<hr /><h3><code>luaL_typename</code></h3>
4178<pre>4258<pre>
4179 const char *luaL_typename (lua_State *L, int idx);4259 const char *luaL_typename (lua_State *L, int idx);
4180</pre>4260</pre>
@@ -4183,7 +4263,7 @@ on the top of the stack. · 2 unmodified lines
4183<p>Returns the name of the type of the value at index <code>idx</code>.4263<p>Returns the name of the type of the value at index <code>idx</code>.
4184 4264
4185<p><a name="luaL_typerror"></a>4265<p><a name="luaL_typerror"></a>
4186<hr/><h3><code>luaL_typerror</code></h3>4266<hr /><h3><code>luaL_typerror</code></h3>
4187<pre>4267<pre>
4188 int luaL_typerror (lua_State *L, int narg, const char *tname);4268 int luaL_typerror (lua_State *L, int narg, const char *tname);
4189</pre>4269</pre>
@@ -4198,7 +4278,7 @@ where <code>&#060;location></code> is produced by <a href="#luaL_where"><code>lu · 8 unmodified lines
4198and <code>&#060;realt></code> is the type name of the actual argument.4278and <code>&#060;realt></code> is the type name of the actual argument.
4199 4279
4200<p><a name="luaL_unref"></a>4280<p><a name="luaL_unref"></a>
4201<hr/><h3><code>luaL_unref</code></h3>4281<hr /><h3><code>luaL_unref</code></h3>
4202<pre>4282<pre>
4203 void luaL_unref (lua_State *L, int t, int ref);4283 void luaL_unref (lua_State *L, int t, int ref);
4204</pre>4284</pre>
@@ -4214,7 +4294,7 @@ The reference <code>ref</code> is also freed to be used again. · 9 unmodified lines
4214<a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.4294<a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
4215 4295
4216<p><a name="luaL_where"></a>4296<p><a name="luaL_where"></a>
4217<hr/><h3><code>luaL_where</code></h3>4297<hr /><h3><code>luaL_where</code></h3>
4218<pre>4298<pre>
4219 void luaL_where (lua_State *L, int lvl);4299 void luaL_where (lua_State *L, int lvl);
4220</pre>4300</pre>
@@ -4224,20 +4304,21 @@ The reference <code>ref</code> is also freed to be used again. · 3 unmodified lines
4224of the control at level <code>lvl</code> in the call stack.4304of the control at level <code>lvl</code> in the call stack.
4225Typically this string has the format <code>&#060;chunkname>:&#060;currentline>:</code>.4305Typically this string has the format <code>&#060;chunkname>:&#060;currentline>:</code>.
4226Level 0 is the running function,4306Level 0 is the running function,
4227level 1 is the function that called the running function.4307level 1 is the function that called the running function,
4308etc.
4228 4309
4229<p>This function is used to build a prefix for error messages.4310<p>This function is used to build a prefix for error messages.
4230 4311
4231<p>4312<p>
4232<a name="libraries"></a><a name="5"></a><h1>5 - Standard Libraries</h1>4313<a name="libraries"></a><a name="5"></a><h1>5 - Standard Libraries</h1>
4233 4314
4234<p>The standard libraries provide useful functions4315<p>The standard Lua libraries provide useful functions
4235that are implemented directly through the C API.4316that are implemented directly through the C API.
4236Some of these functions provide essential services to the language4317Some of these functions provide essential services to the language
4237(e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable</code></a>);4318(e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable</code></a>);
4238others provide access to "outside" services (e.g., I/O);4319others provide access to "outside" services (e.g., I/O);
4239and others could be implemented in Lua itself,4320and others could be implemented in Lua itself,
4240but are quite useful or have critical performance to4321but are quite useful or have critical performance requirements that
4241deserve an implementation in C (e.g., <code>sort</code>).4322deserve an implementation in C (e.g., <code>sort</code>).
4242 4323
4243<p>All libraries are implemented through the official C API4324<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
4258or as methods of its objects.4339or as methods of its objects.
4259 4340
4260<p>To have access to these libraries,4341<p>To have access to these libraries,
4261the C host program must first call the function4342the C host program must call
4262<code>luaL_openlibs</code>;4343<code>luaL_openlibs</code>,
4263or else it can open them individually calling4344which open all standard libraries.
4345Alternatively,
4346it can open them individually by calling
4264<code>luaopen_base</code> (for the basic library),4347<code>luaopen_base</code> (for the basic library),
4265<code>luaopen_package</code> (for the package library),4348<code>luaopen_package</code> (for the package library),
4266<code>luaopen_string</code> (for the string library),4349<code>luaopen_string</code> (for the string library),
@@ -4268,86 +4351,90 @@ or else it can open them individually calling · 1 unmodified line
4268<code>luaopen_math</code> (for the mathematical library),4351<code>luaopen_math</code> (for the mathematical library),
4269<code>luaopen_io</code> (for the I/O and the Operating System libraries),4352<code>luaopen_io</code> (for the I/O and the Operating System libraries),
4270and <code>luaopen_debug</code> (for the debug library).4353and <code>luaopen_debug</code> (for the debug library).
4271These functions are declared in <code>lualib.h</code>.4354These functions are declared in <code>lualib.h</code>
4355and should not be called directly:
4356you must call them like any other Lua C function,
4357e.g., by using <code>lua_call</code>.
4272 4358
4273<p><a name="predefined"></a><a name="5.1"></a><h2>5.1 - Basic Functions</h2>4359<p><a name="predefined"></a><a name="5.1"></a><h2>5.1 - Basic Functions</h2>
4274 4360
4275<p>The basic library provides some core functions to Lua.4361<p>The basic library provides some core functions to Lua.
4276If you do not include this library in your application,4362If you do not include this library in your application,
4277you should check carefully whether you need to provide some alternative4363you should check carefully whether you need to provide
4278implementation for some of its facilities.4364implementations for some of its facilities.
4279 4365
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>
4281Issues an error when4367Issues an error when
4282the value of its argument <code>v</code> is <b>nil</b> or <b>false</b>;4368the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);
4283otherwise, returns all its arguments.4369otherwise, returns all its arguments.
4284<code>message</code> is an error message;4370<code>message</code> is an error message;
4285when absent, it defaults to "assertion failed!"4371when absent, it defaults to "assertion failed!"
4286 4372
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>
4288 4374
4289<p>This function is a generic interface to the garbage collector.4375<p>This function is a generic interface to the garbage collector.
4290It performs different functions according to its first argument, <code>opt</code>:4376It performs different functions according to its first argument, <code>opt</code>:
4291<ul>4377<ul>
4292<li><b>"stop"</b> stops the garbage collector.4378<li><b>"stop"</b> --- stops the garbage collector.
4293<li><b>"restart"</b> restarts the garbage collector.4379<li><b>"restart"</b> --- restarts the garbage collector.
4294<li><b>"collect"</b> performs a full garbage-collection cycle.4380<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).4381<li><b>"count"</b> --- returns the total memory in use by Lua (in Kbytes).
4296<li><b>"step"</b> performs a garbage-collection step.4382<li><b>"step"</b> --- performs a garbage-collection step.
4297The step "size" is controlled by <code>arg</code>4383The step "size" is controlled by <code>arg</code>
4298(larger values mean more steps) in a non-specified way.4384(larger values mean more steps) in a non-specified way.
4299If you want to control the step size4385If you want to control the step size
4300you must tune experimentally the value of <code>arg</code>.4386you must tune experimentally the value of <code>arg</code>.
4301Returns <b>true</b> if that step finished a collection cycle.4387Returns <b>true</b> if that step finished a collection cycle.
4302<li><b>"steppause"</b>4388<li><b>"steppause"</b> ---
4303sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of4389sets <code>arg</code>/100 as the new value for the <em>pause</em> of
4304the collector (see <a href="#GC">2.10</a>).4390the collector (see <a href="#GC">2.10</a>).
4305<li><b>"setstepmul"</b>4391<li><b>"setstepmul"</b> ---
4306sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of4392sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of
4307the collector (see <a href="#GC">2.10</a>).4393the collector (see <a href="#GC">2.10</a>).
4308</ul>4394</ul>
4309 4395
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>
4311Opens the named file and executes its contents as a Lua chunk.4397Opens the named file and executes its contents as a Lua chunk.
4312When called without arguments,4398When called without arguments,
4313<a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>).4399<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).
4314Returns any value returned by the chunk.4400Returns all values returned by the chunk.
4315In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error4401In case of errors, <code>dofile</code> propagates the error
4316to its caller (that is, it does not run in protected mode).4402to its caller (that is, <code>dofile</code> does not run in protected mode).
4317 4403
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>
4319Terminates the last protected function called4405Terminates the last protected function called
4320and returns <code>message</code> as the error message.4406and returns <code>message</code> as the error message.
4321Function <a href="#pdf-error"><code>error</code></a> never returns.4407Function <code>error</code> never returns.
4322 4408
4323<p>Usually, <a href="#pdf-error"><code>error</code></a> adds some information about the error position4409<p>Usually, <code>error</code> adds some information about the error position
4324at the beginning of the message.4410at the beginning of the message.
4325The <code>level</code> argument specifies how to get the error position.4411The <code>level</code> argument specifies how to get the error position.
4326With level 1 (the default), the error position is where the4412With 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.
4328Level 2 points the error to where the function4414Level 2 points the error to where the function
4329that called <a href="#pdf-error"><code>error</code></a> was called; and so on.4415that called <code>error</code> was called; and so on.
4330Passing a level 0 avoids the addition of error position information4416Passing a level 0 avoids the addition of error position information
4331to the message.4417to the message.
4332 4418
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>
4334A global variable (not a function) that4420A global variable (not a function) that
4335holds the global environment (that is, <code>_G._G = _G</code>).4421holds the global environment (that is, <code>_G._G = _G</code>).
4336Lua itself does not use this variable;4422Lua itself does not use this variable;
4337changing its value does not affect any environment.4423changing its value does not affect any environment,
4424nor vice-versa.
4338(Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.)4425(Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.)
4339 4426
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>
4341Returns the current environment in use by the function.4428Returns the current environment in use by the function.
4342<code>f</code> can be a Lua function or a number,4429<code>f</code> can be a Lua function or a number
4343which specifies the function at that stack level:4430that specifies the function at that stack level:
4344Level 1 is the function calling <a href="#pdf-getfenv"><code>getfenv</code></a>.4431Level 1 is the function calling <code>getfenv</code>.
4345If the given function is not a Lua function,4432If the given function is not a Lua function,
4346or if <code>f</code> is 0,4433or 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.
4348The default for <code>f</code> is 1.4435The default for <code>f</code> is 1.
4349 4436
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>
4351 4438
4352<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.4439<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
4353Otherwise,4440Otherwise,
@@ -4355,9 +4442,9 @@ if the object's metatable has a <code>"__metatable"</code> field, · 1 unmodified line
4355returns the associated value.4442returns the associated value.
4356Otherwise, returns the metatable of the given object.4443Otherwise, returns the metatable of the given object.
4357 4444
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>
4359 4446
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,
4361so that the construction4448so that the construction
4362<pre>4449<pre>
4363 for i,v in ipairs(t) do ... end4450 for i,v in ipairs(t) do ... end
@@ -4365,7 +4452,9 @@ so that the construction · 1 unmodified line
4365will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,4452will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
4366up to the first integer key with a nil value in the table.4453up to the first integer key with a nil value in the table.
4367 4454
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>
4369 4458
4370<p>Loads a chunk using function <code>func</code> to get its pieces.4459<p>Loads a chunk using function <code>func</code> to get its pieces.
4371Each call to <code>func</code> must return a string that concatenates4460Each 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
4380<p><code>chunkname</code> is used as the chunk name for error messages4469<p><code>chunkname</code> is used as the chunk name for error messages
4381and debug information.4470and debug information.
4382 4471
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>
4384 4473
4385<p>Similar to <a href="#pdf-load"><code>load</code></a>,4474<p>Similar to <a href="#pdf-load"><code>load</code></a>,
4386but gets the chunk from file <code>filename</code>.4475but gets the chunk from file <code>filename</code>
4476or from the standard input,
4477if no file name given.
4387 4478
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>
4389 4480
4390<p>Similar to <a href="#pdf-load"><code>load</code></a>,4481<p>Similar to <a href="#pdf-load"><code>load</code></a>,
4391but gets the chunk from the given string.4482but gets the chunk from the given string.
@@ -4395,106 +4486,112 @@ but gets the chunk from the given string. · 3 unmodified lines
4395 assert(loadstring(s))()4486 assert(loadstring(s))()
4396</pre>4487</pre>
4397 4488
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>
4399 4490
4400<p>Allows a program to traverse all fields of a table.4491<p>Allows a program to traverse all fields of a table.
4401Its first argument is a table and its second argument4492Its first argument is a table and its second argument
4402is an index in this table.4493is an index in this table.
4403<a href="#pdf-next"><code>next</code></a> returns the next index of the table and the4494<code>next</code> returns the next index of the table
4404value associated with the index.4495and its associated value.
4405When called with <b>nil</b> as its second argument,4496When called with <b>nil</b> as its second argument,
4406<a href="#pdf-next"><code>next</code></a> returns the first index4497<code>next</code> returns an initial index
4407of the table and its associated value.4498and its associated value.
4408When called with the last index,4499When called with the last index,
4409or with <b>nil</b> in an empty table,4500or 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>.
4411If the second argument is absent, then it is interpreted as <b>nil</b>.4502If the second argument is absent, then it is interpreted as <b>nil</b>.
4503In particular,
4504you can use <code>next(t)</code> to check whether a table is empty.
4412 4505
4413<p>Lua has no declaration of fields;4506<p>Lua has no declaration of fields.
4414There is no difference between a4507There is no difference between a
4415field not present in a table or a field with value <b>nil</b>.4508field not present in a table or a field with value <b>nil</b>.
4416Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<b>nil</b> values.4509Therefore, <code>next</code> only considers fields with non-<b>nil</b> values.
4417The order in which the indices are enumerated is not specified,4510The order in which the indices are enumerated is not specified,
4418<em>even for numeric indices</em>.4511<em>even for numeric indices</em>.
4419(To traverse a table in numeric order,4512(To traverse a table in numeric order,
4420use a numerical <b>for</b> or the <a href="#pdf-ipairs"><code>ipairs</code></a> function.)4513use a numerical <b>for</b> or the <a href="#pdf-ipairs"><code>ipairs</code></a> function.)
4421 4514
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,
4423during the traversal,4516during the traversal,
4424you assign any value to a non-existent field in the table.4517you assign any value to a non-existent field in the table.
4518You may however modify existing fields.
4519In particular, you may clear existing fields.
4425 4520
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>
4427 4522
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>,
4429so that the construction4524so that the construction
4430<pre>4525<pre>
4431 for k,v in pairs(t) do ... end4526 for k,v in pairs(t) do ... end
4432</pre>4527</pre>
4433will iterate over all key--value pairs of table <code>t</code>.4528will iterate over all key--value pairs of table <code>t</code>.
4434 4529
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>
4436 4533
4437<p>Calls function <code>f</code> with4534<p>Calls function <code>f</code> with
4438the given arguments in protected mode.4535the given arguments in protected mode.
4439That means that any error inside <code>f</code> is not propagated;4536That means that any error inside <code>f</code> is not propagated;
4440instead, <a href="#pdf-pcall"><code>pcall</code></a> catches the error4537instead, <code>pcall</code> catches the error
4441and returns a status code.4538and returns a status code.
4442Its first result is the status code (a boolean),4539Its first result is the status code (a boolean),
4443which is true if the call succeeds without errors.4540which is true if the call succeeds without errors.
4444In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call,4541In such case, <code>pcall</code> also returns all results from the call,
4445after this first result.4542after this first result.
4446In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <b>false</b> plus the error message.4543In case of any error, <code>pcall</code> returns <b>false</b> plus the error message.
4447 4544
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>
4449Receives any number of arguments,4546Receives any number of arguments,
4450and prints their values in <code>stdout</code>,4547and prints their values in <code>stdout</code>,
4451using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.4548using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.
4452This function is not intended for formatted output,4549<code>print</code> is not intended for formatted output,
4453but only as a quick way to show a value,4550but only as a quick way to show a value,
4454typically for debugging.4551typically for debugging.
4455For formatted output, use <code>format</code> (see <a href="#format">5.4</a>).4552For formatted output, use <a href="#pdf-string.format"><code>string.format</code></a>.
4456 4553
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>
4458Checks whether <code>v1</code> is equal to <code>v2</code>,4555Checks whether <code>v1</code> is equal to <code>v2</code>,
4459without invoking any metamethod.4556without invoking any metamethod.
4460Returns a boolean.4557Returns a boolean.
4461 4558
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>
4463Gets the real value of <code>table[index]</code>,4560Gets the real value of <code>table[index]</code>,
4464without invoking any metamethod.4561without invoking any metamethod.
4465<code>table</code> must be a table;4562<code>table</code> must be a table and
4466<code>index</code> is any value different from <b>nil</b>.4563<code>index</code> any value different from <b>nil</b>.
4467 4564
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>
4469Sets the real value of <code>table[index]</code> to <code>value</code>,4566Sets the real value of <code>table[index]</code> to <code>value</code>,
4470without invoking any metamethod.4567without invoking any metamethod.
4471<code>table</code> must be a table,4568<code>table</code> must be a table,
4472<code>index</code> is any value different from <b>nil</b>,4569<code>index</code> any value different from <b>nil</b>,
4473and <code>value</code> is any Lua value.4570and <code>value</code> any Lua value.
4474 4571
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>
4476 4573
4477<p>If <code>index</code> is a number,4574<p>If <code>index</code> is a number,
4478returns all argument after argument number <code>index</code>.4575returns all arguments after argument number <code>index</code>.
4479Otherwise, <code>index</code> must be the string <code>"#"</code>,4576Otherwise, <code>index</code> must be the string <code>"#"</code>,
4480and <code>select</code> returns the total number of extra arguments it received.4577and <code>select</code> returns the total number of extra arguments it received.
4481 4578
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>
4483 4580
4484<p>Sets the environment to be used by the given function.4581<p>Sets the environment to be used by the given function.
4485<code>f</code> can be a Lua function or a number,4582<code>f</code> can be a Lua function or a number
4486which specifies the function at that stack level:4583that specifies the function at that stack level:
4487Level 1 is the function calling <a href="#pdf-setfenv"><code>setfenv</code></a>.4584Level 1 is the function calling <code>setfenv</code>.
4488<a href="#pdf-setfenv"><code>setfenv</code></a> returns the given function.4585<code>setfenv</code> returns the given function.
4489 4586
4490<p>As a special case, when <code>f</code> is 0 <a href="#pdf-setfenv"><code>setfenv</code></a> changes4587<p>As a special case, when <code>f</code> is 0 <code>setfenv</code> changes
4491the environment of the running thread.4588the environment of the running thread.
4492In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values.4589In this case, <code>setfenv</code> returns no values.
4493 4590
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>
4495 4592
4496<p>Sets the metatable for the given table.4593<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.)
4498If <code>metatable</code> is <b>nil</b>,4595If <code>metatable</code> is <b>nil</b>,
4499removes the metatable of the given table.4596removes the metatable of the given table.
4500If the original metatable has a <code>"__metatable"</code> field,4597If the original metatable has a <code>"__metatable"</code> field,
@@ -4502,10 +4599,10 @@ raises an error. · 1 unmodified line
4502 4599
4503<p>This function returns <code>table</code>.4600<p>This function returns <code>table</code>.
4504 4601
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>
4506Tries to convert its argument to a number.4603Tries to convert its argument to a number.
4507If the argument is already a number or a string convertible4604If the argument is already a number or a string convertible
4508to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number;4605to a number, then <code>tonumber</code> returns that number;
4509otherwise, it returns <b>nil</b>.4606otherwise, it returns <b>nil</b>.
4510 4607
4511<p>An optional argument specifies the base to interpret the numeral.4608<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
4514represents 10, `<code>B</code>&acute; represents 11, and so forth,4611represents 10, `<code>B</code>&acute; represents 11, and so forth,
4515with `<code>Z</code>&acute; representing 35.4612with `<code>Z</code>&acute; representing 35.
4516In base 10 (the default), the number may have a decimal part,4613In base 10 (the default), the number may have a decimal part,
4517as well as an optional exponent part (see <a href="#coercion">2.2.1</a>).4614as well as an optional exponent part (see <a href="#lexical">2.1</a>).
4518In other bases, only unsigned integers are accepted.4615In other bases, only unsigned integers are accepted.
4519 4616
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>
4521Receives an argument of any type and4618Receives an argument of any type and
4522converts it to a string in a reasonable format.4619converts it to a string in a reasonable format.
4523For complete control of how numbers are converted,4620For complete control of how numbers are converted,
4524use <a href="#pdf-string.format"><code>string.format</code></a> (see <a href="#format">5.4</a>).4621use <a href="#pdf-string.format"><code>string.format</code></a>.
4525 4622
4526<p>If the metatable of <code>e</code> has a <code>"__tostring"</code> field,4623<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 value4624then <code>tostring</code> calls the corresponding value
4528with <code>e</code> as argument,4625with <code>e</code> as argument,
4529and uses the result of the call as its result.4626and uses the result of the call as its result.
4530 4627
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>
4532Returns the type of its only argument, coded as a string.4629Returns the type of its only argument, coded as a string.
4533The possible results of this function are4630The possible results of this function are
4534<code>"nil"</code> (a string, not the value <b>nil</b>),4631<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
4540<code>"thread"</code>,4637<code>"thread"</code>,
4541and <code>"userdata"</code>.4638and <code>"userdata"</code>.
4542 4639
4543<p><a name="pdf-unpack"></a><hr/><h3><code>unpack (list [, i [, j]])</code></h3>4640<p><a name="pdf-unpack"></a><hr /><h3><code>unpack (list [, i [, j]])</code></h3>
4544Returns the elements from the given list.4641Returns the elements from the given table.
4545This function is equivalent to4642This function is equivalent to
4546<pre>4643<pre>
4547 return list[i], list[i+1], ..., list[j]4644 return list[i], list[i+1], ..., list[j]
@@ -4549,30 +4646,30 @@ This function is equivalent to · 1 unmodified line
4549except that the above code can be written only for a fixed number4646except that the above code can be written only for a fixed number
4550of elements.4647of elements.
4551By default, <code>i</code> is 1 and <code>j</code> is the length of the list,4648By default, <code>i</code> is 1 and <code>j</code> is the length of the list,
4552as defined by the length operator.4649as defined by the length operator (see <a href="#len-op">2.5.5</a>).
4553 4650
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>
4555A global variable (not a function) that4652A global variable (not a function) that
4556holds a string containing the current interpreter version.4653holds a string containing the current interpreter version.
4557The current contents of this variable is <code>"Lua 5.1"</code>.4654The current contents of this variable is <code>"Lua 5.1"</code>.
4558 4655
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>
4560 4657
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>,
4562except that you can set a new error handler.4659except that you can set a new error handler.
4563 4660
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,
4565using <code>err</code> as the error handler.4662using <code>err</code> as the error handler.
4566Any error inside <code>f</code> is not propagated;4663Any error inside <code>f</code> is not propagated;
4567instead, <a href="#pdf-xpcall"><code>xpcall</code></a> catches the error,4664instead, <code>xpcall</code> catches the error,
4568calls the <code>err</code> function with the original error object,4665calls the <code>err</code> function with the original error object,
4569and returns a status code.4666and returns a status code.
4570Its first result is the status code (a boolean),4667Its first result is the status code (a boolean),
4571which is true if the call succeeds without errors.4668which is true if the call succeeds without errors.
4572In such case, <a href="#pdf-xpcall"><code>xpcall</code></a> also returns all results from the call,4669In this case, <code>xpcall</code> also returns all results from the call,
4573after this first result.4670after this first result.
4574In case of any error,4671In 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>.
4576 4673
4577<p><a name="5.2"></a><h2>5.2 - Coroutine Manipulation</h2>4674<p><a name="5.2"></a><h2>5.2 - Coroutine Manipulation</h2>
4578 4675
@@ -4580,22 +4677,24 @@ In case of any error, · 1 unmodified line
4580the basic library and come inside the table <code>coroutine</code>.4677the basic library and come inside the table <code>coroutine</code>.
4581See <a href="#coroutine">2.11</a> for a general description of coroutines.4678See <a href="#coroutine">2.11</a> for a general description of coroutines.
4582 4679
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>
4584 4681
4585<p>Creates a new coroutine, with body <code>f</code>.4682<p>Creates a new coroutine, with body <code>f</code>.
4586<code>f</code> must be a Lua function.4683<code>f</code> must be a Lua function.
4587Returns this new coroutine,4684Returns this new coroutine,
4588an object with type <code>"thread"</code>.4685an object with type <code>"thread"</code>.
4589 4686
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>
4591 4688
4592<p>Starts or continues the execution of coroutine <code>co</code>.4689<p>Starts or continues the execution of coroutine <code>co</code>.
4593The first time you resume a coroutine,4690The first time you resume a coroutine,
4594it starts running its body.4691it starts running its body.
4595The arguments <code>val1</code>, ... go as the arguments to the body function.4692The values <code>val1</code>, ..., <code>valn</code> are passed
4693as the arguments to the body function.
4596If the coroutine has yielded,4694If the coroutine has yielded,
4597<code>resume</code> restarts it;4695<code>resume</code> restarts it;
4598the arguments <code>val1</code>, ... go as the results from the yield.4696the values <code>val1</code>, ..., <code>valn</code> are passed
4697as the results from the yield.
4599 4698
4600<p>If the coroutine runs without any errors,4699<p>If the coroutine runs without any errors,
4601<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>4700<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
4604If there is any error,4703If there is any error,
4605<code>resume</code> returns <b>false</b> plus the error message.4704<code>resume</code> returns <b>false</b> plus the error message.
4606 4705
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>
4608 4707
4609<p>Returns the running coroutine,4708<p>Returns the running coroutine,
4610or <b>nil</b> when called by the main thread.4709or <b>nil</b> when called by the main thread.
4611 4710
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>
4613 4712
4614<p>Returns the status of coroutine <code>co</code>, as a string:4713<p>Returns the status of coroutine <code>co</code>, as a string:
4615<code>"running"</code>,4714<code>"running"</code>,
@@ -4621,7 +4720,7 @@ or if it has not started running yet; · 5 unmodified lines
4621and <code>"dead"</code> if the coroutine has finished its body function,4720and <code>"dead"</code> if the coroutine has finished its body function,
4622or if it has stopped with an error.4721or if it has stopped with an error.
4623 4722
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>
4625 4724
4626<p>Creates a new coroutine, with body <code>f</code>.4725<p>Creates a new coroutine, with body <code>f</code>.
4627<code>f</code> must be a Lua function.4726<code>f</code> must be a Lua function.
@@ -4632,22 +4731,22 @@ Returns the same values returned by <code>resume</code>, · 4 unmodified lines
4632except the first boolean.4731except the first boolean.
4633In case of error, propagates the error.4732In case of error, propagates the error.
4634 4733
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>
4636 4735
4637<p>Suspends the execution of the calling coroutine.4736<p>Suspends the execution of the calling coroutine.
4638The coroutine cannot be running neither a C function,4737The coroutine can be running neither a C function,
4639nor a metamethod, nor an iterator.4738nor a metamethod, nor an iterator.
4640Any arguments to <code>yield</code> go as extra results to <code>resume</code>.4739Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
4641 4740
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>
4643 4742
4644<p>The package library provides basic4743<p>The package library provides basic
4645facilities for packages and modules in Lua.4744facilities for loading and building modules in Lua.
4646It exports two of its functions directly in the global environment:4745It exports two of its functions directly in the global environment:
4647<a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.4746<a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.
4648Everything else is exported in a table <code>package</code>.4747Everything else is exported in a table <code>package</code>.
4649 4748
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>
4651 4750
4652<p>Creates a module.4751<p>Creates a module.
4653If there is a table in <code>package.loaded[name]</code>,4752If 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
4666so that <a href="#pdf-require"><code>require</code></a> returns <code>t</code>.4765so that <a href="#pdf-require"><code>require</code></a> returns <code>t</code>.
4667 4766
4668<p>If <code>name</code> is a compound name4767<p>If <code>name</code> is a compound name
4669(that is, one with components separated by dots)4768(that is, one with components separated by dots),
4670<code>module</code> creates (or reuses, if they already exists)4769<code>module</code> creates (or reuses, if they already exist)
4671tables for each component.4770tables for each component.
4672For instance, if <code>name</code> is <code>a.b.c</code>,4771For instance, if <code>name</code> is <code>a.b.c</code>,
4673<code>module</code> stores the module table in field <code>c</code> of4772then <code>module</code> stores the module table in field <code>c</code> of
4674field <code>b</code> of global <code>a</code>.4773field <code>b</code> of global <code>a</code>.
4675 4774
4676<p>This function may receive optional <em>options</em> after4775<p>This function may receive optional <em>options</em> after
4677the module name,4776the module name,
4678where each option is a function to be applied over the module.4777where each option is a function to be applied over the module.
4679 4778
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>
4681 4780
4682<p>Loads the given module.4781<p>Loads the given module.
4683The function starts by looking into the table <code>package.loaded</code>4782The function starts by looking into the table <code>package.loaded</code>
4684to determine whether <code>modname</code> is already loaded.4783to determine whether <code>modname</code> is already loaded.
4685If it is, then <a href="#pdf-require"><code>require</code></a> returns the value stored4784If it is, then <code>require</code> returns the value stored
4686at <code>package.loaded[modname]</code>.4785at <code>package.loaded[modname]</code>.
4687Otherwise, it tries to find a loader for that module.4786Otherwise, it tries to find a <em>loader</em> for that module.
4688 4787
4689<p>To find a loader,4788<p>To find a loader,
4690first <a href="#pdf-require"><code>require</code></a> queries <code>package.preload[modname]</code>.4789first <code>require</code> queries <code>package.preload[modname]</code>.
4691If it is a true value,4790If it has a value,
4692that value (which should be a function) is the loader.4791that value (which should be a function) is the loader.
4693Otherwise <a href="#pdf-require"><code>require</code></a> searches for a Lua loader using the4792Otherwise <code>require</code> searches for a Lua loader using the
4694path stored in <code>package.path</code>.4793path stored in <code>package.path</code>.
4695if that also fails, it searches for a C loader using the4794If that also fails, it searches for a C loader using the
4696path stored in <code>package.cpath</code>.4795path stored in <code>package.cpath</code>.
4697If that also fails,4796If that also fails,
4698it tries an <em>all-in-one</em> loader.4797it tries an <em>all-in-one</em> loader (see below).
4699 4798
4700<p>When loading a C library,4799<p>When loading a C library,
4701<a href="#pdf-require"><code>require</code></a> first uses a dynamic link facility to link the4800<code>require</code> first uses a dynamic link facility to link the
4702application with the library.4801application with the library.
4703Then it tries to find a C function inside that library to4802Then it tries to find a C function inside that library to
4704be used as the loader.4803be used as the loader.
4705The name of that C function is the string <code>"luaopen_"</code>4804The name of that C function is the string <code>"luaopen_"</code>
4706concatenated with a copy of the module name wherein each dot4805concatenated with a copy of the module name where each dot
4707is replaced by an underscore.4806is replaced by an underscore.
4708Moreover, if the module name has a hyphen,4807Moreover, if the module name has a hyphen,
4709its prefix up to (and including) the first hyphen is removed.4808its prefix up to (and including) the first hyphen is removed.
4710For instance, if the module name is <code>a.v1-b.c</code>,4809For instance, if the module name is <code>a.v1-b.c</code>,
4711the function name will be <code>luaopen_b_c</code>.4810the function name will be <code>luaopen_b_c</code>.
4712 4811
4713<p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a4812<p>If <code>require</code> finds neither a Lua library nor a
4714C library for a module,4813C library for a module,
4715it calls the <em>all-in-one loader</em>.4814it calls the <em>all-in-one loader</em>.
4716That loader searches the C path for a library for4815That loader searches the C path for a library for
@@ -4725,29 +4824,29 @@ into one single library, · 8 unmodified lines
4725with each submodule keeping its original open function.4824with each submodule keeping its original open function.
4726 4825
4727<p>Once a loader is found,4826<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>.
4729If the loader returns any value,4828If 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>.
4731If the loader returns no value and4830If the loader returns no value and
4732has not assigned any value to <code>package.loaded[modname]</code>,4831has 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.4832then <code>require</code> assigns <b>true</b> to that entry.
4734In any case, require returns the4833In any case, require returns the
4735final value of <code>package.loaded[modname]</code>.4834final value of <code>package.loaded[modname]</code>.
4736 4835
4737<p>If there is any error loading or running the module,4836<p>If there is any error loading or running the module,
4738or if it cannot find any loader for that module,4837or if it cannot find any loader for that module,
4739then <a href="#pdf-require"><code>require</code></a> signals an error. 4838then <code>require</code> signals an error.
4740 4839
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>
4742 4841
4743<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader.4842<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader.
4744 4843
4745<p>Lua initializes the C path <code>package.cpath</code> in the same way4844<p>Lua initializes the C path <code>package.cpath</code> in the same way
4746it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>,4845it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>,
4747using the environment variable <code>LUA_CPATH</code>4846using 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>).
4749 4848
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>
4751 4850
4752<p>A table used by <a href="#pdf-require"><code>require</code></a> to control which4851<p>A table used by <a href="#pdf-require"><code>require</code></a> to control which
4753modules are already loaded.4852modules are already loaded.
@@ -4755,27 +4854,34 @@ When you require a module <code>modname</code> and · 1 unmodified line
4755<code>package.loaded[modname]</code> is not false,4854<code>package.loaded[modname]</code> is not false,
4756<a href="#pdf-require"><code>require</code></a> simply returns the value stored there.4855<a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
4757 4856
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>
4759 4858
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>.
4761Inside this library, looks for a function <code>funcname</code>4860Inside this library, looks for a function <code>funcname</code>
4762and returns this function as a C function.4861and 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>)).
4763 4863
4764<p><code>libname</code> must be the complete file name of the C library,4864<p>This is a low-level function.
4765including any eventual path and extension.4865It completely bypasses the package and module system.
4866Unlike <a href="#pdf-require"><code>require</code></a>,
4867it does not perform any path searching or automatically adds extensions.
4868<code>libname</code> must be the complete file name of the C library,
4869including 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).
4766 4872
4767<p>This function is not supported by ANSI C.4873<p>This function is not supported by ANSI C.
4768As such, it is only available on some platforms4874As such, it is only available on some platforms
4769(Windows, Linux, Solaris, BSD, plus other Unix systems that4875(Windows, Linux, Mac OS X, Solaris, BSD,
4770support the <code>dlfcn</code> standard).4876plus other Unix systems that support the <code>dlfcn</code> standard).
4771 4877
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>
4773 4879
4774<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader.4880<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader.
4775 4881
4776<p>At start-up, Lua initializes this variable with4882<p>At start-up, Lua initializes this variable with
4777the value of the environment variable <code>LUA_PATH</code> or4883the value of the environment variable <code>LUA_PATH</code> or
4778with a compiled-defined default path,4884with a default path defined in <code>luaconf.h</code>,
4779if the environment variable is not defined.4885if the environment variable is not defined.
4780Any <code>";;"</code> in the value of the environment variable4886Any <code>";;"</code> in the value of the environment variable
4781is replaced by the default path.4887is replaced by the default path.
@@ -4790,21 +4896,21 @@ So, for instance, if the Lua path is · 8 unmodified lines
4790<pre>4896<pre>
4791 "./?.lua;./?.lc;/usr/local/?/init.lua"4897 "./?.lua;./?.lc;/usr/local/?/init.lua"
4792</pre>4898</pre>
4793the search for a Lua loader for module <code>mod</code>4899the search for a Lua loader for module <code>foo</code>
4794will try to load the files4900will try to load the files
4795<code>./mod.lua</code>, <code>./mod.lc</code>, and4901<code>./foo.lua</code>, <code>./foo.lc</code>, and
4796<code>/usr/local/mod/init.lua</code>, in that order.4902<code>/usr/local/foo/init.lua</code>, in that order.
4797 4903
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>
4799 4905
4800<p>A table to store loaders for specific modules4906<p>A table to store loaders for specific modules
4801(see <a href="#pdf-require"><code>require</code></a>).4907(see <a href="#pdf-require"><code>require</code></a>).
4802 4908
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>
4804 4910
4805<p>Sets a metatable for <code>module</code> with4911<p>Sets a metatable for <code>module</code> with
4806its <code>__index</code> field refering to the global environment,4912its <code>__index</code> field referring to the global environment,
4807so that this module inherits undefined values4913so that this module inherits values
4808from the global environment.4914from the global environment.
4809To be used as an option to function <a href="#pdf-module"><code>module</code></a>.4915To be used as an option to function <a href="#pdf-module"><code>module</code></a>.
4810 4916
@@ -4821,12 +4927,12 @@ Thus, the last character is at position <em>-1</em>, and so on. · 10 unmodified lines
4821<p>The string library provides all its functions inside the table4927<p>The string library provides all its functions inside the table
4822<code>string</code>.4928<code>string</code>.
4823It also sets a metatable for strings4929It also sets a metatable for strings
4824wherein <code>__index</code> points to itself.4930where the <code>__index</code> field points to the metatable itself.
4825Therefore, you can use the string function is object-oriented style.4931Therefore, you can use the string functions in object-oriented style.
4826For instance, <code>string.byte(s, i)</code>4932For instance, <code>string.byte(s, i)</code>
4827can be written as <code>s:byte(i)</code>.4933can be written as <code>s:byte(i)</code>.
4828 4934
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>
4830Returns the internal numerical codes of the characters <code>s[i]</code>,4936Returns the internal numerical codes of the characters <code>s[i]</code>,
4831<code>s[i+1]</code>, ..., <code>s[j]</code>.4937<code>s[i+1]</code>, ..., <code>s[j]</code>.
4832The default value for <code>i</code> is 1;4938The 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
4834 4940
4835<p>Note that numerical codes are not necessarily portable across platforms.4941<p>Note that numerical codes are not necessarily portable across platforms.
4836 4942
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>
4838Receives 0 or more integers.4944Receives 0 or more integers.
4839Returns a string with length equal to the number of arguments,4945Returns a string with length equal to the number of arguments,
4840in which each character has the internal numerical code equal4946in which each character has the internal numerical code equal
4841to its correspondent argument.4947to its corresponding argument.
4842 4948
4843<p>Note that numerical codes are not necessarily portable across platforms.4949<p>Note that numerical codes are not necessarily portable across platforms.
4844 4950
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>
4846 4952
4847<p>Returns a binary representation of the given function,4953<p>Returns a string containing a binary representation of the given function,
4848so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns4954so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns
4849a copy of the function.4955a copy of the function.
4850<code>function</code> must be a Lua function.4956<code>function</code> must be a Lua function without upvalues.
4851 4957
4852<p><a name="pdf-string.find"></a><hr/><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>4958<p><a name="pdf-string.find"></a><hr /><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>
4853Looks for the first <em>match</em> of4959Looks for the first match of
4854<code>pattern</code> in the string <code>s</code>.4960<code>pattern</code> in the string <code>s</code>.
4855If it finds one, then <code>find</code> returns the indices of <code>s</code>4961If it finds a match, then <code>find</code> returns the indices of <code>s</code>
4856where this occurrence starts and ends;4962where this occurrence starts and ends;
4857otherwise, it returns <b>nil</b>.4963otherwise, it returns <b>nil</b>.
4858A third, optional numerical argument <code>init</code> specifies4964A 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
4862turns off the pattern matching facilities,4968turns off the pattern matching facilities,
4863so the function does a plain "find substring" operation,4969so the function does a plain "find substring" operation,
4864with no characters in <code>pattern</code> being considered "magic".4970with no characters in <code>pattern</code> being considered "magic".
4865Note that if <code>plain</code> is given, then <code>init</code> must be given too.4971Note that if <code>plain</code> is given, then <code>init</code> must be given as well.
4866 4972
4867<p>If the pattern has captures,4973<p>If the pattern has captures,
4868then in a successful match4974then in a successful match
4869the captured values are also returned,4975the captured values are also returned,
4870after the two indices.4976after the two indices.
4871 4977
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>
4873Returns a formatted version of its variable number of arguments4979Returns a formatted version of its variable number of arguments
4874following the description given in its first argument (which must be a string).4980following the description given in its first argument (which must be a string).
4875The format string follows the same rules as the <code>printf</code> family of4981The format string follows the same rules as the <code>printf</code> family of
4876standard C functions.4982standard C functions.
4877The only differences are that the options/modifiers4983The only differences are that the options/modifiers
4878<code>*</code>, <code>l</code>, <code>L</code>, <code>n</code>, <code>p</code>,4984<code>*</code>, <code>l</code>, <code>L</code>, <code>n</code>, <code>p</code>,
4879and <code>h</code> are not supported,4985and <code>h</code> are not supported
4880and there is an extra option, <code>q</code>.4986and that there is an extra option, <code>q</code>.
4881The <code>q</code> option formats a string in a form suitable to be safely read4987The <code>q</code> option formats a string in a form suitable to be safely read
4882back by the Lua interpreter:4988back by the Lua interpreter:
4883The string is written between double quotes,4989The string is written between double quotes,
4884and all double quotes, newlines, and backslashes in the string4990and all double quotes, newlines, embedded zeros,
4991and backslashes in the string
4885are correctly escaped when written.4992are correctly escaped when written.
4886For instance, the call4993For instance, the call
4887<pre>4994<pre>
@@ -4901,12 +5008,12 @@ whereas <code>q</code> and <code>s</code> expect a string. · 13 unmodified lines
4901<p>This function does not accept string values5008<p>This function does not accept string values
4902containing embedded zeros.5009containing embedded zeros.
4903 5010
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>
4905Returns an iterator function that,5012Returns an iterator function that,
4906each time it is called,5013each time it is called,
4907returns the next captures from pattern <code>pat</code> over string <code>s</code>.5014returns the next captures from <code>pattern</code> over string <code>s</code>.
4908 5015
4909<p>If <code>pat</code> specifies no captures,5016<p>If <code>pattern</code> specifies no captures,
4910then the whole match is produced in each call.5017then the whole match is produced in each call.
4911 5018
4912<p>As an example, the following loop5019<p>As an example, the following loop
@@ -4928,11 +5035,12 @@ given string into a table: · 15 unmodified lines
4928 end5035 end
4929</pre>5036</pre>
4930 5037
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>
4932Returns a copy of <code>s</code>5039Returns a copy of <code>s</code>
4933in which all occurrences of the pattern <code>pat</code> have been5040in which all occurrences of the <code>pattern</code> have been
4934replaced by a replacement string specified by <code>repl</code>.5041replaced by a replacement string specified by <code>repl</code>,
4935<code>gsub</code> also returns, as a second value,5042which may be a string, a table, or a function.
5043<code>gsub</code> also returns, as its second value,
4936the total number of substitutions made.5044the total number of substitutions made.
4937 5045
4938<p>If <code>repl</code> is a string, then its value is used for replacement.5046<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
4943The sequence <code>%0</code> stands for the whole match.5051The sequence <code>%0</code> stands for the whole match.
4944The sequence <code>%%</code> stands for a single <code>%</code>.5052The sequence <code>%%</code> stands for a single <code>%</code>.
4945 5053
5054<p>If <code>repl</code> is a table, then the table is queried for every match,
5055using the first capture as the key;
5056if the pattern specifies no captures,
5057then the whole match is used as the key.
5058
4946<p>If <code>repl</code> is a function, then this function is called every time a5059<p>If <code>repl</code> is a function, then this function is called every time a
4947match occurs, with all captured substrings passed as arguments,5060match occurs, with all captured substrings passed as arguments,
4948in order;5061in order;
@@ -4951,9 +5064,10 @@ then the whole match is passed as a sole argument. · 2 unmodified lines
4951If <code>repl</code> is a table, then this table is queried with the5064If <code>repl</code> is a table, then this table is queried with the
4952value of the first capture or of the whole match,5065value of the first capture or of the whole match,
4953if the pattern specifies no captures.5066if the pattern specifies no captures.
4954In both cases,5067
4955if the value returned by the function or resulted by the query5068<p>In both cases,
4956is a string,5069if the value returned by the function or by the table query
5070is a string or a number,
4957then it is used as the replacement string;5071then it is used as the replacement string;
4958otherwise, if it is <b>false</b> or <b>nil</b>,5072otherwise, if it is <b>false</b> or <b>nil</b>,
4959then there is no replacement5073then there is no replacement
@@ -4962,7 +5076,7 @@ then there is no replacement · 2 unmodified lines
4962<p>The optional last parameter <code>n</code> limits5076<p>The optional last parameter <code>n</code> limits
4963the maximum number of substitutions to occur.5077the maximum number of substitutions to occur.
4964For instance, when <code>n</code> is 1 only the first occurrence of5078For instance, when <code>n</code> is 1 only the first occurrence of
4965<code>pat</code> is replaced.5079<code>pattern</code> is replaced.
4966 5080
4967<p>Here are some examples:5081<p>Here are some examples:
4968<pre>5082<pre>
@@ -4983,24 +5097,24 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 14 unmodified lines
4983 end)5097 end)
4984 --> x="4+5 = 9"5098 --> x="4+5 = 9"
4985 5099
4986 local t = {name="lua", version="5.0"}5100 local t = {name="lua", version="5.1"}
4987 x = string.gsub("$name_$version.tar.gz", "%$(%w+)", t)5101 x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t)
4988 --> x="lua_5.0.tar.gz"5102 --> x="lua-5.1.tar.gz"
4989</pre>5103</pre>
4990 5104
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>
4992Receives a string and returns its length.5106Receives a string and returns its length.
4993The empty string <code>""</code> has length 0.5107The empty string <code>""</code> has length 0.
4994Embedded zeros are counted,5108Embedded zeros are counted,
4995so <code>"a\000bc\000"</code> has length 5.5109so <code>"a\000bc\000"</code> has length 5.
4996 5110
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>
4998Receives a string and returns a copy of that string with all5112Receives a string and returns a copy of that string with all
4999uppercase letters changed to lowercase.5113uppercase letters changed to lowercase.
5000All other characters are left unchanged.5114All other characters are left unchanged.
5001The definition of what is an uppercase letter depends on the current locale.5115The definition of what an uppercase letter is depends on the current locale.
5002 5116
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>
5004Looks for the first <em>match</em> of5118Looks for the first <em>match</em> of
5005<code>pattern</code> in the string <code>s</code>.5119<code>pattern</code> in the string <code>s</code>.
5006If it finds one, then <code>match</code> returns5120If it finds one, then <code>match</code> returns
@@ -5012,14 +5126,14 @@ A third, optional numerical argument <code>init</code> specifies · 5 unmodified lines
5012where to start the search;5126where to start the search;
5013its default value is 1 and may be negative.5127its default value is 1 and may be negative.
5014 5128
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>
5016Returns a string that is the concatenation of <code>n</code> copies of5130Returns a string that is the concatenation of <code>n</code> copies of
5017the string <code>s</code>.5131the string <code>s</code>.
5018 5132
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>
5020Returns a string that is the string <code>s</code> reversed.5134Returns a string that is the string <code>s</code> reversed.
5021 5135
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>
5023Returns the substring of <code>s</code> that5137Returns the substring of <code>s</code> that
5024starts at <code>i</code> and continues until <code>j</code>;5138starts at <code>i</code> and continues until <code>j</code>;
5025<code>i</code> and <code>j</code> may be negative.5139<code>i</code> and <code>j</code> may be negative.
@@ -5031,11 +5145,11 @@ with length <code>j</code>, · 5 unmodified lines
5031and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>5145and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>
5032with length <code>i</code>.5146with length <code>i</code>.
5033 5147
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>
5035Receives a string and returns a copy of that string with all5149Receives a string and returns a copy of that string with all
5036lowercase letters changed to uppercase.5150lowercase letters changed to uppercase.
5037All other characters are left unchanged.5151All other characters are left unchanged.
5038The definition of what is a lowercase letter depends on the current locale.5152The definition of what a lowercase letter is depends on the current locale.
5039 5153
5040<p><a name="pm"></a><h3>Patterns</h3>5154<p><a name="pm"></a><h3>Patterns</h3>
5041 5155
@@ -5043,7 +5157,7 @@ The definition of what is a lowercase letter depends on the current locale. · 1 unmodified line
5043A <em>character class</em> is used to represent a set of characters.5157A <em>character class</em> is used to represent a set of characters.
5044The following combinations are allowed in describing a character class:5158The following combinations are allowed in describing a character class:
5045<ul>5159<ul>
5046<li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters5160<li><b><em>x</em></b> (where <em>x</em> is not one of the <em>magic characters</em>
5047<code>^$()%.[]*+-?</code>)5161<code>^$()%.[]*+-?</code>)
5048--- represents the character <em>x</em> itself.5162--- represents the character <em>x</em> itself.
5049<li><b><code>.</code></b> --- (a dot) represents all characters.5163<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
5117a single character class followed by `<code>?</code>&acute;,5231a single character class followed by `<code>?</code>&acute;,
5118which matches 0 or 1 occurrence of a character in the class;5232which matches 0 or 1 occurrence of a character in the class;
5119<li> 5233<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;
5121such item matches a substring equal to the <em>n</em>-th captured string5235such item matches a substring equal to the <em>n</em>-th captured string
5122(see below);5236(see below);
5123<li> 5237<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;
5125such item matches strings that start with <em>x</em>, end with <em>y</em>,5239such item matches strings that start with <em>x</em>, end with <em>y</em>,
5126and where the <em>x</em> and <em>y</em> are <em>balanced</em>.5240and where the <em>x</em> and <em>y</em> are <em>balanced</em>.
5127This means that, if one reads the string from left to right,5241This 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
5149For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>,5263For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>,
5150the part of the string matching <code>"a*(.)%w(%s*)"</code> is5264the part of the string matching <code>"a*(.)%w(%s*)"</code> is
5151stored as the first capture (and therefore has number 1);5265stored as the first capture (and therefore has number 1);
5152the character matching <code>.</code> is captured with number 2,5266the character matching <code>"."</code> is captured with number 2,
5153and the part matching <code>%s*</code> has number 3.5267and the part matching <code>"%s*"</code> has number 3.
5154 5268
5155<p>As a special case, the empty capture <code>()</code> captures5269<p>As a special case, the empty capture <code>()</code> captures
5156the current string position (a number).5270the current string position (a number).
@@ -5168,14 +5282,14 @@ represents an array or a list. · 11 unmodified lines
5168For those functions, when we talk about "the length" of a table5282For those functions, when we talk about "the length" of a table
5169we mean the result of the length operator.5283we mean the result of the length operator.
5170 5284
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>
5172Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>.5286Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>.
5173The default value for <code>sep</code> is the empty string,5287The default value for <code>sep</code> is the empty string,
5174the default for <code>i</code> is 1,5288the default for <code>i</code> is 1,
5175and the default for <code>j</code> is the length of the table.5289and the default for <code>j</code> is the length of the table.
5176If <code>i</code> is greater than <code>j</code>, returns the empty string.5290If <code>i</code> is greater than <code>j</code>, returns the empty string.
5177 5291
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>
5179 5293
5180<p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>,5294<p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>,
5181shifting up other elements to open space, if necessary.5295shifting 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
5184so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end5298so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
5185of table <code>t</code>.5299of table <code>t</code>.
5186 5300
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>
5188 5302
5189<p>Returns the largest positive numerical index of the given table,5303<p>Returns the largest positive numerical index of the given table,
5190or zero if the table has no positive numerical indices.5304or zero if the table has no positive numerical indices.
5191 5305
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>
5193 5307
5194<p>Removes from <code>table</code> the element at position <code>pos</code>,5308<p>Removes from <code>table</code> the element at position <code>pos</code>,
5195shifting down other elements to close the space, if necessary.5309shifting 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
5199so that a call <code>table.remove(t)</code> removes the last element5313so that a call <code>table.remove(t)</code> removes the last element
5200of table <code>t</code>.5314of table <code>t</code>.
5201 5315
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>
5203Sorts table elements in a given order, <em>in-place</em>,5317Sorts table elements in a given order, <em>in-place</em>,
5204from <code>table[1]</code> to <code>table[n]</code>,5318from <code>table[1]</code> to <code>table[n]</code>,
5205where <code>n</code> is the length of the table.5319where <code>n</code> is the length of the table.
@@ -5211,7 +5325,7 @@ when the first is less than the second · 5 unmodified lines
5211If <code>comp</code> is not given,5325If <code>comp</code> is not given,
5212then the standard Lua operator <code>&#060;</code> is used instead.5326then the standard Lua operator <code>&#060;</code> is used instead.
5213 5327
5214<p>The sort algorithm is not stable,5328<p>The sort algorithm is not stable;
5215that is, elements considered equal by the given order5329that is, elements considered equal by the given order
5216may have their relative positions changed by the sort.5330may have their relative positions changed by the sort.
5217 5331
@@ -5276,7 +5390,7 @@ Equal seeds produce equal sequences of numbers. · 58 unmodified lines
5276<p><a name="libio"></a><a name="5.7"></a><h2>5.7 - Input and Output Facilities</h2>5390<p><a name="libio"></a><a name="5.7"></a><h2>5.7 - Input and Output Facilities</h2>
5277 5391
5278<p>The I/O library provides two different styles for file manipulation.5392<p>The I/O library provides two different styles for file manipulation.
5279The first one uses implicit file descriptors,5393The first one uses implicit file descriptors;
5280that is, there are operations to set a default input file and a5394that is, there are operations to set a default input file and a
5281default output file,5395default output file,
5282and all input/output operations are over those default files.5396and 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
5297(plus an error message as a second result)5411(plus an error message as a second result)
5298and some value different from <b>nil</b> on success.5412and some value different from <b>nil</b> on success.
5299 5413
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>
5301 5415
5302<p>Equivalent to <code>file:close()</code>.5416<p>Equivalent to <code>file:close()</code>.
5303Without a <code>file</code>, closes the default output file.5417Without a <code>file</code>, closes the default output file.
5304 5418
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>
5306 5420
5307<p>Equivalent to <code>file:flush</code> over the default output file.5421<p>Equivalent to <code>file:flush</code> over the default output file.
5308 5422
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>
5310 5424
5311<p>When called with a file name, it opens the named file (in text mode),5425<p>When called with a file name, it opens the named file (in text mode),
5312and sets its handle as the default input file.5426and sets its handle as the default input file.
@@ -5318,7 +5432,7 @@ it returns the current default input file. · 5 unmodified lines
5318<p>In case of errors this function raises the error,5432<p>In case of errors this function raises the error,
5319instead of returning an error code.5433instead of returning an error code.
5320 5434
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>
5322 5436
5323<p>Opens the given file name in read mode5437<p>Opens the given file name in read mode
5324and returns an iterator function that,5438and returns an iterator function that,
@@ -5333,11 +5447,11 @@ When the iterator function detects the end of file, · 8 unmodified lines
5333it returns <b>nil</b> (to finish the loop) and automatically closes the file.5447it returns <b>nil</b> (to finish the loop) and automatically closes the file.
5334 5448
5335<p>The call <code>io.lines()</code> (without a file name) is equivalent5449<p>The call <code>io.lines()</code> (without a file name) is equivalent
5336to <code>io.input():lines()</code>, that is, it iterates over the5450to <code>io.input():lines()</code>;
5337lines of the default input file.5451that is, it iterates over the lines of the default input file.
5338In that case it does not close the file when the loop ends.5452In that case it does not close the file when the loop ends.
5339 5453
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>
5341 5455
5342<p>This function opens a file,5456<p>This function opens a file,
5343in the mode specified in the string <code>mode</code>.5457in 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
5346 5460
5347<p>The <code>mode</code> string can be any of the following:5461<p>The <code>mode</code> string can be any of the following:
5348<ul>5462<ul>
5349<li><b>"r"</b> read mode (the default);5463<li><b>"r"</b> --- read mode (the default);
5350<li><b>"w"</b> write mode;5464<li><b>"w"</b> --- write mode;
5351<li><b>"a"</b> append mode;5465<li><b>"a"</b> --- append mode;
5352<li><b>"r+"</b> update mode, all previous data is preserved;5466<li><b>"r+"</b> --- update mode, all previous data is preserved;
5353<li><b>"w+"</b> update mode, all previous data is erased;5467<li><b>"w+"</b> --- update mode, all previous data is erased;
5354<li><b>"a+"</b> append update mode, previous data is preserved,5468<li><b>"a+"</b> --- append update mode, previous data is preserved,
5355 writing is only allowed at the end of file.5469 writing is only allowed at the end of file.
5356</ul>5470</ul>
5357The <code>mode</code> string may also have a <code>b</code> at the end,5471The <code>mode</code> string may also have a `<code>b</code>&acute; at the end,
5358which is needed in some systems to open the file in binary mode.5472which is needed in some systems to open the file in binary mode.
5359This string is exactly what is used in the5473This string is exactly what is used in the
5360standard C function <code>fopen</code>.5474standard C function <code>fopen</code>.
5361 5475
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>
5363 5477
5364<p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file.5478<p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file.
5365 5479
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>
5367 5481
5368<p>Starts program <code>prog</code> in a separated process and returns5482<p>Starts program <code>prog</code> in a separated process and returns
5369a file handle that you can use to read data from that program5483a 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
5372(if <code>mode</code> is <code>"w"</code>).5486(if <code>mode</code> is <code>"w"</code>).
5373 5487
5374<p>This function is system dependent and is not available5488<p>This function is system dependent and is not available
5375in all platforms.5489on all platforms.
5376 5490
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>
5378 5492
5379<p>Equivalent to <code>io.input():read</code>.5493<p>Equivalent to <code>io.input():read</code>.
5380 5494
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>
5382 5496
5383<p>Returns a handle for a temporary file.5497<p>Returns a handle for a temporary file.
5384This file is open in update mode5498This file is opened in update mode
5385and it is automatically removed when the program ends.5499and it is automatically removed when the program ends.
5386 5500
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>
5388 5502
5389<p>Checks whether <code>obj</code> is a valid file handle.5503<p>Checks whether <code>obj</code> is a valid file handle.
5390Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,5504Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
5391<code>"closed file"</code> if <code>obj</code> is a closed file handle,5505<code>"closed file"</code> if <code>obj</code> is a closed file handle,
5392and <b>nil</b> if <code>obj</code> is not a file handle.5506and <b>nil</b> if <code>obj</code> is not a file handle.
5393 5507
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>
5395 5509
5396<p>Equivalent to <code>io.output():write</code>.5510<p>Equivalent to <code>io.output():write</code>.
5397 5511
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>
5399 5513
5400<p>Closes <code>file</code>.5514<p>Closes <code>file</code>.
5401Note that files are automatically closed when garbage collected,5515Note that files are automatically closed when
5516their handles are garbage collected,
5402but that takes an unpredictable time to happen.5517but that takes an unpredictable time to happen.
5403 5518
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>
5405 5520
5406<p>Saves any written data to <code>file</code>.5521<p>Saves any written data to <code>file</code>.
5407 5522
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>
5409 5524
5410<p>Returns an iterator function that,5525<p>Returns an iterator function that,
5411each time it is called,5526each time it is called,
@@ -5418,7 +5533,7 @@ will iterate over all lines of the file. · 6 unmodified lines
5418(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file5533(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
5419when the loop ends.)5534when the loop ends.)
5420 5535
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>
5422 5537
5423<p>Reads the file <code>file</code>,5538<p>Reads the file <code>file</code>,
5424according to the given formats, which specify what to read.5539according to the given formats, which specify what to read.
@@ -5445,7 +5560,7 @@ it reads nothing and returns an empty string, · 20 unmodified lines
5445or <b>nil</b> on end of file.5560or <b>nil</b> on end of file.
5446</ul>5561</ul>
5447 5562
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>
5449 5564
5450<p>Sets and gets the file position,5565<p>Sets and gets the file position,
5451measured from the beginning of the file,5566measured from the beginning of the file,
@@ -5470,26 +5585,29 @@ beginning of the file (and returns 0); · 18 unmodified lines
5470and the call <code>file:seek("end")</code> sets the position to the5585and the call <code>file:seek("end")</code> sets the position to the
5471end of the file, and returns its size.5586end of the file, and returns its size.
5472 5587
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>
5474 5589
5475<p>Sets the buffering mode for an output file.5590<p>Sets the buffering mode for an output file.
5476There are three available modes:5591There are three available modes:
5477<ul>5592<ul>
5478<li><b>"no"</b> no buffering; any output operation appear immediately.5593<li><b>"no"</b> ---
5479<li><b>"full"</b> full buffering; output operation is performed only5594no buffering; the result of any output operation appears immediately.
5480when the buffer is full (or when you <code>flush</code> the file (see <a href="#flush">5.7</a>)).5595<li><b>"full"</b> ---
5481<li><b>"line"</b> line buffering; output is buffered until a newline is5596full buffering; output operation is performed only
5482output or there is any input from some special files5597when 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> ---
5599line buffering; output is buffered until a newline is output
5600or there is any input from some special files
5483(such as a terminal device).5601(such as a terminal device).
5484</ul>5602</ul>
5485For the last two cases, <code>sizes</code>5603For the last two cases, <code>sizes</code>
5486specifies the size of the buffer, in bytes.5604specifies the size of the buffer, in bytes.
5487The default is an appropriate size.5605The default is an appropriate size.
5488 5606
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>
5490 5608
5491<p>Writes the value of each of its arguments to5609<p>Writes the value of each of its arguments to
5492the filehandle <code>file</code>.5610the <code>file</code>.
5493The arguments must be strings or numbers.5611The arguments must be strings or numbers.
5494To write other values,5612To write other values,
5495use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.format"><code>string.format</code></a> before <code>write</code>.5613use <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
5498 5616
5499<p>This library is implemented through table <code>os</code>.5617<p>This library is implemented through table <code>os</code>.
5500 5618
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>
5502 5620
5503<p>Returns an approximation of the amount of CPU time5621<p>Returns an approximation of the amount in seconds of CPU time
5504used by the program, in seconds.5622used by the program.
5505 5623
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>
5507 5625
5508<p>Returns a string or a table containing date and time,5626<p>Returns a string or a table containing date and time,
5509formatted according to the given string <code>format</code>.5627formatted 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
5533the host system and on the current locale5651the host system and on the current locale
5534(that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).5652(that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).
5535 5653
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>
5537 5655
5538<p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>.5656<p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>.
5539In Posix, Windows, and some other systems,5657In Posix, Windows, and some other systems,
5540this value is exactly <code>t2</code><em>-</em><code>t1</code>.5658this value is exactly <code>t2</code><em>-</em><code>t1</code>.
5541 5659
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>
5543 5661
5544<p>This function is equivalent to the C function <code>system</code>.5662<p>This function is equivalent to the C function <code>system</code>.
5545It passes <code>command</code> to be executed by an operating system shell.5663It passes <code>command</code> to be executed by an operating system shell.
5546It returns a status code, which is system-dependent.5664It returns a status code, which is system-dependent.
5665If <code>command</code> is absent, then it returns nonzero if a shell is available
5666and zero otherwise.
5547 5667
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>
5549 5669
5550<p>Calls the C function <code>exit</code>,5670<p>Calls the C function <code>exit</code>,
5551with an optional <code>code</code>,5671with an optional <code>code</code>,
5552to terminate the host program.5672to terminate the host program.
5553The default value for <code>code</code> is the success code.5673The default value for <code>code</code> is the success code.
5554 5674
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>
5556 5676
5557<p>Returns the value of the process environment variable <code>varname</code>,5677<p>Returns the value of the process environment variable <code>varname</code>,
5558or <b>nil</b> if the variable is not defined.5678or <b>nil</b> if the variable is not defined.
5559 5679
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>
5561 5681
5562<p>Deletes the file with the given name.5682<p>Deletes the file or directory with the given name.
5683Directories must be empty to be removed.
5563If this function fails, it returns <b>nil</b>,5684If this function fails, it returns <b>nil</b>,
5564plus a string describing the error.5685plus a string describing the error.
5565 5686
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>
5567 5688
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>.
5569If this function fails, it returns <b>nil</b>,5690If this function fails, it returns <b>nil</b>,
5570plus a string describing the error.5691plus a string describing the error.
5571 5692
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>
5573 5694
5574<p>Sets the current locale of the program.5695<p>Sets the current locale of the program.
5575<code>locale</code> is a string specifying a locale;5696<code>locale</code> is a string specifying a locale;
@@ -5580,7 +5701,7 @@ the default category is <code>"all"</code>. · 4 unmodified lines
5580The function returns the name of the new locale,5701The function returns the name of the new locale,
5581or <b>nil</b> if the request cannot be honored.5702or <b>nil</b> if the request cannot be honored.
5582 5703
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>
5584 5705
5585<p>Returns the current time when called without arguments,5706<p>Returns the current time when called without arguments,
5586or a time representing the date and time specified by the given table.5707or 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
5595and the number returned by <code>time</code> can be used only as an argument to5716and the number returned by <code>time</code> can be used only as an argument to
5596<code>date</code> and <code>difftime</code>.5717<code>date</code> and <code>difftime</code>.
5597 5718
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>
5599 5720
5600<p>Returns a string with a file name that can5721<p>Returns a string with a file name that can
5601be used for a temporary file.5722be used for a temporary file.
5602The file must be explicitly opened before its use5723The file must be explicitly opened before its use
5603and removed when no longer needed.5724and explicitly removed when no longer needed.
5604 5725
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>
5606 5727
5607<p>The <em>debug library</em> provides5728<p>This library provides
5608the functionality of the debug interface to Lua programs.5729the functionality of the debug interface to Lua programs.
5609You should exert care when using this library.5730You should exert care when using this library.
5610The functions provided here should be used exclusively for debugging5731The functions provided here should be used exclusively for debugging
@@ -5614,14 +5735,15 @@ usual programming tool: · 3 unmodified lines
5614They can be very slow.5735They can be very slow.
5615Moreover, several of its functions5736Moreover, several of its functions
5616violate some assumptions about Lua code5737violate some assumptions about Lua code
5617(e.g., that local variables cannot be accessed from outside or5738(e.g., that variables local to a function
5739cannot be accessed from outside or
5618that userdata metatables cannot be changed by Lua code)5740that userdata metatables cannot be changed by Lua code)
5619and therefore can compromise some otherwise secure code.5741and therefore can compromise otherwise secure code.
5620 5742
5621<p>All functions in this library are provided5743<p>All functions in this library are provided
5622inside a <code>debug</code> table.5744inside the <code>debug</code> table.
5623 5745
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>
5625 5747
5626<p>Enters an interactive mode with the user,5748<p>Enters an interactive mode with the user,
5627running each string that the user enters.5749running each string that the user enters.
@@ -5631,22 +5753,22 @@ change their values, evaluate expressions, and so on. · 3 unmodified lines
5631A line containing only the word <code>cont</code> finishes this function,5753A line containing only the word <code>cont</code> finishes this function,
5632so that the caller continues its execution.5754so that the caller continues its execution.
5633 5755
5634<p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested5756<p>Note that commands for <code>debug.debug</code> are not lexically nested
5635with any function, so they have no direct access to local variables.5757within any function, and so have no direct access to local variables.
5636 5758
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>
5638Returns the environment of object <code>o</code>.5760Returns the environment of object <code>o</code>.
5639 5761
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>
5641 5763
5642<p>Returns the current hook settings, as three values:5764<p>Returns the current hook settings, as three values:
5643the current hook function, the current hook mask,5765the current hook function, the current hook mask,
5644and the current hook count5766and the current hook count
5645(as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).5767(as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).
5646 5768
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>
5648 5770
5649<p>This function returns a table with information about a function.5771<p>Returns a table with information about a function.
5650You can give the function directly,5772You can give the function directly,
5651or you can give a number as the value of <code>function</code>,5773or you can give a number as the value of <code>function</code>,
5652which means the function running at level <code>function</code> of the call stack:5774which 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
5664adds a field named <code>func</code> with the function itself.5786adds a field named <code>func</code> with the function itself.
5665 5787
5666<p>For instance, the expression <code>debug.getinfo(1,"n").name</code> returns5788<p>For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
5667the name of the current function, if a reasonable name can be found,5789a name of the current function, if a reasonable name can be found,
5668and <code>debug.getinfo(print)</code> returns a table with all available information5790and <code>debug.getinfo(print)</code> returns a table with all available information
5669about the <a href="#pdf-print"><code>print</code></a> function.5791about the <a href="#pdf-print"><code>print</code></a> function.
5670 5792
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>
5672 5794
5673<p>This function returns the name and the value of the local variable5795<p>This function returns the name and the value of the local variable
5674with index <code>local</code> of the function at level <code>level</code> of the stack.5796with 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
5683represent internal variables5805represent internal variables
5684(loop control variables, temporaries, and C function locals).5806(loop control variables, temporaries, and C function locals).
5685 5807
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>
5687 5809
5688<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.5810<p>Returns the metatable of the given <code>object</code>
5689Otherwise, returns the metatable of the given object.5811or <b>nil</b> if it does not have a metatable.
5690 5812
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>
5692 5814
5693<p>Returns the registry table (see <a href="#registry">3.5</a>).5815<p>Returns the registry table (see <a href="#registry">3.5</a>).
5694 5816
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>
5696 5818
5697<p>This function returns the name and the value of the upvalue5819<p>This function returns the name and the value of the upvalue
5698with index <code>up</code> of the function <code>func</code>.5820with index <code>up</code> of the function <code>func</code>.
5699The function returns <b>nil</b> if there is no upvalue with the given index.5821The function returns <b>nil</b> if there is no upvalue with the given index.
5700 5822
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>
5702 5824
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>.
5704 5826
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>
5706 5828
5707<p>Sets the given function as a hook.5829<p>Sets the given function as a hook.
5708The string <code>mask</code> and the number <code>count</code> describe5830The string <code>mask</code> and the number <code>count</code> describe
@@ -5710,22 +5832,22 @@ when the hook will be called. · 1 unmodified line
5710The string mask may have the following characters,5832The string mask may have the following characters,
5711with the given meaning:5833with the given meaning:
5712<ul>5834<ul>
5713<li><b><code>"c"</code></b> The hook is called every time Lua calls a function;5835<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;5836<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.5837<li><b><code>"l"</code></b> --- The hook is called every time Lua enters a new line of code.
5716</ul>5838</ul>
5717With a <code>count</code> different from zero,5839With a <code>count</code> different from zero,
5718the hook is called after every <code>count</code> instructions.5840the hook is called after every <code>count</code> instructions.
5719 5841
5720<p>When called without arguments,5842<p>When called without arguments,
5721the <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.
5722 5844
5723<p>When the hook is called, its first parameter is always a string5845<p>When the hook is called, its first parameter is a string
5724describing the event that triggered its call:5846describing the event that has triggered its call:
5725<code>"call"</code>, <code>"return"</code> (or <code>"tail return"</code>),5847<code>"call"</code>, <code>"return"</code> (or <code>"tail return"</code>),
5726<code>"line"</code>, and <code>"count"</code>.5848<code>"line"</code>, and <code>"count"</code>.
5727Moreover, for line events,5849For line events,
5728it also gets as its second parameter the new line number.5850the hook also gets the new line number as its second parameter.
5729Inside a hook,5851Inside a hook,
5730you can call <code>getinfo</code> with level 2 to get more information about5852you can call <code>getinfo</code> with level 2 to get more information about
5731the running function5853the running function
@@ -5735,7 +5857,7 @@ unless the event is <code>"tail return"</code>. · 3 unmodified lines
5735In this case, Lua is only simulating the return,5857In this case, Lua is only simulating the return,
5736and a call to <code>getinfo</code> will return invalid data.5858and a call to <code>getinfo</code> will return invalid data.
5737 5859
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>
5739 5861
5740<p>This function assigns the value <code>value</code> to the local variable5862<p>This function assigns the value <code>value</code> to the local variable
5741with index <code>local</code> of the function at level <code>level</code> of the stack.5863with 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
5745(You can call <code>getinfo</code> to check whether the level is valid.)5867(You can call <code>getinfo</code> to check whether the level is valid.)
5746Otherwise, it returns the name of the local variable.5868Otherwise, it returns the name of the local variable.
5747 5869
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>
5749 5871
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>).
5751 5874
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>
5753 5876
5754<p>This function assigns the value <code>value</code> to the upvalue5877<p>This function assigns the value <code>value</code> to the upvalue
5755with index <code>up</code> of the function <code>func</code>.5878with 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
5757with the given index.5880with the given index.
5758Otherwise, it returns the name of the upvalue.5881Otherwise, it returns the name of the upvalue.
5759 5882
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>
5761 5884
5762<p>Returns a string with a traceback of the call stack.5885<p>Returns a string with a traceback of the call stack.
5763An optional <code>message</code> string is appended5886An optional <code>message</code> string is appended
@@ -5775,7 +5898,7 @@ An interpreter for Lua as a stand-alone language, · 11 unmodified lines
5775called simply <code>lua</code>,5898called simply <code>lua</code>,
5776is provided with the standard distribution.5899is provided with the standard distribution.
5777The stand-alone interpreter includes5900The stand-alone interpreter includes
5778all standard libraries plus the reflexive debug interface.5901all standard libraries, including the debug library.
5779Its usage is:5902Its usage is:
5780<pre>5903<pre>
5781 lua [options] [script [args]]5904 lua [options] [script [args]]
@@ -5790,30 +5913,31 @@ The options are: · 8 unmodified lines
5790<li><b><code>-</code> </b> executes <code>stdin</code> as a file and stops handling options.5913<li><b><code>-</code> </b> executes <code>stdin</code> as a file and stops handling options.
5791</ul>5914</ul>
5792After handling its options, <code>lua</code> runs the given <em>script</em>,5915After handling its options, <code>lua</code> runs the given <em>script</em>,
5793passing to it the given <em>args</em>.5916passing to it the given <em>args</em> as string arguments.
5794When called without arguments,5917When 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>
5919when the standard input (<code>stdin</code>) is a terminal,
5796and as <code>lua -</code> otherwise.5920and as <code>lua -</code> otherwise.
5797 5921
5798<p>Before running any argument,5922<p>Before running any argument,
5799the interpreter checks for an environment variable <code>LUA_INIT</code>.5923the interpreter checks for an environment variable <code>LUA_INIT</code>.
5800If its format is @<em>filename</em>,5924If its format is @<em>filename</em>,
5801then lua executes the file.5925then <code>lua</code> executes the file.
5802Otherwise, lua executes the string itself.5926Otherwise, <code>lua</code> executes the string itself.
5803 5927
5804<p>All options are handled in order, except <code>-i</code>.5928<p>All options are handled in order, except <code>-i</code>.
5805For instance, an invocation like5929For instance, an invocation like
5806<pre>5930<pre>
5807 $ lua -e'a=1' -e 'print(a)' script.lua5931 $ lua -e'a=1' -e 'print(a)' script.lua
5808</pre>5932</pre>
5809will first set <code>a</code> to 1, then print <code>a</code>,5933will first set <code>a</code> to 1, then print the value of <code>a</code> (which is `<code>1</code>&acute;),
5810and finally run the file <code>script.lua</code>.5934and finally run the file <code>script.lua</code> with no arguments.
5811(Here <code>$</code> is the shell prompt. Your prompt may be different.)5935(Here <code>$</code> is the shell prompt. Your prompt may be different.)
5812 5936
5813<p>Before starting to run the script,5937<p>Before starting to run the script,
5814<code>lua</code> collects all arguments in the command line5938<code>lua</code> collects all arguments in the command line
5815in a global table called <code>arg</code>.5939in a global table called <code>arg</code>.
5816The script name is stored in index 0,5940The script name is stored at index 0,
5817the first argument after the script name goes to index 1,5941the first argument after the script name goes to index 1,
5818and so on.5942and so on.
5819Any arguments before the script name5943Any arguments before the script name
@@ -5821,34 +5945,40 @@ Any arguments before the script name · 1 unmodified line
5821go to negative indices.5945go to negative indices.
5822For instance, in the call5946For instance, in the call
5823<pre>5947<pre>
5824 $ lua -la.lua b.lua t1 t25948 $ lua -la b.lua t1 t2
5825</pre>5949</pre>
5826the interpreter first runs the file <code>a.lua</code>,5950the interpreter first runs the file <code>a.lua</code>,
5827then creates a table5951then creates a table
5828<pre>5952<pre>
5829 arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua",5953 arg = { [-2] = "lua", [-1] = "-la",
5954 [0] = "b.lua",
5830 [1] = "t1", [2] = "t2" }5955 [1] = "t1", [2] = "t2" }
5831</pre>5956</pre>
5832and finally runs the file <code>b.lua</code>.5957and finally runs the file <code>b.lua</code>.
5833The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...5958The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...
5834as arguments;5959as arguments;
5835it can access those arguments with the vararg expression <code>...</code>.5960it can also access those arguments with the vararg expression `<code>...</code>&acute;.
5836 5961
5837<p>In interactive mode,5962<p>In interactive mode,
5838if you write an incomplete statement,5963if you write an incomplete statement,
5839the interpreter waits for its completion.5964the interpreter waits for its completion
5965by issuing a different prompt.
5840 5966
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,
5842then its value is used as the prompt.5968then its value is used as the prompt.
5843Therefore, the prompt can be changed directly on the command line:5969Similarly, if the global variable <code>_PROMPT2</code> contains a string,
5970it its value is used as the secondary prompt
5971(issued during incomplete statements).
5972Therefore, both prompts can be changed directly on the command line.
5973For instance,
5844<pre>5974<pre>
5845 $ lua -e"_PROMPT='myprompt> '" -i5975 $ lua -e"_PROMPT='myprompt> '" -i
5846</pre>5976</pre>
5847(the outer pair of quotes is for the shell,5977(the outer pair of quotes is for the shell,
5848the inner is for Lua),5978the inner pair is for Lua),
5849or in any Lua programs by assigning to <code>_PROMPT</code>.5979or in any Lua programs by assigning to <code>_PROMPT</code>.
5850Note the use of <code>-i</code> to enter interactive mode; otherwise,5980Note the use of <code>-i</code> to enter interactive mode; otherwise,
5851the program would end just after the assignment to <code>_PROMPT</code>.5981the program would just end silently right after the assignment to <code>_PROMPT</code>.
5852 5982
5853<p>To allow the use of Lua as a5983<p>To allow the use of Lua as a
5854script interpreter in Unix systems,5984script interpreter in Unix systems,
@@ -5869,17 +5999,17 @@ then · 14 unmodified lines
5869</pre>5999</pre>
5870is a more portable solution.) 6000is a more portable solution.)
5871 6001
5872<p><hr/>6002<p><hr />
5873 6003
5874<p><h1>Incompatibilities with Previous Version</h1>6004<p><h1>Incompatibilities with the Previous Version</h1>
5875 6005
5876 6006
5877<p>Here we list the incompatibilities when moving a program6007<p>Here we list the incompatibilities that may be found when moving a program
5878from Lua 5.0 to Lua 5.1.6008from Lua 5.0 to Lua 5.1.
5879You can avoid most of the incompatibilities compiling Lua with6009You can avoid most of the incompatibilities compiling Lua with
5880appropriate options.6010appropriate options (see file <code>luaconf.h</code>).
5881However,6011However,
5882all those compatibility options will be removed in the next version.6012all those compatibility options will be removed in the next version of Lua.
5883 6013
5884<p><h2>Incompatibilities with version 5.0</h2>6014<p><h2>Incompatibilities with version 5.0</h2>
5885 6015
@@ -5888,25 +6018,21 @@ all those compatibility options will be removed in the next version. · 2 unmodified lines
5888<li>6018<li>
5889The vararg system changed from the pseudo-argument <code>arg</code> with a6019The vararg system changed from the pseudo-argument <code>arg</code> with a
5890table with the extra arguments to the vararg expression.6020table 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>.)
5892 6022
5893<p><li>6023<p><li>
5894There was a subtle change in the scope of the implicit6024There was a subtle change in the scope of the implicit
5895variables of the <b>for</b> constructor.6025variables of the <b>for</b> statement and for the <b>repeat</b> statement.
5896 6026
5897<p><li>6027<p><li>
5898The long string/long comment syntax (<code>[[...]]</code>) does not allow nesting.6028The long string/long comment syntax (<code>[[...]]</code>) does not allow nesting.
5899You can use the new syntax (<code>[=[...]=]</code>) in those cases.6029You 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>.)
5901 6031
5902<p></ul>6032<p></ul>
5903 6033
5904<p><h3>Changes in the Libraries</h3>6034<p><h3>Changes in the Libraries</h3>
5905<ul>6035<ul>
5906<li>
5907Function <a href="#pdf-string.find"><code>string.find</code></a> does not return its captures.
5908Use <a href="#pdf-string.match"><code>string.match</code></a> for that.
5909(Option <code>LUA_COMPAT_FIND</code>)
5910 6036
5911<p><li> 6037<p><li>
5912Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.6038Function <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
5935(Option <code>LUA_COMPAT_MOD</code>)6061(Option <code>LUA_COMPAT_MOD</code>)
5936 6062
5937<p><li>6063<p><li>
5938There was substantial changes in function <a href="#pdf-require"><code>require</code></a> due to6064There were substantial changes in function <a href="#pdf-require"><code>require</code></a> due to
5939the new module system.6065the new module system.
5940However, the new behavior is mostly compatible with the old,6066However, the new behavior is mostly compatible with the old,
5941but it gets the path from <a href="#pdf-package.path"><code>package.path</code></a> instead6067but <code>require</code> gets the path from <a href="#pdf-package.path"><code>package.path</code></a> instead
5942of from <code>LUA_PATH</code>.6068of from <code>LUA_PATH</code>.
5943 6069
5944<p><li>6070<p><li>
@@ -5952,7 +6078,7 @@ use <code>collectgarbage("count")</code> instead. · 7 unmodified lines
5952<ul>6078<ul>
5953<li>6079<li>
5954Function <code>lua_open</code> was replaced by <a href="#lua_newstate"><code>lua_newstate</code></a> to6080Function <code>lua_open</code> was replaced by <a href="#lua_newstate"><code>lua_newstate</code></a> to
5955allow the user to set an allocation function.6081allow the user to set a memory allocation function.
5956You can use <a href="#luaL_newstate"><code>luaL_newstate</code></a> from the standard library to6082You can use <a href="#luaL_newstate"><code>luaL_newstate</code></a> from the standard library to
5957create a state with a standard allocation function6083create a state with a standard allocation function
5958(based on <code>realloc</code>).6084(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
5973<a name="BNF"></a><h1>The Complete Syntax of Lua</h1>6099<a name="BNF"></a><h1>The Complete Syntax of Lua</h1>
5974 6100
5975 6101
6102<p>Here is the complete syntax of Lua in extended BNF.
6103It does not describe operator priorities nor some syntactical restrictions,
6104such as <b>return</b> and <b>break</b> statements
6105can only appear as the <em>last</em> statement of a block.
6106
5976<p>6107<p>
5977 6108
5978<p><pre>6109<p><pre>
@@ -5991,7 +6122,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 12 unmodified lines
5991 <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | 6122 <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> |
5992 <b>function</b> funcname funcbody | 6123 <b>function</b> funcname funcbody |
5993 <b>local</b> <b>function</b> Name funcbody | 6124 <b>local</b> <b>function</b> Name funcbody |
5994 <b>local</b> namelist [init] 6125 <b>local</b> namelist [`<b>=</b>&acute; explist1]
5995 6126
5996 laststat ::= <b>return</b> [explist1] | <b>break</b>6127 laststat ::= <b>return</b> [explist1] | <b>break</b>
5997 6128
@@ -6003,18 +6134,16 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 5 unmodified lines
6003 6134
6004 namelist ::= Name {`<b>,</b>&acute; Name}6135 namelist ::= Name {`<b>,</b>&acute; Name}
6005 6136
6006 init ::= `<b>=</b>&acute; explist1
6007
6008 explist1 ::= {exp `<b>,</b>&acute;} exp6137 explist1 ::= {exp `<b>,</b>&acute;} exp
6009 6138
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; |
6011 function | prefixexp | tableconstructor | exp binop exp | unop exp 6140 function | prefixexp | tableconstructor | exp binop exp | unop exp
6012 6141
6013 prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;6142 prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
6014 6143
6015 functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args 6144 functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args
6016 6145
6017 args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Literal 6146 args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | String
6018 6147
6019 function ::= <b>function</b> funcbody6148 function ::= <b>function</b> funcbody
6020 6149
@@ -6026,7 +6155,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 5 unmodified lines
6026 6155
6027 fieldlist ::= field {fieldsep field} [fieldsep]6156 fieldlist ::= field {fieldsep field} [fieldsep]
6028 6157
6029 field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | name `<b>=</b>&acute; exp | exp6158 field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp
6030 6159
6031 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;6160 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
6032 6161
@@ -6042,10 +6171,5 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 9 unmodified lines
6042 6171
6043<p>6172<p>
6044 6173
6045<HR>
6046<SMALL>
6047Last update:
6048Tue Nov 1 15:20:21 BRST 2005
6049</SMALL>
6050
6051</body></html>6174</body></html>
6175
src/Makefile+42−9
@@ -4,6 +4,9 @@ · 3 unmodified lines
4 4
5# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================5# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
6 6
7# Your platform. See PLATS for possible values.
8PLAT= none
9
7CC= gcc10CC= gcc
8CFLAGS= -O2 -Wall $(MYCFLAGS)11CFLAGS= -O2 -Wall $(MYCFLAGS)
9AR= ar rcu12AR= ar rcu
@@ -14,12 +17,11 @@ LIBS= -lm $(MYLIBS) · 4 unmodified lines
14MYCFLAGS=17MYCFLAGS=
15MYLDFLAGS=18MYLDFLAGS=
16MYLIBS=19MYLIBS=
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
20 20
21# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========21# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
22 22
23PLATS= ansi bsd generic linux macosx mingw posix
24
23LUA_A= liblua.a25LUA_A= liblua.a
24CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \26CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
25 lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \27 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
37ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)39ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
38ALL_A= $(LUA_A)40ALL_A= $(LUA_A)
39 41
42default: $(PLAT)
43
40all: $(ALL_T)44all: $(ALL_T)
41 45
42o: $(ALL_O)46o: $(ALL_O)
@@ -60,6 +64,7 @@ depend: · 17 unmodified lines
60 @$(CC) $(CFLAGS) -MM l*.c print.c64 @$(CC) $(CFLAGS) -MM l*.c print.c
61 65
62echo:66echo:
67 @echo "PLAT = $(PLAT)"
63 @echo "CC = $(CC)"68 @echo "CC = $(CC)"
64 @echo "CFLAGS = $(CFLAGS)"69 @echo "CFLAGS = $(CFLAGS)"
65 @echo "AR = $(AR)"70 @echo "AR = $(AR)"
@@ -69,6 +74,34 @@ echo: · 3 unmodified lines
69 @echo "MYLDFLAGS = $(MYLDFLAGS)"74 @echo "MYLDFLAGS = $(MYLDFLAGS)"
70 @echo "MYLIBS = $(MYLIBS)"75 @echo "MYLIBS = $(MYLIBS)"
71 76
77# convenience targets for usual platforms
78
79none:
80 @echo "Please choose a platform: $(PLATS)"
81
82ansi:
83 $(MAKE) all MYCFLAGS=-DLUA_ANSI
84
85bsd:
86 $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
87
88generic:
89 $(MAKE) all MYCFLAGS=
90
91linux:
92 $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
93
94macosx:
95 $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
96
97mingw:
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
102posix:
103 $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
104
72# DO NOT DELETE105# DO NOT DELETE
73 106
74lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \107lapi.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
86ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \119ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
87 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \120 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
88 lstring.h lundump.h lvm.h121 lstring.h lundump.h lvm.h
89ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \122ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
90 ltm.h lzio.h lmem.h lundump.h123 lzio.h lmem.h lundump.h
91lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \124lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
92 lstate.h ltm.h lzio.h125 lstate.h ltm.h lzio.h
93lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \126lgc.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
99lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h132lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
100lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \133lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
101 ltm.h lzio.h lmem.h ldo.h134 ltm.h lzio.h lmem.h ldo.h
102loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h135loadlib.o: loadlib.c lauxlib.h lua.h luaconf.h lobject.h llimits.h \
136 lualib.h
103lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \137lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
104 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h138 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
105lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h139lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
106loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h140loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
107lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \141lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
108 lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \142 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
122 lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \156 lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
123 lundump.h157 lundump.h
124lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \158lundump.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 \159 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
126 lundump.h
127lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \160lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
128 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h161 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
129lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \162lzio.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 @@
1/*1/*
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 $
3** Lua API3** Lua API
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -40,7 +40,7 @@ const char lua_ident[] = · 34 unmodified lines
40 40
41#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))41#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
42 42
43#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject)43#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject)
44 44
45#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}45#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;}
46 46
@@ -50,7 +50,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 3 unmodified lines
50 if (idx > 0) {50 if (idx > 0) {
51 TValue *o = L->base + (idx - 1);51 TValue *o = L->base + (idx - 1);
52 api_check(L, idx <= L->ci->top - L->base);52 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);
54 else return o;54 else return o;
55 }55 }
56 else if (idx > LUA_REGISTRYINDEX) {56 else if (idx > LUA_REGISTRYINDEX) {
@@ -70,7 +70,7 @@ static TValue *index2adr (lua_State *L, int idx) { · 13 unmodified lines
70 idx = LUA_GLOBALSINDEX - idx;70 idx = LUA_GLOBALSINDEX - idx;
71 return (idx <= func->c.nupvalues)71 return (idx <= func->c.nupvalues)
72 ? &func->c.upvalue[idx-1]72 ? &func->c.upvalue[idx-1]
73 : cast(TValue *, &luaO_nilobject);73 : cast(TValue *, luaO_nilobject);
74 }74 }
75 }75 }
76}76}
@@ -153,7 +153,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 76 unmodified lines
153 153
154 154
155LUA_API int lua_gettop (lua_State *L) {155LUA_API int lua_gettop (lua_State *L) {
156 return cast(int, L->top - L->base);156 return cast_int(L->top - L->base);
157}157}
158 158
159 159
@@ -234,7 +234,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 74 unmodified lines
234 234
235LUA_API int lua_type (lua_State *L, int idx) {235LUA_API int lua_type (lua_State *L, int idx) {
236 StkId o = index2adr(L, idx);236 StkId o = index2adr(L, idx);
237 return (o == &luaO_nilobject) ? LUA_TNONE : ttype(o);237 return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
238}238}
239 239
240 240
@@ -272,7 +272,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { · 31 unmodified lines
272LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {272LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
273 StkId o1 = index2adr(L, index1);273 StkId o1 = index2adr(L, index1);
274 StkId o2 = index2adr(L, index2);274 StkId o2 = index2adr(L, index2);
275 return (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0275 return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
276 : luaO_rawequalObj(o1, o2);276 : luaO_rawequalObj(o1, o2);
277}277}
278 278
@@ -283,8 +283,7 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { · 4 unmodified lines
283 lua_lock(L); /* may call tag method */283 lua_lock(L); /* may call tag method */
284 o1 = index2adr(L, index1);284 o1 = index2adr(L, index1);
285 o2 = index2adr(L, index2);285 o2 = index2adr(L, index2);
286 i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0286 i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
287 : equalobj(L, o1, o2);
288 lua_unlock(L);287 lua_unlock(L);
289 return i;288 return i;
290}289}
@@ -296,7 +295,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { · 5 unmodified lines
296 lua_lock(L); /* may call tag method */295 lua_lock(L); /* may call tag method */
297 o1 = index2adr(L, index1);296 o1 = index2adr(L, index1);
298 o2 = index2adr(L, index2);297 o2 = index2adr(L, index2);
299 i = (o1 == &luaO_nilobject || o2 == &luaO_nilobject) ? 0298 i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
300 : luaV_lessthan(L, o1, o2);299 : luaV_lessthan(L, o1, o2);
301 lua_unlock(L);300 lua_unlock(L);
302 return i;301 return i;
@@ -430,7 +429,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { · 127 unmodified lines
430 429
431LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {430LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
432 lua_lock(L);431 lua_lock(L);
433 setnvalue(L->top, cast(lua_Number, n));432 setnvalue(L->top, cast_num(n));
434 api_incr_top(L);433 api_incr_top(L);
435 lua_unlock(L);434 lua_unlock(L);
436}435}
@@ -910,11 +909,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 473 unmodified lines
910 }909 }
911 case LUA_GCCOUNT: {910 case LUA_GCCOUNT: {
912 /* GC values are expressed in Kbytes: #bytes/2^10 */911 /* GC values are expressed in Kbytes: #bytes/2^10 */
913 res = cast(int, g->totalbytes >> 10);912 res = cast_int(g->totalbytes >> 10);
914 break;913 break;
915 }914 }
916 case LUA_GCCOUNTB: {915 case LUA_GCCOUNTB: {
917 res = cast(int, g->totalbytes & 0x3ff);916 res = cast_int(g->totalbytes & 0x3ff);
918 break;917 break;
919 }918 }
920 case LUA_GCSTEP: {919 case LUA_GCSTEP: {
@@ -983,7 +982,7 @@ LUA_API void lua_concat (lua_State *L, int n) { · 62 unmodified lines
983 api_checknelems(L, n);982 api_checknelems(L, n);
984 if (n >= 2) {983 if (n >= 2) {
985 luaC_checkGC(L);984 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);
987 L->top -= (n-1);986 L->top -= (n-1);
988 }987 }
989 else if (n == 0) { /* push empty string */988 else if (n == 0) { /* push empty string */
src/lauxlib.c+13−5
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Auxiliary functions for building Lua libraries3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -226,16 +226,24 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname, · 220 unmodified lines
226}226}
227 227
228 228
229static int libsize (const luaL_Reg *l) {
230 int size = 0;
231 for (; l->name; l++) size++;
232 return size;
233}
234
235
229LUALIB_API void luaI_openlib (lua_State *L, const char *libname,236LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
230 const luaL_Reg *l, int nup) {237 const luaL_Reg *l, int nup) {
231 if (libname) {238 if (libname) {
239 int size = libsize(l);
232 /* check whether lib already exists */240 /* check whether lib already exists */
233 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");241 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size);
234 lua_getfield(L, -1, libname); /* get _LOADED[libname] */242 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
235 if (!lua_istable(L, -1)) { /* not found? */243 if (!lua_istable(L, -1)) { /* not found? */
236 lua_pop(L, 1); /* remove previous result */244 lua_pop(L, 1); /* remove previous result */
237 /* try global variable (and create one if it does not exist) */245 /* 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)
239 luaL_error(L, "name conflict for module " LUA_QS, libname);247 luaL_error(L, "name conflict for module " LUA_QS, libname);
240 lua_pushvalue(L, -1);248 lua_pushvalue(L, -1);
241 lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */249 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
331 339
332 340
333LUALIB_API const char *luaL_findtable (lua_State *L, int idx,341LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
334 const char *fname) {342 const char *fname, int szhint) {
335 const char *e;343 const char *e;
336 lua_pushvalue(L, idx);344 lua_pushvalue(L, idx);
337 do {345 do {
@@ -341,7 +349,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, · 3 unmodified lines
341 lua_rawget(L, -2);349 lua_rawget(L, -2);
342 if (lua_isnil(L, -1)) { /* no such field? */350 if (lua_isnil(L, -1)) { /* no such field? */
343 lua_pop(L, 1); /* remove this nil */351 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 */
345 lua_pushlstring(L, fname, e - fname);353 lua_pushlstring(L, fname, e - fname);
346 lua_pushvalue(L, -2);354 lua_pushvalue(L, -2);
347 lua_settable(L, -4); /* set new table into field */355 lua_settable(L, -4); /* set new table into field */
src/lauxlib.h+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Auxiliary functions for building Lua libraries3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -86,7 +86,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, · 80 unmodified lines
86 const char *r);86 const char *r);
87 87
88LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,88LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
89 const char *fname);89 const char *fname, int szhint);
90 90
91 91
92 92
src/lbaselib.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -201,7 +201,7 @@ static int luaB_collectgarbage (lua_State *L) { · 195 unmodified lines
201 switch (optsnum[o]) {201 switch (optsnum[o]) {
202 case LUA_GCCOUNT: {202 case LUA_GCCOUNT: {
203 int b = lua_gc(L, LUA_GCCOUNTB, 0);203 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);
205 return 1;205 return 1;
206 }206 }
207 case LUA_GCSTEP: {207 case LUA_GCSTEP: {
@@ -625,7 +625,7 @@ static void base_open (lua_State *L) { · 417 unmodified lines
625 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);625 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
626 auxopen(L, "pairs", luaB_pairs, luaB_next);626 auxopen(L, "pairs", luaB_pairs, luaB_next);
627 /* `newproxy' needs a weaktable as upvalue */627 /* `newproxy' needs a weaktable as upvalue */
628 lua_newtable(L); /* new table `w' */628 lua_createtable(L, 0, 1); /* new table `w' */
629 lua_pushvalue(L, -1); /* `w' will be its own metatable */629 lua_pushvalue(L, -1); /* `w' will be its own metatable */
630 lua_setmetatable(L, -2);630 lua_setmetatable(L, -2);
631 lua_pushliteral(L, "kv");631 lua_pushliteral(L, "kv");
src/lcode.c+6−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -196,7 +196,7 @@ void luaK_checkstack (FuncState *fs, int n) { · 190 unmodified lines
196 if (newstack > fs->f->maxstacksize) {196 if (newstack > fs->f->maxstacksize) {
197 if (newstack >= MAXSTACK)197 if (newstack >= MAXSTACK)
198 luaX_syntaxerror(fs->ls, "function or expression too complex");198 luaX_syntaxerror(fs->ls, "function or expression too complex");
199 fs->f->maxstacksize = cast(lu_byte, newstack);199 fs->f->maxstacksize = cast_byte(newstack);
200 }200 }
201}201}
202 202
@@ -227,11 +227,11 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { · 24 unmodified lines
227 Proto *f = fs->f;227 Proto *f = fs->f;
228 int oldsize = f->sizek;228 int oldsize = f->sizek;
229 if (ttisnumber(idx)) {229 if (ttisnumber(idx)) {
230 lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v));230 lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
231 return cast(int, nvalue(idx));231 return cast_int(nvalue(idx));
232 }232 }
233 else { /* constant not found; create a new entry */233 else { /* constant not found; create a new entry */
234 setnvalue(idx, cast(lua_Number, fs->nk));234 setnvalue(idx, cast_num(fs->nk));
235 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,235 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
236 MAXARG_Bx, "constant table overflow");236 MAXARG_Bx, "constant table overflow");
237 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);237 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
@@ -647,7 +647,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { · 409 unmodified lines
647 case OP_LEN: return 0; /* no constant folding for 'len' */647 case OP_LEN: return 0; /* no constant folding for 'len' */
648 default: lua_assert(0); r = 0; break;648 default: lua_assert(0); r = 0; break;
649 }649 }
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 */
651 e1->u.nval = r;651 e1->u.nval = r;
652 return 1;652 return 1;
653}653}
src/ldblib.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Interface from Lua to its debug API3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -116,7 +116,7 @@ static int db_getinfo (lua_State *L) { · 110 unmodified lines
116 return luaL_argerror(L, arg+1, "function or level expected");116 return luaL_argerror(L, arg+1, "function or level expected");
117 if (!lua_getinfo(L1, options, &ar))117 if (!lua_getinfo(L1, options, &ar))
118 return luaL_argerror(L, arg+2, "invalid option");118 return luaL_argerror(L, arg+2, "invalid option");
119 lua_newtable(L);119 lua_createtable(L, 0, 2);
120 if (strchr(options, 'S')) {120 if (strchr(options, 'S')) {
121 settabss(L, "source", ar.source);121 settabss(L, "source", ar.source);
122 settabss(L, "short_src", ar.short_src);122 settabss(L, "short_src", ar.short_src);
@@ -246,7 +246,7 @@ static void gethooktable (lua_State *L) { · 123 unmodified lines
246 lua_rawget(L, LUA_REGISTRYINDEX);246 lua_rawget(L, LUA_REGISTRYINDEX);
247 if (!lua_istable(L, -1)) {247 if (!lua_istable(L, -1)) {
248 lua_pop(L, 1);248 lua_pop(L, 1);
249 lua_newtable(L);249 lua_createtable(L, 0, 1);
250 lua_pushlightuserdata(L, (void *)&KEY_HOOK);250 lua_pushlightuserdata(L, (void *)&KEY_HOOK);
251 lua_pushvalue(L, -2);251 lua_pushvalue(L, -2);
252 lua_rawset(L, LUA_REGISTRYINDEX);252 lua_rawset(L, LUA_REGISTRYINDEX);
src/ldebug.c+4−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Debug Interface3** Debug Interface
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -61,7 +61,7 @@ LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { · 55 unmodified lines
61 L->hook = func;61 L->hook = func;
62 L->basehookcount = count;62 L->basehookcount = count;
63 resethookcount(L);63 resethookcount(L);
64 L->hookmask = cast(lu_byte, mask);64 L->hookmask = cast_byte(mask);
65 return 1;65 return 1;
66}66}
67 67
@@ -92,7 +92,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 24 unmodified lines
92 }92 }
93 if (level == 0 && ci > L->base_ci) { /* level found? */93 if (level == 0 && ci > L->base_ci) { /* level found? */
94 status = 1;94 status = 1;
95 ar->i_ci = cast(int, ci - L->base_ci);95 ar->i_ci = cast_int(ci - L->base_ci);
96 }96 }
97 else if (level < 0) { /* level is of a lost tail call? */97 else if (level < 0) { /* level is of a lost tail call? */
98 status = 1;98 status = 1;
@@ -550,7 +550,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 451 unmodified lines
550 const char *name = NULL;550 const char *name = NULL;
551 const char *t = luaT_typenames[ttype(o)];551 const char *t = luaT_typenames[ttype(o)];
552 const char *kind = (isinstack(L->ci, o)) ?552 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) :
554 NULL;554 NULL;
555 if (kind)555 if (kind)
556 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",556 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
src/ldo.c+8−9
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Stack and Call structure of Lua3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -71,7 +71,7 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 65 unmodified lines
71static void restore_stack_limit (lua_State *L) {71static void restore_stack_limit (lua_State *L) {
72 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);72 lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
73 if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */73 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);
75 if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */75 if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */
76 luaD_reallocCI(L, LUAI_MAXCALLS);76 luaD_reallocCI(L, LUAI_MAXCALLS);
77 }77 }
@@ -97,7 +97,7 @@ void luaD_throw (lua_State *L, int errcode) { · 19 unmodified lines
97 LUAI_THROW(L, L->errorJmp);97 LUAI_THROW(L, L->errorJmp);
98 }98 }
99 else {99 else {
100 L->status = cast(lu_byte, errcode);100 L->status = cast_byte(errcode);
101 if (G(L)->panic) {101 if (G(L)->panic) {
102 resetstack(L, errcode);102 resetstack(L, errcode);
103 lua_unlock(L);103 lua_unlock(L);
@@ -189,7 +189,7 @@ void luaD_callhook (lua_State *L, int event, int line) { · 85 unmodified lines
189 if (event == LUA_HOOKTAILRET)189 if (event == LUA_HOOKTAILRET)
190 ar.i_ci = 0; /* tail call; no debug information about it */190 ar.i_ci = 0; /* tail call; no debug information about it */
191 else191 else
192 ar.i_ci = cast(int, L->ci - L->base_ci);192 ar.i_ci = cast_int(L->ci - L->base_ci);
193 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */193 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
194 L->ci->top = L->top + LUA_MINSTACK;194 L->ci->top = L->top + LUA_MINSTACK;
195 lua_assert(L->ci->top <= L->stack_last);195 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
221 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */221 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
222 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);222 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);
223 /* store counter in field `n' */223 /* store counter in field `n' */
224 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),224 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
225 cast(lua_Number, nvar));
226 }225 }
227#endif226#endif
228 /* move fixed parameters to final position */227 /* move fixed parameters to final position */
@@ -282,7 +281,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 53 unmodified lines
282 L->top = base + p->numparams;281 L->top = base + p->numparams;
283 }282 }
284 else { /* vararg function */283 else { /* vararg function */
285 int nargs = cast(int, L->top - func) - 1;284 int nargs = cast_int(L->top - func) - 1;
286 base = adjust_varargs(L, p, nargs);285 base = adjust_varargs(L, p, nargs);
287 func = restorestack(L, funcr); /* previous call may change the stack */286 func = restorestack(L, funcr); /* previous call may change the stack */
288 }287 }
@@ -401,7 +400,7 @@ static void resume (lua_State *L, void *ud) { · 112 unmodified lines
401 L->base = L->ci->base;400 L->base = L->ci->base;
402 }401 }
403 L->status = 0;402 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));
405}404}
406 405
407 406
@@ -427,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 19 unmodified lines
427 lua_assert(L->errfunc == 0 && L->nCcalls == 0);426 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
428 status = luaD_rawrunprotected(L, resume, L->top - nargs);427 status = luaD_rawrunprotected(L, resume, L->top - nargs);
429 if (status != 0) { /* error? */428 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' */
431 luaD_seterrorobj(L, status, L->top);430 luaD_seterrorobj(L, status, L->top);
432 L->ci->top = L->top;431 L->ci->top = L->top;
433 }432 }
src/lfunc.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Auxiliary functions to manipulate prototypes and closures3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -25,7 +25,7 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { · 19 unmodified lines
25 luaC_link(L, obj2gco(c), LUA_TFUNCTION);25 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
26 c->c.isC = 1;26 c->c.isC = 1;
27 c->c.env = e;27 c->c.env = e;
28 c->c.nupvalues = cast(lu_byte, nelems);28 c->c.nupvalues = cast_byte(nelems);
29 return c;29 return c;
30}30}
31 31
@@ -35,7 +35,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { · 3 unmodified lines
35 luaC_link(L, obj2gco(c), LUA_TFUNCTION);35 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
36 c->l.isC = 0;36 c->l.isC = 0;
37 c->l.env = e;37 c->l.env = e;
38 c->l.nupvalues = cast(lu_byte, nelems);38 c->l.nupvalues = cast_byte(nelems);
39 while (nelems--) c->l.upvals[nelems] = NULL;39 while (nelems--) c->l.upvals[nelems] = NULL;
40 return c;40 return c;
41}41}
src/lgc.c+8−9
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -29,11 +29,10 @@ · 23 unmodified lines
29#define GCFINALIZECOST 10029#define GCFINALIZECOST 100
30 30
31 31
32#define maskmarks \32#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
33 cast(lu_byte, ~(bitmask(BLACKBIT)|WHITEBITS))
34 33
35#define makewhite(g,x) \34#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)))
37 36
38#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)37#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
39#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)38#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
@@ -169,8 +168,8 @@ static int traversetable (global_State *g, Table *h) { · 129 unmodified lines
169 weakvalue = (strchr(svalue(mode), 'v') != NULL);168 weakvalue = (strchr(svalue(mode), 'v') != NULL);
170 if (weakkey || weakvalue) { /* is really weak? */169 if (weakkey || weakvalue) { /* is really weak? */
171 h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */170 h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
172 h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) |171 h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
173 (weakvalue << VALUEWEAKBIT));172 (weakvalue << VALUEWEAKBIT));
174 h->gclist = g->weak; /* must be cleared after GC, ... */173 h->gclist = g->weak; /* must be cleared after GC, ... */
175 g->weak = obj2gco(h); /* ... so put in the appropriate list */174 g->weak = obj2gco(h); /* ... so put in the appropriate list */
176 }175 }
@@ -240,8 +239,8 @@ static void traverseclosure (global_State *g, Closure *cl) { · 63 unmodified lines
240 239
241 240
242static void checkstacksizes (lua_State *L, StkId max) {241static void checkstacksizes (lua_State *L, StkId max) {
243 int ci_used = cast(int, L->ci - L->base_ci); /* number of `ci' in use */242 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 */243 int s_used = cast_int(max - L->stack); /* part of stack in use */
245 if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */244 if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
246 return; /* do not touch the stacks */245 return; /* do not touch the stacks */
247 if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)246 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
544 propagateall(g); /* remark, to propagate `preserveness' */543 propagateall(g); /* remark, to propagate `preserveness' */
545 cleartable(g->weak); /* remove collected objects from weak tables */544 cleartable(g->weak); /* remove collected objects from weak tables */
546 /* flip current white */545 /* flip current white */
547 g->currentwhite = cast(lu_byte, otherwhite(g));546 g->currentwhite = cast_byte(otherwhite(g));
548 g->sweepstrgc = 0;547 g->sweepstrgc = 0;
549 g->sweepgc = &g->rootgc;548 g->sweepgc = &g->rootgc;
550 g->gcstate = GCSsweepstring;549 g->gcstate = GCSsweepstring;
src/linit.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Initialization of libraries for lua.c3** Initialization of libraries for lua.c
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -16,13 +16,13 @@ · 10 unmodified lines
16 16
17static const luaL_Reg lualibs[] = {17static const luaL_Reg lualibs[] = {
18 {"", luaopen_base},18 {"", luaopen_base},
19 {LUA_LOADLIBNAME, luaopen_package},
19 {LUA_TABLIBNAME, luaopen_table},20 {LUA_TABLIBNAME, luaopen_table},
20 {LUA_IOLIBNAME, luaopen_io},21 {LUA_IOLIBNAME, luaopen_io},
21 {LUA_OSLIBNAME, luaopen_os},22 {LUA_OSLIBNAME, luaopen_os},
22 {LUA_STRLIBNAME, luaopen_string},23 {LUA_STRLIBNAME, luaopen_string},
23 {LUA_MATHLIBNAME, luaopen_math},24 {LUA_MATHLIBNAME, luaopen_math},
24 {LUA_DBLIBNAME, luaopen_debug},25 {LUA_DBLIBNAME, luaopen_debug},
25 {LUA_LOADLIBNAME, luaopen_package},
26 {NULL, NULL}26 {NULL, NULL}
27};27};
28 28
src/liolib.c+4−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard I/O (and system) library3** Standard I/O (and system) library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -507,8 +507,8 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { · 501 unmodified lines
507 507
508LUALIB_API int luaopen_io (lua_State *L) {508LUALIB_API int luaopen_io (lua_State *L) {
509 createmeta(L);509 createmeta(L);
510 /* create new (private) environment */510 /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
511 lua_newtable(L);511 lua_createtable(L, 2, 1);
512 lua_replace(L, LUA_ENVIRONINDEX);512 lua_replace(L, LUA_ENVIRONINDEX);
513 /* open library */513 /* open library */
514 luaL_register(L, LUA_IOLIBNAME, iolib);514 luaL_register(L, LUA_IOLIBNAME, iolib);
@@ -518,7 +518,7 @@ LUALIB_API int luaopen_io (lua_State *L) { · 3 unmodified lines
518 createstdfile(L, stderr, 0, "stderr");518 createstdfile(L, stderr, 0, "stderr");
519 /* create environment for 'popen' */519 /* create environment for 'popen' */
520 lua_getfield(L, -1, "popen");520 lua_getfield(L, -1, "popen");
521 lua_newtable(L);521 lua_createtable(L, 0, 1);
522 lua_pushcfunction(L, io_pclose);522 lua_pushcfunction(L, io_pclose);
523 lua_setfield(L, -2, "__close");523 lua_setfield(L, -2, "__close");
524 lua_setfenv(L, -2);524 lua_setfenv(L, -2);
src/llex.c+46−6
@@ -1,11 +1,12 @@
1/*1/*
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 $
3** Lexical Analyzer3** Lexical Analyzer
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
7 7
8#include <ctype.h>8#include <ctype.h>
9#include <locale.h>
9#include <string.h>10#include <string.h>
10 11
11#define llex_c12#define llex_c
@@ -65,7 +66,7 @@ void luaX_init (lua_State *L) { · 53 unmodified lines
65 TString *ts = luaS_new(L, luaX_tokens[i]);66 TString *ts = luaS_new(L, luaX_tokens[i]);
66 luaS_fix(ts); /* reserved words are never collected */67 luaS_fix(ts); /* reserved words are never collected */
67 lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);68 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 */
69 }70 }
70}71}
71 72
@@ -134,6 +135,7 @@ static void inclinenumber (LexState *ls) { · 62 unmodified lines
134 135
135 136
136void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {137void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
138 ls->decpoint = '.';
137 ls->L = L;139 ls->L = L;
138 ls->lookahead.token = TK_EOS; /* no look-ahead token */140 ls->lookahead.token = TK_EOS; /* no look-ahead token */
139 ls->z = z;141 ls->z = z;
@@ -163,6 +165,27 @@ static int check_next (LexState *ls, const char *set) { · 23 unmodified lines
163}165}
164 166
165 167
168static 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
176static 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
166 189
167/* LUA_NUMBER */190/* LUA_NUMBER */
168static void read_numeral (LexState *ls, SemInfo *seminfo) {191static void read_numeral (LexState *ls, SemInfo *seminfo) {
@@ -177,8 +200,9 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 8 unmodified lines
177 }200 }
178 }201 }
179 save(ls, '\0');202 save(ls, '\0');
180 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))203 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
181 luaX_lexerror(ls, "malformed number", TK_NUMBER);204 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
205 trydecpoint(ls, seminfo); /* try to update decimal point separator */
182}206}
183 207
184 208
@@ -306,7 +330,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 121 unmodified lines
306}330}
307 331
308 332
309int luaX_lex (LexState *ls, SemInfo *seminfo) {333static int llex (LexState *ls, SemInfo *seminfo) {
310 luaZ_resetbuffer(ls->buff);334 luaZ_resetbuffer(ls->buff);
311 for (;;) {335 for (;;) {
312 switch (ls->current) {336 switch (ls->current) {
@@ -419,4 +443,20 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 106 unmodified lines
419 }443 }
420}444}
421 445
422#undef next446
447void 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
458void 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 @@
1/*1/*
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 $
3** Lexical Analyzer3** Lexical Analyzer
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -63,6 +63,7 @@ typedef struct LexState { · 57 unmodified lines
63 ZIO *z; /* input stream */63 ZIO *z; /* input stream */
64 Mbuffer *buff; /* buffer for tokens */64 Mbuffer *buff; /* buffer for tokens */
65 TString *source; /* current source name */65 TString *source; /* current source name */
66 char decpoint; /* locale decimal point */
66} LexState;67} LexState;
67 68
68 69
@@ -70,7 +71,8 @@ LUAI_FUNC void luaX_init (lua_State *L); · 1 unmodified line
70LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,71LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z,
71 TString *source);72 TString *source);
72LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);73LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l);
73LUAI_FUNC int luaX_lex (LexState *LS, SemInfo *seminfo);74LUAI_FUNC void luaX_next (LexState *ls);
75LUAI_FUNC void luaX_lookahead (LexState *ls);
74LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);76LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
75LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);77LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
76LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);78LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
src/llimits.h+18−5
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Limits, basic types, and some other `installation-dependent' definitions3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -15,9 +15,6 @@ · 9 unmodified lines
15#include "lua.h"15#include "lua.h"
16 16
17 17
18#define api_check luai_apicheck
19
20
21typedef LUAI_UINT32 lu_int32;18typedef LUAI_UINT32 lu_int32;
22 19
23typedef LUAI_UMEM lu_mem;20typedef LUAI_UMEM lu_mem;
@@ -54,7 +51,19 @@ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; · 30 unmodified lines
54typedef LUAI_UACNUMBER l_uacNumber;51typedef LUAI_UACNUMBER l_uacNumber;
55 52
56 53
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
58 67
59 68
60#ifndef UNUSED69#ifndef UNUSED
@@ -66,6 +75,10 @@ typedef LUAI_UACNUMBER l_uacNumber; · 5 unmodified lines
66#define cast(t, exp) ((t)(exp))75#define cast(t, exp) ((t)(exp))
67#endif76#endif
68 77
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
69 82
70 83
71/*84/*
src/lmem.c+1−17
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Interface to Memory Manager3** Interface to Memory Manager
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -81,22 +81,6 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 75 unmodified lines
81 luaD_throw(L, LUA_ERRMEM);81 luaD_throw(L, LUA_ERRMEM);
82 lua_assert((nsize == 0) == (block == NULL));82 lua_assert((nsize == 0) == (block == NULL));
83 g->totalbytes = (g->totalbytes - osize) + nsize;83 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
100 return block;84 return block;
101}85}
102 86
src/loadlib.c+38−27
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Dynamic library loader for Lua3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5**5**
@@ -16,8 +16,9 @@ · 10 unmodified lines
16#define loadlib_c16#define loadlib_c
17#define LUA_LIB17#define LUA_LIB
18 18
19#include "lua.h"
20#include "lauxlib.h"19#include "lauxlib.h"
20#include "lobject.h"
21#include "lua.h"
21#include "lualib.h"22#include "lualib.h"
22 23
23 24
@@ -236,11 +237,8 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 212 unmodified lines
236#define LIB_FAIL "absent"237#define LIB_FAIL "absent"
237 238
238 239
239#if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux)240#define DLMSG "dynamic libraries not enabled; check your Lua installation"
240#define DLMSG LUA_QL("loadlib") " not enabled; check your Lua installation"241
241#else
242#define DLMSG LUA_QL("loadlib") " not supported"
243#endif
244 242
245static void ll_unloadlib (void *lib) {243static void ll_unloadlib (void *lib) {
246 (void)lib; /* to avoid warnings */244 (void)lib; /* to avoid warnings */
@@ -362,20 +360,23 @@ static const char *findfile (lua_State *L, const char *name, · 115 unmodified lines
362 path = lua_tostring(L, -1);360 path = lua_tostring(L, -1);
363 if (path == NULL)361 if (path == NULL)
364 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);362 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
363 lua_pushstring(L, ""); /* error accumulator */
365 while ((path = pushnexttemplate(L, path)) != NULL) {364 while ((path = pushnexttemplate(L, path)) != NULL) {
366 const char *filename;365 const char *filename;
367 filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);366 filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
368 if (readable(filename)) /* does file exist and is readable? */367 if (readable(filename)) /* does file exist and is readable? */
369 return filename; /* return that file name */368 return filename; /* return that file name */
370 lua_pop(L, 2); /* remove path template and file name */ 369 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);
371 }372 }
372 return NULL; /* not found */373 return NULL; /* not found */
373}374}
374 375
375 376
376static void loaderror (lua_State *L) {377static void loaderror (lua_State *L, const char *filename) {
377 luaL_error(L, "error loading module " LUA_QS " (%s)",378 luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
378 lua_tostring(L, 1), lua_tostring(L, -1));379 lua_tostring(L, 1), filename, lua_tostring(L, -1));
379}380}
380 381
381 382
@@ -383,9 +384,9 @@ static int loader_Lua (lua_State *L) { · 1 unmodified line
383 const char *filename;384 const char *filename;
384 const char *name = luaL_checkstring(L, 1);385 const char *name = luaL_checkstring(L, 1);
385 filename = findfile(L, name, "path");386 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 */
387 if (luaL_loadfile(L, filename) != 0)388 if (luaL_loadfile(L, filename) != 0)
388 loaderror(L);389 loaderror(L, filename);
389 return 1; /* library loaded successfully */390 return 1; /* library loaded successfully */
390}391}
391 392
@@ -405,10 +406,10 @@ static int loader_C (lua_State *L) { · 13 unmodified lines
405 const char *funcname;406 const char *funcname;
406 const char *name = luaL_checkstring(L, 1);407 const char *name = luaL_checkstring(L, 1);
407 const char *filename = findfile(L, name, "cpath");408 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 */
409 funcname = mkfuncname(L, name);410 funcname = mkfuncname(L, name);
410 if (ll_loadfunc(L, filename, funcname) != 0)411 if (ll_loadfunc(L, filename, funcname) != 0)
411 loaderror(L);412 loaderror(L, filename);
412 return 1; /* library loaded successfully */413 return 1; /* library loaded successfully */
413}414}
414 415
@@ -422,22 +423,26 @@ static int loader_Croot (lua_State *L) { · 7 unmodified lines
422 if (p == NULL) return 0; /* is root */423 if (p == NULL) return 0; /* is root */
423 lua_pushlstring(L, name, p - name);424 lua_pushlstring(L, name, p - name);
424 filename = findfile(L, lua_tostring(L, -1), "cpath");425 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 */
426 funcname = mkfuncname(L, name);427 funcname = mkfuncname(L, name);
427 if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {428 if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {
428 if (stat == ERRFUNC) return 0; /* function not found */429 if (stat != ERRFUNC) loaderror(L, filename); /* real error */
429 else430 luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
430 loaderror(L); /* real error */431 name, filename);
432 return 1; /* function not found */
431 }433 }
432 return 1;434 return 1;
433}435}
434 436
435 437
436static int loader_preload (lua_State *L) {438static int loader_preload (lua_State *L) {
439 const char *name = luaL_checkstring(L, 1);
437 lua_getfield(L, LUA_ENVIRONINDEX, "preload");440 lua_getfield(L, LUA_ENVIRONINDEX, "preload");
438 if (!lua_istable(L, -1))441 if (!lua_istable(L, -1))
439 luaL_error(L, LUA_QL("package.preload") " must be a table");442 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);
441 return 1;446 return 1;
442}447}
443 448
@@ -461,14 +466,20 @@ static int ll_require (lua_State *L) { · 17 unmodified lines
461 lua_getfield(L, LUA_ENVIRONINDEX, "loaders");466 lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
462 if (!lua_istable(L, -1))467 if (!lua_istable(L, -1))
463 luaL_error(L, LUA_QL("package.loaders") " must be a table");468 luaL_error(L, LUA_QL("package.loaders") " must be a table");
469 lua_pushstring(L, ""); /* error message accumulator */
464 for (i=1; ; i++) {470 for (i=1; ; i++) {
465 lua_rawgeti(L, -1, i); /* get a loader */471 lua_rawgeti(L, -2, i); /* get a loader */
466 if (lua_isnil(L, -1))472 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));
468 lua_pushstring(L, name);475 lua_pushstring(L, name);
469 lua_call(L, 1, 1); /* call it */476 lua_call(L, 1, 1); /* call it */
470 if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */477 if (lua_isfunction(L, -1)) /* did it find module? */
471 else break; /* module loaded successfully */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);
472 }483 }
473 lua_pushlightuserdata(L, sentinel);484 lua_pushlightuserdata(L, sentinel);
474 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */485 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
@@ -539,7 +550,7 @@ static int ll_module (lua_State *L) { · 64 unmodified lines
539 if (!lua_istable(L, -1)) { /* not found? */550 if (!lua_istable(L, -1)) { /* not found? */
540 lua_pop(L, 1); /* remove previous result */551 lua_pop(L, 1); /* remove previous result */
541 /* try global variable (and create one if it does not exist) */552 /* 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)
543 return luaL_error(L, "name conflict for module " LUA_QS, modname);554 return luaL_error(L, "name conflict for module " LUA_QS, modname);
544 lua_pushvalue(L, -1);555 lua_pushvalue(L, -1);
545 lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */556 lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
@@ -562,7 +573,7 @@ static int ll_module (lua_State *L) { · 16 unmodified lines
562static int ll_seeall (lua_State *L) {573static int ll_seeall (lua_State *L) {
563 luaL_checktype(L, 1, LUA_TTABLE);574 luaL_checktype(L, 1, LUA_TTABLE);
564 if (!lua_getmetatable(L, 1)) {575 if (!lua_getmetatable(L, 1)) {
565 lua_newtable(L); /* create new metatable */576 lua_createtable(L, 0, 1); /* create new metatable */
566 lua_pushvalue(L, -1);577 lua_pushvalue(L, -1);
567 lua_setmetatable(L, 1);578 lua_setmetatable(L, 1);
568 }579 }
@@ -629,7 +640,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 60 unmodified lines
629 lua_pushvalue(L, -1);640 lua_pushvalue(L, -1);
630 lua_replace(L, LUA_ENVIRONINDEX);641 lua_replace(L, LUA_ENVIRONINDEX);
631 /* create `loaders' table */642 /* create `loaders' table */
632 lua_newtable(L);643 lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
633 /* fill it with pre-defined loaders */644 /* fill it with pre-defined loaders */
634 for (i=0; loaders[i] != NULL; i++) {645 for (i=0; loaders[i] != NULL; i++) {
635 lua_pushcfunction(L, loaders[i]);646 lua_pushcfunction(L, loaders[i]);
@@ -643,7 +654,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 7 unmodified lines
643 LUA_EXECDIR "\n" LUA_IGMARK);654 LUA_EXECDIR "\n" LUA_IGMARK);
644 lua_setfield(L, -2, "config");655 lua_setfield(L, -2, "config");
645 /* set field `loaded' */656 /* set field `loaded' */
646 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");657 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
647 lua_setfield(L, -2, "loaded");658 lua_setfield(L, -2, "loaded");
648 /* set field `preload' */659 /* set field `preload' */
649 lua_newtable(L);660 lua_newtable(L);
src/lobject.c+6−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Some generic functions over Lua objects3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -24,7 +24,7 @@ · 18 unmodified lines
24 24
25 25
26 26
27const TValue luaO_nilobject = {{NULL}, LUA_TNIL};27const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
28 28
29 29
30/*30/*
@@ -39,7 +39,7 @@ int luaO_int2fb (unsigned int x) { · 8 unmodified lines
39 e++;39 e++;
40 }40 }
41 if (x < 8) return x;41 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);
43}43}
44 44
45 45
@@ -129,12 +129,12 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 83 unmodified lines
129 break;129 break;
130 }130 }
131 case 'd': {131 case 'd': {
132 setnvalue(L->top, cast(lua_Number, va_arg(argp, int)));132 setnvalue(L->top, cast_num(va_arg(argp, int)));
133 incr_top(L);133 incr_top(L);
134 break;134 break;
135 }135 }
136 case 'f': {136 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)));
138 incr_top(L);138 incr_top(L);
139 break;139 break;
140 }140 }
@@ -161,7 +161,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 20 unmodified lines
161 fmt = e+2;161 fmt = e+2;
162 }162 }
163 pushstr(L, fmt);163 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);
165 L->top -= n;165 L->top -= n;
166 return svalue(L->top - 1);166 return svalue(L->top - 1);
167}167}
src/lobject.h+9−5
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Type definitions for Lua objects3** Type definitions for Lua objects
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -323,9 +323,12 @@ typedef union Closure { · 317 unmodified lines
323** Tables323** Tables
324*/324*/
325 325
326typedef struct TKey {326typedef union TKey {
327 TValuefields;327 struct {
328 struct Node *next; /* for chaining */328 TValuefields;
329 struct Node *next; /* for chaining */
330 } nk;
331 TValue tvk;
329} TKey;332} TKey;
330 333
331 334
@@ -360,8 +363,9 @@ typedef struct Table { · 28 unmodified lines
360#define sizenode(t) (twoto((t)->lsizenode))363#define sizenode(t) (twoto((t)->lsizenode))
361 364
362 365
366#define luaO_nilobject (&luaO_nilobject_)
363 367
364LUAI_DATA const TValue luaO_nilobject;368LUAI_DATA const TValue luaO_nilobject_;
365 369
366#define ceillog2(x) (luaO_log2((x)-1) + 1)370#define ceillog2(x) (luaO_log2((x)-1) + 1)
367 371
src/lopcodes.h+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Opcodes for Lua virtual machine3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -208,7 +208,7 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ · 202 unmodified lines
208} OpCode;208} OpCode;
209 209
210 210
211#define NUM_OPCODES (cast(int, OP_VARARG+1))211#define NUM_OPCODES (cast(int, OP_VARARG) + 1)
212 212
213 213
214 214
src/loslib.c+24−24
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard Operating System library3** Standard Operating System library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -37,26 +37,26 @@ static int os_pushresult (lua_State *L, int i, const char *filename) { · 31 unmodified lines
37}37}
38 38
39 39
40static int io_execute (lua_State *L) {40static int os_execute (lua_State *L) {
41 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));41 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
42 return 1;42 return 1;
43}43}
44 44
45 45
46static int io_remove (lua_State *L) {46static int os_remove (lua_State *L) {
47 const char *filename = luaL_checkstring(L, 1);47 const char *filename = luaL_checkstring(L, 1);
48 return os_pushresult(L, remove(filename) == 0, filename);48 return os_pushresult(L, remove(filename) == 0, filename);
49}49}
50 50
51 51
52static int io_rename (lua_State *L) {52static int os_rename (lua_State *L) {
53 const char *fromname = luaL_checkstring(L, 1);53 const char *fromname = luaL_checkstring(L, 1);
54 const char *toname = luaL_checkstring(L, 2);54 const char *toname = luaL_checkstring(L, 2);
55 return os_pushresult(L, rename(fromname, toname) == 0, fromname);55 return os_pushresult(L, rename(fromname, toname) == 0, fromname);
56}56}
57 57
58 58
59static int io_tmpname (lua_State *L) {59static int os_tmpname (lua_State *L) {
60 char buff[LUA_TMPNAMBUFSIZE];60 char buff[LUA_TMPNAMBUFSIZE];
61 int err;61 int err;
62 lua_tmpnam(buff, err);62 lua_tmpnam(buff, err);
@@ -67,13 +67,13 @@ static int io_tmpname (lua_State *L) { · 4 unmodified lines
67}67}
68 68
69 69
70static int io_getenv (lua_State *L) {70static int os_getenv (lua_State *L) {
71 lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */71 lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
72 return 1;72 return 1;
73}73}
74 74
75 75
76static int io_clock (lua_State *L) {76static int os_clock (lua_State *L) {
77 lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);77 lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
78 return 1;78 return 1;
79}79}
@@ -123,7 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { · 43 unmodified lines
123}123}
124 124
125 125
126static int io_date (lua_State *L) {126static int os_date (lua_State *L) {
127 const char *s = luaL_optstring(L, 1, "%c");127 const char *s = luaL_optstring(L, 1, "%c");
128 time_t t = lua_isnoneornil(L, 2) ? time(NULL) :128 time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
129 (time_t)luaL_checknumber(L, 2);129 (time_t)luaL_checknumber(L, 2);
@@ -159,7 +159,7 @@ static int io_date (lua_State *L) { · 29 unmodified lines
159}159}
160 160
161 161
162static int io_time (lua_State *L) {162static int os_time (lua_State *L) {
163 time_t t;163 time_t t;
164 if (lua_isnoneornil(L, 1)) /* called without args? */164 if (lua_isnoneornil(L, 1)) /* called without args? */
165 t = time(NULL); /* get current time */165 t = time(NULL); /* get current time */
@@ -179,12 +179,12 @@ static int io_time (lua_State *L) { · 13 unmodified lines
179 if (t == (time_t)(-1))179 if (t == (time_t)(-1))
180 lua_pushnil(L);180 lua_pushnil(L);
181 else181 else
182 lua_pushnumber(L, t);182 lua_pushnumber(L, (lua_Number)t);
183 return 1;183 return 1;
184}184}
185 185
186 186
187static int io_difftime (lua_State *L) {187static int os_difftime (lua_State *L) {
188 lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),188 lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
189 (time_t)(luaL_optnumber(L, 2, 0))));189 (time_t)(luaL_optnumber(L, 2, 0))));
190 return 1;190 return 1;
@@ -193,7 +193,7 @@ static int io_difftime (lua_State *L) { · 2 unmodified lines
193/* }====================================================== */193/* }====================================================== */
194 194
195 195
196static int io_setloc (lua_State *L) {196static int os_setlocale (lua_State *L) {
197 static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,197 static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
198 LC_NUMERIC, LC_TIME};198 LC_NUMERIC, LC_TIME};
199 static const char *const catnames[] = {"all", "collate", "ctype", "monetary",199 static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
@@ -206,23 +206,23 @@ static int io_setloc (lua_State *L) { · 6 unmodified lines
206}206}
207 207
208 208
209static int io_exit (lua_State *L) {209static int os_exit (lua_State *L) {
210 exit(luaL_optint(L, 1, EXIT_SUCCESS));210 exit(luaL_optint(L, 1, EXIT_SUCCESS));
211 return 0; /* to avoid warnings */211 return 0; /* to avoid warnings */
212}212}
213 213
214static const luaL_Reg syslib[] = {214static const luaL_Reg syslib[] = {
215 {"clock", io_clock},215 {"clock", os_clock},
216 {"date", io_date},216 {"date", os_date},
217 {"difftime", io_difftime},217 {"difftime", os_difftime},
218 {"execute", io_execute},218 {"execute", os_execute},
219 {"exit", io_exit},219 {"exit", os_exit},
220 {"getenv", io_getenv},220 {"getenv", os_getenv},
221 {"remove", io_remove},221 {"remove", os_remove},
222 {"rename", io_rename},222 {"rename", os_rename},
223 {"setlocale", io_setloc},223 {"setlocale", os_setlocale},
224 {"time", io_time},224 {"time", os_time},
225 {"tmpname", io_tmpname},225 {"tmpname", os_tmpname},
226 {NULL, NULL}226 {NULL, NULL}
227};227};
228 228
src/lparser.c+31−49
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -54,24 +54,6 @@ static void chunk (LexState *ls); · 48 unmodified lines
54static void expr (LexState *ls, expdesc *v);54static void expr (LexState *ls, expdesc *v);
55 55
56 56
57
58static 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
69static 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
75static void anchor_token (LexState *ls) {57static void anchor_token (LexState *ls) {
76 if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {58 if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
77 TString *ts = ls->t.seminfo.ts;59 TString *ts = ls->t.seminfo.ts;
@@ -97,7 +79,7 @@ static void errorlimit (FuncState *fs, int limit, const char *what) { · 19 unmodified lines
97 79
98static int testnext (LexState *ls, int c) {80static int testnext (LexState *ls, int c) {
99 if (ls->t.token == c) {81 if (ls->t.token == c) {
100 next(ls);82 luaX_next(ls);
101 return 1;83 return 1;
102 }84 }
103 else return 0;85 else return 0;
@@ -111,7 +93,7 @@ static void check (LexState *ls, int c) { · 7 unmodified lines
111 93
112static void checknext (LexState *ls, int c) {94static void checknext (LexState *ls, int c) {
113 check(ls, c);95 check(ls, c);
114 next(ls);96 luaX_next(ls);
115}97}
116 98
117 99
@@ -136,7 +118,7 @@ static TString *str_checkname (LexState *ls) { · 18 unmodified lines
136 TString *ts;118 TString *ts;
137 check(ls, TK_NAME);119 check(ls, TK_NAME);
138 ts = ls->t.seminfo.ts;120 ts = ls->t.seminfo.ts;
139 next(ls);121 luaX_next(ls);
140 return ts;122 return ts;
141}123}
142 124
@@ -184,7 +166,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { · 41 unmodified lines
184 166
185static void adjustlocalvars (LexState *ls, int nvars) {167static void adjustlocalvars (LexState *ls, int nvars) {
186 FuncState *fs = ls->fs;168 FuncState *fs = ls->fs;
187 fs->nactvar = cast(lu_byte, fs->nactvar + nvars);169 fs->nactvar = cast_byte(fs->nactvar + nvars);
188 for (; nvars; nvars--) {170 for (; nvars; nvars--) {
189 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;171 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
190 }172 }
@@ -216,8 +198,8 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 25 unmodified lines
216 f->upvalues[f->nups] = name;198 f->upvalues[f->nups] = name;
217 luaC_objbarrier(fs->L, f, name);199 luaC_objbarrier(fs->L, f, name);
218 lua_assert(v->k == VLOCAL || v->k == VUPVAL);200 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
219 fs->upvalues[f->nups].k = cast(lu_byte, v->k);201 fs->upvalues[f->nups].k = cast_byte(v->k);
220 fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);202 fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
221 return f->nups++;203 return f->nups++;
222}204}
223 205
@@ -404,7 +386,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { · 180 unmodified lines
404 luaX_setinput(L, &lexstate, z, luaS_new(L, name));386 luaX_setinput(L, &lexstate, z, luaS_new(L, name));
405 open_func(&lexstate, &funcstate);387 open_func(&lexstate, &funcstate);
406 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */388 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
407 next(&lexstate); /* read first token */389 luaX_next(&lexstate); /* read first token */
408 chunk(&lexstate);390 chunk(&lexstate);
409 check(&lexstate, TK_EOS);391 check(&lexstate, TK_EOS);
410 close_func(&lexstate);392 close_func(&lexstate);
@@ -426,7 +408,7 @@ static void field (LexState *ls, expdesc *v) { · 15 unmodified lines
426 FuncState *fs = ls->fs;408 FuncState *fs = ls->fs;
427 expdesc key;409 expdesc key;
428 luaK_exp2anyreg(fs, v);410 luaK_exp2anyreg(fs, v);
429 next(ls); /* skip the dot or colon */411 luaX_next(ls); /* skip the dot or colon */
430 checkname(ls, &key);412 checkname(ls, &key);
431 luaK_indexed(fs, v, &key);413 luaK_indexed(fs, v, &key);
432}414}
@@ -434,7 +416,7 @@ static void field (LexState *ls, expdesc *v) { · 1 unmodified line
434 416
435static void yindex (LexState *ls, expdesc *v) {417static void yindex (LexState *ls, expdesc *v) {
436 /* index -> '[' expr ']' */418 /* index -> '[' expr ']' */
437 next(ls); /* skip the '[' */419 luaX_next(ls); /* skip the '[' */
438 expr(ls, v);420 expr(ls, v);
439 luaK_exp2val(ls->fs, v);421 luaK_exp2val(ls->fs, v);
440 checknext(ls, ']');422 checknext(ls, ']');
@@ -530,7 +512,7 @@ static void constructor (LexState *ls, expdesc *t) { · 89 unmodified lines
530 closelistfield(fs, &cc);512 closelistfield(fs, &cc);
531 switch(ls->t.token) {513 switch(ls->t.token) {
532 case TK_NAME: { /* may be listfields or recfields */514 case TK_NAME: { /* may be listfields or recfields */
533 lookahead(ls);515 luaX_lookahead(ls);
534 if (ls->lookahead.token != '=') /* expression? */516 if (ls->lookahead.token != '=') /* expression? */
535 listfield(ls, &cc);517 listfield(ls, &cc);
536 else518 else
@@ -571,7 +553,7 @@ static void parlist (LexState *ls) { · 34 unmodified lines
571 break;553 break;
572 }554 }
573 case TK_DOTS: { /* param -> `...' */555 case TK_DOTS: { /* param -> `...' */
574 next(ls);556 luaX_next(ls);
575#if defined(LUA_COMPAT_VARARG)557#if defined(LUA_COMPAT_VARARG)
576 /* use `arg' as default name */558 /* use `arg' as default name */
577 new_localvarliteral(ls, "arg", nparams++);559 new_localvarliteral(ls, "arg", nparams++);
@@ -585,7 +567,7 @@ static void parlist (LexState *ls) { · 7 unmodified lines
585 } while (!f->is_vararg && testnext(ls, ','));567 } while (!f->is_vararg && testnext(ls, ','));
586 }568 }
587 adjustlocalvars(ls, nparams);569 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));
589 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */571 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
590}572}
591 573
@@ -632,7 +614,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 40 unmodified lines
632 case '(': { /* funcargs -> `(' [ explist1 ] `)' */614 case '(': { /* funcargs -> `(' [ explist1 ] `)' */
633 if (line != ls->lastline)615 if (line != ls->lastline)
634 luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");616 luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
635 next(ls);617 luaX_next(ls);
636 if (ls->t.token == ')') /* arg list is empty? */618 if (ls->t.token == ')') /* arg list is empty? */
637 args.k = VVOID;619 args.k = VVOID;
638 else {620 else {
@@ -648,7 +630,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 9 unmodified lines
648 }630 }
649 case TK_STRING: { /* funcargs -> STRING */631 case TK_STRING: { /* funcargs -> STRING */
650 codestring(ls, &args, ls->t.seminfo.ts);632 codestring(ls, &args, ls->t.seminfo.ts);
651 next(ls); /* must use `seminfo' before `next' */633 luaX_next(ls); /* must use `seminfo' before `next' */
652 break;634 break;
653 }635 }
654 default: {636 default: {
@@ -686,7 +668,7 @@ static void prefixexp (LexState *ls, expdesc *v) { · 31 unmodified lines
686 switch (ls->t.token) {668 switch (ls->t.token) {
687 case '(': {669 case '(': {
688 int line = ls->linenumber;670 int line = ls->linenumber;
689 next(ls);671 luaX_next(ls);
690 expr(ls, v);672 expr(ls, v);
691 check_match(ls, ')', '(', line);673 check_match(ls, ')', '(', line);
692 luaK_dischargevars(ls->fs, v);674 luaK_dischargevars(ls->fs, v);
@@ -724,7 +706,7 @@ static void primaryexp (LexState *ls, expdesc *v) { · 31 unmodified lines
724 }706 }
725 case ':': { /* `:' NAME funcargs */707 case ':': { /* `:' NAME funcargs */
726 expdesc key;708 expdesc key;
727 next(ls);709 luaX_next(ls);
728 checkname(ls, &key);710 checkname(ls, &key);
729 luaK_self(fs, v, &key);711 luaK_self(fs, v, &key);
730 funcargs(ls, v);712 funcargs(ls, v);
@@ -779,7 +761,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 48 unmodified lines
779 return;761 return;
780 }762 }
781 case TK_FUNCTION: {763 case TK_FUNCTION: {
782 next(ls);764 luaX_next(ls);
783 body(ls, v, 0, ls->linenumber);765 body(ls, v, 0, ls->linenumber);
784 return;766 return;
785 }767 }
@@ -788,7 +770,7 @@ static void simpleexp (LexState *ls, expdesc *v) { · 2 unmodified lines
788 return;770 return;
789 }771 }
790 }772 }
791 next(ls);773 luaX_next(ls);
792}774}
793 775
794 776
@@ -848,7 +830,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 53 unmodified lines
848 enterlevel(ls);830 enterlevel(ls);
849 uop = getunopr(ls->t.token);831 uop = getunopr(ls->t.token);
850 if (uop != OPR_NOUNOPR) {832 if (uop != OPR_NOUNOPR) {
851 next(ls);833 luaX_next(ls);
852 subexpr(ls, v, UNARY_PRIORITY);834 subexpr(ls, v, UNARY_PRIORITY);
853 luaK_prefix(ls->fs, uop, v);835 luaK_prefix(ls->fs, uop, v);
854 }836 }
@@ -858,7 +840,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { · 3 unmodified lines
858 while (op != OPR_NOBINOPR && priority[op].left > limit) {840 while (op != OPR_NOBINOPR && priority[op].left > limit) {
859 expdesc v2;841 expdesc v2;
860 BinOpr nextop;842 BinOpr nextop;
861 next(ls);843 luaX_next(ls);
862 luaK_infix(ls->fs, op, v);844 luaK_infix(ls->fs, op, v);
863 /* read sub-expression with higher priority */845 /* read sub-expression with higher priority */
864 nextop = subexpr(ls, &v2, priority[op].right);846 nextop = subexpr(ls, &v2, priority[op].right);
@@ -1009,7 +991,7 @@ static void whilestat (LexState *ls, int line) { · 144 unmodified lines
1009 int whileinit;991 int whileinit;
1010 int condexit;992 int condexit;
1011 BlockCnt bl;993 BlockCnt bl;
1012 next(ls); /* skip WHILE */994 luaX_next(ls); /* skip WHILE */
1013 whileinit = luaK_getlabel(fs);995 whileinit = luaK_getlabel(fs);
1014 condexit = cond(ls);996 condexit = cond(ls);
1015 enterblock(fs, &bl, 1);997 enterblock(fs, &bl, 1);
@@ -1030,7 +1012,7 @@ static void repeatstat (LexState *ls, int line) { · 14 unmodified lines
1030 BlockCnt bl1, bl2;1012 BlockCnt bl1, bl2;
1031 enterblock(fs, &bl1, 1); /* loop block */1013 enterblock(fs, &bl1, 1); /* loop block */
1032 enterblock(fs, &bl2, 0); /* scope block */1014 enterblock(fs, &bl2, 0); /* scope block */
1033 next(ls); /* skip REPEAT */1015 luaX_next(ls); /* skip REPEAT */
1034 chunk(ls);1016 chunk(ls);
1035 check_match(ls, TK_UNTIL, TK_REPEAT, line);1017 check_match(ls, TK_UNTIL, TK_REPEAT, line);
1036 condexit = cond(ls); /* read condition (inside scope block) */1018 condexit = cond(ls); /* read condition (inside scope block) */
@@ -1130,7 +1112,7 @@ static void forstat (LexState *ls, int line) { · 93 unmodified lines
1130 TString *varname;1112 TString *varname;
1131 BlockCnt bl;1113 BlockCnt bl;
1132 enterblock(fs, &bl, 1); /* scope for loop and control variables */1114 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1133 next(ls); /* skip `for' */1115 luaX_next(ls); /* skip `for' */
1134 varname = str_checkname(ls); /* first variable name */1116 varname = str_checkname(ls); /* first variable name */
1135 switch (ls->t.token) {1117 switch (ls->t.token) {
1136 case '=': fornum(ls, varname, line); break;1118 case '=': fornum(ls, varname, line); break;
@@ -1145,7 +1127,7 @@ static void forstat (LexState *ls, int line) { · 8 unmodified lines
1145static int test_then_block (LexState *ls) {1127static int test_then_block (LexState *ls) {
1146 /* test_then_block -> [IF | ELSEIF] cond THEN block */1128 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1147 int condexit;1129 int condexit;
1148 next(ls); /* skip IF or ELSEIF */1130 luaX_next(ls); /* skip IF or ELSEIF */
1149 condexit = cond(ls);1131 condexit = cond(ls);
1150 checknext(ls, TK_THEN);1132 checknext(ls, TK_THEN);
1151 block(ls); /* `then' part */1133 block(ls); /* `then' part */
@@ -1167,7 +1149,7 @@ static void ifstat (LexState *ls, int line) { · 15 unmodified lines
1167 if (ls->t.token == TK_ELSE) {1149 if (ls->t.token == TK_ELSE) {
1168 luaK_concat(fs, &escapelist, luaK_jump(fs));1150 luaK_concat(fs, &escapelist, luaK_jump(fs));
1169 luaK_patchtohere(fs, flist);1151 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) */
1171 block(ls); /* `else' part */1153 block(ls); /* `else' part */
1172 }1154 }
1173 else1155 else
@@ -1228,7 +1210,7 @@ static void funcstat (LexState *ls, int line) { · 54 unmodified lines
1228 /* funcstat -> FUNCTION funcname body */1210 /* funcstat -> FUNCTION funcname body */
1229 int needself;1211 int needself;
1230 expdesc v, b;1212 expdesc v, b;
1231 next(ls); /* skip FUNCTION */1213 luaX_next(ls); /* skip FUNCTION */
1232 needself = funcname(ls, &v);1214 needself = funcname(ls, &v);
1233 body(ls, &b, needself, line);1215 body(ls, &b, needself, line);
1234 luaK_storevar(ls->fs, &v, &b);1216 luaK_storevar(ls->fs, &v, &b);
@@ -1255,7 +1237,7 @@ static void retstat (LexState *ls) { · 20 unmodified lines
1255 FuncState *fs = ls->fs;1237 FuncState *fs = ls->fs;
1256 expdesc e;1238 expdesc e;
1257 int first, nret; /* registers with returned values */1239 int first, nret; /* registers with returned values */
1258 next(ls); /* skip RETURN */1240 luaX_next(ls); /* skip RETURN */
1259 if (block_follow(ls->t.token) || ls->t.token == ';')1241 if (block_follow(ls->t.token) || ls->t.token == ';')
1260 first = nret = 0; /* return no values */1242 first = nret = 0; /* return no values */
1261 else {1243 else {
@@ -1295,7 +1277,7 @@ static int statement (LexState *ls) { · 33 unmodified lines
1295 return 0;1277 return 0;
1296 }1278 }
1297 case TK_DO: { /* stat -> DO block END */1279 case TK_DO: { /* stat -> DO block END */
1298 next(ls); /* skip DO */1280 luaX_next(ls); /* skip DO */
1299 block(ls);1281 block(ls);
1300 check_match(ls, TK_END, TK_DO, line);1282 check_match(ls, TK_END, TK_DO, line);
1301 return 0;1283 return 0;
@@ -1313,7 +1295,7 @@ static int statement (LexState *ls) { · 11 unmodified lines
1313 return 0;1295 return 0;
1314 }1296 }
1315 case TK_LOCAL: { /* stat -> localstat */1297 case TK_LOCAL: { /* stat -> localstat */
1316 next(ls); /* skip LOCAL */1298 luaX_next(ls); /* skip LOCAL */
1317 if (testnext(ls, TK_FUNCTION)) /* local function? */1299 if (testnext(ls, TK_FUNCTION)) /* local function? */
1318 localfunc(ls);1300 localfunc(ls);
1319 else1301 else
@@ -1325,7 +1307,7 @@ static int statement (LexState *ls) { · 5 unmodified lines
1325 return 1; /* must be last statement */1307 return 1; /* must be last statement */
1326 }1308 }
1327 case TK_BREAK: { /* stat -> breakstat */1309 case TK_BREAK: { /* stat -> breakstat */
1328 next(ls); /* skip BREAK */1310 luaX_next(ls); /* skip BREAK */
1329 breakstat(ls);1311 breakstat(ls);
1330 return 1; /* must be last statement */1312 return 1; /* must be last statement */
1331 }1313 }
src/lstring.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** String table (keeps all strings handled by Lua)3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) { · 29 unmodified lines
35 GCObject *next = p->gch.next; /* save next */35 GCObject *next = p->gch.next; /* save next */
36 unsigned int h = gco2ts(p)->hash;36 unsigned int h = gco2ts(p)->hash;
37 int h1 = lmod(h, newsize); /* new position */37 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));
39 p->gch.next = newhash[h1]; /* chain it */39 p->gch.next = newhash[h1]; /* chain it */
40 newhash[h1] = p;40 newhash[h1] = p;
41 p = next;41 p = next;
src/lstrlib.c+38−21
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard library for string operations and pattern-matching3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -683,8 +683,13 @@ static int str_gsub (lua_State *L) { · 677 unmodified lines
683 683
684/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */684/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
685#define MAX_ITEM 512685#define MAX_ITEM 512
686/* maximum size of each format specification (such as '%-099.99d') */686/* valid flags in a format specification */
687#define MAX_FORMAT 20687#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)
688 693
689 694
690static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {695static 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
712 luaL_addchar(b, '"');717 luaL_addchar(b, '"');
713}718}
714 719
715 720static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
716static const char *scanformat (lua_State *L, const char *strfrmt,
717 char *form, int *hasprecision) {
718 const char *p = strfrmt;721 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)");
720 if (isdigit(uchar(*p))) p++; /* skip width */725 if (isdigit(uchar(*p))) p++; /* skip width */
721 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */726 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
722 if (*p == '.') {727 if (*p == '.') {
723 p++;728 p++;
724 *hasprecision = 1;
725 if (isdigit(uchar(*p))) p++; /* skip precision */729 if (isdigit(uchar(*p))) p++; /* skip precision */
726 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */730 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
727 }731 }
728 if (isdigit(uchar(*p)))732 if (isdigit(uchar(*p)))
729 luaL_error(L, "invalid format (width or precision too long)");733 luaL_error(L, "invalid format (width or precision too long)");
730 if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */734 *(form++) = '%';
731 luaL_error(L, "invalid format (too long)");735 strncpy(form, strfrmt, p - strfrmt + 1);
732 form[0] = L_ESC;736 form += p - strfrmt + 1;
733 strncpy(form+1, strfrmt, p-strfrmt+1);737 *form = '\0';
734 form[p-strfrmt+2] = 0;
735 return p;738 return p;
736}739}
737 740
738 741
742static 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
739static int str_format (lua_State *L) {751static int str_format (lua_State *L) {
740 int arg = 1;752 int arg = 1;
741 size_t sfl;753 size_t sfl;
@@ -751,21 +763,26 @@ static int str_format (lua_State *L) { · 9 unmodified lines
751 else { /* format item */763 else { /* format item */
752 char form[MAX_FORMAT]; /* to store the format (`%...') */764 char form[MAX_FORMAT]; /* to store the format (`%...') */
753 char buff[MAX_ITEM]; /* to store the formatted item */765 char buff[MAX_ITEM]; /* to store the formatted item */
754 int hasprecision = 0;
755 arg++;766 arg++;
756 strfrmt = scanformat(L, strfrmt, form, &hasprecision);767 strfrmt = scanformat(L, strfrmt, form);
757 switch (*strfrmt++) {768 switch (*strfrmt++) {
758 case 'c': case 'd': case 'i': {769 case 'c': {
759 sprintf(buff, form, luaL_checkint(L, arg));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));
760 break;776 break;
761 }777 }
762 case 'o': case 'u': case 'x': case 'X': {778 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));
764 break;781 break;
765 }782 }
766 case 'e': case 'E': case 'f':783 case 'e': case 'E': case 'f':
767 case 'g': case 'G': {784 case 'g': case 'G': {
768 sprintf(buff, form, luaL_checknumber(L, arg));785 sprintf(buff, form, (double)luaL_checknumber(L, arg));
769 break;786 break;
770 }787 }
771 case 'q': {788 case 'q': {
@@ -775,7 +792,7 @@ static int str_format (lua_State *L) { · 3 unmodified lines
775 case 's': {792 case 's': {
776 size_t l;793 size_t l;
777 const char *s = luaL_checklstring(L, arg, &l);794 const char *s = luaL_checklstring(L, arg, &l);
778 if (!hasprecision && l >= 100) {795 if (!strchr(form, '.') && l >= 100) {
779 /* no precision and string is too long to be formatted;796 /* no precision and string is too long to be formatted;
780 keep original string */797 keep original string */
781 lua_pushvalue(L, arg);798 lua_pushvalue(L, arg);
@@ -820,7 +837,7 @@ static const luaL_Reg strlib[] = { · 38 unmodified lines
820 837
821 838
822static void createmetatable (lua_State *L) {839static void createmetatable (lua_State *L) {
823 lua_newtable(L); /* create metatable for strings */840 lua_createtable(L, 0, 1); /* create metatable for strings */
824 lua_pushliteral(L, ""); /* dummy string */841 lua_pushliteral(L, ""); /* dummy string */
825 lua_pushvalue(L, -2);842 lua_pushvalue(L, -2);
826 lua_setmetatable(L, -2); /* set string metatable */843 lua_setmetatable(L, -2); /* set string metatable */
src/ltable.c+53−39
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua tables (hash)3** Lua tables (hash)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -66,13 +66,15 @@ · 60 unmodified lines
66/*66/*
67** number of ints inside a lua_Number67** number of ints inside a lua_Number
68*/68*/
69#define numints cast(int, sizeof(lua_Number)/sizeof(int))69#define numints cast_int(sizeof(lua_Number)/sizeof(int))
70 70
71 71
72 72
73const Node luaH_dummynode = {73#define dummynode (&dummynode_)
74
75static const Node dummynode_ = {
74 {{NULL}, LUA_TNIL}, /* value */76 {{NULL}, LUA_TNIL}, /* value */
75 {{NULL}, LUA_TNIL, NULL} /* key */77 {{{NULL}, LUA_TNIL, NULL}} /* key */
76};78};
77 79
78 80
@@ -95,7 +97,7 @@ static Node *hashnum (const Table *t, lua_Number n) { · 16 unmodified lines
95** returns the `main' position of an element in a table (that is, the index97** returns the `main' position of an element in a table (that is, the index
96** of its hash value)98** of its hash value)
97*/99*/
98Node *luaH_mainposition (const Table *t, const TValue *key) {100static Node *mainposition (const Table *t, const TValue *key) {
99 switch (ttype(key)) {101 switch (ttype(key)) {
100 case LUA_TNUMBER:102 case LUA_TNUMBER:
101 return hashnum(t, nvalue(key));103 return hashnum(t, nvalue(key));
@@ -120,7 +122,7 @@ static int arrayindex (const TValue *key) { · 18 unmodified lines
120 lua_Number n = nvalue(key);122 lua_Number n = nvalue(key);
121 int k;123 int k;
122 lua_number2int(k, n);124 lua_number2int(k, n);
123 if (luai_numeq(cast(lua_Number, k), nvalue(key)))125 if (luai_numeq(cast_num(k), nvalue(key)))
124 return k;126 return k;
125 }127 }
126 return -1; /* `key' did not match some condition */128 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
139 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */141 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
140 return i-1; /* yes; that's the index (corrected to C) */142 return i-1; /* yes; that's the index (corrected to C) */
141 else {143 else {
142 Node *n = luaH_mainposition(t, key);144 Node *n = mainposition(t, key);
143 do { /* check whether `key' is somewhere in the chain */145 do { /* check whether `key' is somewhere in the chain */
144 /* key may be dead already, but it is ok to use it in `next' */146 /* key may be dead already, but it is ok to use it in `next' */
145 if (luaO_rawequalObj(key2tval(n), key) ||147 if (luaO_rawequalObj(key2tval(n), key) ||
146 (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&148 (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
147 gcvalue(gkey(n)) == gcvalue(key))) {149 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 */
149 /* hash elements are numbered after array ones */151 /* hash elements are numbered after array ones */
150 return i + t->sizearray;152 return i + t->sizearray;
151 }153 }
@@ -161,7 +163,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { · 9 unmodified lines
161 int i = findindex(L, t, key); /* find original element */163 int i = findindex(L, t, key); /* find original element */
162 for (i++; i < t->sizearray; i++) { /* try first array part */164 for (i++; i < t->sizearray; i++) { /* try first array part */
163 if (!ttisnil(&t->array[i])) { /* a non-nil value? */165 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
164 setnvalue(key, cast(lua_Number, i+1));166 setnvalue(key, cast_num(i+1));
165 setobj2s(L, key+1, &t->array[i]);167 setobj2s(L, key+1, &t->array[i]);
166 return 1;168 return 1;
167 }169 }
@@ -270,7 +272,7 @@ static void setarrayvector (lua_State *L, Table *t, int size) { · 102 unmodified lines
270static void setnodevector (lua_State *L, Table *t, int size) {272static void setnodevector (lua_State *L, Table *t, int size) {
271 int lsize;273 int lsize;
272 if (size == 0) { /* no elements to hash part? */274 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' */
274 lsize = 0;276 lsize = 0;
275 }277 }
276 else {278 else {
@@ -281,12 +283,13 @@ static void setnodevector (lua_State *L, Table *t, int size) { · 4 unmodified lines
281 size = twoto(lsize);283 size = twoto(lsize);
282 t->node = luaM_newvector(L, size, Node);284 t->node = luaM_newvector(L, size, Node);
283 for (i=0; i<size; i++) {285 for (i=0; i<size; i++) {
284 gnext(&t->node[i]) = NULL;286 Node *n = gnode(t, i);
285 setnilvalue(gkey(gnode(t, i)));287 gnext(n) = NULL;
286 setnilvalue(gval(gnode(t, i)));288 setnilvalue(gkey(n));
289 setnilvalue(gval(n));
287 }290 }
288 }291 }
289 t->lsizenode = cast(lu_byte, lsize);292 t->lsizenode = cast_byte(lsize);
290 t->lastfree = gnode(t, size); /* all positions are free */293 t->lastfree = gnode(t, size); /* all positions are free */
291}294}
292 295
@@ -316,13 +319,13 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) { · 23 unmodified lines
316 if (!ttisnil(gval(old)))319 if (!ttisnil(gval(old)))
317 setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));320 setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
318 }321 }
319 if (nold != &luaH_dummynode)322 if (nold != dummynode)
320 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */323 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
321}324}
322 325
323 326
324void luaH_resizearray (lua_State *L, Table *t, int nasize) {327void 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);
326 resize(L, t, nasize, nsize);329 resize(L, t, nasize, nsize);
327}330}
328 331
@@ -356,12 +359,12 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 27 unmodified lines
356 Table *t = luaM_new(L, Table);359 Table *t = luaM_new(L, Table);
357 luaC_link(L, obj2gco(t), LUA_TTABLE);360 luaC_link(L, obj2gco(t), LUA_TTABLE);
358 t->metatable = NULL;361 t->metatable = NULL;
359 t->flags = cast(lu_byte, ~0);362 t->flags = cast_byte(~0);
360 /* temporary values (kept only if some malloc fails) */363 /* temporary values (kept only if some malloc fails) */
361 t->array = NULL;364 t->array = NULL;
362 t->sizearray = 0;365 t->sizearray = 0;
363 t->lsizenode = 0;366 t->lsizenode = 0;
364 t->node = cast(Node *, &luaH_dummynode);367 t->node = cast(Node *, dummynode);
365 setarrayvector(L, t, narray);368 setarrayvector(L, t, narray);
366 setnodevector(L, t, nhash);369 setnodevector(L, t, nhash);
367 return t;370 return t;
@@ -369,7 +372,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { · 1 unmodified line
369 372
370 373
371void luaH_free (lua_State *L, Table *t) {374void luaH_free (lua_State *L, Table *t) {
372 if (t->node != &luaH_dummynode)375 if (t->node != dummynode)
373 luaM_freearray(L, t->node, sizenode(t), Node);376 luaM_freearray(L, t->node, sizenode(t), Node);
374 luaM_freearray(L, t->array, t->sizearray, TValue);377 luaM_freearray(L, t->array, t->sizearray, TValue);
375 luaM_free(L, t);378 luaM_free(L, t);
@@ -394,16 +397,16 @@ static Node *getfreepos (Table *t) { · 18 unmodified lines
394** position), new key goes to an empty position. 397** position), new key goes to an empty position.
395*/398*/
396static TValue *newkey (lua_State *L, Table *t, const TValue *key) {399static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
397 Node *mp = luaH_mainposition(t, key);400 Node *mp = mainposition(t, key);
398 if (!ttisnil(gval(mp)) || mp == &luaH_dummynode) {401 if (!ttisnil(gval(mp)) || mp == dummynode) {
399 Node *othern;402 Node *othern;
400 Node *n = getfreepos(t); /* get a free place */403 Node *n = getfreepos(t); /* get a free place */
401 if (n == NULL) { /* cannot find a free place? */404 if (n == NULL) { /* cannot find a free place? */
402 rehash(L, t, key); /* grow table */405 rehash(L, t, key); /* grow table */
403 return luaH_set(L, t, key); /* re-insert key into grown table */406 return luaH_set(L, t, key); /* re-insert key into grown table */
404 }407 }
405 lua_assert(n != &luaH_dummynode);408 lua_assert(n != dummynode);
406 othern = luaH_mainposition(t, key2tval(mp));409 othern = mainposition(t, key2tval(mp));
407 if (othern != mp) { /* is colliding node out of its main position? */410 if (othern != mp) { /* is colliding node out of its main position? */
408 /* yes; move colliding node into free position */411 /* yes; move colliding node into free position */
409 while (gnext(othern) != mp) othern = gnext(othern); /* find previous */412 while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
@@ -434,14 +437,14 @@ const TValue *luaH_getnum (Table *t, int key) { · 24 unmodified lines
434 if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))437 if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
435 return &t->array[key-1];438 return &t->array[key-1];
436 else {439 else {
437 lua_Number nk = cast(lua_Number, key);440 lua_Number nk = cast_num(key);
438 Node *n = hashnum(t, nk);441 Node *n = hashnum(t, nk);
439 do { /* check whether `key' is somewhere in the chain */442 do { /* check whether `key' is somewhere in the chain */
440 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))443 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
441 return gval(n); /* that's it */444 return gval(n); /* that's it */
442 else n = gnext(n);445 else n = gnext(n);
443 } while (n);446 } while (n);
444 return &luaO_nilobject;447 return luaO_nilobject;
445 }448 }
446}449}
447 450
@@ -456,7 +459,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 8 unmodified lines
456 return gval(n); /* that's it */459 return gval(n); /* that's it */
457 else n = gnext(n);460 else n = gnext(n);
458 } while (n);461 } while (n);
459 return &luaO_nilobject;462 return luaO_nilobject;
460}463}
461 464
462 465
@@ -465,24 +468,24 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 2 unmodified lines
465*/468*/
466const TValue *luaH_get (Table *t, const TValue *key) {469const TValue *luaH_get (Table *t, const TValue *key) {
467 switch (ttype(key)) {470 switch (ttype(key)) {
468 case LUA_TNIL: return &luaO_nilobject;471 case LUA_TNIL: return luaO_nilobject;
469 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));472 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
470 case LUA_TNUMBER: {473 case LUA_TNUMBER: {
471 int k;474 int k;
472 lua_Number n = nvalue(key);475 lua_Number n = nvalue(key);
473 lua_number2int(k, n);476 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? */
475 return luaH_getnum(t, k); /* use specialized version */478 return luaH_getnum(t, k); /* use specialized version */
476 /* else go through */479 /* else go through */
477 }480 }
478 default: {481 default: {
479 Node *n = luaH_mainposition(t, key);482 Node *n = mainposition(t, key);
480 do { /* check whether `key' is somewhere in the chain */483 do { /* check whether `key' is somewhere in the chain */
481 if (luaO_rawequalObj(key2tval(n), key))484 if (luaO_rawequalObj(key2tval(n), key))
482 return gval(n); /* that's it */485 return gval(n); /* that's it */
483 else n = gnext(n);486 else n = gnext(n);
484 } while (n);487 } while (n);
485 return &luaO_nilobject;488 return luaO_nilobject;
486 }489 }
487 }490 }
488}491}
@@ -491,11 +494,11 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 2 unmodified lines
491TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {494TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
492 const TValue *p = luaH_get(t, key);495 const TValue *p = luaH_get(t, key);
493 t->flags = 0;496 t->flags = 0;
494 if (p != &luaO_nilobject)497 if (p != luaO_nilobject)
495 return cast(TValue *, p);498 return cast(TValue *, p);
496 else {499 else {
497 if (ttisnil(key)) luaG_runerror(L, "table index is nil");500 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)))
499 luaG_runerror(L, "table index is NaN");502 luaG_runerror(L, "table index is NaN");
500 return newkey(L, t, key);503 return newkey(L, t, key);
501 }504 }
@@ -504,11 +507,11 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 2 unmodified lines
504 507
505TValue *luaH_setnum (lua_State *L, Table *t, int key) {508TValue *luaH_setnum (lua_State *L, Table *t, int key) {
506 const TValue *p = luaH_getnum(t, key);509 const TValue *p = luaH_getnum(t, key);
507 if (p != &luaO_nilobject)510 if (p != luaO_nilobject)
508 return cast(TValue *, p);511 return cast(TValue *, p);
509 else {512 else {
510 TValue k;513 TValue k;
511 setnvalue(&k, cast(lua_Number, key));514 setnvalue(&k, cast_num(key));
512 return newkey(L, t, &k);515 return newkey(L, t, &k);
513 }516 }
514}517}
@@ -516,7 +519,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) { · 1 unmodified line
516 519
517TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {520TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
518 const TValue *p = luaH_getstr(t, key);521 const TValue *p = luaH_getstr(t, key);
519 if (p != &luaO_nilobject)522 if (p != luaO_nilobject)
520 return cast(TValue *, p);523 return cast(TValue *, p);
521 else {524 else {
522 TValue k;525 TValue k;
@@ -528,11 +531,11 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { · 5 unmodified lines
528 531
529static int unbound_search (Table *t, unsigned int j) {532static int unbound_search (Table *t, unsigned int j) {
530 unsigned int i = j; /* i is zero or a present index */533 unsigned int i = j; /* i is zero or a present index */
531 j = j+1;534 j++;
532 /* find `i' and `j' such that i is present and j is not */535 /* find `i' and `j' such that i is present and j is not */
533 while (!ttisnil(luaH_getnum(t, j))) {536 while (!ttisnil(luaH_getnum(t, j))) {
534 i = j;537 i = j;
535 j = i*2;538 j *= 2;
536 if (j > cast(unsigned int, MAX_INT)) { /* overflow? */539 if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
537 /* table was built with bad purposes: resort to linear search */540 /* table was built with bad purposes: resort to linear search */
538 i = 1;541 i = 1;
@@ -541,7 +544,7 @@ static int unbound_search (Table *t, unsigned int j) { · 2 unmodified lines
541 }544 }
542 }545 }
543 /* now do a binary search between them */546 /* now do a binary search between them */
544 while (i < j-1) {547 while (j - i > 1) {
545 unsigned int m = (i+j)/2;548 unsigned int m = (i+j)/2;
546 if (ttisnil(luaH_getnum(t, m))) j = m;549 if (ttisnil(luaH_getnum(t, m))) j = m;
547 else i = m;550 else i = m;
@@ -567,8 +570,19 @@ int luaH_getn (Table *t) { · 19 unmodified lines
567 return i;570 return i;
568 }571 }
569 /* else must find a boundary in hash part */572 /* 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? */
571 return j; /* that is easy... */574 return j; /* that is easy... */
572 else return unbound_search(t, j);575 else return unbound_search(t, j);
573}576}
574 577
578
579
580#if defined(LUA_DEBUG)
581
582Node *luaH_mainposition (const Table *t, const TValue *key) {
583 return mainposition(t, key);
584}
585
586int luaH_isdummy (Node *n) { return n == dummynode; }
587
588#endif
src/ltable.h+8−7
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua tables (hash)3** Lua tables (hash)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -11,15 +11,13 @@ · 5 unmodified lines
11 11
12 12
13#define gnode(t,i) (&(t)->node[i])13#define gnode(t,i) (&(t)->node[i])
14#define gkey(n) (&(n)->i_key)14#define gkey(n) (&(n)->i_key.nk)
15#define gval(n) (&(n)->i_val)15#define gval(n) (&(n)->i_val)
16#define gnext(n) ((n)->i_key.next)16#define gnext(n) ((n)->i_key.nk.next)
17 17
18#define key2tval(n) (cast(const TValue *, gkey(n)))18#define key2tval(n) (&(n)->i_key.tvk)
19 19
20 20
21LUAI_DATA const Node luaH_dummynode;
22
23LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);21LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
24LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);22LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
25LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);23LUAI_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
32LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);30LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
33LUAI_FUNC int luaH_getn (Table *t);31LUAI_FUNC int luaH_getn (Table *t);
34 32
35/* exported only for debugging */33
34#if defined(LUA_DEBUG)
36LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);35LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
36LUAI_FUNC int luaH_isdummy (Node *n);
37#endif
37 38
38 39
39#endif40#endif
src/ltm.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Tag methods3** Tag methods
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -51,7 +51,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { · 45 unmodified lines
51 const TValue *tm = luaH_getstr(events, ename);51 const TValue *tm = luaH_getstr(events, ename);
52 lua_assert(event <= TM_EQ);52 lua_assert(event <= TM_EQ);
53 if (ttisnil(tm)) { /* no tag method? */53 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 */
55 return NULL;55 return NULL;
56 }56 }
57 else return tm;57 else return tm;
@@ -70,6 +70,6 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { · 12 unmodified lines
70 default:70 default:
71 mt = G(L)->mt[ttype(o)];71 mt = G(L)->mt[ttype(o)];
72 }72 }
73 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);73 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
74}74}
75 75
src/lua.c+9−5
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua stand-alone interpreter3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -120,7 +120,7 @@ static int getargs (lua_State *L, char **argv, int n) { · 114 unmodified lines
120 luaL_checkstack(L, narg + 3, "too many arguments to script");120 luaL_checkstack(L, narg + 3, "too many arguments to script");
121 for (i=n+1; i < argc; i++)121 for (i=n+1; i < argc; i++)
122 lua_pushstring(L, argv[i]);122 lua_pushstring(L, argv[i]);
123 lua_newtable(L);123 lua_createtable(L, narg, n + 1);
124 for (i=0; i < argc; i++) {124 for (i=0; i < argc; i++) {
125 lua_pushstring(L, argv[i]);125 lua_pushstring(L, argv[i]);
126 lua_rawseti(L, -2, i - n);126 lua_rawseti(L, -2, i - n);
@@ -215,7 +215,6 @@ static void dotty (lua_State *L) { · 88 unmodified lines
215 int status;215 int status;
216 const char *oldprogname = progname;216 const char *oldprogname = progname;
217 progname = NULL;217 progname = NULL;
218 print_version();
219 while ((status = loadline(L)) != -1) {218 while ((status = loadline(L)) != -1) {
220 if (status == 0) status = docall(L, 0, 0);219 if (status == 0) status = docall(L, 0, 0);
221 report(L, status);220 report(L, status);
@@ -261,7 +260,7 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 39 unmodified lines
261 switch (argv[i][1]) { /* option */260 switch (argv[i][1]) { /* option */
262 case '-': return (argv[i+1] != NULL ? i+1 : 0);261 case '-': return (argv[i+1] != NULL ? i+1 : 0);
263 case '\0': return i;262 case '\0': return i;
264 case 'i': *pi = 1; break;263 case 'i': *pi = 1; /* go through */
265 case 'v': *pv = 1; break;264 case 'v': *pv = 1; break;
266 case 'e': *pe = 1; /* go through */265 case 'e': *pe = 1; /* go through */
267 case 'l':266 case 'l':
@@ -330,7 +329,9 @@ static int pmain (lua_State *L) { · 62 unmodified lines
330 int has_i = 0, has_v = 0, has_e = 0;329 int has_i = 0, has_v = 0, has_e = 0;
331 globalL = L;330 globalL = L;
332 if (argv[0] && argv[0][0]) progname = argv[0];331 if (argv[0] && argv[0][0]) progname = argv[0];
332 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
333 luaL_openlibs(L); /* open libraries */333 luaL_openlibs(L); /* open libraries */
334 lua_gc(L, LUA_GCRESTART, 0);
334 s->status = handle_luainit(L);335 s->status = handle_luainit(L);
335 if (s->status != 0) return 0;336 if (s->status != 0) return 0;
336 script = collectargs(argv, &has_i, &has_v, &has_e);337 script = collectargs(argv, &has_i, &has_v, &has_e);
@@ -348,7 +349,10 @@ static int pmain (lua_State *L) { · 11 unmodified lines
348 if (has_i)349 if (has_i)
349 dotty(L);350 dotty(L);
350 else if (script == 0 && !has_e && !has_v) {351 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 }
352 else dofile(L, NULL); /* executes stdin as a file */356 else dofile(L, NULL); /* executes stdin as a file */
353 }357 }
354 return 0;358 return 0;
src/lua.h+4−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua - An Extensible Extension Language3** Lua - An Extensible Extension Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file5** See Copyright Notice at the end of this file
@@ -16,9 +16,9 @@ · 10 unmodified lines
16#include "luaconf.h"16#include "luaconf.h"
17 17
18 18
19#define LUA_VERSION "Lua 5.1 (beta)"19#define LUA_VERSION "Lua 5.1"
20#define LUA_VERSION_NUM 50120#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"
22#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"22#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
23 23
24 24
@@ -358,7 +358,7 @@ struct lua_Debug { · 333 unmodified lines
358 358
359 359
360/******************************************************************************360/******************************************************************************
361* Copyright (C) 1994-2005 Lua.org, PUC-Rio. All rights reserved.361* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.
362*362*
363* Permission is hereby granted, free of charge, to any person obtaining363* Permission is hereby granted, free of charge, to any person obtaining
364* a copy of this software and associated documentation files (the364* a copy of this software and associated documentation files (the
src/luaconf.h+31−13
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Configuration file for Lua3** Configuration file for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -28,6 +28,11 @@ · 22 unmodified lines
28#define LUA_ANSI28#define LUA_ANSI
29#endif29#endif
30 30
31
32#if !defined(LUA_ANSI) && defined(_WIN32)
33#define LUA_WIN
34#endif
35
31#if defined(LUA_USE_LINUX)36#if defined(LUA_USE_LINUX)
32#define LUA_USE_POSIX37#define LUA_USE_POSIX
33#define LUA_USE_DLOPEN /* needs an extra library: -ldl */38#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
@@ -177,13 +182,6 @@ · 143 unmodified lines
177 182
178 183
179 184
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
187/*185/*
188@@ LUA_QL describes how error messages quote program elements.186@@ LUA_QL describes how error messages quote program elements.
189** CHANGE it if you want a different appearance.187** CHANGE it if you want a different appearance.
@@ -217,7 +215,7 @@ · 27 unmodified lines
217#if defined(LUA_USE_ISATTY)215#if defined(LUA_USE_ISATTY)
218#include <unistd.h>216#include <unistd.h>
219#define lua_stdin_is_tty() isatty(0)217#define lua_stdin_is_tty() isatty(0)
220#elif !defined(LUA_ANSI) && defined(_WIN32)218#elif defined(LUA_WIN)
221#include <io.h>219#include <io.h>
222#include <stdio.h>220#include <stdio.h>
223#define lua_stdin_is_tty() _isatty(_fileno(stdin))221#define lua_stdin_is_tty() _isatty(_fileno(stdin))
@@ -368,8 +366,7 @@ · 144 unmodified lines
368#include <assert.h>366#include <assert.h>
369#define luai_apicheck(L,o) { (void)L; assert(o); }367#define luai_apicheck(L,o) { (void)L; assert(o); }
370#else368#else
371/* (By default lua_assert is empty, so luai_apicheck is also empty.) */369#define luai_apicheck(L,o) { (void)L; }
372#define luai_apicheck(L,o) { (void)L; lua_assert(o); }
373#endif370#endif
374 371
375 372
@@ -529,6 +526,7 @@ · 153 unmodified lines
529#define luai_numeq(a,b) ((a)==(b))526#define luai_numeq(a,b) ((a)==(b))
530#define luai_numlt(a,b) ((a)<(b))527#define luai_numlt(a,b) ((a)<(b))
531#define luai_numle(a,b) ((a)<=(b))528#define luai_numle(a,b) ((a)<=(b))
529#define luai_numisnan(a) (!luai_numeq((a), (a)))
532#endif530#endif
533 531
534 532
@@ -644,7 +642,7 @@ union luai_Cast { double l_d; long l_l; }; · 109 unmodified lines
644#define lua_popen(L,c,m) ((void)L, popen(c,m))642#define lua_popen(L,c,m) ((void)L, popen(c,m))
645#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))643#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
646 644
647#elif !defined(LUA_ANSI) && defined(_WIN32)645#elif defined(LUA_WIN)
648 646
649#define lua_popen(L,c,m) ((void)L, _popen(c,m))647#define lua_popen(L,c,m) ((void)L, _popen(c,m))
650#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))648#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
675#define LUA_DL_DLOPEN673#define LUA_DL_DLOPEN
676#endif674#endif
677 675
678#if !defined(LUA_ANSI) && defined(_WIN32)676#if defined(LUA_WIN)
679#define LUA_DL_DLL677#define LUA_DL_DLL
680#endif678#endif
681 679
@@ -702,6 +700,26 @@ union luai_Cast { double l_d; long l_l; }; · 20 unmodified lines
702#define luai_userstateyield(L,n) ((void)L)700#define luai_userstateyield(L,n) ((void)L)
703 701
704 702
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
705 723
706 724
707/* =================================================================== */725/* =================================================================== */
src/lualib.h+7−1
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua standard libraries3** Lua standard libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -44,4 +44,10 @@ LUALIB_API int (luaopen_package) (lua_State *L); · 38 unmodified lines
44LUALIB_API void (luaL_openlibs) (lua_State *L); 44LUALIB_API void (luaL_openlibs) (lua_State *L);
45 45
46 46
47
48#ifndef lua_assert
49#define lua_assert(x) ((void)0)
50#endif
51
52
47#endif53#endif
src/lvm.c+7−7
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua virtual machine3** Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -509,16 +509,16 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 503 unmodified lines
509 const TValue *rb = RB(i);509 const TValue *rb = RB(i);
510 switch (ttype(rb)) {510 switch (ttype(rb)) {
511 case LUA_TTABLE: {511 case LUA_TTABLE: {
512 setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb))));512 setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
513 break;513 break;
514 }514 }
515 case LUA_TSTRING: {515 case LUA_TSTRING: {
516 setnvalue(ra, cast(lua_Number, tsvalue(rb)->len));516 setnvalue(ra, cast_num(tsvalue(rb)->len));
517 break;517 break;
518 }518 }
519 default: { /* try metamethod */519 default: { /* try metamethod */
520 Protect(520 Protect(
521 if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN))521 if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
522 luaG_typeerror(L, rb, "get length of");522 luaG_typeerror(L, rb, "get length of");
523 )523 )
524 }524 }
@@ -693,10 +693,10 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 168 unmodified lines
693 int last;693 int last;
694 Table *h;694 Table *h;
695 if (n == 0) {695 if (n == 0) {
696 n = cast(int, L->top - ra) - 1;696 n = cast_int(L->top - ra) - 1;
697 L->top = L->ci->top;697 L->top = L->ci->top;
698 }698 }
699 if (c == 0) c = cast(int, *pc++);699 if (c == 0) c = cast_int(*pc++);
700 runtime_check(L, ttistable(ra));700 runtime_check(L, ttistable(ra));
701 h = hvalue(ra);701 h = hvalue(ra);
702 last = ((c-1)*LFIELDS_PER_FLUSH) + n;702 last = ((c-1)*LFIELDS_PER_FLUSH) + n;
@@ -737,7 +737,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 34 unmodified lines
737 int b = GETARG_B(i) - 1;737 int b = GETARG_B(i) - 1;
738 int j;738 int j;
739 CallInfo *ci = L->ci;739 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;
741 if (b == LUA_MULTRET) {741 if (b == LUA_MULTRET) {
742 Protect(luaD_checkstack(L, n));742 Protect(luaD_checkstack(L, n));
743 ra = RA(i); /* previous call may change the stack */743 ra = RA(i); /* previous call may change the stack */
src/print.c+5−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** print bytecodes3** print bytecodes
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -36,7 +36,10 @@ static void PrintString(const Proto* f, int n) · 30 unmodified lines
36 case '\r': printf("\\r"); break;36 case '\r': printf("\\r"); break;
37 case '\t': printf("\\t"); break;37 case '\t': printf("\\t"); break;
38 case '\v': printf("\\v"); break;38 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);
40 }43 }
41 }44 }
42 putchar('"');45 putchar('"');