History

Lua 5.1-beta

Lua Team committed 21 years ago

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

Unified · Split

39 files
  1. HISTORY +1 −1
  2. INSTALL +3 −1
  3. MANIFEST +107 −107
  4. Makefile +9 −3
  5. README +1 −1
  6. doc/contents.html +272 −1
  7. doc/manual.html +678 −607
  8. src/lapi.c +19 −3
  9. src/lauxlib.c +9 −10
  10. src/lauxlib.h +2 −1
  11. src/lbaselib.c +29 −19
  12. src/lcode.c +161 −118
  13. src/lcode.h +3 −5
  14. src/ldblib.c +9 −2
  15. src/ldebug.c +27 −28
  16. src/ldo.c +9 −7
  17. src/ldump.c +24 −29
  18. src/liolib.c +3 −3
  19. src/llex.c +16 −24
  20. src/loadlib.c +13 −12
  21. src/lobject.c +2 −2
  22. src/lobject.h +2 −2
  23. src/lopcodes.c +2 −4
  24. src/lopcodes.h +5 −5
  25. src/loslib.c +3 −3
  26. src/lparser.c +22 −21
  27. src/lparser.h +6 −2
  28. src/lstate.c +6 −4
  29. src/lstrlib.c +75 −58
  30. src/ltable.c +5 −5
  31. src/ltablib.c +40 −18
  32. src/lua.c +96 −90
  33. src/lua.h +7 −5
  34. src/luac.c +7 −12
  35. src/luaconf.h +95 −73
  36. src/lundump.c +41 −108
  37. src/lundump.h +4 −30
  38. src/lvm.c +43 −75
  39. src/print.c +6 −3
HISTORY+1−1
@@ -1,4 +1,4 @@
1This is Lua 5.1 (alpha).1This is Lua 5.1 (beta).
2 2
3* Changes from version 5.0 to 5.13* Changes from version 5.0 to 5.1
4 -------------------------------4 -------------------------------
INSTALL+3−1
@@ -1,10 +1,12 @@
1This is Lua 5.1 (alpha).1This is Lua 5.1 (beta).
2 2
3* Installation3* Installation
4 ------------4 ------------
5 Building Lua on a Unix system should be very easy: simply doing "make"5 Building Lua on a Unix system should be very easy: simply doing "make"
6 should work. This will build Lua in the src directory.6 should work. This will build Lua in the src directory.
7 7
8 There are also special make targets for ansi, linux, bsd, mingw.
9
8 See below for customization instructions.10 See below for customization instructions.
9 11
10 If you want to install Lua in an official place in your system, then12 If you want to install Lua in an official place in your system, then
MANIFEST+107−107
@@ -1,108 +1,108 @@
1MANIFEST contents of Lua 5.1 (alpha) distribution on Fri Sep 9 16:55:12 BRST 20051MANIFEST contents of Lua 5.1 (beta) distribution on Fri Nov 18 07:42:23 BRST 2005
2lua-5.1-alpha2lua-5.1-beta
3lua-5.1-alpha/COPYRIGHT3lua-5.1-beta/COPYRIGHT
4lua-5.1-alpha/HISTORY4lua-5.1-beta/HISTORY
5lua-5.1-alpha/INSTALL5lua-5.1-beta/INSTALL
6lua-5.1-alpha/MANIFEST6lua-5.1-beta/MANIFEST
7lua-5.1-alpha/Makefile7lua-5.1-beta/Makefile
8lua-5.1-alpha/README8lua-5.1-beta/README
9lua-5.1-alpha/doc9lua-5.1-beta/doc
10lua-5.1-alpha/doc/contents.html10lua-5.1-beta/doc/contents.html
11lua-5.1-alpha/doc/logo.gif11lua-5.1-beta/doc/logo.gif
12lua-5.1-alpha/doc/lua.112lua-5.1-beta/doc/lua.1
13lua-5.1-alpha/doc/lua.css13lua-5.1-beta/doc/lua.css
14lua-5.1-alpha/doc/lua.html14lua-5.1-beta/doc/lua.html
15lua-5.1-alpha/doc/luac.115lua-5.1-beta/doc/luac.1
16lua-5.1-alpha/doc/luac.html16lua-5.1-beta/doc/luac.html
17lua-5.1-alpha/doc/manual.html17lua-5.1-beta/doc/manual.html
18lua-5.1-alpha/doc/readme.html18lua-5.1-beta/doc/readme.html
19lua-5.1-alpha/etc19lua-5.1-beta/etc
20lua-5.1-alpha/etc/Makefile20lua-5.1-beta/etc/Makefile
21lua-5.1-alpha/etc/README21lua-5.1-beta/etc/README
22lua-5.1-alpha/etc/all.c22lua-5.1-beta/etc/all.c
23lua-5.1-alpha/etc/lua.hpp23lua-5.1-beta/etc/lua.hpp
24lua-5.1-alpha/etc/lua.ico24lua-5.1-beta/etc/lua.ico
25lua-5.1-alpha/etc/lua.pc25lua-5.1-beta/etc/lua.pc
26lua-5.1-alpha/etc/luavs.bat26lua-5.1-beta/etc/luavs.bat
27lua-5.1-alpha/etc/min.c27lua-5.1-beta/etc/min.c
28lua-5.1-alpha/etc/noparser.c28lua-5.1-beta/etc/noparser.c
29lua-5.1-alpha/etc/strict.lua29lua-5.1-beta/etc/strict.lua
30lua-5.1-alpha/src30lua-5.1-beta/src
31lua-5.1-alpha/src/Makefile31lua-5.1-beta/src/Makefile
32lua-5.1-alpha/src/lapi.c32lua-5.1-beta/src/lapi.c
33lua-5.1-alpha/src/lapi.h33lua-5.1-beta/src/lapi.h
34lua-5.1-alpha/src/lauxlib.c34lua-5.1-beta/src/lauxlib.c
35lua-5.1-alpha/src/lauxlib.h35lua-5.1-beta/src/lauxlib.h
36lua-5.1-alpha/src/lbaselib.c36lua-5.1-beta/src/lbaselib.c
37lua-5.1-alpha/src/lcode.c37lua-5.1-beta/src/lcode.c
38lua-5.1-alpha/src/lcode.h38lua-5.1-beta/src/lcode.h
39lua-5.1-alpha/src/ldblib.c39lua-5.1-beta/src/ldblib.c
40lua-5.1-alpha/src/ldebug.c40lua-5.1-beta/src/ldebug.c
41lua-5.1-alpha/src/ldebug.h41lua-5.1-beta/src/ldebug.h
42lua-5.1-alpha/src/ldo.c42lua-5.1-beta/src/ldo.c
43lua-5.1-alpha/src/ldo.h43lua-5.1-beta/src/ldo.h
44lua-5.1-alpha/src/ldump.c44lua-5.1-beta/src/ldump.c
45lua-5.1-alpha/src/lfunc.c45lua-5.1-beta/src/lfunc.c
46lua-5.1-alpha/src/lfunc.h46lua-5.1-beta/src/lfunc.h
47lua-5.1-alpha/src/lgc.c47lua-5.1-beta/src/lgc.c
48lua-5.1-alpha/src/lgc.h48lua-5.1-beta/src/lgc.h
49lua-5.1-alpha/src/linit.c49lua-5.1-beta/src/linit.c
50lua-5.1-alpha/src/liolib.c50lua-5.1-beta/src/liolib.c
51lua-5.1-alpha/src/llex.c51lua-5.1-beta/src/llex.c
52lua-5.1-alpha/src/llex.h52lua-5.1-beta/src/llex.h
53lua-5.1-alpha/src/llimits.h53lua-5.1-beta/src/llimits.h
54lua-5.1-alpha/src/lmathlib.c54lua-5.1-beta/src/lmathlib.c
55lua-5.1-alpha/src/lmem.c55lua-5.1-beta/src/lmem.c
56lua-5.1-alpha/src/lmem.h56lua-5.1-beta/src/lmem.h
57lua-5.1-alpha/src/loadlib.c57lua-5.1-beta/src/loadlib.c
58lua-5.1-alpha/src/lobject.c58lua-5.1-beta/src/lobject.c
59lua-5.1-alpha/src/lobject.h59lua-5.1-beta/src/lobject.h
60lua-5.1-alpha/src/lopcodes.c60lua-5.1-beta/src/lopcodes.c
61lua-5.1-alpha/src/lopcodes.h61lua-5.1-beta/src/lopcodes.h
62lua-5.1-alpha/src/loslib.c62lua-5.1-beta/src/loslib.c
63lua-5.1-alpha/src/lparser.c63lua-5.1-beta/src/lparser.c
64lua-5.1-alpha/src/lparser.h64lua-5.1-beta/src/lparser.h
65lua-5.1-alpha/src/lstate.c65lua-5.1-beta/src/lstate.c
66lua-5.1-alpha/src/lstate.h66lua-5.1-beta/src/lstate.h
67lua-5.1-alpha/src/lstring.c67lua-5.1-beta/src/lstring.c
68lua-5.1-alpha/src/lstring.h68lua-5.1-beta/src/lstring.h
69lua-5.1-alpha/src/lstrlib.c69lua-5.1-beta/src/lstrlib.c
70lua-5.1-alpha/src/ltable.c70lua-5.1-beta/src/ltable.c
71lua-5.1-alpha/src/ltable.h71lua-5.1-beta/src/ltable.h
72lua-5.1-alpha/src/ltablib.c72lua-5.1-beta/src/ltablib.c
73lua-5.1-alpha/src/ltm.c73lua-5.1-beta/src/ltm.c
74lua-5.1-alpha/src/ltm.h74lua-5.1-beta/src/ltm.h
75lua-5.1-alpha/src/lua.c75lua-5.1-beta/src/lua.c
76lua-5.1-alpha/src/lua.h76lua-5.1-beta/src/lua.h
77lua-5.1-alpha/src/luac.c77lua-5.1-beta/src/luac.c
78lua-5.1-alpha/src/luaconf.h78lua-5.1-beta/src/luaconf.h
79lua-5.1-alpha/src/lualib.h79lua-5.1-beta/src/lualib.h
80lua-5.1-alpha/src/lundump.c80lua-5.1-beta/src/lundump.c
81lua-5.1-alpha/src/lundump.h81lua-5.1-beta/src/lundump.h
82lua-5.1-alpha/src/lvm.c82lua-5.1-beta/src/lvm.c
83lua-5.1-alpha/src/lvm.h83lua-5.1-beta/src/lvm.h
84lua-5.1-alpha/src/lzio.c84lua-5.1-beta/src/lzio.c
85lua-5.1-alpha/src/lzio.h85lua-5.1-beta/src/lzio.h
86lua-5.1-alpha/src/print.c86lua-5.1-beta/src/print.c
87lua-5.1-alpha/test87lua-5.1-beta/test
88lua-5.1-alpha/test/README88lua-5.1-beta/test/README
89lua-5.1-alpha/test/bisect.lua89lua-5.1-beta/test/bisect.lua
90lua-5.1-alpha/test/cf.lua90lua-5.1-beta/test/cf.lua
91lua-5.1-alpha/test/echo.lua91lua-5.1-beta/test/echo.lua
92lua-5.1-alpha/test/env.lua92lua-5.1-beta/test/env.lua
93lua-5.1-alpha/test/factorial.lua93lua-5.1-beta/test/factorial.lua
94lua-5.1-alpha/test/fib.lua94lua-5.1-beta/test/fib.lua
95lua-5.1-alpha/test/fibfor.lua95lua-5.1-beta/test/fibfor.lua
96lua-5.1-alpha/test/globals.lua96lua-5.1-beta/test/globals.lua
97lua-5.1-alpha/test/hello.lua97lua-5.1-beta/test/hello.lua
98lua-5.1-alpha/test/life.lua98lua-5.1-beta/test/life.lua
99lua-5.1-alpha/test/luac.lua99lua-5.1-beta/test/luac.lua
100lua-5.1-alpha/test/printf.lua100lua-5.1-beta/test/printf.lua
101lua-5.1-alpha/test/readonly.lua101lua-5.1-beta/test/readonly.lua
102lua-5.1-alpha/test/sieve.lua102lua-5.1-beta/test/sieve.lua
103lua-5.1-alpha/test/sort.lua103lua-5.1-beta/test/sort.lua
104lua-5.1-alpha/test/table.lua104lua-5.1-beta/test/table.lua
105lua-5.1-alpha/test/trace-calls.lua105lua-5.1-beta/test/trace-calls.lua
106lua-5.1-alpha/test/trace-globals.lua106lua-5.1-beta/test/trace-globals.lua
107lua-5.1-alpha/test/xd.lua107lua-5.1-beta/test/xd.lua
108END OF MANIFEST108END OF MANIFEST
Makefile+9−3
@@ -55,15 +55,21 @@ ansi: · 54 unmodified lines
55 cd src; $(MAKE) MYCFLAGS=-DLUA_ANSI55 cd src; $(MAKE) MYCFLAGS=-DLUA_ANSI
56 56
57linux:57linux:
58 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_DLOPEN MYLIBS="-Wl,-E -ldl"58 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
59
60macosx:
61 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_MACOSX
62
63posix:
64 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_POSIX
59 65
60bsd:66bsd:
61 cd src; $(MAKE) MYCFLAGS=-DLUA_USE_DLOPEN MYLIBS="-Wl,-E"67 cd src; $(MAKE) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
62 68
63mingw:69mingw:
64 cd src; $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \70 cd src; $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
65 "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \71 "AR=gcc -shared -o" "RANLIB=strip --strip-unneeded" \
66 "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" MYLDFLAGS=-s" lua.exe72 "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
67 73
68# echo config parameters74# echo config parameters
69echo:75echo:
README+1−1
@@ -1,4 +1,4 @@
1This is Lua 5.1 (alpha).1This is Lua 5.1 (beta).
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+272−1
@@ -19,6 +19,7 @@ Lua 5.1 Reference Manual · 18 unmodified lines
19<HR>19<HR>
20 20
21<UL>21<UL>
22<LI><A HREF="#words">Word index</A>
22<LI><A HREF="manual.html">Top</A>23<LI><A HREF="manual.html">Top</A>
23<LI><A HREF="manual.html#1">1 - Introduction</A>24<LI><A HREF="manual.html#1">1 - Introduction</A>
24<LI><A HREF="manual.html#2">2 - The Language</A>25<LI><A HREF="manual.html#2">2 - The Language</A>
@@ -93,10 +94,280 @@ Lua 5.1 Reference Manual · 68 unmodified lines
93<LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>94<LI><A HREF="manual.html#BNF">The Complete Syntax of Lua</A>
94</UL>95</UL>
95 96
97<H3><A NAME="words">Word index</A></H3>
98
99<A HREF="manual.html#pdf-_G">_G</A><BR>
100<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
101<A HREF="manual.html#pdf-assert">assert</A><BR>
102<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
103<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
104<A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>
105<A HREF="manual.html#pdf-coroutine.running">coroutine.running</A><BR>
106<A HREF="manual.html#pdf-coroutine.status">coroutine.status</A><BR>
107<A HREF="manual.html#pdf-coroutine.wrap">coroutine.wrap</A><BR>
108<A HREF="manual.html#pdf-coroutine.yield">coroutine.yield</A><BR>
109<A HREF="manual.html#pdf-debug.debug">debug.debug</A><BR>
110<A HREF="manual.html#pdf-debug.getfenv">debug.getfenv</A><BR>
111<A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR>
112<A HREF="manual.html#pdf-debug.getinfo">debug.getinfo</A><BR>
113<A HREF="manual.html#pdf-debug.getlocal">debug.getlocal</A><BR>
114<A HREF="manual.html#pdf-debug.getmetatable">debug.getmetatable</A><BR>
115<A HREF="manual.html#pdf-debug.getregistry">debug.getregistry</A><BR>
116<A HREF="manual.html#pdf-debug.getupvalue">debug.getupvalue</A><BR>
117<A HREF="manual.html#pdf-debug.setfenv">debug.setfenv</A><BR>
118<A HREF="manual.html#pdf-debug.sethook">debug.sethook</A><BR>
119<A HREF="manual.html#pdf-debug.setlocal">debug.setlocal</A><BR>
120<A HREF="manual.html#pdf-debug.setmetatable">debug.setmetatable</A><BR>
121<A HREF="manual.html#pdf-debug.setupvalue">debug.setupvalue</A><BR>
122<A HREF="manual.html#pdf-debug.traceback">debug.traceback</A><BR>
123<A HREF="manual.html#pdf-dofile">dofile</A><BR>
124<A HREF="manual.html#pdf-error">error</A><BR>
125<A HREF="manual.html#pdf-file:close">file:close</A><BR>
126<A HREF="manual.html#pdf-file:flush">file:flush</A><BR>
127<A HREF="manual.html#pdf-file:lines">file:lines</A><BR>
128<A HREF="manual.html#pdf-file:read">file:read</A><BR>
129<A HREF="manual.html#pdf-file:seek">file:seek</A><BR>
130<A HREF="manual.html#pdf-file:setvbuf">file:setvbuf</A><BR>
131<A HREF="manual.html#pdf-file:write">file:write</A><BR>
132<A HREF="manual.html#pdf-getfenv">getfenv</A><BR>
133<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
134<A HREF="manual.html#pdf-io.close">io.close</A><BR>
135<A HREF="manual.html#pdf-io.flush">io.flush</A><BR>
136<A HREF="manual.html#pdf-io.input">io.input</A><BR>
137<A HREF="manual.html#pdf-io.lines">io.lines</A><BR>
138<A HREF="manual.html#pdf-io.open">io.open</A><BR>
139<A HREF="manual.html#pdf-io.output">io.output</A><BR>
140<A HREF="manual.html#pdf-io.popen">io.popen</A><BR>
141<A HREF="manual.html#pdf-io.read">io.read</A><BR>
142<A HREF="manual.html#pdf-io.tmpfile">io.tmpfile</A><BR>
143<A HREF="manual.html#pdf-io.type">io.type</A><BR>
144<A HREF="manual.html#pdf-io.write">io.write</A><BR>
145<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
146<A HREF="manual.html#pdf-load">load</A><BR>
147<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
148<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
149
150<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
151<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
152<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>
153<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR>
154<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR>
155<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR>
156<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR>
157<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR>
158<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR>
159<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR>
160<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>
161<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>
162<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
163<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>
164<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>
165<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>
166<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>
167<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR>
168<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR>
169<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
170<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
171<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
172<A HREF="manual.html#luaL_error">luaL_error</A><BR>
173<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
174<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
175<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>
176<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
177<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
178<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
179<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
180<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
181<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
182<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
183<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>
184<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
185<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
186<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
187<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
188<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
189<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
190<A HREF="manual.html#luaL_register">luaL_register</A><BR>
191<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
192<A HREF="manual.html#luaL_typerror">luaL_typerror</A><BR>
193<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
194<A HREF="manual.html#luaL_where">luaL_where</A><BR>
195<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
196<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
197<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
198<A HREF="manual.html#lua_Hook">lua_Hook</A><BR>
199<A HREF="manual.html#lua_Integer">lua_Integer</A><BR>
200<A HREF="manual.html#lua_Number">lua_Number</A><BR>
201<A HREF="manual.html#lua_Reader">lua_Reader</A><BR>
202<A HREF="manual.html#lua_State">lua_State</A><BR>
203<A HREF="manual.html#lua_Writer">lua_Writer</A><BR>
204<A HREF="manual.html#lua_atpanic">lua_atpanic</A><BR>
205<A HREF="manual.html#lua_call">lua_call</A><BR>
206<A HREF="manual.html#lua_checkstack">lua_checkstack</A><BR>
207<A HREF="manual.html#lua_close">lua_close</A><BR>
208<A HREF="manual.html#lua_concat">lua_concat</A><BR>
209<A HREF="manual.html#lua_cpcall">lua_cpcall</A><BR>
210<A HREF="manual.html#lua_createtable">lua_createtable</A><BR>
211<A HREF="manual.html#lua_dump">lua_dump</A><BR>
212<A HREF="manual.html#lua_equal">lua_equal</A><BR>
213<A HREF="manual.html#lua_error">lua_error</A><BR>
214<A HREF="manual.html#lua_gc">lua_gc</A><BR>
215<A HREF="manual.html#lua_getallocf">lua_getallocf</A><BR>
216<A HREF="manual.html#lua_getfenv">lua_getfenv</A><BR>
217<A HREF="manual.html#lua_getfield">lua_getfield</A><BR>
218<A HREF="manual.html#lua_gethook">lua_gethook</A><BR>
219<A HREF="manual.html#lua_gethookcount">lua_gethookcount</A><BR>
220<A HREF="manual.html#lua_gethookmask">lua_gethookmask</A><BR>
221<A HREF="manual.html#lua_getinfo">lua_getinfo</A><BR>
222<A HREF="manual.html#lua_getlocal">lua_getlocal</A><BR>
223<A HREF="manual.html#lua_getmetatable">lua_getmetatable</A><BR>
224<A HREF="manual.html#lua_getstack">lua_getstack</A><BR>
225<A HREF="manual.html#lua_gettable">lua_gettable</A><BR>
226<A HREF="manual.html#lua_gettop">lua_gettop</A><BR>
227<A HREF="manual.html#lua_getupvalue">lua_getupvalue</A><BR>
228<A HREF="manual.html#lua_insert">lua_insert</A><BR>
229<A HREF="manual.html#lua_isboolean">lua_isboolean</A><BR>
230<A HREF="manual.html#lua_iscfunction">lua_iscfunction</A><BR>
231<A HREF="manual.html#lua_isfunction">lua_isfunction</A><BR>
232<A HREF="manual.html#lua_islightuserdata">lua_islightuserdata</A><BR>
233<A HREF="manual.html#lua_isnil">lua_isnil</A><BR>
234<A HREF="manual.html#lua_isnumber">lua_isnumber</A><BR>
235<A HREF="manual.html#lua_isstring">lua_isstring</A><BR>
236<A HREF="manual.html#lua_istable">lua_istable</A><BR>
237<A HREF="manual.html#lua_isthread">lua_isthread</A><BR>
238<A HREF="manual.html#lua_isuserdata">lua_isuserdata</A><BR>
239<A HREF="manual.html#lua_lessthan">lua_lessthan</A><BR>
240<A HREF="manual.html#lua_load">lua_load</A><BR>
241<A HREF="manual.html#lua_newstate">lua_newstate</A><BR>
242<A HREF="manual.html#lua_newtable">lua_newtable</A><BR>
243<A HREF="manual.html#lua_newthread">lua_newthread</A><BR>
244<A HREF="manual.html#lua_newuserdata">lua_newuserdata</A><BR>
245<A HREF="manual.html#lua_next">lua_next</A><BR>
246<A HREF="manual.html#lua_objlen">lua_objlen</A><BR>
247<A HREF="manual.html#lua_pcall">lua_pcall</A><BR>
248<A HREF="manual.html#lua_pop">lua_pop</A><BR>
249<A HREF="manual.html#lua_pushboolean">lua_pushboolean</A><BR>
250<A HREF="manual.html#lua_pushcclosure">lua_pushcclosure</A><BR>
251<A HREF="manual.html#lua_pushcfunction">lua_pushcfunction</A><BR>
252<A HREF="manual.html#lua_pushfstring">lua_pushfstring</A><BR>
253<A HREF="manual.html#lua_pushinteger">lua_pushinteger</A><BR>
254<A HREF="manual.html#lua_pushlightuserdata">lua_pushlightuserdata</A><BR>
255<A HREF="manual.html#lua_pushlstring">lua_pushlstring</A><BR>
256<A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR>
257<A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR>
258<A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR>
259<A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR>
260<A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR>
261<A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR>
262<A HREF="manual.html#lua_rawget">lua_rawget</A><BR>
263<A HREF="manual.html#lua_rawgeti">lua_rawgeti</A><BR>
264<A HREF="manual.html#lua_rawset">lua_rawset</A><BR>
265<A HREF="manual.html#lua_rawseti">lua_rawseti</A><BR>
266<A HREF="manual.html#lua_remove">lua_remove</A><BR>
267<A HREF="manual.html#lua_replace">lua_replace</A><BR>
268<A HREF="manual.html#lua_resume">lua_resume</A><BR>
269<A HREF="manual.html#lua_setallocf">lua_setallocf</A><BR>
270<A HREF="manual.html#lua_setfenv">lua_setfenv</A><BR>
271<A HREF="manual.html#lua_setfield">lua_setfield</A><BR>
272<A HREF="manual.html#lua_sethook">lua_sethook</A><BR>
273<A HREF="manual.html#lua_setlocal">lua_setlocal</A><BR>
274<A HREF="manual.html#lua_setmetatable">lua_setmetatable</A><BR>
275<A HREF="manual.html#lua_settable">lua_settable</A><BR>
276<A HREF="manual.html#lua_settop">lua_settop</A><BR>
277<A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>
278<A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>
279<A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>
280<A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>
281<A HREF="manual.html#lua_tolstring">lua_tolstring</A><BR>
282<A HREF="manual.html#lua_tonumber">lua_tonumber</A><BR>
283<A HREF="manual.html#lua_topointer">lua_topointer</A><BR>
284<A HREF="manual.html#lua_tostring">lua_tostring</A><BR>
285<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
286<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
287<A HREF="manual.html#lua_type">lua_type</A><BR>
288<A HREF="manual.html#lua_xmove">lua_xmove</A><BR>
289<A HREF="manual.html#lua_yield">lua_yield</A><BR>
290
291<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
292<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
293<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
294<A HREF="manual.html#pdf-math.atan">math.atan</A><BR>
295<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR>
296<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR>
297<A HREF="manual.html#pdf-math.cos">math.cos</A><BR>
298<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR>
299<A HREF="manual.html#pdf-math.def">math.def</A><BR>
300<A HREF="manual.html#pdf-math.exp">math.exp</A><BR>
301<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>
302<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>
303<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
304<A HREF="manual.html#pdf-math.log">math.log</A><BR>
305<A HREF="manual.html#pdf-math.log10">math.log10</A><BR>
306<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>
307<A HREF="manual.html#pdf-math.sin">math.sin</A><BR>
308<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR>
309<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>
310<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>
311<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
312<A HREF="manual.html#pdf-module">module</A><BR>
313<A HREF="manual.html#pdf-next">next</A><BR>
314<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
315<A HREF="manual.html#pdf-os.date">os.date</A><BR>
316<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
317<A HREF="manual.html#pdf-os.execute">os.execute</A><BR>
318<A HREF="manual.html#pdf-os.exit">os.exit</A><BR>
319<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR>
320<A HREF="manual.html#pdf-os.remove">os.remove</A><BR>
321<A HREF="manual.html#pdf-os.rename">os.rename</A><BR>
322<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR>
323<A HREF="manual.html#pdf-os.time">os.time</A><BR>
324<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>
325<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
326<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
327<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>
328<A HREF="manual.html#pdf-package.path">package.path</A><BR>
329<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
330<A HREF="manual.html#pdf-package.seeall">package.seeall</A><BR>
331<A HREF="manual.html#pdf-pairs">pairs</A><BR>
332<A HREF="manual.html#pdf-pcall">pcall</A><BR>
333<A HREF="manual.html#pdf-print">print</A><BR>
334<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
335<A HREF="manual.html#pdf-rawget">rawget</A><BR>
336<A HREF="manual.html#pdf-rawset">rawset</A><BR>
337<A HREF="manual.html#pdf-require">require</A><BR>
338<A HREF="manual.html#pdf-select">select</A><BR>
339<A HREF="manual.html#pdf-setfenv">setfenv</A><BR>
340<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>
341<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
342<A HREF="manual.html#pdf-string.char">string.char</A><BR>
343<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
344<A HREF="manual.html#pdf-string.find">string.find</A><BR>
345<A HREF="manual.html#pdf-string.format">string.format</A><BR>
346<A HREF="manual.html#pdf-string.gmatch">string.gmatch</A><BR>
347<A HREF="manual.html#pdf-string.gsub">string.gsub</A><BR>
348<A HREF="manual.html#pdf-string.len">string.len</A><BR>
349<A HREF="manual.html#pdf-string.lower">string.lower</A><BR>
350<A HREF="manual.html#pdf-string.match">string.match</A><BR>
351<A HREF="manual.html#pdf-string.rep">string.rep</A><BR>
352<A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR>
353<A HREF="manual.html#pdf-string.sub">string.sub</A><BR>
354<A HREF="manual.html#pdf-string.upper">string.upper</A><BR>
355<A HREF="manual.html#pdf-table.concat">table.concat</A><BR>
356<A HREF="manual.html#pdf-table.insert">table.insert</A><BR>
357<A HREF="manual.html#pdf-table.maxn(table)">table.maxn(table)</A><BR>
358<A HREF="manual.html#pdf-table.remove">table.remove</A><BR>
359<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
360<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
361<A HREF="manual.html#pdf-tostring">tostring</A><BR>
362<A HREF="manual.html#pdf-type">type</A><BR>
363<A HREF="manual.html#pdf-unpack">unpack</A><BR>
364<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
365<P>
366
96<HR>367<HR>
97<SMALL>368<SMALL>
98Last update:369Last update:
99Fri Sep 9 14:44:10 BRST 2005370Tue Nov 1 15:40:46 BRST 2005
100</SMALL>371</SMALL>
101 372
102</BODY>373</BODY>
doc/manual.html+678−607
@@ -1,16 +1,16 @@
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2<html>2<html>
3 3
4<head>4<head>
5<title>Lua 5.1 Reference Manual</title>5<title>Lua 5.1 Reference Manual</title>
6<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">6<link rel="stylesheet" href="lua.css">
7</head>7</head>
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
@@ -20,7 +20,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 3 unmodified lines
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; 2005 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>
@@ -28,7 +28,6 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line
28 28
29 29
30 30
31<p>
32<a name="1"></a><h1>1 - Introduction</h1>31<a name="1"></a><h1>1 - Introduction</h1>
33 32
34<p>Lua is an extension programming language designed to support33<p>Lua is an extension programming language designed to support
@@ -68,21 +67,21 @@ which are available at Lua's web site. · 33 unmodified lines
68<ul>67<ul>
69<li>68<li>
70R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.69R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
71Lua&mdash;an extensible extension language.70Lua---an extensible extension language.
72<em>Software: Practice &#038; Experience</em> <b>26</b>:6 (1996) 635&ndash;652.71<em>Software: Practice &#038; Experience</em> <b>26</b>:6 (1996) 635--652.
73<li>72<li>
74L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.73L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
75The design and implementation of a language for extending applications.74The design and implementation of a language for extending applications.
76<em>Proceedings of XXI Brazilian Seminar on Software and Hardware</em>75<em>Proceedings of XXI Brazilian Seminar on Software and Hardware</em>
77(1994) 273&ndash;283.76(1994) 273--283.
78<li>77<li>
79L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.78L. H. de Figueiredo, R. Ierusalimschy, and W. Celes.
80Lua: an extensible embedded language.79Lua: an extensible embedded language.
81<em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26&ndash;33.80<em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26--33.
82<li>81<li>
83R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.82R. Ierusalimschy, L. H. de Figueiredo, and W. Celes.
84The evolution of an extension language: a history of Lua,83The evolution of an extension language: a history of Lua,
85<em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14&ndash;B-28.84<em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14--B-28.
86</ul>85</ul>
87 86
88<p>Lua means "moon" in Portuguese and is pronounced LOO-ah.87<p>Lua means "moon" in Portuguese and is pronounced LOO-ah.
@@ -119,12 +118,12 @@ can be used in an identifier.) · 30 unmodified lines
119<p>The following <em>keywords</em> are reserved118<p>The following <em>keywords</em> are reserved
120and cannot be used as names:119and cannot be used as names:
121 120
122<PRE>121<pre>
123 and break do else elseif122 and break do else elseif
124 end false for function if123 end false for function if
125 in local nil not or124 in local nil not or
126 repeat return then true until while125 repeat return then true until while
127</PRE>126</pre>
128 127
129<p>Lua is a case-sensitive language:128<p>Lua is a case-sensitive language:
130<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>129<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>
@@ -134,27 +133,27 @@ uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>) · 3 unmodified lines
134are reserved for internal variables used by Lua.133are reserved for internal variables used by Lua.
135 134
136<p>The following strings denote other tokens:135<p>The following strings denote other tokens:
137<PRE>136<pre>
138 + - * / % ^ #137 + - * / % ^ #
139 == ~= &#060;= >= &#060; > =138 == ~= &#060;= >= &#060; > =
140 ( ) { } [ ]139 ( ) { } [ ]
141 ; : , . .. ...140 ; : , . .. ...
142</PRE>141</pre>
143 142
144<p><em>Literal strings</em>143<p><em>Literal strings</em>
145can be delimited by matching single or double quotes,144can be delimited by matching single or double quotes,
146and can contain the following C-like escape sequences:145and can contain the following C-like escape sequences:
147<ul>146<ul>
148<li><b><code>\a</code></b> &mdash; bell147<li><b><code>\a</code></b> --- bell
149<li><b><code>\b</code></b> &mdash; backspace148<li><b><code>\b</code></b> --- backspace
150<li><b><code>\f</code></b> &mdash; form feed149<li><b><code>\f</code></b> --- form feed
151<li><b><code>\n</code></b> &mdash; newline150<li><b><code>\n</code></b> --- newline
152<li><b><code>\r</code></b> &mdash; carriage return151<li><b><code>\r</code></b> --- carriage return
153<li><b><code>\t</code></b> &mdash; horizontal tab152<li><b><code>\t</code></b> --- horizontal tab
154<li><b><code>\v</code></b> &mdash; vertical tab153<li><b><code>\v</code></b> --- vertical tab
155<li><b><code>\\</code></b> &mdash; backslash154<li><b><code>\\</code></b> --- backslash
156<li><b><code>\"</code></b> &mdash; quotation mark155<li><b><code>\"</code></b> --- quotation mark
157<li><b><code>\'</code></b> &mdash; apostrophe156<li><b><code>\'</code></b> --- apostrophe
158</ul>157</ul>
159Moreover, a `<code>\</code><em>newline</em>&acute;158Moreover, a `<code>\</code><em>newline</em>&acute;
160(that is, a backslash followed by a real newline)159(that is, a backslash followed by a real newline)
@@ -188,7 +187,7 @@ As an example, in a system using ASCII · 27 unmodified lines
188(in which `<code>a</code>&acute; is coded as 97,187(in which `<code>a</code>&acute; is coded as 97,
189newline is coded as 10, and `<code>1</code>&acute; is coded as 49),188newline is coded as 10, and `<code>1</code>&acute; is coded as 49),
190the four literals below denote the same string:189the four literals below denote the same string:
191<PRE>190<pre>
192 (1) "alo\n123\""191 (1) "alo\n123\""
193 (2) '\97lo\10\04923"'192 (2) '\97lo\10\04923"'
194 (3) [[alo193 (3) [[alo
@@ -196,14 +195,14 @@ the four literals below denote the same string: · 1 unmodified line
196 (4) [==[195 (4) [==[
197 alo196 alo
198 123"]==]197 123"]==]
199</PRE>198</pre>
200 199
201<p><em>Numerical constants</em> may be written with an optional decimal part200<p><em>Numerical constants</em> may be written with an optional decimal part
202and an optional decimal exponent.201and an optional decimal exponent.
203Examples of valid numerical constants are202Examples of valid numerical constants are
204<PRE>203<pre>
205 3 3.0 3.1416 314.16e-2 0.31416E1204 3 3.0 3.1416 314.16e-2 0.31416E1
206</PRE>205</pre>
207 206
208<p><em>Comments</em> start anywhere outside a string with a207<p><em>Comments</em> start anywhere outside a string with a
209double hyphen (<code>--</code>).208double hyphen (<code>--</code>).
@@ -225,11 +224,11 @@ All values carry their own type. · 15 unmodified lines
225<em>nil</em>, <em>boolean</em>, <em>number</em>,224<em>nil</em>, <em>boolean</em>, <em>number</em>,
226<em>string</em>, <em>function</em>, <em>userdata</em>,225<em>string</em>, <em>function</em>, <em>userdata</em>,
227<em>thread</em>, and <em>table</em>.226<em>thread</em>, and <em>table</em>.
228<em>Nil</em> is the type of the value <B>nil</B>,227<em>Nil</em> is the type of the value <b>nil</b>,
229whose main property is to be different from any other value;228whose main property is to be different from any other value;
230usually it represents the absence of a useful value.229usually it represents the absence of a useful value.
231<em>Boolean</em> is the type of the values <B>false</B> and <B>true</B>.230<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
232In Lua, both <B>nil</B> and <B>false</B> make a condition false;231In Lua, both <b>nil</b> and <b>false</b> make a condition false;
233any other value makes it true.232any other value makes it true.
234<em>Number</em> represents real (double-precision floating-point) numbers.233<em>Number</em> represents real (double-precision floating-point) numbers.
235(It is easy to build Lua interpreters that use other234(It is easy to build Lua interpreters that use other
@@ -266,10 +265,10 @@ and it is used to implement coroutines (see <a href="#coroutine">2.11</a>). · 30 unmodified lines
266 265
267<p>The type <em>table</em> implements associative arrays,266<p>The type <em>table</em> implements associative arrays,
268that is, arrays that can be indexed not only with numbers,267that is, arrays that can be indexed not only with numbers,
269but with any value (except <B>nil</B>).268but with any value (except <b>nil</b>).
270Moreover,269Moreover,
271tables can be <em>heterogeneous</em>,270tables can be <em>heterogeneous</em>,
272that is, they can contain values of all types (except <B>nil</B>).271that is, they can contain values of all types (except <b>nil</b>).
273Tables are the sole data structuring mechanism in Lua;272Tables are the sole data structuring mechanism in Lua;
274they may be used to represent ordinary arrays,273they may be used to represent ordinary arrays,
275symbol tables, sets, records, graphs, trees, etc.274symbol tables, sets, records, graphs, trees, etc.
@@ -280,7 +279,7 @@ There are several convenient ways to create tables in Lua · 4 unmodified lines
280(see <a href="#tableconstructor">2.5.7</a>).279(see <a href="#tableconstructor">2.5.7</a>).
281 280
282<p>Like indices,281<p>Like indices,
283the value of a table field can be of any type (except <B>nil</B>).282the value of a table field can be of any type (except <b>nil</b>).
284In particular,283In particular,
285because functions are first class values,284because functions are first class values,
286table fields may contain functions.285table fields may contain functions.
@@ -327,7 +326,7 @@ Local variables are <em>lexically scoped</em>: · 40 unmodified lines
327Local variables can be freely accessed by functions326Local variables can be freely accessed by functions
328defined inside their scope (see <a href="#visibility">2.6</a>).327defined inside their scope (see <a href="#visibility">2.6</a>).
329 328
330<p>Before the first assignment to a variable, its value is <B>nil</B>.329<p>Before the first assignment to a variable, its value is <b>nil</b>.
331 330
332<p>Square brackets are used to index a table:331<p>Square brackets are used to index a table:
333<pre>332<pre>
@@ -370,9 +369,9 @@ through the debug library; (see <a href="#libdebug">5.9</a>).) · 36 unmodified lines
370<p>An access to a global variable <code>x</code>369<p>An access to a global variable <code>x</code>
371is equivalent to <code>_env.x</code>,370is equivalent to <code>_env.x</code>,
372which in turn is equivalent to371which in turn is equivalent to
373<PRE>372<pre>
374 gettable_event(_env, "x")373 gettable_event(_env, "x")
375</PRE>374</pre>
376where <code>_env</code> is the environment of the running function.375where <code>_env</code> is the environment of the running function.
377(See <a href="#metatable">2.8</a> for a complete description of the376(See <a href="#metatable">2.8</a> for a complete description of the
378<code>gettable_event</code> function.377<code>gettable_event</code> function.
@@ -454,7 +453,7 @@ the list of variables. · 75 unmodified lines
454If there are more values than needed,453If there are more values than needed,
455the excess values are thrown away.454the excess values are thrown away.
456If there are fewer values than needed,455If there are fewer values than needed,
457the list is extended with as many <B>nil</B>'s as needed.456the list is extended with as many <b>nil</b>'s as needed.
458If the list of expressions ends with a function call,457If the list of expressions ends with a function call,
459then all values returned by that function call enter in the list of values,458then all values returned by that function call enter in the list of values,
460before the adjustment459before the adjustment
@@ -463,17 +462,17 @@ before the adjustment · 2 unmodified lines
463<p>The assignment statement first evaluates all its expressions462<p>The assignment statement first evaluates all its expressions
464and only then are the assignments performed.463and only then are the assignments performed.
465Thus the code464Thus the code
466<PRE>465<pre>
467 i = 3466 i = 3
468 i, a[i] = i+1, 20467 i, a[i] = i+1, 20
469</PRE>468</pre>
470sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>469sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
471because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)470because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
472before it is assigned 4.471before it is assigned 4.
473Similarly, the line472Similarly, the line
474<PRE>473<pre>
475 x, y = y, x474 x, y = y, x
476</PRE>475</pre>
477exchanges the values of <code>x</code> and <code>y</code>.476exchanges the values of <code>x</code> and <code>y</code>.
478 477
479<p>The meaning of assignments to global variables478<p>The meaning of assignments to global variables
@@ -489,9 +488,9 @@ We use it here only for explanatory purposes.) · 9 unmodified lines
489is equivalent to the assignment488is equivalent to the assignment
490<code>_env.x = val</code>,489<code>_env.x = val</code>,
491which in turn is equivalent to490which in turn is equivalent to
492<PRE>491<pre>
493 settable_event(_env, "x", val)492 settable_event(_env, "x", val)
494</PRE>493</pre>
495where <code>_env</code> is the environment of the running function.494where <code>_env</code> is the environment of the running function.
496(The <code>_env</code> variable is not defined in Lua.495(The <code>_env</code> variable is not defined in Lua.
497We use it here only for explanatory purposes.)496We use it here only for explanatory purposes.)
@@ -512,11 +511,11 @@ Lua also has a <b>for</b> statement, in two flavors (see <a href="#for">2.4.5</a · 14 unmodified lines
512 511
513<p>The condition expression <em>exp</em> of a512<p>The condition expression <em>exp</em> of a
514control structure may return any value.513control structure may return any value.
515Both <B>false</B> and <B>nil</B> are considered false.514Both <b>false</b> and <b>nil</b> are considered false.
516All values different from <B>nil</B> and <B>false</B> are considered true515All values different from <b>nil</b> and <b>false</b> are considered true
517(in particular, the number 0 and the empty string are also true).516(in particular, the number 0 and the empty string are also true).
518 517
519<p>In the <b>repeat</b>&ndash;<b>until</b> loop,518<p>In the <b>repeat</b>--<b>until</b> loop,
520the inner block does not end at the <b>until</b> keyword,519the inner block does not end at the <b>until</b> keyword,
521but only after the condition.520but only after the condition.
522That means the condition can refer to local variables521That means the condition can refer to local variables
@@ -567,11 +566,11 @@ The <em>block</em> is repeated for <em>name</em> starting at the value of · 44 unmodified lines
567the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the566the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the
568third <em>exp</em>.567third <em>exp</em>.
569More precisely, a <b>for</b> statement like568More precisely, a <b>for</b> statement like
570<PRE>569<pre>
571 for var = e1, e2, e3 do block end570 for var = e1, e2, e3 do block end
572</PRE>571</pre>
573is equivalent to the code:572is equivalent to the code:
574<PRE>573<pre>
575 do574 do
576 local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)575 local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
577 if not (_var and _limit and _step) then error() end576 if not (_var and _limit and _step) then error() end
@@ -581,7 +580,7 @@ is equivalent to the code: · 3 unmodified lines
581 _var = _var + _step580 _var = _var + _step
582 end581 end
583 end582 end
584</PRE>583</pre>
585Note the following:584Note the following:
586<ul>585<ul>
587<li> All three control expressions are evaluated only once,586<li> All three control expressions are evaluated only once,
@@ -601,17 +600,17 @@ then assign it to another variable before breaking or exiting the loop. · 13 unmodified lines
601<p>The generic <b>for</b> statement works over functions,600<p>The generic <b>for</b> statement works over functions,
602called <em>iterators</em>.601called <em>iterators</em>.
603For each iteration, it calls its iterator function to produce a new value,602For each iteration, it calls its iterator function to produce a new value,
604stopping when the new value is <B>nil</B>.603stopping when the new value is <b>nil</b>.
605The generic <b>for</b> loop has the following syntax:604The generic <b>for</b> loop has the following syntax:
606<pre>605<pre>
607 stat ::= <b>for</b> Name {`<b>,</b>&acute; Name} <b>in</b> explist1 <b>do</b> block <b>end</b>606 stat ::= <b>for</b> Name {`<b>,</b>&acute; Name} <b>in</b> explist1 <b>do</b> block <b>end</b>
608</pre>607</pre>
609A <b>for</b> statement like608A <b>for</b> statement like
610<PRE>609<pre>
611 for var_1, ..., var_n in explist do block end610 for var_1, ..., var_n in explist do block end
612</PRE>611</pre>
613is equivalent to the code:612is equivalent to the code:
614<PRE>613<pre>
615 do614 do
616 local _f, _s, _var = explist615 local _f, _s, _var = explist
617 while true do616 while true do
@@ -621,7 +620,7 @@ is equivalent to the code: · 3 unmodified lines
621 block620 block
622 end621 end
623 end622 end
624</PRE>623</pre>
625Note the following:624Note the following:
626<ul>625<ul>
627<li> <code>explist</code> is evaluated only once.626<li> <code>explist</code> is evaluated only once.
@@ -654,7 +653,7 @@ The declaration may include an initial assignment: · 26 unmodified lines
654</pre>653</pre>
655If present, an initial assignment has the same semantics654If present, an initial assignment has the same semantics
656of a multiple assignment (see <a href="#assignment">2.4.3</a>).655of a multiple assignment (see <a href="#assignment">2.4.3</a>).
657Otherwise, all variables are initialized with <B>nil</B>.656Otherwise, all variables are initialized with <b>nil</b>.
658 657
659<p>A chunk is also a block (see <a href="#chunks">2.4.1</a>),658<p>A chunk is also a block (see <a href="#chunks">2.4.1</a>),
660so local variables can be declared in a chunk outside any explicit block.659so local variables can be declared in a chunk outside any explicit block.
@@ -668,7 +667,7 @@ The scope of such local variables extends until the end of the chunk. · 7 unmodified lines
668The basic expressions in Lua are the following:667The basic expressions in Lua are the following:
669<pre>668<pre>
670 exp ::= prefixexp669 exp ::= prefixexp
671 exp ::= <b>nil</b> | <b>false</b> | <b>true</b>670 exp ::= <b>nil</b> | <b>false</b> | <b>true</b>
672 exp ::= Number671 exp ::= Number
673 exp ::= Literal672 exp ::= Literal
674 exp ::= function673 exp ::= function
@@ -676,7 +675,7 @@ The basic expressions in Lua are the following: · 1 unmodified line
676 exp ::= `<b>...</b>&acute;675 exp ::= `<b>...</b>&acute;
677 exp ::= exp binop exp676 exp ::= exp binop exp
678 exp ::= unop exp677 exp ::= unop exp
679 prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;678 prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
680</pre>679</pre>
681 680
682<p>Numbers and literal strings are explained in <a href="#lexical">2.1</a>;681<p>Numbers and literal strings are explained in <a href="#lexical">2.1</a>;
@@ -710,7 +709,7 @@ then no adjustment is made, · 27 unmodified lines
710unless the call is enclosed in parentheses.709unless the call is enclosed in parentheses.
711 710
712<p>Here are some examples:711<p>Here are some examples:
713<PRE>712<pre>
714 f() -- adjusted to 0 results713 f() -- adjusted to 0 results
715 g(f(), x) -- f() is adjusted to 1 result714 g(f(), x) -- f() is adjusted to 1 result
716 g(x, f()) -- g gets x plus all values returned by f()715 g(x, f()) -- g gets x plus all values returned by f()
@@ -726,14 +725,14 @@ unless the call is enclosed in parentheses. · 9 unmodified lines
726 {f()} -- creates a list with all values returned by f()725 {f()} -- creates a list with all values returned by f()
727 {...} -- creates a list with all vararg parameters726 {...} -- creates a list with all vararg parameters
728 {f(), nil} -- f() is adjusted to 1 result727 {f(), nil} -- f() is adjusted to 1 result
729</PRE>728</pre>
730 729
731<p>An expression enclosed in parentheses always results in only one value.730<p>An expression enclosed in parentheses always results in only one value.
732Thus,731Thus,
733<code>(f(x,y,z))</code> is always a single value,732<code>(f(x,y,z))</code> is always a single value,
734even if <code>f</code> returns several values.733even if <code>f</code> returns several values.
735(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>734(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>
736or <B>nil</B> if <code>f</code> does not return any values.)735or <b>nil</b> if <code>f</code> does not return any values.)
737 736
738<p><a name="arith"></a><a name="2.5.1"></a><h3>2.5.1 - Arithmetic Operators</h3>737<p><a name="arith"></a><a name="2.5.1"></a><h3>2.5.1 - Arithmetic Operators</h3>
739Lua supports the usual arithmetic operators:738Lua supports the usual arithmetic operators:
@@ -747,21 +746,21 @@ then all operations have the usual meaning. · 7 unmodified lines
747Exponentiation works for any exponent.746Exponentiation works for any exponent.
748For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>.747For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>.
749Modulus is defined as748Modulus is defined as
750<PRE>749<pre>
751 a % b == a - math.floor(a/b)*b750 a % b == a - math.floor(a/b)*b
752</PRE>751</pre>
753That is, it is the remaining of a division that rounds752That is, it is the remaining of a division that rounds
754the quotient towards minus infinity.753the quotient towards minus infinity.
755 754
756<p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3>755<p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3>
757The relational operators in Lua are756The relational operators in Lua are
758<PRE>757<pre>
759 == ~= &#060; > &#060;= >=758 == ~= &#060; > &#060;= >=
760</PRE>759</pre>
761These operators always result in <B>false</B> or <B>true</B>.760These operators always result in <b>false</b> or <b>true</b>.
762 761
763<p>Equality (<code>==</code>) first compares the type of its operands.762<p>Equality (<code>==</code>) first compares the type of its operands.
764If the types are different, then the result is <B>false</B>.763If the types are different, then the result is <b>false</b>.
765Otherwise, the values of the operands are compared.764Otherwise, the values of the operands are compared.
766Numbers and strings are compared in the usual way.765Numbers and strings are compared in the usual way.
767Objects (tables, userdata, threads, and functions)766Objects (tables, userdata, threads, and functions)
@@ -775,7 +774,7 @@ using the "eq" metamethod (see <a href="#metatable">2.8</a>). · 7 unmodified lines
775 774
776<p>The conversion rules of <a href="#coercion">2.2.1</a>775<p>The conversion rules of <a href="#coercion">2.2.1</a>
777<em>do not</em> apply to equality comparisons.776<em>do not</em> apply to equality comparisons.
778Thus, <code>"0"==0</code> evaluates to <B>false</B>,777Thus, <code>"0"==0</code> evaluates to <b>false</b>,
779and <code>t[0]</code> and <code>t["0"]</code> denote different778and <code>t[0]</code> and <code>t["0"]</code> denote different
780entries in a table.779entries in a table.
781 780
@@ -792,27 +791,27 @@ metamethod (see <a href="#metatable">2.8</a>). · 10 unmodified lines
792<p><a name="logic"></a><a name="2.5.3"></a><h3>2.5.3 - Logical Operators</h3>791<p><a name="logic"></a><a name="2.5.3"></a><h3>2.5.3 - Logical Operators</h3>
793The logical operators in Lua are792The logical operators in Lua are
794 793
795<PRE>794<pre>
796 and or not795 and or not
797</PRE>796</pre>
798Like the control structures (see <a href="#control">2.4.4</a>),797Like the control structures (see <a href="#control">2.4.4</a>),
799all logical operators consider both <B>false</B> and <B>nil</B> as false798all logical operators consider both <b>false</b> and <b>nil</b> as false
800and anything else as true.799and anything else as true.
801 800
802 801
803<p>The operator <b>not</b> always returns <B>false</B> or <B>true</B>.802<p>The operator <b>not</b> always returns <b>false</b> or <b>true</b>.
804 803
805<p>The conjunction operator <b>and</b> returns its first argument804<p>The conjunction operator <b>and</b> returns its first argument
806if this value is <B>false</B> or <B>nil</B>;805if this value is <b>false</b> or <b>nil</b>;
807otherwise, <b>and</b> returns its second argument.806otherwise, <b>and</b> returns its second argument.
808The disjunction operator <b>or</b> returns its first argument807The disjunction operator <b>or</b> returns its first argument
809if this value is different from <B>nil</B> and <B>false</B>;808if this value is different from <b>nil</b> and <b>false</b>;
810otherwise, <b>or</b> returns its second argument.809otherwise, <b>or</b> returns its second argument.
811Both <b>and</b> and <b>or</b> use short-cut evaluation,810Both <b>and</b> and <b>or</b> use short-cut evaluation,
812that is,811that is,
813the second operand is evaluated only if necessary.812the second operand is evaluated only if necessary.
814For example,813For example,
815<PRE>814<pre>
816 10 or error() -> 10815 10 or error() -> 10
817 nil or "a" -> "a"816 nil or "a" -> "a"
818 nil and 10 -> nil817 nil and 10 -> nil
@@ -820,7 +819,7 @@ For example, · 1 unmodified line
820 false and nil -> false819 false and nil -> false
821 false or nil -> nil820 false or nil -> nil
822 10 and 20 -> 20821 10 and 20 -> 20
823</PRE>822</pre>
824 823
825<p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3>824<p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3>
826The string concatenation operator in Lua is825The string concatenation operator in Lua is
@@ -837,22 +836,22 @@ The length of a string is its number of bytes · 10 unmodified lines
837character is one byte).836character is one byte).
838The length of a table <code>t</code> is defined to be any837The length of a table <code>t</code> is defined to be any
839integer index <code>n</code>838integer index <code>n</code>
840such that <code>t[n]</code> is not <B>nil</B> and <code>t[n+1]</code> is <B>nil</B>;839such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;
841moreover, if <code>t[1]</code> is <B>nil</B>, <code>n</code> may be zero.840moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> may be zero.
842 841
843<p>For 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>,
844its length is exactly that <code>n</code>,843its length is exactly that <code>n</code>,
845the index of its last value.844the index of its last value.
846If the array has "holes"845If the array has "holes"
847(that is, <B>nil</B> values between other non-nil values),846(that is, <b>nil</b> values between other non-nil values),
848then <code>#t</code> may be any of the indices that precede a <B>nil</B> value847then <code>#t</code> may be any of the indices that precede a <b>nil</b> value
849(that is, it may consider any such <B>nil</B> value as the end of848(that is, it may consider any such <b>nil</b> value as the end of
850the array). 849the array).
851 850
852<p><a name="2.5.6"></a><h3>2.5.6 - Precedence</h3>851<p><a name="2.5.6"></a><h3>2.5.6 - Precedence</h3>
853Operator precedence in Lua follows the table below,852Operator precedence in Lua follows the table below,
854from lower to higher priority:853from lower to higher priority:
855<PRE>854<pre>
856 or855 or
857 and856 and
858 &#060; > &#060;= >= ~= ==857 &#060; > &#060;= >= ~= ==
@@ -861,7 +860,7 @@ from lower to higher priority: · 2 unmodified lines
861 * / %860 * / %
862 not # - (unary)861 not # - (unary)
863 ^862 ^
864</PRE>863</pre>
865You can use parentheses to change the precedences of an expression.864You can use parentheses to change the precedences of an expression.
866The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)865The concatenation (`<code>..</code>&acute;) and exponentiation (`<code>^</code>&acute;)
867operators are right associative.866operators are right associative.
@@ -876,8 +875,8 @@ The general syntax for constructors is · 8 unmodified lines
876<pre>875<pre>
877 tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;876 tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;
878 fieldlist ::= field {fieldsep field} [fieldsep]877 fieldlist ::= field {fieldsep field} [fieldsep]
879 field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp878 field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp
880 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;879 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
881</pre>880</pre>
882 881
883<p>Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry882<p>Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry
@@ -889,11 +888,11 @@ Finally, fields of the form <code>exp</code> are equivalent to · 5 unmodified lines
889starting with 1.888starting with 1.
890Fields in the other formats do not affect this counting.889Fields in the other formats do not affect this counting.
891For example,890For example,
892<PRE>891<pre>
893 a = {[f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45}892 a = {[f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45}
894</PRE>893</pre>
895is equivalent to894is equivalent to
896<PRE>895<pre>
897 do896 do
898 local temp = {}897 local temp = {}
899 temp[f(1)] = g898 temp[f(1)] = g
@@ -905,7 +904,7 @@ is equivalent to · 5 unmodified lines
905 temp[4] = 45 -- 4th exp904 temp[4] = 45 -- 4th exp
906 a = temp905 a = temp
907 end906 end
908</PRE>907</pre>
909 908
910<p>If the last field in the list has the form <code>exp</code>909<p>If the last field in the list has the form <code>exp</code>
911and the expression is a function call or a vararg expression,910and the expression is a function call or a vararg expression,
@@ -961,10 +960,10 @@ the argument list is a single literal string. · 49 unmodified lines
961you cannot put a line break before the `<code>(</code>&acute; in a function call.960you cannot put a line break before the `<code>(</code>&acute; in a function call.
962That restriction avoids some ambiguities in the language.961That restriction avoids some ambiguities in the language.
963If you write962If you write
964<PRE>963<pre>
965 a = f964 a = f
966 (g).x(a)965 (g).x(a)
967</PRE>966</pre>
968Lua would read that as <code>a = f(g).x(a)</code>.967Lua would read that as <code>a = f(g).x(a)</code>.
969So, if you want two statements, you must add a semi-colon between them.968So, if you want two statements, you must add a semi-colon between them.
970If you actually want to call <code>f</code>,969If you actually want to call <code>f</code>,
@@ -985,13 +984,13 @@ where the <b>return</b> has one single function call as argument; · 14 unmodified lines
985this syntax makes the calling function returns exactly984this syntax makes the calling function returns exactly
986the returns of the called function.985the returns of the called function.
987So, all the following examples are not tail calls:986So, all the following examples are not tail calls:
988<PRE>987<pre>
989 return (f(x)) -- results adjusted to 1988 return (f(x)) -- results adjusted to 1
990 return 2 * f(x)989 return 2 * f(x)
991 return x, f(x) -- additional results990 return x, f(x) -- additional results
992 f(x); return -- results discarded991 f(x); return -- results discarded
993 return x or f(x) -- results adjusted to 1992 return x or f(x) -- results adjusted to 1
994</PRE>993</pre>
995 994
996<p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3>995<p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3>
997 996
@@ -1008,29 +1007,29 @@ So, all the following examples are not tail calls: · 10 unmodified lines
1008 funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]1007 funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]
1009</pre>1008</pre>
1010The statement1009The statement
1011<PRE>1010<pre>
1012 function f () ... end1011 function f () ... end
1013</PRE>1012</pre>
1014translates to1013translates to
1015<PRE>1014<pre>
1016 f = function () ... end1015 f = function () ... end
1017</PRE>1016</pre>
1018The statement1017The statement
1019<PRE>1018<pre>
1020 function t.a.b.c.f () ... end1019 function t.a.b.c.f () ... end
1021</PRE>1020</pre>
1022translates to1021translates to
1023<PRE>1022<pre>
1024 t.a.b.c.f = function () ... end1023 t.a.b.c.f = function () ... end
1025</PRE>1024</pre>
1026The statement1025The statement
1027<PRE>1026<pre>
1028 local function f () ... end1027 local function f () ... end
1029</PRE>1028</pre>
1030translates to1029translates to
1031<PRE>1030<pre>
1032 local f; f = function () ... end1031 local f; f = function () ... end
1033</PRE>1032</pre>
1034 1033
1035<p>A function definition is an executable expression,1034<p>A function definition is an executable expression,
1036whose value has type <em>function</em>.1035whose value has type <em>function</em>.
@@ -1047,7 +1046,7 @@ and may have different environment tables. · 10 unmodified lines
1047<p>Parameters act as local variables that are1046<p>Parameters act as local variables that are
1048initialized with the argument values:1047initialized with the argument values:
1049<pre>1048<pre>
1050 parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;1049 parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;
1051</pre>1050</pre>
1052When a function is called,1051When a function is called,
1053the list of arguments is adjusted to1052the list of arguments is adjusted to
@@ -1069,14 +1068,14 @@ then no adjustment is made · 15 unmodified lines
1069(unless the call is enclosed in parentheses).1068(unless the call is enclosed in parentheses).
1070 1069
1071<p>As an example, consider the following definitions:1070<p>As an example, consider the following definitions:
1072<PRE>1071<pre>
1073 function f(a, b) end1072 function f(a, b) end
1074 function g(a, b, ...) end1073 function g(a, b, ...) end
1075 function r() return 1,2,3 end1074 function r() return 1,2,3 end
1076</PRE>1075</pre>
1077Then, we have the following mapping from arguments to parameters and1076Then, we have the following mapping from arguments to parameters and
1078to the vararg expression:1077to the vararg expression:
1079<PRE>1078<pre>
1080 CALL PARAMETERS1079 CALL PARAMETERS
1081 1080
1082 f(3) a=3, b=nil1081 f(3) a=3, b=nil
@@ -1089,7 +1088,7 @@ to the vararg expression: · 6 unmodified lines
1089 g(3, 4) a=3, b=4, ... -> (nothing)1088 g(3, 4) a=3, b=4, ... -> (nothing)
1090 g(3, 4, 5, 8) a=3, b=4, ... -> 5 81089 g(3, 4, 5, 8) a=3, b=4, ... -> 5 8
1091 g(5, r()) a=5, b=1, ... -> 2 31090 g(5, r()) a=5, b=1, ... -> 2 3
1092</PRE>1091</pre>
1093 1092
1094<p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>).1093<p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>).
1095If control reaches the end of a function1094If control reaches the end of a function
@@ -1100,13 +1099,13 @@ then the function returns with no results. · 4 unmodified lines
1100is used for defining <em>methods</em>,1099is used for defining <em>methods</em>,
1101that is, functions that have an implicit extra parameter <code>self</code>.1100that is, functions that have an implicit extra parameter <code>self</code>.
1102Thus, the statement1101Thus, the statement
1103<PRE>1102<pre>
1104 function t.a.b.c:f (...) ... end1103 function t.a.b.c:f (...) ... end
1105</PRE>1104</pre>
1106is syntactic sugar for1105is syntactic sugar for
1107<PRE>1106<pre>
1108 t.a.b.c.f = function (self, ...) ... end1107 t.a.b.c.f = function (self, ...) ... end
1109</PRE>1108</pre>
1110 1109
1111<p><a name="visibility"></a><a name="2.6"></a><h2>2.6 - Visibility Rules</h2>1110<p><a name="visibility"></a><a name="2.6"></a><h2>2.6 - Visibility Rules</h2>
1112 1111
@@ -1116,7 +1115,7 @@ The scope of variables begins at the first statement <em>after</em> · 3 unmodified lines
1116their declaration and lasts until the end of the innermost block that1115their declaration and lasts until the end of the innermost block that
1117includes the declaration.1116includes the declaration.
1118For instance:1117For instance:
1119<PRE>1118<pre>
1120 x = 10 -- global variable1119 x = 10 -- global variable
1121 do -- new block1120 do -- new block
1122 local x = x -- new `x', with value 101121 local x = x -- new `x', with value 10
@@ -1129,7 +1128,7 @@ For instance: · 6 unmodified lines
1129 print(x) --> 111128 print(x) --> 11
1130 end1129 end
1131 print(x) --> 10 (the global one)1130 print(x) --> 10 (the global one)
1132</PRE>1131</pre>
1133Notice that, in a declaration like <code>local x = x</code>,1132Notice that, in a declaration like <code>local x = x</code>,
1134the new <code>x</code> being declared is not in scope yet,1133the new <code>x</code> being declared is not in scope yet,
1135and so the second <code>x</code> refers to the outside variable.1134and so the second <code>x</code> refers to the outside variable.
@@ -1138,13 +1137,13 @@ and so the second <code>x</code> refers to the outside variable. · 2 unmodified lines
1138local variables can be freely accessed by functions1137local variables can be freely accessed by functions
1139defined inside their scope.1138defined inside their scope.
1140For instance:1139For instance:
1141<PRE>1140<pre>
1142 local counter = 01141 local counter = 0
1143 function inc (x)1142 function inc (x)
1144 counter = counter + x1143 counter = counter + x
1145 return counter1144 return counter
1146 end1145 end
1147</PRE>1146</pre>
1148A local variable used by an inner function is called1147A local variable used by an inner function is called
1149an <em>upvalue</em>, or <em>external local variable</em>,1148an <em>upvalue</em>, or <em>external local variable</em>,
1150inside the inner function.1149inside the inner function.
@@ -1152,14 +1151,14 @@ inside the inner function. · 1 unmodified line
1152<p>Notice that each execution of a <b>local</b> statement1151<p>Notice that each execution of a <b>local</b> statement
1153defines new local variables.1152defines new local variables.
1154Consider the following example:1153Consider the following example:
1155<PRE>1154<pre>
1156 a = {}1155 a = {}
1157 local x = 201156 local x = 20
1158 for i=1,10 do1157 for i=1,10 do
1159 local y = 01158 local y = 0
1160 a[i] = function () y=y+1; return x+y end1159 a[i] = function () y=y+1; return x+y end
1161 end1160 end
1162</PRE>1161</pre>
1163The loop creates ten closures1162The loop creates ten closures
1164(that is, ten instances of the anonymous function).1163(that is, ten instances of the anonymous function).
1165Each of these closures uses a different <code>y</code> variable,1164Each of these closures uses a different <code>y</code> variable,
@@ -1243,16 +1242,16 @@ All functions used in these descriptions · 77 unmodified lines
1243are described in <a href="#predefined">5.1</a>.1242are described in <a href="#predefined">5.1</a>.
1244In particular, to retrieve the metamethod of a given object,1243In particular, to retrieve the metamethod of a given object,
1245we use the expression1244we use the expression
1246<PRE>1245<pre>
1247 metatable(obj)[event]1246 metatable(obj)[event]
1248</PRE>1247</pre>
1249This should be read as1248This should be read as
1250<PRE>1249<pre>
1251 rawget(metatable(obj) or {}, event)1250 rawget(metatable(obj) or {}, event)
1252</PRE>1251</pre>
1253That is, the access to a metamethod does not invoke other metamethods,1252That is, the access to a metamethod does not invoke other metamethods,
1254and the access to objects with no metatables does not fail1253and the access to objects with no metatables does not fail
1255(it simply results in <B>nil</B>).1254(it simply results in <b>nil</b>).
1256 1255
1257<p><ul>1256<p><ul>
1258<li><b>"add":</b>1257<li><b>"add":</b>
@@ -1263,14 +1262,14 @@ for a binary operation. · 4 unmodified lines
1263First, Lua tries the first operand.1262First, Lua tries the first operand.
1264If its type does not define a handler for the operation,1263If its type does not define a handler for the operation,
1265then Lua tries the second operand.1264then Lua tries the second operand.
1266<PRE>1265<pre>
1267 function getbinhandler (op1, op2, event)1266 function getbinhandler (op1, op2, event)
1268 return metatable(op1)[event] or metatable(op2)[event]1267 return metatable(op1)[event] or metatable(op2)[event]
1269 end1268 end
1270</PRE>1269</pre>
1271Using that function,1270Using that function,
1272the behavior of the <code>op1 + op2</code> is1271the behavior of the <code>op1 + op2</code> is
1273<PRE>1272<pre>
1274 function add_event (op1, op2)1273 function add_event (op1, op2)
1275 local o1, o2 = tonumber(op1), tonumber(op2)1274 local o1, o2 = tonumber(op1), tonumber(op2)
1276 if o1 and o2 then -- both operands are numeric?1275 if o1 and o2 then -- both operands are numeric?
@@ -1285,7 +1284,7 @@ the behavior of the <code>op1 + op2</code> is · 8 unmodified lines
1285 end1284 end
1286 end1285 end
1287 end1286 end
1288</PRE>1287</pre>
1289 1288
1290<p><li><b>"sub":</b>1289<p><li><b>"sub":</b>
1291the <code>-</code> operation.1290the <code>-</code> operation.
@@ -1313,7 +1312,7 @@ as the primitive operation. · 21 unmodified lines
1313 1312
1314<p><li><b>"unm":</b>1313<p><li><b>"unm":</b>
1315the unary <code>-</code> operation.1314the unary <code>-</code> operation.
1316<PRE>1315<pre>
1317 function unm_event (op)1316 function unm_event (op)
1318 local o = tonumber(op)1317 local o = tonumber(op)
1319 if o then -- operand is numeric?1318 if o then -- operand is numeric?
@@ -1329,11 +1328,11 @@ the unary <code>-</code> operation. · 9 unmodified lines
1329 end1328 end
1330 end1329 end
1331 end1330 end
1332</PRE>1331</pre>
1333 1332
1334<p><li><b>"concat":</b>1333<p><li><b>"concat":</b>
1335the <code>..</code> (concatenation) operation.1334the <code>..</code> (concatenation) operation.
1336<PRE>1335<pre>
1337 function concat_event (op1, op2)1336 function concat_event (op1, op2)
1338 if (type(op1) == "string" or type(op1) == "number") and1337 if (type(op1) == "string" or type(op1) == "number") and
1339 (type(op2) == "string" or type(op2) == "number") then1338 (type(op2) == "string" or type(op2) == "number") then
@@ -1347,11 +1346,11 @@ the <code>..</code> (concatenation) operation. · 7 unmodified lines
1347 end1346 end
1348 end1347 end
1349 end1348 end
1350</PRE>1349</pre>
1351 1350
1352<p><li><b>"len":</b>1351<p><li><b>"len":</b>
1353the <code>#</code> operation.1352the <code>#</code> operation.
1354<PRE>1353<pre>
1355 function len_event (op)1354 function len_event (op)
1356 if type(op) == "string" then1355 if type(op) == "string" then
1357 return strlen(op) -- primitive string length1356 return strlen(op) -- primitive string length
@@ -1367,7 +1366,7 @@ the <code>#</code> operation. · 9 unmodified lines
1367 end1366 end
1368 end1367 end
1369 end1368 end
1370</PRE>1369</pre>
1371See <a href="#len-op">2.5.5</a> for a description of the length of a table.1370See <a href="#len-op">2.5.5</a> for a description of the length of a table.
1372 1371
1373<p><li><b>"eq":</b>1372<p><li><b>"eq":</b>
@@ -1377,16 +1376,16 @@ for comparison operators. · 3 unmodified lines
1377A metamethod only is selected when both objects1376A metamethod only is selected when both objects
1378being compared have the same type1377being compared have the same type
1379and the same metamethod for the selected operation.1378and the same metamethod for the selected operation.
1380<PRE>1379<pre>
1381 function getcomphandler (op1, op2, event)1380 function getcomphandler (op1, op2, event)
1382 if type(op1) ~= type(op2) then return nil end1381 if type(op1) ~= type(op2) then return nil end
1383 local mm1 = metatable(op1)[event]1382 local mm1 = metatable(op1)[event]
1384 local mm2 = metatable(op2)[event]1383 local mm2 = metatable(op2)[event]
1385 if mm1 == mm2 then return mm1 else return nil end1384 if mm1 == mm2 then return mm1 else return nil end
1386 end1385 end
1387</PRE>1386</pre>
1388The "eq" event is defined as follows:1387The "eq" event is defined as follows:
1389<PRE>1388<pre>
1390 function eq_event (op1, op2)1389 function eq_event (op1, op2)
1391 if type(op1) ~= type(op2) then -- different types?1390 if type(op1) ~= type(op2) then -- different types?
1392 return false -- different objects1391 return false -- different objects
@@ -1402,12 +1401,12 @@ The "eq" event is defined as follows: · 9 unmodified lines
1402 return false1401 return false
1403 end1402 end
1404 end1403 end
1405</PRE>1404</pre>
1406<code>a ~= b</code> is equivalent to <code>not (a == b)</code>.1405<code>a ~= b</code> is equivalent to <code>not (a == b)</code>.
1407 1406
1408<p><li><b>"lt":</b>1407<p><li><b>"lt":</b>
1409the <code>&#060;</code> operation.1408the <code>&#060;</code> operation.
1410<PRE>1409<pre>
1411 function lt_event (op1, op2)1410 function lt_event (op1, op2)
1412 if type(op1) == "number" and type(op2) == "number" then1411 if type(op1) == "number" and type(op2) == "number" then
1413 return op1 &#060; op2 -- numeric comparison1412 return op1 &#060; op2 -- numeric comparison
@@ -1422,12 +1421,12 @@ the <code>&#060;</code> operation. · 8 unmodified lines
1422 end1421 end
1423 end1422 end
1424 end1423 end
1425</PRE>1424</pre>
1426<code>a > b</code> is equivalent to <code>b &#060; a</code>.1425<code>a > b</code> is equivalent to <code>b &#060; a</code>.
1427 1426
1428<p><li><b>"le":</b>1427<p><li><b>"le":</b>
1429the <code>&#060;=</code> operation.1428the <code>&#060;=</code> operation.
1430<PRE>1429<pre>
1431 function le_event (op1, op2)1430 function le_event (op1, op2)
1432 if type(op1) == "number" and type(op2) == "number" then1431 if type(op1) == "number" and type(op2) == "number" then
1433 return op1 &#060;= op2 -- numeric comparison1432 return op1 &#060;= op2 -- numeric comparison
@@ -1447,7 +1446,7 @@ the <code>&#060;=</code> operation. · 13 unmodified lines
1447 end1446 end
1448 end1447 end
1449 end1448 end
1450</PRE>1449</pre>
1451<code>a >= b</code> is equivalent to <code>b &#060;= a</code>.1450<code>a >= b</code> is equivalent to <code>b &#060;= a</code>.
1452Note that, in the absence of a "le" metamethod,1451Note that, in the absence of a "le" metamethod,
1453Lua tries the "lt", assuming that <code>a &#060;= b</code> is1452Lua tries the "lt", assuming that <code>a &#060;= b</code> is
@@ -1455,7 +1454,7 @@ equivalent to <code>not (b &#060; a)</code>. · 1 unmodified line
1455 1454
1456<p><li><b>"index":</b>1455<p><li><b>"index":</b>
1457The indexing access <code>table[key]</code>.1456The indexing access <code>table[key]</code>.
1458<PRE>1457<pre>
1459 function gettable_event (table, key)1458 function gettable_event (table, key)
1460 local h1459 local h
1461 if type(table) == "table" then1460 if type(table) == "table" then
@@ -1474,11 +1473,11 @@ The indexing access <code>table[key]</code>. · 12 unmodified lines
1474 else return h[key] -- or repeat operation on it1473 else return h[key] -- or repeat operation on it
1475 end1474 end
1476 end1475 end
1477</PRE>1476</pre>
1478 1477
1479<p><li><b>"newindex":</b>1478<p><li><b>"newindex":</b>
1480The indexing assignment <code>table[key] = value</code>.1479The indexing assignment <code>table[key] = value</code>.
1481<PRE>1480<pre>
1482 function settable_event (table, key, value)1481 function settable_event (table, key, value)
1483 local h1482 local h
1484 if type(table) == "table" then1483 if type(table) == "table" then
@@ -1497,11 +1496,11 @@ The indexing assignment <code>table[key] = value</code>. · 12 unmodified lines
1497 else h[key] = value -- or repeat operation on it1496 else h[key] = value -- or repeat operation on it
1498 end1497 end
1499 end1498 end
1500</PRE>1499</pre>
1501 1500
1502<p><li><b>"call":</b>1501<p><li><b>"call":</b>
1503called when Lua calls a value.1502called when Lua calls a value.
1504<PRE>1503<pre>
1505 function function_event (func, ...)1504 function function_event (func, ...)
1506 if type(func) == "function" then1505 if type(func) == "function" then
1507 return func(unpack(arg)) -- primitive call1506 return func(unpack(arg)) -- primitive call
@@ -1514,7 +1513,7 @@ called when Lua calls a value. · 6 unmodified lines
1514 end1513 end
1515 end1514 end
1516 end1515 end
1517</PRE>1516</pre>
1518 1517
1519<p></ul>1518<p></ul>
1520 1519
@@ -1612,14 +1611,14 @@ Instead, Lua puts them in a list. · 91 unmodified lines
1612After the collection,1611After the collection,
1613Lua does the equivalent of the following function1612Lua does the equivalent of the following function
1614for each userdata in that list:1613for each userdata in that list:
1615<PRE>1614<pre>
1616 function gc_event (udata)1615 function gc_event (udata)
1617 local h = metatable(udata).__gc1616 local h = metatable(udata).__gc
1618 if h then1617 if h then
1619 h(udata)1618 h(udata)
1620 end1619 end
1621 end1620 end
1622</PRE>1621</pre>
1623 1622
1624<p>At the end of each garbage-collection cycle,1623<p>At the end of each garbage-collection cycle,
1625the finalizers for userdata are called in <em>reverse</em>1624the finalizers for userdata are called in <em>reverse</em>
@@ -1686,9 +1685,9 @@ it runs until it terminates or <em>yields</em>. · 60 unmodified lines
1686Normally, when its main function returns1685Normally, when its main function returns
1687(explicitly or implicitly, after the last instruction);1686(explicitly or implicitly, after the last instruction);
1688and abnormally, if there is an unprotected error.1687and abnormally, if there is an unprotected error.
1689In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <B>true</B>,1688In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>,
1690plus any values returned by the coroutine main function.1689plus any values returned by the coroutine main function.
1691In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <B>false</B>1690In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>false</b>
1692plus an error message.1691plus an error message.
1693 1692
1694<p>A coroutine yields by calling <code>coroutine.yield</code>.1693<p>A coroutine yields by calling <code>coroutine.yield</code>.
@@ -1697,7 +1696,7 @@ the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code>< · 2 unmodified lines
1697even if the yield happens inside nested function calls1696even if the yield happens inside nested function calls
1698(that is, not in the main function,1697(that is, not in the main function,
1699but in a function directly or indirectly called by the main function).1698but in a function directly or indirectly called by the main function).
1700In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <B>true</B>,1699In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <b>true</b>,
1701plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.1700plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
1702The next time you resume the same coroutine,1701The next time you resume the same coroutine,
1703it continues its execution from the point where it yielded,1702it continues its execution from the point where it yielded,
@@ -1718,7 +1717,7 @@ any error is propagated to the caller. · 14 unmodified lines
1718 1717
1719<p>As an example,1718<p>As an example,
1720consider the next code:1719consider the next code:
1721<PRE>1720<pre>
1722function foo1 (a)1721function foo1 (a)
1723 print("foo", a)1722 print("foo", a)
1724 return coroutine.yield(2*a)1723 return coroutine.yield(2*a)
@@ -1741,9 +1740,9 @@ a, b, c = coroutine.resume(co, "x", "y") · 16 unmodified lines
1741print("main", a, b, c)1740print("main", a, b, c)
1742a, b = coroutine.resume(co, "x", "y")1741a, b = coroutine.resume(co, "x", "y")
1743print("main", a, b)1742print("main", a, b)
1744</PRE>1743</pre>
1745When you run it, it produces the following output:1744When you run it, it produces the following output:
1746<PRE>1745<pre>
1747co-body 1 101746co-body 1 10
1748foo 21747foo 2
1749main true 41748main true 4
@@ -1752,7 +1751,7 @@ main true 11 -9 · 2 unmodified lines
1752co-body x y1751co-body x y
1753main true 10 end1752main true 10 end
1754main false cannot resume dead coroutine1753main false cannot resume dead coroutine
1755</PRE>1754</pre>
1756 1755
1757<p>1756<p>
1758<a name="API"></a><a name="3"></a><h1>3 - The Application Program Interface</h1>1757<a name="API"></a><a name="3"></a><h1>3 - The Application Program Interface</h1>
@@ -1780,7 +1779,7 @@ in file <code>luaconf.h</code>. · 21 unmodified lines
1780 1779
1781<p>Lua uses a <em>virtual stack</em> to pass values to and from C.1780<p>Lua uses a <em>virtual stack</em> to pass values to and from C.
1782Each element in this stack represents a Lua value1781Each element in this stack represents a Lua value
1783(<B>nil</B>, number, string, etc.).1782(<b>nil</b>, number, string, etc.).
1784 1783
1785<p>Whenever Lua calls C, the called function gets a new stack,1784<p>Whenever Lua calls C, the called function gets a new stack,
1786which is independent of previous stacks and of stacks of1785which is independent of previous stacks and of stacks of
@@ -1828,9 +1827,9 @@ you have set through <a href="#lua_checkstack"><code>lua_checkstack</code></a>. · 41 unmodified lines
1828Such indices are called <em>acceptable indices</em>.1827Such indices are called <em>acceptable indices</em>.
1829More formally, we define an <em>acceptable index</em>1828More formally, we define an <em>acceptable index</em>
1830as follows:1829as follows:
1831<PRE>1830<pre>
1832 (index &#060; 0 &#038;&#038; abs(index) &#060;= top) || (index > 0 &#038;&#038; index &#060;= stackspace)1831 (index &#060; 0 &#038;&#038; abs(index) &#060;= top) || (index > 0 &#038;&#038; index &#060;= stackspace)
1833</PRE>1832</pre>
1834Note that 0 is never an acceptable index.1833Note that 0 is never an acceptable index.
1835 1834
1836<p><a name="pseudo-index"></a><a name="3.3"></a><h2>3.3 - Pseudo-Indices</h2>1835<p><a name="pseudo-index"></a><a name="3.3"></a><h2>3.3 - Pseudo-Indices</h2>
@@ -1853,9 +1852,9 @@ at pseudo-index <code>LUA_ENVIRONINDEX</code>. · 16 unmodified lines
1853<p>To access and change the value of global variables,1852<p>To access and change the value of global variables,
1854you can use regular table operations over an environment table.1853you can use regular table operations over an environment table.
1855For instance, to access the value of a global variable, do1854For instance, to access the value of a global variable, do
1856<PRE>1855<pre>
1857 lua_getfield(L, LUA_GLOBALSINDEX, varname);1856 lua_getfield(L, LUA_GLOBALSINDEX, varname);
1858</PRE>1857</pre>
1859 1858
1860<p><a name="c-closure"></a><a name="3.4"></a><h2>3.4 - C Closures</h2>1859<p><a name="c-closure"></a><a name="3.4"></a><h2>3.4 - C Closures</h2>
1861 1860
@@ -1918,7 +1917,7 @@ so they never raise an error: · 56 unmodified lines
1918alphabetical order.1917alphabetical order.
1919 1918
1920<p><a name="lua_Alloc"></a>1919<p><a name="lua_Alloc"></a>
1921<hr><h3><code>lua_Alloc</code></h3>1920<hr/><h3><code>lua_Alloc</code></h3>
1922<pre>1921<pre>
1923 typedef void * (*lua_Alloc) (void *ud,1922 typedef void * (*lua_Alloc) (void *ud,
1924 void *ptr,1923 void *ptr,
@@ -1950,8 +1949,9 @@ the allocator behaves like <code>realloc</code>. · 25 unmodified lines
1950Lua assumes that the allocator never fails when1949Lua assumes that the allocator never fails when
1951<code>osize >= nsize</code>.1950<code>osize >= nsize</code>.
1952 1951
1953<p>A simple implementation for the allocator function could be like this:1952<p>A simple implementation for the allocator function
1954<PRE>1953could be like this:
1954<pre>
1955static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {1955static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
1956 (void)ud; /* not used */1956 (void)ud; /* not used */
1957 (void)osize; /* not used */1957 (void)osize; /* not used */
@@ -1963,10 +1963,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { · 5 unmodified lines
1963 /* ANSI ensures that realloc(NULL, size) == malloc(size) */1963 /* ANSI ensures that realloc(NULL, size) == malloc(size) */
1964 return realloc(ptr, nsize);1964 return realloc(ptr, nsize);
1965}1965}
1966</PRE>1966</pre>
1967 1967
1968<p><a name="lua_atpanic"></a>1968<p><a name="lua_atpanic"></a>
1969<hr><h3><code>lua_atpanic</code></h3>1969<hr/><h3><code>lua_atpanic</code></h3>
1970<pre>1970<pre>
1971 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);1971 lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
1972</pre>1972</pre>
@@ -1983,7 +1983,7 @@ never returning (e.g., doing a long jump). · 10 unmodified lines
1983<p>The panic function can access the error message at the top of the stack.1983<p>The panic function can access the error message at the top of the stack.
1984 1984
1985<p><a name="lua_call"></a>1985<p><a name="lua_call"></a>
1986<hr><h3><code>lua_call</code></h3>1986<hr/><h3><code>lua_call</code></h3>
1987<pre>1987<pre>
1988 void lua_call (lua_State *L, int nargs, int nresults);1988 void lua_call (lua_State *L, int nargs, int nresults);
1989</pre>1989</pre>
@@ -2012,11 +2012,11 @@ so that after the call the last result is on the top. · 22 unmodified lines
2012 2012
2013<p>The following example shows how the host program may do the2013<p>The following example shows how the host program may do the
2014equivalent to this Lua code:2014equivalent to this Lua code:
2015<PRE>2015<pre>
2016 a = f("how", t.x, 14)2016 a = f("how", t.x, 14)
2017</PRE>2017</pre>
2018Here it is in C:2018Here it is in C:
2019<PRE>2019<pre>
2020 lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */2020 lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */
2021 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */2021 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
2022 lua_pushstring(L, "how"); /* 1st argument */2022 lua_pushstring(L, "how"); /* 1st argument */
@@ -2025,13 +2025,13 @@ Here it is in C: · 2 unmodified lines
2025 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */2025 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */
2026 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */2026 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */
2027 lua_pop(L, 1); /* remove `t' from the stack */2027 lua_pop(L, 1); /* remove `t' from the stack */
2028</PRE>2028</pre>
2029Note that the code above is "balanced":2029Note that the code above is "balanced":
2030at its end, the stack is back to its original configuration.2030at its end, the stack is back to its original configuration.
2031This is considered good programming practice.2031This is considered good programming practice.
2032 2032
2033<p><a name="lua_CFunction"></a>2033<p><a name="lua_CFunction"></a>
2034<hr><h3><code>lua_CFunction</code></h3>2034<hr/><h3><code>lua_CFunction</code></h3>
2035<pre>2035<pre>
2036 typedef int (*lua_CFunction) (lua_State *L);2036 typedef int (*lua_CFunction) (lua_State *L);
2037</pre>2037</pre>
@@ -2056,7 +2056,7 @@ many results. · 18 unmodified lines
2056 2056
2057<p>As an example, the following function receives a variable number2057<p>As an example, the following function receives a variable number
2058of numerical arguments and returns their average and sum:2058of numerical arguments and returns their average and sum:
2059<PRE>2059<pre>
2060 static int foo (lua_State *L) {2060 static int foo (lua_State *L) {
2061 int n = lua_gettop(L); /* number of arguments */2061 int n = lua_gettop(L); /* number of arguments */
2062 lua_Number sum = 0;2062 lua_Number sum = 0;
@@ -2072,10 +2072,10 @@ of numerical arguments and returns their average and sum: · 9 unmodified lines
2072 lua_pushnumber(L, sum); /* second result */2072 lua_pushnumber(L, sum); /* second result */
2073 return 2; /* number of results */2073 return 2; /* number of results */
2074 }2074 }
2075</PRE>2075</pre>
2076 2076
2077<p><a name="lua_checkstack"></a>2077<p><a name="lua_checkstack"></a>
2078<hr><h3><code>lua_checkstack</code></h3>2078<hr/><h3><code>lua_checkstack</code></h3>
2079<pre>2079<pre>
2080 int lua_checkstack (lua_State *L, int extra);2080 int lua_checkstack (lua_State *L, int extra);
2081</pre>2081</pre>
@@ -2088,7 +2088,7 @@ if the stack is already larger than the new size, · 6 unmodified lines
2088it is left unchanged.2088it is left unchanged.
2089 2089
2090<p><a name="lua_close"></a>2090<p><a name="lua_close"></a>
2091<hr><h3><code>lua_close</code></h3>2091<hr/><h3><code>lua_close</code></h3>
2092<pre>2092<pre>
2093 void lua_close (lua_State *L);2093 void lua_close (lua_State *L);
2094</pre>2094</pre>
@@ -2105,7 +2105,7 @@ might need to release states as soon as they are not needed, · 10 unmodified lines
2105to avoid growing too large.2105to avoid growing too large.
2106 2106
2107<p><a name="lua_concat"></a>2107<p><a name="lua_concat"></a>
2108<hr><h3><code>lua_concat</code></h3>2108<hr/><h3><code>lua_concat</code></h3>
2109<pre>2109<pre>
2110 void lua_concat (lua_State *L, int n);2110 void lua_concat (lua_State *L, int n);
2111</pre>2111</pre>
@@ -2120,7 +2120,7 @@ Concatenation is done following the usual semantics of Lua · 8 unmodified lines
2120(see <a href="#concat">2.5.4</a>).2120(see <a href="#concat">2.5.4</a>).
2121 2121
2122<p><a name="lua_cpcall"></a>2122<p><a name="lua_cpcall"></a>
2123<hr><h3><code>lua_cpcall</code></h3>2123<hr/><h3><code>lua_cpcall</code></h3>
2124<pre>2124<pre>
2125 int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);2125 int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
2126</pre>2126</pre>
@@ -2136,7 +2136,7 @@ otherwise, it returns zero, and does not change the stack. · 9 unmodified lines
2136Any value returned by <code>func</code> is discarded.2136Any value returned by <code>func</code> is discarded.
2137 2137
2138<p><a name="lua_createtable"></a>2138<p><a name="lua_createtable"></a>
2139<hr><h3><code>lua_createtable</code></h3>2139<hr/><h3><code>lua_createtable</code></h3>
2140<pre>2140<pre>
2141 void lua_createtable (lua_State *L, int narr, int nrec);2141 void lua_createtable (lua_State *L, int narr, int nrec);
2142</pre>2142</pre>
@@ -2150,7 +2150,7 @@ the table will have. · 7 unmodified lines
2150Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.2150Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
2151 2151
2152<p><a name="lua_dump"></a>2152<p><a name="lua_dump"></a>
2153<hr><h3><code>lua_dump</code></h3>2153<hr/><h3><code>lua_dump</code></h3>
2154<pre>2154<pre>
2155 int lua_dump (lua_State *L, lua_Writer writer, void *data);2155 int lua_dump (lua_State *L, lua_Writer writer, void *data);
2156</pre>2156</pre>
@@ -2172,7 +2172,7 @@ call to the writer; · 15 unmodified lines
2172<p>This function does not pop the function from the stack.2172<p>This function does not pop the function from the stack.
2173 2173
2174<p><a name="lua_equal"></a>2174<p><a name="lua_equal"></a>
2175<hr><h3><code>lua_equal</code></h3>2175<hr/><h3><code>lua_equal</code></h3>
2176<pre>2176<pre>
2177 int lua_equal (lua_State *L, int index1, int index2);2177 int lua_equal (lua_State *L, int index1, int index2);
2178</pre>2178</pre>
@@ -2180,13 +2180,13 @@ call to the writer; · 1 unmodified line
2180 2180
2181<p>Returns 1 if the two values in acceptable indices <code>index1</code> and2181<p>Returns 1 if the two values in acceptable indices <code>index1</code> and
2182<code>index2</code> are equal,2182<code>index2</code> are equal,
2183following the semantics of the Lua <code>=</code> operator2183following the semantics of the Lua <code>==</code> operator
2184(that is, may call metamethods).2184(that is, may call metamethods).
2185Otherwise returns 0.2185Otherwise returns 0.
2186Also returns 0 if any of the indices are non valid.2186Also returns 0 if any of the indices are non valid.
2187 2187
2188<p><a name="lua_error"></a>2188<p><a name="lua_error"></a>
2189<hr><h3><code>lua_error</code></h3>2189<hr/><h3><code>lua_error</code></h3>
2190<pre>2190<pre>
2191 int lua_error (lua_State *L);2191 int lua_error (lua_State *L);
2192</pre>2192</pre>
@@ -2199,7 +2199,7 @@ This function does a long jump, · 6 unmodified lines
2199and therefore never returns.2199and therefore never returns.
2200 2200
2201<p><a name="lua_gc"></a>2201<p><a name="lua_gc"></a>
2202<hr><h3><code>lua_gc</code></h3>2202<hr/><h3><code>lua_gc</code></h3>
2203<pre>2203<pre>
2204 int lua_gc (lua_State *L, int what, int data);2204 int lua_gc (lua_State *L, int what, int data);
2205</pre>2205</pre>
@@ -2210,12 +2210,15 @@ and therefore never returns. · 4 unmodified lines
2210<p>This function performs several tasks,2210<p>This function performs several tasks,
2211according to the value of the parameter <code>what</code>:2211according to the value of the parameter <code>what</code>:
2212<ul>2212<ul>
2213<li> <code>LUA_GCSTOP</code>&mdash; stops the garbage collector.2213<li> <code>LUA_GCSTOP</code>--- stops the garbage collector.
2214<li> <code>LUA_GCRESTART</code>&mdash; restarts the garbage collector.2214<li> <code>LUA_GCRESTART</code>--- restarts the garbage collector.
2215<li> <code>LUA_GCCOLLECT</code>&mdash; performs a full garbage-collection cycle.2215<li> <code>LUA_GCCOLLECT</code>--- performs a full garbage-collection cycle.
2216<li> <code>LUA_GCCOUNT</code>&mdash; returns the current2216<li> <code>LUA_GCCOUNT</code>--- returns the current
2217amount of memory (in Kbytes) in use by Lua.2217amount of memory (in Kbytes) in use by Lua.
2218<li> <code>LUA_GCSTEP</code>&mdash; performs an incremental step of2218<li> <code>LUA_GCCOUNTB</code>--- returns the remainder of
2219dividing the current amount of bytes of memory in use by Lua
2220by 1024.
2221<li> <code>LUA_GCSTEP</code>--- performs an incremental step of
2219garbage collection.2222garbage collection.
2220The step "size" is controlled by <code>data</code>2223The step "size" is controlled by <code>data</code>
2221(larger values mean more steps) in a non-specified way.2224(larger values mean more steps) in a non-specified way.
@@ -2223,16 +2226,18 @@ If you want to control the step size · 1 unmodified line
2223you must tune experimentally the value of <code>data</code>.2226you must tune experimentally the value of <code>data</code>.
2224The function returns 1 if that step finished a2227The function returns 1 if that step finished a
2225garbage-collection cycle.2228garbage-collection cycle.
2226<li> <code>LUA_GCSETPAUSE</code>&mdash;2229<li> <code>LUA_GCSETPAUSE</code>---
2227sets <em><code>data</code>/100</em> as the new value2230sets <em><code>data</code>/100</em> as the new value
2228for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>).2231for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>).
2229<li> <code>LUA_GCSETSTEPMUL</code>&mdash;2232The function returns the previous value of the pause.
2233<li> <code>LUA_GCSETSTEPMUL</code>---
2230sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of2234sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of
2231the collector (see <a href="#GC">2.10</a>).2235the collector (see <a href="#GC">2.10</a>).
2236The function returns the previous value of the step multiplier.
2232</ul>2237</ul>
2233 2238
2234<p><a name="lua_getallocf"></a>2239<p><a name="lua_getallocf"></a>
2235<hr><h3><code>lua_getallocf</code></h3>2240<hr/><h3><code>lua_getallocf</code></h3>
2236<pre>2241<pre>
2237 lua_Alloc lua_getallocf (lua_State *L, void **ud);2242 lua_Alloc lua_getallocf (lua_State *L, void **ud);
2238</pre>2243</pre>
@@ -2243,7 +2248,7 @@ If <code>ud</code> is not <code>NULL</code> Lua stores in <code>*ud</code> the · 4 unmodified lines
2243opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.2248opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>.
2244 2249
2245<p><a name="lua_getfenv"></a>2250<p><a name="lua_getfenv"></a>
2246<hr><h3><code>lua_getfenv</code></h3>2251<hr/><h3><code>lua_getfenv</code></h3>
2247<pre>2252<pre>
2248 void lua_getfenv (lua_State *L, int index);2253 void lua_getfenv (lua_State *L, int index);
2249</pre>2254</pre>
@@ -2253,7 +2258,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 3 unmodified lines
2253the value at the given index.2258the value at the given index.
2254 2259
2255<p><a name="lua_getfield"></a>2260<p><a name="lua_getfield"></a>
2256<hr><h3><code>lua_getfield</code></h3>2261<hr/><h3><code>lua_getfield</code></h3>
2257<pre>2262<pre>
2258 void lua_getfield (lua_State *L, int index, const char *k);2263 void lua_getfield (lua_State *L, int index, const char *k);
2259</pre>2264</pre>
@@ -2265,7 +2270,7 @@ As in Lua, this function may trigger a metamethod · 5 unmodified lines
2265for the "index" event (see <a href="#metatable">2.8</a>).2270for the "index" event (see <a href="#metatable">2.8</a>).
2266 2271
2267<p><a name="lua_getmetatable"></a>2272<p><a name="lua_getmetatable"></a>
2268<hr><h3><code>lua_getmetatable</code></h3>2273<hr/><h3><code>lua_getmetatable</code></h3>
2269<pre>2274<pre>
2270 int lua_getmetatable (lua_State *L, int index);2275 int lua_getmetatable (lua_State *L, int index);
2271</pre>2276</pre>
@@ -2278,7 +2283,7 @@ or if the value does not have a metatable, · 6 unmodified lines
2278returns 0 and pushes nothing on the stack.2283returns 0 and pushes nothing on the stack.
2279 2284
2280<p><a name="lua_gettable"></a>2285<p><a name="lua_gettable"></a>
2281<hr><h3><code>lua_gettable</code></h3>2286<hr/><h3><code>lua_gettable</code></h3>
2282<pre>2287<pre>
2283 void lua_gettable (lua_State *L, int index);2288 void lua_gettable (lua_State *L, int index);
2284</pre>2289</pre>
@@ -2294,7 +2299,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
2294for the "index" event (see <a href="#metatable">2.8</a>).2299for the "index" event (see <a href="#metatable">2.8</a>).
2295 2300
2296<p><a name="lua_gettop"></a>2301<p><a name="lua_gettop"></a>
2297<hr><h3><code>lua_gettop</code></h3>2302<hr/><h3><code>lua_gettop</code></h3>
2298<pre>2303<pre>
2299 int lua_gettop (lua_State *L);2304 int lua_gettop (lua_State *L);
2300</pre>2305</pre>
@@ -2306,7 +2311,7 @@ that result is equal to the number of elements in the stack · 5 unmodified lines
2306(and so 0 means an empty stack).2311(and so 0 means an empty stack).
2307 2312
2308<p><a name="lua_insert"></a>2313<p><a name="lua_insert"></a>
2309<hr><h3><code>lua_insert</code></h3>2314<hr/><h3><code>lua_insert</code></h3>
2310<pre>2315<pre>
2311 void lua_insert (lua_State *L, int index);2316 void lua_insert (lua_State *L, int index);
2312</pre>2317</pre>
@@ -2318,7 +2323,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
2318because a pseudo-index is not an actual stack position.2323because a pseudo-index is not an actual stack position.
2319 2324
2320<p><a name="lua_Integer"></a>2325<p><a name="lua_Integer"></a>
2321<hr><h3><code>lua_Integer</code></h3>2326<hr/><h3><code>lua_Integer</code></h3>
2322<pre>2327<pre>
2323 typedef ptrdiff_t lua_Integer;2328 typedef ptrdiff_t lua_Integer;
2324</pre>2329</pre>
@@ -2331,7 +2336,7 @@ which is usually the largest type the machine handles · 6 unmodified lines
2331"comfortably".2336"comfortably".
2332 2337
2333<p><a name="lua_isboolean"></a>2338<p><a name="lua_isboolean"></a>
2334<hr><h3><code>lua_isboolean</code></h3>2339<hr/><h3><code>lua_isboolean</code></h3>
2335<pre>2340<pre>
2336 int lua_isboolean (lua_State *L, int index);2341 int lua_isboolean (lua_State *L, int index);
2337</pre>2342</pre>
@@ -2341,7 +2346,7 @@ which is usually the largest type the machine handles · 3 unmodified lines
2341and 0 otherwise.2346and 0 otherwise.
2342 2347
2343<p><a name="lua_iscfunction"></a>2348<p><a name="lua_iscfunction"></a>
2344<hr><h3><code>lua_iscfunction</code></h3>2349<hr/><h3><code>lua_iscfunction</code></h3>
2345<pre>2350<pre>
2346 int lua_iscfunction (lua_State *L, int index);2351 int lua_iscfunction (lua_State *L, int index);
2347</pre>2352</pre>
@@ -2351,7 +2356,7 @@ and 0 otherwise. · 3 unmodified lines
2351and 0 otherwise.2356and 0 otherwise.
2352 2357
2353<p><a name="lua_isfunction"></a>2358<p><a name="lua_isfunction"></a>
2354<hr><h3><code>lua_isfunction</code></h3>2359<hr/><h3><code>lua_isfunction</code></h3>
2355<pre>2360<pre>
2356 int lua_isfunction (lua_State *L, int index);2361 int lua_isfunction (lua_State *L, int index);
2357</pre>2362</pre>
@@ -2361,7 +2366,7 @@ and 0 otherwise. · 3 unmodified lines
2361(either C or Lua), and 0 otherwise.2366(either C or Lua), and 0 otherwise.
2362 2367
2363<p><a name="lua_islightuserdata"></a>2368<p><a name="lua_islightuserdata"></a>
2364<hr><h3><code>lua_islightuserdata</code></h3>2369<hr/><h3><code>lua_islightuserdata</code></h3>
2365<pre>2370<pre>
2366 int lua_islightuserdata (lua_State *L, int index);2371 int lua_islightuserdata (lua_State *L, int index);
2367</pre>2372</pre>
@@ -2371,17 +2376,17 @@ and 0 otherwise. · 3 unmodified lines
2371and 0 otherwise.2376and 0 otherwise.
2372 2377
2373<p><a name="lua_isnil"></a>2378<p><a name="lua_isnil"></a>
2374<hr><h3><code>lua_isnil</code></h3>2379<hr/><h3><code>lua_isnil</code></h3>
2375<pre>2380<pre>
2376 int lua_isnil (lua_State *L, int index);2381 int lua_isnil (lua_State *L, int index);
2377</pre>2382</pre>
2378 2383
2379 2384
2380<p>Returns 1 if the value at the given acceptable index is <B>nil</B>,2385<p>Returns 1 if the value at the given acceptable index is <b>nil</b>,
2381and 0 otherwise.2386and 0 otherwise.
2382 2387
2383<p><a name="lua_isnumber"></a>2388<p><a name="lua_isnumber"></a>
2384<hr><h3><code>lua_isnumber</code></h3>2389<hr/><h3><code>lua_isnumber</code></h3>
2385<pre>2390<pre>
2386 int lua_isnumber (lua_State *L, int index);2391 int lua_isnumber (lua_State *L, int index);
2387</pre>2392</pre>
@@ -2392,7 +2397,7 @@ or a string convertible to a number, · 4 unmodified lines
2392and 0 otherwise.2397and 0 otherwise.
2393 2398
2394<p><a name="lua_isstring"></a>2399<p><a name="lua_isstring"></a>
2395<hr><h3><code>lua_isstring</code></h3>2400<hr/><h3><code>lua_isstring</code></h3>
2396<pre>2401<pre>
2397 int lua_isstring (lua_State *L, int index);2402 int lua_isstring (lua_State *L, int index);
2398</pre>2403</pre>
@@ -2403,7 +2408,7 @@ or a number (which is always convertible to a string), · 4 unmodified lines
2403and 0 otherwise.2408and 0 otherwise.
2404 2409
2405<p><a name="lua_istable"></a>2410<p><a name="lua_istable"></a>
2406<hr><h3><code>lua_istable</code></h3>2411<hr/><h3><code>lua_istable</code></h3>
2407<pre>2412<pre>
2408 int lua_istable (lua_State *L, int index);2413 int lua_istable (lua_State *L, int index);
2409</pre>2414</pre>
@@ -2413,7 +2418,7 @@ and 0 otherwise. · 3 unmodified lines
2413and 0 otherwise.2418and 0 otherwise.
2414 2419
2415<p><a name="lua_isthread"></a>2420<p><a name="lua_isthread"></a>
2416<hr><h3><code>lua_isthread</code></h3>2421<hr/><h3><code>lua_isthread</code></h3>
2417<pre>2422<pre>
2418 int lua_isthread (lua_State *L, int index);2423 int lua_isthread (lua_State *L, int index);
2419</pre>2424</pre>
@@ -2423,7 +2428,7 @@ and 0 otherwise. · 3 unmodified lines
2423and 0 otherwise.2428and 0 otherwise.
2424 2429
2425<p><a name="lua_isuserdata"></a>2430<p><a name="lua_isuserdata"></a>
2426<hr><h3><code>lua_isuserdata</code></h3>2431<hr/><h3><code>lua_isuserdata</code></h3>
2427<pre>2432<pre>
2428 int lua_isuserdata (lua_State *L, int index);2433 int lua_isuserdata (lua_State *L, int index);
2429</pre>2434</pre>
@@ -2433,7 +2438,7 @@ and 0 otherwise. · 3 unmodified lines
2433(either full or light), and 0 otherwise.2438(either full or light), and 0 otherwise.
2434 2439
2435<p><a name="lua_lessthan"></a>2440<p><a name="lua_lessthan"></a>
2436<hr><h3><code>lua_lessthan</code></h3>2441<hr/><h3><code>lua_lessthan</code></h3>
2437<pre>2442<pre>
2438 int lua_lessthan (lua_State *L, int index1, int index2);2443 int lua_lessthan (lua_State *L, int index1, int index2);
2439</pre>2444</pre>
@@ -2447,7 +2452,7 @@ Otherwise returns 0. · 7 unmodified lines
2447Also returns 0 if any of the indices are non valid.2452Also returns 0 if any of the indices are non valid.
2448 2453
2449<p><a name="lua_load"></a>2454<p><a name="lua_load"></a>
2450<hr><h3><code>lua_load</code></h3>2455<hr/><h3><code>lua_load</code></h3>
2451<pre>2456<pre>
2452 int lua_load (lua_State *L, lua_Reader reader, void *data,2457 int lua_load (lua_State *L, lua_Reader reader, void *data,
2453 const char *chunkname);2458 const char *chunkname);
@@ -2462,10 +2467,10 @@ function on top of the stack. · 8 unmodified lines
2462Otherwise, it pushes an error message.2467Otherwise, it pushes an error message.
2463The return values of <a href="#lua_load"><code>lua_load</code></a> are:2468The return values of <a href="#lua_load"><code>lua_load</code></a> are:
2464<ul>2469<ul>
2465<li> 0 &mdash; no errors;2470<li> 0 --- no errors;
2466<li> <code>LUA_ERRSYNTAX</code> &mdash;2471<li> <code>LUA_ERRSYNTAX</code> ---
2467syntax error during pre-compilation.2472syntax error during pre-compilation.
2468<li> <code>LUA_ERRMEM</code> &mdash;2473<li> <code>LUA_ERRMEM</code> ---
2469memory allocation error.2474memory allocation error.
2470</ul>2475</ul>
2471 2476
@@ -2480,7 +2485,7 @@ The <code>data</code> argument is an opaque value passed to the reader function. · 8 unmodified lines
2480It is used for error messages and debug information (see <a href="#debugI">3.8</a>).2485It is used for error messages and debug information (see <a href="#debugI">3.8</a>).
2481 2486
2482<p><a name="lua_newstate"></a>2487<p><a name="lua_newstate"></a>
2483<hr><h3><code>lua_newstate</code></h3>2488<hr/><h3><code>lua_newstate</code></h3>
2484<pre>2489<pre>
2485 lua_State *lua_newstate (lua_Alloc f, void *ud);2490 lua_State *lua_newstate (lua_Alloc f, void *ud);
2486</pre>2491</pre>
@@ -2495,7 +2500,7 @@ The second argument, <code>ud</code>, is an opaque pointer that Lua · 8 unmodified lines
2495simply passes to the allocator in every call.2500simply passes to the allocator in every call.
2496 2501
2497<p><a name="lua_newtable"></a>2502<p><a name="lua_newtable"></a>
2498<hr><h3><code>lua_newtable</code></h3>2503<hr/><h3><code>lua_newtable</code></h3>
2499<pre>2504<pre>
2500 void lua_newtable (lua_State *L);2505 void lua_newtable (lua_State *L);
2501</pre>2506</pre>
@@ -2505,7 +2510,7 @@ simply passes to the allocator in every call. · 3 unmodified lines
2505Equivalent to <code>lua_createtable(L, 0, 0)</code>.2510Equivalent to <code>lua_createtable(L, 0, 0)</code>.
2506 2511
2507<p><a name="lua_newthread"></a>2512<p><a name="lua_newthread"></a>
2508<hr><h3><code>lua_newthread</code></h3>2513<hr/><h3><code>lua_newthread</code></h3>
2509<pre>2514<pre>
2510 lua_State *lua_newthread (lua_State *L);2515 lua_State *lua_newthread (lua_State *L);
2511</pre>2516</pre>
@@ -2522,7 +2527,7 @@ Threads are subject to garbage collection, · 10 unmodified lines
2522like any Lua object.2527like any Lua object.
2523 2528
2524<p><a name="lua_newuserdata"></a>2529<p><a name="lua_newuserdata"></a>
2525<hr><h3><code>lua_newuserdata</code></h3>2530<hr/><h3><code>lua_newuserdata</code></h3>
2526<pre>2531<pre>
2527 void *lua_newuserdata (lua_State *L, size_t size);2532 void *lua_newuserdata (lua_State *L, size_t size);
2528</pre>2533</pre>
@@ -2544,7 +2549,7 @@ it calls the userdata's <code>gc</code> metamethod, if any, · 15 unmodified lines
2544and then it frees the userdata's corresponding memory.2549and then it frees the userdata's corresponding memory.
2545 2550
2546<p><a name="lua_next"></a>2551<p><a name="lua_next"></a>
2547<hr><h3><code>lua_next</code></h3>2552<hr/><h3><code>lua_next</code></h3>
2548<pre>2553<pre>
2549 int lua_next (lua_State *L, int index);2554 int lua_next (lua_State *L, int index);
2550</pre>2555</pre>
@@ -2557,7 +2562,7 @@ If there are no more elements, · 6 unmodified lines
2557then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).2562then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).
2558 2563
2559<p>A typical traversal looks like this:2564<p>A typical traversal looks like this:
2560<PRE>2565<pre>
2561 /* table is in the stack at index `t' */2566 /* table is in the stack at index `t' */
2562 lua_pushnil(L); /* first key */2567 lua_pushnil(L); /* first key */
2563 while (lua_next(L, t) != 0) {2568 while (lua_next(L, t) != 0) {
@@ -2566,7 +2571,7 @@ then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing · 2 unmodified lines
2566 lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)));2571 lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)));
2567 lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */2572 lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */
2568 }2573 }
2569</PRE>2574</pre>
2570 2575
2571<p>While traversing a table,2576<p>While traversing a table,
2572do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,2577do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,
@@ -2576,7 +2581,7 @@ the value at the given index; · 3 unmodified lines
2576this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.2581this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
2577 2582
2578<p><a name="lua_Number"></a>2583<p><a name="lua_Number"></a>
2579<hr><h3><code>lua_Number</code></h3>2584<hr/><h3><code>lua_Number</code></h3>
2580<pre>2585<pre>
2581 typedef double lua_Number;2586 typedef double lua_Number;
2582</pre>2587</pre>
@@ -2588,7 +2593,7 @@ this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>. · 5 unmodified lines
2588Lua to operate with other type for numbers (e.g., float or long).2593Lua to operate with other type for numbers (e.g., float or long).
2589 2594
2590<p><a name="lua_objlen"></a>2595<p><a name="lua_objlen"></a>
2591<hr><h3><code>lua_objlen</code></h3>2596<hr/><h3><code>lua_objlen</code></h3>
2592<pre>2597<pre>
2593 size_t lua_objlen (lua_State *L, int index);2598 size_t lua_objlen (lua_State *L, int index);
2594</pre>2599</pre>
@@ -2602,7 +2607,7 @@ for the userdatum. · 7 unmodified lines
2602For other values, returns 0.2607For other values, returns 0.
2603 2608
2604<p><a name="lua_pcall"></a>2609<p><a name="lua_pcall"></a>
2605<hr><h3><code>lua_pcall</code></h3>2610<hr/><h3><code>lua_pcall</code></h3>
2606<pre>2611<pre>
2607 lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);2612 lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
2608</pre>2613</pre>
@@ -2640,15 +2645,15 @@ since by then the stack has unwound. · 31 unmodified lines
2640or one of the following error codes2645or one of the following error codes
2641(defined in <code>lua.h</code>):2646(defined in <code>lua.h</code>):
2642<ul>2647<ul>
2643<li> <code>LUA_ERRRUN</code> &mdash; a runtime error.2648<li> <code>LUA_ERRRUN</code> --- a runtime error.
2644<li> <code>LUA_ERRMEM</code> &mdash; memory allocation error.2649<li> <code>LUA_ERRMEM</code> --- memory allocation error.
2645For such errors, Lua does not call the error handler function.2650For such errors, Lua does not call the error handler function.
2646<li> <code>LUA_ERRERR</code> &mdash;2651<li> <code>LUA_ERRERR</code> ---
2647error while running the error handler function.2652error while running the error handler function.
2648</ul>2653</ul>
2649 2654
2650<p><a name="lua_pop"></a>2655<p><a name="lua_pop"></a>
2651<hr><h3><code>lua_pop</code></h3>2656<hr/><h3><code>lua_pop</code></h3>
2652<pre>2657<pre>
2653 void lua_pop (lua_State *L, int n);2658 void lua_pop (lua_State *L, int n);
2654</pre>2659</pre>
@@ -2657,7 +2662,7 @@ error while running the error handler function. · 2 unmodified lines
2657<p>Pops <code>n</code> elements from the stack.2662<p>Pops <code>n</code> elements from the stack.
2658 2663
2659<p><a name="lua_pushboolean"></a>2664<p><a name="lua_pushboolean"></a>
2660<hr><h3><code>lua_pushboolean</code></h3>2665<hr/><h3><code>lua_pushboolean</code></h3>
2661<pre>2666<pre>
2662 void lua_pushboolean (lua_State *L, int b);2667 void lua_pushboolean (lua_State *L, int b);
2663</pre>2668</pre>
@@ -2666,7 +2671,7 @@ error while running the error handler function. · 2 unmodified lines
2666<p>Pushes a boolean value with value <code>b</code> onto the stack.2671<p>Pushes a boolean value with value <code>b</code> onto the stack.
2667 2672
2668<p><a name="lua_pushcclosure"></a>2673<p><a name="lua_pushcclosure"></a>
2669<hr><h3><code>lua_pushcclosure</code></h3>2674<hr/><h3><code>lua_pushcclosure</code></h3>
2670<pre>2675<pre>
2671 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);2676 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
2672</pre>2677</pre>
@@ -2688,7 +2693,7 @@ associated with the function. · 15 unmodified lines
2688<a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.2693<a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
2689 2694
2690<p><a name="lua_pushcfunction"></a>2695<p><a name="lua_pushcfunction"></a>
2691<hr><h3><code>lua_pushcfunction</code></h3>2696<hr/><h3><code>lua_pushcfunction</code></h3>
2692<pre>2697<pre>
2693 void lua_pushcfunction (lua_State *L, lua_CFunction f);2698 void lua_pushcfunction (lua_State *L, lua_CFunction f);
2694</pre>2699</pre>
@@ -2698,7 +2703,7 @@ associated with the function. · 3 unmodified lines
2698This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>.2703This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>.
2699 2704
2700<p><a name="lua_pushfstring"></a>2705<p><a name="lua_pushfstring"></a>
2701<hr><h3><code>lua_pushfstring</code></h3>2706<hr/><h3><code>lua_pushfstring</code></h3>
2702<pre>2707<pre>
2703 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);2708 const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
2704</pre>2709</pre>
@@ -2724,7 +2729,7 @@ The conversion specifiers can be simply · 19 unmodified lines
2724</ul>2729</ul>
2725 2730
2726<p><a name="lua_pushinteger"></a>2731<p><a name="lua_pushinteger"></a>
2727<hr><h3><code>lua_pushinteger</code></h3>2732<hr/><h3><code>lua_pushinteger</code></h3>
2728<pre>2733<pre>
2729 void lua_pushinteger (lua_State *L, lua_Integer n);2734 void lua_pushinteger (lua_State *L, lua_Integer n);
2730</pre>2735</pre>
@@ -2733,7 +2738,7 @@ The conversion specifiers can be simply · 2 unmodified lines
2733<p>Pushes a number with value <code>n</code> onto the stack.2738<p>Pushes a number with value <code>n</code> onto the stack.
2734 2739
2735<p><a name="lua_pushlightuserdata"></a>2740<p><a name="lua_pushlightuserdata"></a>
2736<hr><h3><code>lua_pushlightuserdata</code></h3>2741<hr/><h3><code>lua_pushlightuserdata</code></h3>
2737<pre>2742<pre>
2738 void lua_pushlightuserdata (lua_State *L, void *p);2743 void lua_pushlightuserdata (lua_State *L, void *p);
2739</pre>2744</pre>
@@ -2750,7 +2755,7 @@ A light userdata is equal to "any" · 10 unmodified lines
2750light userdata with the same C address.2755light userdata with the same C address.
2751 2756
2752<p><a name="lua_pushlstring"></a>2757<p><a name="lua_pushlstring"></a>
2753<hr><h3><code>lua_pushlstring</code></h3>2758<hr/><h3><code>lua_pushlstring</code></h3>
2754<pre>2759<pre>
2755 void lua_pushlstring (lua_State *L, const char *s, size_t len);2760 void lua_pushlstring (lua_State *L, const char *s, size_t len);
2756</pre>2761</pre>
@@ -2763,7 +2768,7 @@ so the memory at <code>s</code> can be freed or reused immediately after · 6 unmodified lines
2763the function returns.2768the function returns.
2764 2769
2765<p><a name="lua_pushnil"></a>2770<p><a name="lua_pushnil"></a>
2766<hr><h3><code>lua_pushnil</code></h3>2771<hr/><h3><code>lua_pushnil</code></h3>
2767<pre>2772<pre>
2768 void lua_pushnil (lua_State *L);2773 void lua_pushnil (lua_State *L);
2769</pre>2774</pre>
@@ -2772,7 +2777,7 @@ the function returns. · 2 unmodified lines
2772<p>Pushes a nil value onto the stack.2777<p>Pushes a nil value onto the stack.
2773 2778
2774<p><a name="lua_pushnumber"></a>2779<p><a name="lua_pushnumber"></a>
2775<hr><h3><code>lua_pushnumber</code></h3>2780<hr/><h3><code>lua_pushnumber</code></h3>
2776<pre>2781<pre>
2777 void lua_pushnumber (lua_State *L, lua_Number n);2782 void lua_pushnumber (lua_State *L, lua_Number n);
2778</pre>2783</pre>
@@ -2781,7 +2786,7 @@ the function returns. · 2 unmodified lines
2781<p>Pushes a number with value <code>n</code> onto the stack.2786<p>Pushes a number with value <code>n</code> onto the stack.
2782 2787
2783<p><a name="lua_pushstring"></a>2788<p><a name="lua_pushstring"></a>
2784<hr><h3><code>lua_pushstring</code></h3>2789<hr/><h3><code>lua_pushstring</code></h3>
2785<pre>2790<pre>
2786 void lua_pushstring (lua_State *L, const char *s);2791 void lua_pushstring (lua_State *L, const char *s);
2787</pre>2792</pre>
@@ -2794,7 +2799,7 @@ so the memory at <code>s</code> can be freed or reused immediately after · 6 unmodified lines
2794the function returns.2799the function returns.
2795 2800
2796<p><a name="lua_pushvalue"></a>2801<p><a name="lua_pushvalue"></a>
2797<hr><h3><code>lua_pushvalue</code></h3>2802<hr/><h3><code>lua_pushvalue</code></h3>
2798<pre>2803<pre>
2799 void lua_pushvalue (lua_State *L, int index);2804 void lua_pushvalue (lua_State *L, int index);
2800</pre>2805</pre>
@@ -2804,7 +2809,7 @@ the function returns. · 3 unmodified lines
2804onto the stack.2809onto the stack.
2805 2810
2806<p><a name="lua_pushvfstring"></a>2811<p><a name="lua_pushvfstring"></a>
2807<hr><h3><code>lua_pushvfstring</code></h3>2812<hr/><h3><code>lua_pushvfstring</code></h3>
2808<pre>2813<pre>
2809 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);2814 const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
2810</pre>2815</pre>
@@ -2814,7 +2819,7 @@ onto the stack. · 3 unmodified lines
2814instead of a variable number of arguments.2819instead of a variable number of arguments.
2815 2820
2816<p><a name="lua_rawequal"></a>2821<p><a name="lua_rawequal"></a>
2817<hr><h3><code>lua_rawequal</code></h3>2822<hr/><h3><code>lua_rawequal</code></h3>
2818<pre>2823<pre>
2819 int lua_rawequal (lua_State *L, int index1, int index2);2824 int lua_rawequal (lua_State *L, int index1, int index2);
2820</pre>2825</pre>
@@ -2827,7 +2832,7 @@ Otherwise returns 0. · 6 unmodified lines
2827Also returns 0 if any of the indices are non valid.2832Also returns 0 if any of the indices are non valid.
2828 2833
2829<p><a name="lua_rawget"></a>2834<p><a name="lua_rawget"></a>
2830<hr><h3><code>lua_rawget</code></h3>2835<hr/><h3><code>lua_rawget</code></h3>
2831<pre>2836<pre>
2832 void lua_rawget (lua_State *L, int index);2837 void lua_rawget (lua_State *L, int index);
2833</pre>2838</pre>
@@ -2837,7 +2842,7 @@ Also returns 0 if any of the indices are non valid. · 3 unmodified lines
2837(i.e., without metamethods).2842(i.e., without metamethods).
2838 2843
2839<p><a name="lua_rawgeti"></a>2844<p><a name="lua_rawgeti"></a>
2840<hr><h3><code>lua_rawgeti</code></h3>2845<hr/><h3><code>lua_rawgeti</code></h3>
2841<pre>2846<pre>
2842 void lua_rawgeti (lua_State *L, int index, int n);2847 void lua_rawgeti (lua_State *L, int index, int n);
2843</pre>2848</pre>
@@ -2849,7 +2854,7 @@ The access is raw, · 5 unmodified lines
2849that is, it does not invoke metamethods.2854that is, it does not invoke metamethods.
2850 2855
2851<p><a name="lua_rawset"></a>2856<p><a name="lua_rawset"></a>
2852<hr><h3><code>lua_rawset</code></h3>2857<hr/><h3><code>lua_rawset</code></h3>
2853<pre>2858<pre>
2854 void lua_rawset (lua_State *L, int index);2859 void lua_rawset (lua_State *L, int index);
2855</pre>2860</pre>
@@ -2859,7 +2864,7 @@ that is, it does not invoke metamethods. · 3 unmodified lines
2859(i.e., without metamethods).2864(i.e., without metamethods).
2860 2865
2861<p><a name="lua_rawseti"></a>2866<p><a name="lua_rawseti"></a>
2862<hr><h3><code>lua_rawseti</code></h3>2867<hr/><h3><code>lua_rawseti</code></h3>
2863<pre>2868<pre>
2864 void lua_rawseti (lua_State *L, int index, int n);2869 void lua_rawseti (lua_State *L, int index, int n);
2865</pre>2870</pre>
@@ -2874,7 +2879,7 @@ The assignment is raw, · 8 unmodified lines
2874that is, it does not invoke metamethods.2879that is, it does not invoke metamethods.
2875 2880
2876<p><a name="lua_Reader"></a>2881<p><a name="lua_Reader"></a>
2877<hr><h3><code>lua_Reader</code></h3>2882<hr/><h3><code>lua_Reader</code></h3>
2878<pre>2883<pre>
2879 typedef const char * (*lua_Reader)2884 typedef const char * (*lua_Reader)
2880 (lua_State *L, void *data, size_t *size);2885 (lua_State *L, void *data, size_t *size);
@@ -2893,7 +2898,7 @@ To signal the end of the chunk, the reader returns <code>NULL</code>. · 12 unmodified lines
2893The reader function may return pieces of any size greater than zero.2898The reader function may return pieces of any size greater than zero.
2894 2899
2895<p><a name="lua_remove"></a>2900<p><a name="lua_remove"></a>
2896<hr><h3><code>lua_remove</code></h3>2901<hr/><h3><code>lua_remove</code></h3>
2897<pre>2902<pre>
2898 void lua_remove (lua_State *L, int index);2903 void lua_remove (lua_State *L, int index);
2899</pre>2904</pre>
@@ -2905,7 +2910,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines
2905because a pseudo-index is not an actual stack position.2910because a pseudo-index is not an actual stack position.
2906 2911
2907<p><a name="lua_replace"></a>2912<p><a name="lua_replace"></a>
2908<hr><h3><code>lua_replace</code></h3>2913<hr/><h3><code>lua_replace</code></h3>
2909<pre>2914<pre>
2910 void lua_replace (lua_State *L, int index);2915 void lua_replace (lua_State *L, int index);
2911</pre>2916</pre>
@@ -2916,7 +2921,7 @@ without shifting any element · 4 unmodified lines
2916(therefore replacing the value at the given position).2921(therefore replacing the value at the given position).
2917 2922
2918<p><a name="lua_resume"></a>2923<p><a name="lua_resume"></a>
2919<hr><h3><code>lua_resume</code></h3>2924<hr/><h3><code>lua_resume</code></h3>
2920<pre>2925<pre>
2921 int lua_resume (lua_State *L, int narg);2926 int lua_resume (lua_State *L, int narg);
2922</pre>2927</pre>
@@ -2932,8 +2937,11 @@ with <code>narg</code> being the number of arguments. · 9 unmodified lines
2932This call returns when the coroutine suspends or finishes its execution.2937This call returns when the coroutine suspends or finishes its execution.
2933When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>,2938When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>,
2934or all values returned by the body function.2939or all values returned by the body function.
2935<a href="#lua_resume"><code>lua_resume</code></a> returns 0 if there are no errors running the coroutine,2940<a href="#lua_resume"><code>lua_resume</code></a> returns
2936or an error code (see <a href="#lua_pcall"><code>lua_pcall</code></a>).2941<a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields,
29420 if the coroutine finishes its execution
2943without errors,
2944or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>).
2937In case of errors,2945In case of errors,
2938the stack is not unwound,2946the stack is not unwound,
2939so you can use the debug API over it;2947so you can use the debug API over it;
@@ -2942,8 +2950,18 @@ To restart a coroutine, you put on its stack only the values to · 2 unmodified lines
2942be passed as results from <code>yield</code>,2950be passed as results from <code>yield</code>,
2943and then call <a href="#lua_resume"><code>lua_resume</code></a>.2951and then call <a href="#lua_resume"><code>lua_resume</code></a>.
2944 2952
2953<p><a name="lua_setallocf"></a>
2954<hr/><h3><code>lua_setallocf</code></h3>
2955<pre>
2956 void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
2957</pre>
2958
2959
2960<p>Changes the allocator function of a given state to <code>f</code>
2961with user data <code>ud</code>.
2962
2945<p><a name="lua_setfenv"></a>2963<p><a name="lua_setfenv"></a>
2946<hr><h3><code>lua_setfenv</code></h3>2964<hr/><h3><code>lua_setfenv</code></h3>
2947<pre>2965<pre>
2948 int lua_setfenv (lua_State *L, int index);2966 int lua_setfenv (lua_State *L, int index);
2949</pre>2967</pre>
@@ -2956,7 +2974,7 @@ neither a function nor a thread nor a userdata, · 6 unmodified lines
2956<a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0 (false).2974<a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0 (false).
2957 2975
2958<p><a name="lua_setfield"></a>2976<p><a name="lua_setfield"></a>
2959<hr><h3><code>lua_setfield</code></h3>2977<hr/><h3><code>lua_setfield</code></h3>
2960<pre>2978<pre>
2961 void lua_setfield (lua_State *L, int index, const char *k);2979 void lua_setfield (lua_State *L, int index, const char *k);
2962</pre>2980</pre>
@@ -2971,7 +2989,7 @@ As in Lua, this function may trigger a metamethod · 8 unmodified lines
2971for the "newindex" event (see <a href="#metatable">2.8</a>).2989for the "newindex" event (see <a href="#metatable">2.8</a>).
2972 2990
2973<p><a name="lua_setmetatable"></a>2991<p><a name="lua_setmetatable"></a>
2974<hr><h3><code>lua_setmetatable</code></h3>2992<hr/><h3><code>lua_setmetatable</code></h3>
2975<pre>2993<pre>
2976 int lua_setmetatable (lua_State *L, int index);2994 int lua_setmetatable (lua_State *L, int index);
2977</pre>2995</pre>
@@ -2982,7 +3000,7 @@ sets it as the new metatable for the value at the given · 4 unmodified lines
2982acceptable index.3000acceptable index.
2983 3001
2984<p><a name="lua_settable"></a>3002<p><a name="lua_settable"></a>
2985<hr><h3><code>lua_settable</code></h3>3003<hr/><h3><code>lua_settable</code></h3>
2986<pre>3004<pre>
2987 void lua_settable (lua_State *L, int index);3005 void lua_settable (lua_State *L, int index);
2988</pre>3006</pre>
@@ -2998,7 +3016,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines
2998for the "newindex" event (see <a href="#metatable">2.8</a>).3016for the "newindex" event (see <a href="#metatable">2.8</a>).
2999 3017
3000<p><a name="lua_settop"></a>3018<p><a name="lua_settop"></a>
3001<hr><h3><code>lua_settop</code></h3>3019<hr/><h3><code>lua_settop</code></h3>
3002<pre>3020<pre>
3003 void lua_settop (lua_State *L, int index);3021 void lua_settop (lua_State *L, int index);
3004</pre>3022</pre>
@@ -3007,11 +3025,11 @@ for the "newindex" event (see <a href="#metatable">2.8</a>). · 2 unmodified lines
3007<p>Accepts any acceptable index, or 0,3025<p>Accepts any acceptable index, or 0,
3008and sets the stack top to that index.3026and sets the stack top to that index.
3009If the new top is larger than the old one,3027If the new top is larger than the old one,
3010then the new elements are filled with <B>nil</B>.3028then the new elements are filled with <b>nil</b>.
3011If <code>index</code> is 0, then all stack elements are removed.3029If <code>index</code> is 0, then all stack elements are removed.
3012 3030
3013<p><a name="lua_State"></a>3031<p><a name="lua_State"></a>
3014<hr><h3><code>lua_State</code></h3>3032<hr/><h3><code>lua_State</code></h3>
3015<pre>3033<pre>
3016 typedef struct lua_State lua_State;3034 typedef struct lua_State lua_State;
3017</pre>3035</pre>
@@ -3027,7 +3045,7 @@ every function in the library, except to <a href="#lua_newstate"><code>lua_newst · 9 unmodified lines
3027which creates a Lua state from scratch.3045which creates a Lua state from scratch.
3028 3046
3029<p><a name="lua_toboolean"></a>3047<p><a name="lua_toboolean"></a>
3030<hr><h3><code>lua_toboolean</code></h3>3048<hr/><h3><code>lua_toboolean</code></h3>
3031<pre>3049<pre>
3032 int lua_toboolean (lua_State *L, int index);3050 int lua_toboolean (lua_State *L, int index);
3033</pre>3051</pre>
@@ -3037,14 +3055,14 @@ which creates a Lua state from scratch. · 3 unmodified lines
3037value ((0 or 1).3055value ((0 or 1).
3038Like all tests in Lua,3056Like all tests in Lua,
3039<a href="#lua_toboolean"><code>lua_toboolean</code></a> returns 1 for any Lua value3057<a href="#lua_toboolean"><code>lua_toboolean</code></a> returns 1 for any Lua value
3040different from <B>false</B> and <B>nil</B>;3058different from <b>false</b> and <b>nil</b>;
3041otherwise it returns 0.3059otherwise it returns 0.
3042It also returns 0 when called with a non-valid index.3060It also returns 0 when called with a non-valid index.
3043(If you want to accept only real boolean values,3061(If you want to accept only real boolean values,
3044use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)3062use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
3045 3063
3046<p><a name="lua_tocfunction"></a>3064<p><a name="lua_tocfunction"></a>
3047<hr><h3><code>lua_tocfunction</code></h3>3065<hr/><h3><code>lua_tocfunction</code></h3>
3048<pre>3066<pre>
3049 lua_CFunction lua_tocfunction (lua_State *L, int index);3067 lua_CFunction lua_tocfunction (lua_State *L, int index);
3050</pre>3068</pre>
@@ -3055,7 +3073,7 @@ That value must be a C function; · 4 unmodified lines
3055otherwise, returns <code>NULL</code>.3073otherwise, returns <code>NULL</code>.
3056 3074
3057<p><a name="lua_tointeger"></a>3075<p><a name="lua_tointeger"></a>
3058<hr><h3><code>lua_tointeger</code></h3>3076<hr/><h3><code>lua_tointeger</code></h3>
3059<pre>3077<pre>
3060 lua_Integer lua_tointeger (lua_State *L, int idx);3078 lua_Integer lua_tointeger (lua_State *L, int idx);
3061</pre>3079</pre>
@@ -3071,7 +3089,7 @@ otherwise, <a href="#lua_tointeger"><code>lua_tointeger</code></a> returns 0. · 9 unmodified lines
3071it is truncated in some non-specified way.3089it is truncated in some non-specified way.
3072 3090
3073<p><a name="lua_tolstring"></a>3091<p><a name="lua_tolstring"></a>
3074<hr><h3><code>lua_tolstring</code></h3>3092<hr/><h3><code>lua_tolstring</code></h3>
3075<pre>3093<pre>
3076 const char *lua_tolstring (lua_State *L, int index, size_t *len);3094 const char *lua_tolstring (lua_State *L, int index, size_t *len);
3077</pre>3095</pre>
@@ -3099,7 +3117,7 @@ there is no guarantee that the pointer returned by <a href="#lua_tolstring"><cod · 21 unmodified lines
3099will be valid after the corresponding value is removed from the stack.3117will be valid after the corresponding value is removed from the stack.
3100 3118
3101<p><a name="lua_tonumber"></a>3119<p><a name="lua_tonumber"></a>
3102<hr><h3><code>lua_tonumber</code></h3>3120<hr/><h3><code>lua_tonumber</code></h3>
3103<pre>3121<pre>
3104 lua_Number lua_tonumber (lua_State *L, int index);3122 lua_Number lua_tonumber (lua_State *L, int index);
3105</pre>3123</pre>
@@ -3112,7 +3130,7 @@ The Lua value must be a number or a string convertible to number · 6 unmodified lines
3112otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0.3130otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0.
3113 3131
3114<p><a name="lua_topointer"></a>3132<p><a name="lua_topointer"></a>
3115<hr><h3><code>lua_topointer</code></h3>3133<hr/><h3><code>lua_topointer</code></h3>
3116<pre>3134<pre>
3117 const void *lua_topointer (lua_State *L, int index);3135 const void *lua_topointer (lua_State *L, int index);
3118</pre>3136</pre>
@@ -3128,7 +3146,7 @@ There is no direct way to convert the pointer back to its original value. · 9 unmodified lines
3128<p>Typically this function is used for debug information.3146<p>Typically this function is used for debug information.
3129 3147
3130<p><a name="lua_tostring"></a>3148<p><a name="lua_tostring"></a>
3131<hr><h3><code>lua_tostring</code></h3>3149<hr/><h3><code>lua_tostring</code></h3>
3132<pre>3150<pre>
3133 const char *lua_tostring (lua_State *L, int index);3151 const char *lua_tostring (lua_State *L, int index);
3134</pre>3152</pre>
@@ -3137,7 +3155,7 @@ There is no direct way to convert the pointer back to its original value. · 2 unmodified lines
3137<p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.3155<p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.
3138 3156
3139<p><a name="lua_tothread"></a>3157<p><a name="lua_tothread"></a>
3140<hr><h3><code>lua_tothread</code></h3>3158<hr/><h3><code>lua_tothread</code></h3>
3141<pre>3159<pre>
3142 lua_State *lua_tothread (lua_State *L, int index);3160 lua_State *lua_tothread (lua_State *L, int index);
3143</pre>3161</pre>
@@ -3149,7 +3167,7 @@ This value must be a thread; · 5 unmodified lines
3149otherwise, the function returns <code>NULL</code>.3167otherwise, the function returns <code>NULL</code>.
3150 3168
3151<p><a name="lua_touserdata"></a>3169<p><a name="lua_touserdata"></a>
3152<hr><h3><code>lua_touserdata</code></h3>3170<hr/><h3><code>lua_touserdata</code></h3>
3153<pre>3171<pre>
3154 void *lua_touserdata (lua_State *L, int index);3172 void *lua_touserdata (lua_State *L, int index);
3155</pre>3173</pre>
@@ -3162,7 +3180,7 @@ returns its pointer. · 6 unmodified lines
3162Otherwise, returns <code>NULL</code>.3180Otherwise, returns <code>NULL</code>.
3163 3181
3164<p><a name="lua_type"></a>3182<p><a name="lua_type"></a>
3165<hr><h3><code>lua_type</code></h3>3183<hr/><h3><code>lua_type</code></h3>
3166<pre>3184<pre>
3167 int lua_type (lua_State *L, int index);3185 int lua_type (lua_State *L, int index);
3168</pre>3186</pre>
@@ -3184,7 +3202,7 @@ defined in <code>lua.h</code>: · 15 unmodified lines
3184<code>LUA_TLIGHTUSERDATA</code>.3202<code>LUA_TLIGHTUSERDATA</code>.
3185 3203
3186<p><a name="lua_Writer"></a>3204<p><a name="lua_Writer"></a>
3187<hr><h3><code>lua_Writer</code></h3>3205<hr/><h3><code>lua_Writer</code></h3>
3188<pre>3206<pre>
3189 typedef int (*lua_Writer)3207 typedef int (*lua_Writer)
3190 (lua_State *L, const void* p, size_t sz, void* ud);3208 (lua_State *L, const void* p, size_t sz, void* ud);
@@ -3205,7 +3223,7 @@ any other value means an error and stops <a href="#lua_dump"><code>lua_dump</cod · 14 unmodified lines
3205calling the writer again.3223calling the writer again.
3206 3224
3207<p><a name="lua_xmove"></a>3225<p><a name="lua_xmove"></a>
3208<hr><h3><code>lua_xmove</code></h3>3226<hr/><h3><code>lua_xmove</code></h3>
3209<pre>3227<pre>
3210 void lua_xmove (lua_State *from, lua_State *to, int n);3228 void lua_xmove (lua_State *from, lua_State *to, int n);
3211</pre>3229</pre>
@@ -3217,7 +3235,7 @@ calling the writer again. · 5 unmodified lines
3217and pushes them into the stack <code>to</code>.3235and pushes them into the stack <code>to</code>.
3218 3236
3219<p><a name="lua_yield"></a>3237<p><a name="lua_yield"></a>
3220<hr><h3><code>lua_yield</code></h3>3238<hr/><h3><code>lua_yield</code></h3>
3221<pre>3239<pre>
3222 int lua_yield (lua_State *L, int nresults);3240 int lua_yield (lua_State *L, int nresults);
3223</pre>3241</pre>
@@ -3227,9 +3245,9 @@ and pushes them into the stack <code>to</code>. · 3 unmodified lines
3227 3245
3228<p>This function can only be called as the3246<p>This function can only be called as the
3229return expression of a C function, as follows:3247return expression of a C function, as follows:
3230<PRE>3248<pre>
3231 return lua_yield (L, nresults);3249 return lua_yield (L, nresults);
3232</PRE>3250</pre>
3233When a C function calls <a href="#lua_yield"><code>lua_yield</code></a> in that way,3251When a C function calls <a href="#lua_yield"><code>lua_yield</code></a> in that way,
3234the running coroutine suspends its execution,3252the running coroutine suspends its execution,
3235and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns.3253and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns.
@@ -3247,7 +3265,7 @@ kinds of debuggers, profilers, and other tools · 11 unmodified lines
3247that need "inside information" from the interpreter.3265that need "inside information" from the interpreter.
3248 3266
3249<p><a name="lua_Debug"></a>3267<p><a name="lua_Debug"></a>
3250<hr><h3><code>lua_Debug</code></h3>3268<hr/><h3><code>lua_Debug</code></h3>
3251<pre>3269<pre>
3252 typedef struct lua_Debug {3270 typedef struct lua_Debug {
3253 int event;3271 int event;
@@ -3260,8 +3278,8 @@ that need "inside information" from the interpreter. · 6 unmodified lines
3260 int linedefined; /* (S) */3278 int linedefined; /* (S) */
3261 int lastlinedefined; /* (S) */3279 int lastlinedefined; /* (S) */
3262 char short_src[LUA_IDSIZE]; /* (S) */3280 char short_src[LUA_IDSIZE]; /* (S) */
3263 3281
3264<p> /* private part */3282 /* private part */
3265 ...3283 ...
3266 } lua_Debug;3284 } lua_Debug;
3267 3285
@@ -3329,7 +3347,7 @@ The number of upvalues of the function. · 61 unmodified lines
3329<p></ul>3347<p></ul>
3330 3348
3331<p><a name="lua_gethook"></a>3349<p><a name="lua_gethook"></a>
3332<hr><h3><code>lua_gethook</code></h3>3350<hr/><h3><code>lua_gethook</code></h3>
3333<pre>3351<pre>
3334 lua_Hook lua_gethook (lua_State *L);3352 lua_Hook lua_gethook (lua_State *L);
3335</pre>3353</pre>
@@ -3338,7 +3356,7 @@ The number of upvalues of the function. · 2 unmodified lines
3338<p>Returns the current hook function.3356<p>Returns the current hook function.
3339 3357
3340<p><a name="lua_gethookcount"></a>3358<p><a name="lua_gethookcount"></a>
3341<hr><h3><code>lua_gethookcount</code></h3>3359<hr/><h3><code>lua_gethookcount</code></h3>
3342<pre>3360<pre>
3343 int lua_gethookcount (lua_State *L);3361 int lua_gethookcount (lua_State *L);
3344</pre>3362</pre>
@@ -3347,7 +3365,7 @@ The number of upvalues of the function. · 2 unmodified lines
3347<p>Returns the current hook count.3365<p>Returns the current hook count.
3348 3366
3349<p><a name="lua_gethookmask"></a>3367<p><a name="lua_gethookmask"></a>
3350<hr><h3><code>lua_gethookmask</code></h3>3368<hr/><h3><code>lua_gethookmask</code></h3>
3351<pre>3369<pre>
3352 int lua_gethookmask (lua_State *L);3370 int lua_gethookmask (lua_State *L);
3353</pre>3371</pre>
@@ -3356,7 +3374,7 @@ The number of upvalues of the function. · 2 unmodified lines
3356<p>Returns the current hook mask.3374<p>Returns the current hook mask.
3357 3375
3358<p><a name="lua_getinfo"></a>3376<p><a name="lua_getinfo"></a>
3359<hr><h3><code>lua_getinfo</code></h3>3377<hr/><h3><code>lua_getinfo</code></h3>
3360<pre>3378<pre>
3361 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);3379 int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
3362</pre>3380</pre>
@@ -3382,15 +3400,15 @@ you push it onto the stack · 19 unmodified lines
3382and start the <code>what</code> string with the character `<code>></code>&acute;.3400and start the <code>what</code> string with the character `<code>></code>&acute;.
3383For instance, to know in which line a function <code>f</code> was defined,3401For instance, to know in which line a function <code>f</code> was defined,
3384you can write the following code:3402you can write the following code:
3385<PRE>3403<pre>
3386 lua_Debug ar;3404 lua_Debug ar;
3387 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global `f' */3405 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global `f' */
3388 lua_getinfo(L, ">S", &#038;ar);3406 lua_getinfo(L, ">S", &#038;ar);
3389 printf("%d\n", ar.linedefined);3407 printf("%d\n", ar.linedefined);
3390</PRE>3408</pre>
3391 3409
3392<p><a name="lua_getlocal"></a>3410<p><a name="lua_getlocal"></a>
3393<hr><h3><code>lua_getlocal</code></h3>3411<hr/><h3><code>lua_getlocal</code></h3>
3394<pre>3412<pre>
3395 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);3413 const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
3396</pre>3414</pre>
@@ -3406,12 +3424,16 @@ until the last active local variable). · 9 unmodified lines
3406<a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack,3424<a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack,
3407and returns its name.3425and returns its name.
3408 3426
3427<p>Variable names starting with `<code>(</code>&acute; (open parentheses)
3428represent internal variables
3429(loop control variables, temporaries, and C function locals).
3430
3409<p>Returns <code>NULL</code> (and pushes nothing)3431<p>Returns <code>NULL</code> (and pushes nothing)
3410when the index is greater than3432when the index is greater than
3411the number of active local variables.3433the number of active local variables.
3412 3434
3413<p><a name="lua_getstack"></a>3435<p><a name="lua_getstack"></a>
3414<hr><h3><code>lua_getstack</code></h3>3436<hr/><h3><code>lua_getstack</code></h3>
3415<pre>3437<pre>
3416 int lua_getstack (lua_State *L, int level, lua_Debug *ar);3438 int lua_getstack (lua_State *L, int level, lua_Debug *ar);
3417</pre>3439</pre>
@@ -3429,7 +3451,7 @@ when called with a level greater than the stack depth, · 11 unmodified lines
3429it returns 0.3451it returns 0.
3430 3452
3431<p><a name="lua_getupvalue"></a>3453<p><a name="lua_getupvalue"></a>
3432<hr><h3><code>lua_getupvalue</code></h3>3454<hr/><h3><code>lua_getupvalue</code></h3>
3433<pre>3455<pre>
3434 const char *lua_getupvalue (lua_State *L, int funcindex, int n);3456 const char *lua_getupvalue (lua_State *L, int funcindex, int n);
3435</pre>3457</pre>
@@ -3452,7 +3474,7 @@ For C functions, this function uses the empty string <code>""</code> · 16 unmodified lines
3452as a name for all upvalues.3474as a name for all upvalues.
3453 3475
3454<p><a name="lua_Hook"></a>3476<p><a name="lua_Hook"></a>
3455<hr><h3><code>lua_Hook</code></h3>3477<hr/><h3><code>lua_Hook</code></h3>
3456<pre>3478<pre>
3457 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);3479 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
3458</pre>3480</pre>
@@ -3480,7 +3502,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 21 unmodified lines
3480that execution occurs without any calls to hooks.3502that execution occurs without any calls to hooks.
3481 3503
3482<p><a name="lua_sethook"></a>3504<p><a name="lua_sethook"></a>
3483<hr><h3><code>lua_sethook</code></h3>3505<hr/><h3><code>lua_sethook</code></h3>
3484<pre>3506<pre>
3485 int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);3507 int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
3486</pre>3508</pre>
@@ -3515,7 +3537,7 @@ or when it jumps back in the code (even to the same line). · 28 unmodified lines
3515<p>A hook is disabled by setting <code>mask</code> to zero.3537<p>A hook is disabled by setting <code>mask</code> to zero.
3516 3538
3517<p><a name="lua_setlocal"></a>3539<p><a name="lua_setlocal"></a>
3518<hr><h3><code>lua_setlocal</code></h3>3540<hr/><h3><code>lua_setlocal</code></h3>
3519<pre>3541<pre>
3520 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);3542 const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
3521</pre>3543</pre>
@@ -3533,7 +3555,7 @@ when the index is greater than · 11 unmodified lines
3533the number of active local variables.3555the number of active local variables.
3534 3556
3535<p><a name="lua_setupvalue"></a>3557<p><a name="lua_setupvalue"></a>
3536<hr><h3><code>lua_setupvalue</code></h3>3558<hr/><h3><code>lua_setupvalue</code></h3>
3537<pre>3559<pre>
3538 const char *lua_setupvalue (lua_State *L, int funcindex, int n);3560 const char *lua_setupvalue (lua_State *L, int funcindex, int n);
3539</pre>3561</pre>
@@ -3582,7 +3604,7 @@ you should not use those functions for other stack values. · 42 unmodified lines
3582in alphabetical order.3604in alphabetical order.
3583 3605
3584<p><a name="luaL_addchar"></a>3606<p><a name="luaL_addchar"></a>
3585<hr><h3><code>luaL_addchar</code></h3>3607<hr/><h3><code>luaL_addchar</code></h3>
3586<pre>3608<pre>
3587 void luaL_addchar (luaL_Buffer B, char c);3609 void luaL_addchar (luaL_Buffer B, char c);
3588</pre>3610</pre>
@@ -3592,7 +3614,7 @@ in alphabetical order. · 3 unmodified lines
3592(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3614(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3593 3615
3594<p><a name="luaL_addlstring"></a>3616<p><a name="luaL_addlstring"></a>
3595<hr><h3><code>luaL_addlstring</code></h3>3617<hr/><h3><code>luaL_addlstring</code></h3>
3596<pre>3618<pre>
3597 void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);3619 void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
3598</pre>3620</pre>
@@ -3603,7 +3625,7 @@ the buffer <code>B</code> · 4 unmodified lines
3603(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3625(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3604 3626
3605<p><a name="luaL_addsize"></a>3627<p><a name="luaL_addsize"></a>
3606<hr><h3><code>luaL_addsize</code></h3>3628<hr/><h3><code>luaL_addsize</code></h3>
3607<pre>3629<pre>
3608 void luaL_addsize (luaL_Buffer B, size_t n);3630 void luaL_addsize (luaL_Buffer B, size_t n);
3609</pre>3631</pre>
@@ -3614,7 +3636,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 4 unmodified lines
3614(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3636(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3615 3637
3616<p><a name="luaL_addstring"></a>3638<p><a name="luaL_addstring"></a>
3617<hr><h3><code>luaL_addstring</code></h3>3639<hr/><h3><code>luaL_addstring</code></h3>
3618<pre>3640<pre>
3619 void luaL_addstring (luaL_Buffer *B, const char *s);3641 void luaL_addstring (luaL_Buffer *B, const char *s);
3620</pre>3642</pre>
@@ -3625,7 +3647,7 @@ to the buffer <code>B</code> · 4 unmodified lines
3625(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3647(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3626 3648
3627<p><a name="luaL_addvalue"></a>3649<p><a name="luaL_addvalue"></a>
3628<hr><h3><code>luaL_addvalue</code></h3>3650<hr/><h3><code>luaL_addvalue</code></h3>
3629<pre>3651<pre>
3630 void luaL_addvalue (luaL_Buffer *B);3652 void luaL_addvalue (luaL_Buffer *B);
3631</pre>3653</pre>
@@ -3641,7 +3663,7 @@ be called with an extra element on the stack, · 9 unmodified lines
3641which is the value to be added to the buffer.3663which is the value to be added to the buffer.
3642 3664
3643<p><a name="luaL_argcheck"></a>3665<p><a name="luaL_argcheck"></a>
3644<hr><h3><code>luaL_argcheck</code></h3>3666<hr/><h3><code>luaL_argcheck</code></h3>
3645<pre>3667<pre>
3646 void luaL_argcheck (lua_State *L, int cond, int numarg,3668 void luaL_argcheck (lua_State *L, int cond, int numarg,
3647 const char *extramsg);3669 const char *extramsg);
@@ -3654,7 +3676,7 @@ If not, raise an error with message · 6 unmodified lines
3654where <code>func</code> is retrieved from the call stack.3676where <code>func</code> is retrieved from the call stack.
3655 3677
3656<p><a name="luaL_argerror"></a>3678<p><a name="luaL_argerror"></a>
3657<hr><h3><code>luaL_argerror</code></h3>3679<hr/><h3><code>luaL_argerror</code></h3>
3658<pre>3680<pre>
3659 int luaL_argerror (lua_State *L, int numarg, const char *extramsg);3681 int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
3660</pre>3682</pre>
@@ -3667,7 +3689,7 @@ where <code>func</code> is retrieved from the call stack. · 6 unmodified lines
3667<p>This function never returns.3689<p>This function never returns.
3668 3690
3669<p><a name="luaL_Buffer"></a>3691<p><a name="luaL_Buffer"></a>
3670<hr><h3><code>luaL_Buffer</code></h3>3692<hr/><h3><code>luaL_Buffer</code></h3>
3671<pre>3693<pre>
3672 typedef struct luaL_Buffer luaL_Buffer;3694 typedef struct luaL_Buffer luaL_Buffer;
3673</pre>3695</pre>
@@ -3700,7 +3722,7 @@ level when the buffer was initialized, · 26 unmodified lines
3700plus the final string on its top.3722plus the final string on its top.
3701 3723
3702<p><a name="luaL_buffinit"></a>3724<p><a name="luaL_buffinit"></a>
3703<hr><h3><code>luaL_buffinit</code></h3>3725<hr/><h3><code>luaL_buffinit</code></h3>
3704<pre>3726<pre>
3705 void luaL_buffinit (lua_State *L, luaL_Buffer *B);3727 void luaL_buffinit (lua_State *L, luaL_Buffer *B);
3706</pre>3728</pre>
@@ -3712,7 +3734,7 @@ the buffer must be declared as a variable · 5 unmodified lines
3712(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).3734(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
3713 3735
3714<p><a name="luaL_callmeta"></a>3736<p><a name="luaL_callmeta"></a>
3715<hr><h3><code>luaL_callmeta</code></h3>3737<hr/><h3><code>luaL_callmeta</code></h3>
3716<pre>3738<pre>
3717 int luaL_callmeta (lua_State *L, int obj, const char *e);3739 int luaL_callmeta (lua_State *L, int obj, const char *e);
3718</pre>3740</pre>
@@ -3729,7 +3751,7 @@ If there is no metatable or no metamethod returns 0 · 10 unmodified lines
3729(without pushing any value on the stack).3751(without pushing any value on the stack).
3730 3752
3731<p><a name="luaL_checkany"></a>3753<p><a name="luaL_checkany"></a>
3732<hr><h3><code>luaL_checkany</code></h3>3754<hr/><h3><code>luaL_checkany</code></h3>
3733<pre>3755<pre>
3734 void luaL_checkany (lua_State *L, int narg);3756 void luaL_checkany (lua_State *L, int narg);
3735</pre>3757</pre>
@@ -3738,7 +3760,7 @@ If there is no metatable or no metamethod returns 0 · 2 unmodified lines
3738<p>Checks whether the function has an argument <code>narg</code>.3760<p>Checks whether the function has an argument <code>narg</code>.
3739 3761
3740<p><a name="luaL_checkint"></a>3762<p><a name="luaL_checkint"></a>
3741<hr><h3><code>luaL_checkint</code></h3>3763<hr/><h3><code>luaL_checkint</code></h3>
3742<pre>3764<pre>
3743 int luaL_checkint (lua_State *L, int narg);3765 int luaL_checkint (lua_State *L, int narg);
3744</pre>3766</pre>
@@ -3748,7 +3770,7 @@ If there is no metatable or no metamethod returns 0 · 3 unmodified lines
3748and returns that number casted to an <code>int</code>.3770and returns that number casted to an <code>int</code>.
3749 3771
3750<p><a name="luaL_checkinteger"></a>3772<p><a name="luaL_checkinteger"></a>
3751<hr><h3><code>luaL_checkinteger</code></h3>3773<hr/><h3><code>luaL_checkinteger</code></h3>
3752<pre>3774<pre>
3753 lua_Integer luaL_checkinteger (lua_State *L, int numArg);3775 lua_Integer luaL_checkinteger (lua_State *L, int numArg);
3754</pre>3776</pre>
@@ -3758,7 +3780,7 @@ and returns that number casted to an <code>int</code>. · 3 unmodified lines
3758and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.3780and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
3759 3781
3760<p><a name="luaL_checklong"></a>3782<p><a name="luaL_checklong"></a>
3761<hr><h3><code>luaL_checklong</code></h3>3783<hr/><h3><code>luaL_checklong</code></h3>
3762<pre>3784<pre>
3763 long luaL_checklong (lua_State *L, int narg);3785 long luaL_checklong (lua_State *L, int narg);
3764</pre>3786</pre>
@@ -3768,7 +3790,7 @@ and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</co · 3 unmodified lines
3768and returns that number casted to a <code>long</code>.3790and returns that number casted to a <code>long</code>.
3769 3791
3770<p><a name="luaL_checklstring"></a>3792<p><a name="luaL_checklstring"></a>
3771<hr><h3><code>luaL_checklstring</code></h3>3793<hr/><h3><code>luaL_checklstring</code></h3>
3772<pre>3794<pre>
3773 const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);3795 const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);
3774</pre>3796</pre>
@@ -3780,7 +3802,7 @@ if <code>l</code> is not <code>NULL</code> fills the position <code>*l</code> · 5 unmodified lines
3780with the string's length.3802with the string's length.
3781 3803
3782<p><a name="luaL_checknumber"></a>3804<p><a name="luaL_checknumber"></a>
3783<hr><h3><code>luaL_checknumber</code></h3>3805<hr/><h3><code>luaL_checknumber</code></h3>
3784<pre>3806<pre>
3785 lua_Number luaL_checknumber (lua_State *L, int numArg);3807 lua_Number luaL_checknumber (lua_State *L, int numArg);
3786</pre>3808</pre>
@@ -3790,7 +3812,7 @@ with the string's length. · 3 unmodified lines
3790and returns that number.3812and returns that number.
3791 3813
3792<p><a name="luaL_checkoption"></a>3814<p><a name="luaL_checkoption"></a>
3793<hr><h3><code>luaL_checkoption</code></h3>3815<hr/><h3><code>luaL_checkoption</code></h3>
3794<pre>3816<pre>
3795 int luaL_checkoption (lua_State *L, int narg, const char *def,3817 int luaL_checkoption (lua_State *L, int narg, const char *def,
3796 const char *const lst[]);3818 const char *const lst[]);
@@ -3802,14 +3824,14 @@ searches for that string into the array <code>lst</code> · 5 unmodified lines
3802(which must be NULL-terminated).3824(which must be NULL-terminated).
3803If <code>def</code> is not <code>NULL</code>,3825If <code>def</code> is not <code>NULL</code>,
3804uses <code>def</code> as a default value when3826uses <code>def</code> as a default value when
3805the function has no argument <code>narg</code> or if that argument is <B>nil</B>.3827the function has no argument <code>narg</code> or if that argument is <b>nil</b>.
3806 3828
3807<p>Returns the index in the array where the string was found.3829<p>Returns the index in the array where the string was found.
3808Raises an error if the argument is not a string or3830Raises an error if the argument is not a string or
3809if the string cannot be found.3831if the string cannot be found.
3810 3832
3811<p><a name="luaL_checkstack"></a>3833<p><a name="luaL_checkstack"></a>
3812<hr><h3><code>luaL_checkstack</code></h3>3834<hr/><h3><code>luaL_checkstack</code></h3>
3813<pre>3835<pre>
3814 void luaL_checkstack (lua_State *L, int sz, const char *msg);3836 void luaL_checkstack (lua_State *L, int sz, const char *msg);
3815</pre>3837</pre>
@@ -3820,7 +3842,7 @@ raising an error if the stack cannot grow to that size. · 4 unmodified lines
3820<code>msg</code> is an additional text to go into the error message.3842<code>msg</code> is an additional text to go into the error message.
3821 3843
3822<p><a name="luaL_checkstring"></a>3844<p><a name="luaL_checkstring"></a>
3823<hr><h3><code>luaL_checkstring</code></h3>3845<hr/><h3><code>luaL_checkstring</code></h3>
3824<pre>3846<pre>
3825 const char *luaL_checkstring (lua_State *L, int narg);3847 const char *luaL_checkstring (lua_State *L, int narg);
3826</pre>3848</pre>
@@ -3830,7 +3852,7 @@ raising an error if the stack cannot grow to that size. · 3 unmodified lines
3830and returns that string.3852and returns that string.
3831 3853
3832<p><a name="luaL_checktype"></a>3854<p><a name="luaL_checktype"></a>
3833<hr><h3><code>luaL_checktype</code></h3>3855<hr/><h3><code>luaL_checktype</code></h3>
3834<pre>3856<pre>
3835 void luaL_checktype (lua_State *L, int narg, int t);3857 void luaL_checktype (lua_State *L, int narg, int t);
3836</pre>3858</pre>
@@ -3839,7 +3861,7 @@ and returns that string. · 2 unmodified lines
3839<p>Checks whether the function argument <code>narg</code> has type <code>t</code>.3861<p>Checks whether the function argument <code>narg</code> has type <code>t</code>.
3840 3862
3841<p><a name="luaL_checkudata"></a>3863<p><a name="luaL_checkudata"></a>
3842<hr><h3><code>luaL_checkudata</code></h3>3864<hr/><h3><code>luaL_checkudata</code></h3>
3843<pre>3865<pre>
3844 void *luaL_checkudata (lua_State *L, int ud, const char *tname);3866 void *luaL_checkudata (lua_State *L, int ud, const char *tname);
3845</pre>3867</pre>
@@ -3849,7 +3871,7 @@ and returns that string. · 3 unmodified lines
3849of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).3871of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
3850 3872
3851<p><a name="luaL_error"></a>3873<p><a name="luaL_error"></a>
3852<hr><h3><code>luaL_error</code></h3>3874<hr/><h3><code>luaL_error</code></h3>
3853<pre>3875<pre>
3854 int luaL_error (lua_State *L, const char *fmt, ...);3876 int luaL_error (lua_State *L, const char *fmt, ...);
3855</pre>3877</pre>
@@ -3866,7 +3888,7 @@ if that information is available. · 10 unmodified lines
3866<p>This function never returns.3888<p>This function never returns.
3867 3889
3868<p><a name="luaL_getmetafield"></a>3890<p><a name="luaL_getmetafield"></a>
3869<hr><h3><code>luaL_getmetafield</code></h3>3891<hr/><h3><code>luaL_getmetafield</code></h3>
3870<pre>3892<pre>
3871 int luaL_getmetafield (lua_State *L, int obj, const char *e);3893 int luaL_getmetafield (lua_State *L, int obj, const char *e);
3872</pre>3894</pre>
@@ -3879,7 +3901,7 @@ or if the metatable does not have that field, · 6 unmodified lines
3879returns 0 (false) and pushes nothing.3901returns 0 (false) and pushes nothing.
3880 3902
3881<p><a name="luaL_getmetatable"></a>3903<p><a name="luaL_getmetatable"></a>
3882<hr><h3><code>luaL_getmetatable</code></h3>3904<hr/><h3><code>luaL_getmetatable</code></h3>
3883<pre>3905<pre>
3884 void luaL_getmetatable (lua_State *L, const char *tname);3906 void luaL_getmetatable (lua_State *L, const char *tname);
3885</pre>3907</pre>
@@ -3889,7 +3911,7 @@ returns 0 (false) and pushes nothing. · 3 unmodified lines
3889in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).3911in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
3890 3912
3891<p><a name="luaL_gsub"></a>3913<p><a name="luaL_gsub"></a>
3892<hr><h3><code>luaL_gsub</code></h3>3914<hr/><h3><code>luaL_gsub</code></h3>
3893<pre>3915<pre>
3894 const char *luaL_gsub (lua_State *L, const char *s,3916 const char *luaL_gsub (lua_State *L, const char *s,
3895 const char *p, const char *r);3917 const char *p, const char *r);
@@ -3901,7 +3923,7 @@ by the string <code>r</code>. · 5 unmodified lines
3901Pushes the resulting string on the stack and returns it.3923Pushes the resulting string on the stack and returns it.
3902 3924
3903<p><a name="luaL_loadbuffer"></a>3925<p><a name="luaL_loadbuffer"></a>
3904<hr><h3><code>luaL_loadbuffer</code></h3>3926<hr/><h3><code>luaL_loadbuffer</code></h3>
3905<pre>3927<pre>
3906 int luaL_loadbuffer (lua_State *L, const char *buff,3928 int luaL_loadbuffer (lua_State *L, const char *buff,
3907 size_t sz, const char *name);3929 size_t sz, const char *name);
@@ -3917,7 +3939,7 @@ buffer pointed by <code>buff</code> with size <code>sz</code>. · 9 unmodified lines
3917used for debug information and error messages.3939used for debug information and error messages.
3918 3940
3919<p><a name="luaL_loadfile"></a>3941<p><a name="luaL_loadfile"></a>
3920<hr><h3><code>luaL_loadfile</code></h3>3942<hr/><h3><code>luaL_loadfile</code></h3>
3921<pre>3943<pre>
3922 int luaL_loadfile (lua_State *L, const char *filename);3944 int luaL_loadfile (lua_State *L, const char *filename);
3923</pre>3945</pre>
@@ -3933,7 +3955,7 @@ but it has an extra error code <code>LUA_ERRFILE</code> · 9 unmodified lines
3933if it cannot open the file.3955if it cannot open the file.
3934 3956
3935<p><a name="luaL_loadstring"></a>3957<p><a name="luaL_loadstring"></a>
3936<hr><h3><code>luaL_loadstring</code></h3>3958<hr/><h3><code>luaL_loadstring</code></h3>
3937<pre>3959<pre>
3938 int luaL_loadstring (lua_State *L, const char *s);3960 int luaL_loadstring (lua_State *L, const char *s);
3939</pre>3961</pre>
@@ -3946,7 +3968,7 @@ the zero-terminated string <code>s</code>. · 6 unmodified lines
3946<p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.3968<p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
3947 3969
3948<p><a name="luaL_newmetatable"></a>3970<p><a name="luaL_newmetatable"></a>
3949<hr><h3><code>luaL_newmetatable</code></h3>3971<hr/><h3><code>luaL_newmetatable</code></h3>
3950<pre>3972<pre>
3951 int luaL_newmetatable (lua_State *L, const char *tname);3973 int luaL_newmetatable (lua_State *L, const char *tname);
3952</pre>3974</pre>
@@ -3963,7 +3985,7 @@ and returns 1. · 10 unmodified lines
3963with <code>"tname"</code> in the registry.3985with <code>"tname"</code> in the registry.
3964 3986
3965<p><a name="luaL_newstate"></a>3987<p><a name="luaL_newstate"></a>
3966<hr><h3><code>luaL_newstate</code></h3>3988<hr/><h3><code>luaL_newstate</code></h3>
3967<pre>3989<pre>
3968 lua_State *luaL_newstate (void);3990 lua_State *luaL_newstate (void);
3969</pre>3991</pre>
@@ -3979,7 +4001,7 @@ errors. · 9 unmodified lines
3979or <code>NULL</code> if there is a memory allocation error.4001or <code>NULL</code> if there is a memory allocation error.
3980 4002
3981<p><a name="luaL_optint"></a>4003<p><a name="luaL_optint"></a>
3982<hr><h3><code>luaL_optint</code></h3>4004<hr/><h3><code>luaL_optint</code></h3>
3983<pre>4005<pre>
3984 int luaL_optint (lua_State *L, int narg, int d);4006 int luaL_optint (lua_State *L, int narg, int d);
3985</pre>4007</pre>
@@ -3987,12 +4009,12 @@ or <code>NULL</code> if there is a memory allocation error. · 1 unmodified line
3987 4009
3988<p>If the function argument <code>narg</code> is a number,4010<p>If the function argument <code>narg</code> is a number,
3989returns that number casted to an <code>int</code>.4011returns that number casted to an <code>int</code>.
3990If that argument is absent or is <B>nil</B>,4012If that argument is absent or is <b>nil</b>,
3991returns <code>d</code>.4013returns <code>d</code>.
3992Otherwise, raise an error.4014Otherwise, raise an error.
3993 4015
3994<p><a name="luaL_optinteger"></a>4016<p><a name="luaL_optinteger"></a>
3995<hr><h3><code>luaL_optinteger</code></h3>4017<hr/><h3><code>luaL_optinteger</code></h3>
3996<pre>4018<pre>
3997 lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d);4019 lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d);
3998</pre>4020</pre>
@@ -4000,12 +4022,12 @@ Otherwise, raise an error. · 1 unmodified line
4000 4022
4001<p>If the function argument <code>narg</code> is a number,4023<p>If the function argument <code>narg</code> is a number,
4002returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.4024returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
4003If that argument is absent or is <B>nil</B>,4025If that argument is absent or is <b>nil</b>,
4004returns <code>d</code>.4026returns <code>d</code>.
4005Otherwise, raise an error.4027Otherwise, raise an error.
4006 4028
4007<p><a name="luaL_optlong"></a>4029<p><a name="luaL_optlong"></a>
4008<hr><h3><code>luaL_optlong</code></h3>4030<hr/><h3><code>luaL_optlong</code></h3>
4009<pre>4031<pre>
4010 long luaL_optlong (lua_State *L, int narg, long d);4032 long luaL_optlong (lua_State *L, int narg, long d);
4011</pre>4033</pre>
@@ -4013,12 +4035,12 @@ Otherwise, raise an error. · 1 unmodified line
4013 4035
4014<p>If the function argument <code>narg</code> is a number,4036<p>If the function argument <code>narg</code> is a number,
4015returns that number casted to a <code>long</code>.4037returns that number casted to a <code>long</code>.
4016If that argument is absent or is <B>nil</B>,4038If that argument is absent or is <b>nil</b>,
4017returns <code>d</code>.4039returns <code>d</code>.
4018Otherwise, raise an error.4040Otherwise, raise an error.
4019 4041
4020<p><a name="luaL_optlstring"></a>4042<p><a name="luaL_optlstring"></a>
4021<hr><h3><code>luaL_optlstring</code></h3>4043<hr/><h3><code>luaL_optlstring</code></h3>
4022<pre>4044<pre>
4023 const char *luaL_optlstring (lua_State *L, int numArg,4045 const char *luaL_optlstring (lua_State *L, int numArg,
4024 const char *d, size_t *l);4046 const char *d, size_t *l);
@@ -4027,7 +4049,7 @@ Otherwise, raise an error. · 2 unmodified lines
4027 4049
4028<p>If the function argument <code>narg</code> is a string,4050<p>If the function argument <code>narg</code> is a string,
4029returns that string.4051returns that string.
4030If that argument is absent or is <B>nil</B>,4052If that argument is absent or is <b>nil</b>,
4031returns <code>d</code>.4053returns <code>d</code>.
4032Otherwise, raise an error.4054Otherwise, raise an error.
4033 4055
@@ -4035,7 +4057,7 @@ Otherwise, raise an error. · 1 unmodified line
4035with the results's length.4057with the results's length.
4036 4058
4037<p><a name="luaL_optnumber"></a>4059<p><a name="luaL_optnumber"></a>
4038<hr><h3><code>luaL_optnumber</code></h3>4060<hr/><h3><code>luaL_optnumber</code></h3>
4039<pre>4061<pre>
4040 lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d);4062 lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d);
4041</pre>4063</pre>
@@ -4043,12 +4065,12 @@ with the results's length. · 1 unmodified line
4043 4065
4044<p>If the function argument <code>narg</code> is a number,4066<p>If the function argument <code>narg</code> is a number,
4045returns that number.4067returns that number.
4046If that argument is absent or is <B>nil</B>,4068If that argument is absent or is <b>nil</b>,
4047returns <code>d</code>.4069returns <code>d</code>.
4048Otherwise, raise an error.4070Otherwise, raise an error.
4049 4071
4050<p><a name="luaL_optstring"></a>4072<p><a name="luaL_optstring"></a>
4051<hr><h3><code>luaL_optstring</code></h3>4073<hr/><h3><code>luaL_optstring</code></h3>
4052<pre>4074<pre>
4053 const char *luaL_optstring (lua_State *L, int narg, const char *d);4075 const char *luaL_optstring (lua_State *L, int narg, const char *d);
4054</pre>4076</pre>
@@ -4056,12 +4078,12 @@ Otherwise, raise an error. · 1 unmodified line
4056 4078
4057<p>If the function argument <code>narg</code> is a string,4079<p>If the function argument <code>narg</code> is a string,
4058returns that string.4080returns that string.
4059If that argument is absent or is <B>nil</B>,4081If that argument is absent or is <b>nil</b>,
4060returns <code>d</code>.4082returns <code>d</code>.
4061Otherwise, raise an error.4083Otherwise, raise an error.
4062 4084
4063<p><a name="luaL_prepbuffer"></a>4085<p><a name="luaL_prepbuffer"></a>
4064<hr><h3><code>luaL_prepbuffer</code></h3>4086<hr/><h3><code>luaL_prepbuffer</code></h3>
4065<pre>4087<pre>
4066 char *luaL_prepbuffer (luaL_Buffer *B);4088 char *luaL_prepbuffer (luaL_Buffer *B);
4067</pre>4089</pre>
@@ -4075,7 +4097,7 @@ After copying the string into that space you must call · 7 unmodified lines
4075it to the buffer.4097it to the buffer.
4076 4098
4077<p><a name="luaL_pushresult"></a>4099<p><a name="luaL_pushresult"></a>
4078<hr><h3><code>luaL_pushresult</code></h3>4100<hr/><h3><code>luaL_pushresult</code></h3>
4079<pre>4101<pre>
4080 void luaL_pushresult (luaL_Buffer *B);4102 void luaL_pushresult (luaL_Buffer *B);
4081</pre>4103</pre>
@@ -4085,7 +4107,7 @@ it to the buffer. · 3 unmodified lines
4085the top of the stack.4107the top of the stack.
4086 4108
4087<p><a name="luaL_ref"></a>4109<p><a name="luaL_ref"></a>
4088<hr><h3><code>luaL_ref</code></h3>4110<hr/><h3><code>luaL_ref</code></h3>
4089<pre>4111<pre>
4090 int luaL_ref (lua_State *L, int t);4112 int luaL_ref (lua_State *L, int t);
4091</pre>4113</pre>
@@ -4102,13 +4124,13 @@ You can retrieve an object referred by reference <code>r</code> · 10 unmodified lines
4102calling <code>lua_rawgeti(L, t, r)</code>.4124calling <code>lua_rawgeti(L, t, r)</code>.
4103Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.4125Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.
4104 4126
4105<p>Whenever the object at the top of the stack is <B>nil</B>,4127<p>Whenever the object at the top of the stack is <b>nil</b>,
4106<a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>.4128<a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>.
4107The constant <code>LUA_NOREF</code> is garanteed to be different4129The constant <code>LUA_NOREF</code> is garanteed to be different
4108from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.4130from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
4109 4131
4110<p><a name="luaL_Reg"></a>4132<p><a name="luaL_Reg"></a>
4111<hr><h3><code>luaL_Reg</code></h3>4133<hr/><h3><code>luaL_Reg</code></h3>
4112<pre>4134<pre>
4113 typedef struct luaL_Reg {4135 typedef struct luaL_Reg {
4114 const char *name;4136 const char *name;
@@ -4126,7 +4148,7 @@ Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sent · 11 unmodified lines
4126wherein both <code>name</code> and <code>func</code> are <code>NULL</code>.4148wherein both <code>name</code> and <code>func</code> are <code>NULL</code>.
4127 4149
4128<p><a name="luaL_register"></a>4150<p><a name="luaL_register"></a>
4129<hr><h3><code>luaL_register</code></h3>4151<hr/><h3><code>luaL_register</code></h3>
4130<pre>4152<pre>
4131 void luaL_register (lua_State *L, const char *libname,4153 void luaL_register (lua_State *L, const char *libname,
4132 const luaL_Reg *l);4154 const luaL_Reg *l);
@@ -4152,7 +4174,7 @@ reuses that table instead of creating a new one. · 19 unmodified lines
4152on the top of the stack.4174on the top of the stack.
4153 4175
4154<p><a name="luaL_typename"></a>4176<p><a name="luaL_typename"></a>
4155<hr><h3><code>luaL_typename</code></h3>4177<hr/><h3><code>luaL_typename</code></h3>
4156<pre>4178<pre>
4157 const char *luaL_typename (lua_State *L, int idx);4179 const char *luaL_typename (lua_State *L, int idx);
4158</pre>4180</pre>
@@ -4161,22 +4183,22 @@ on the top of the stack. · 2 unmodified lines
4161<p>Returns the name of the type of the value at index <code>idx</code>.4183<p>Returns the name of the type of the value at index <code>idx</code>.
4162 4184
4163<p><a name="luaL_typerror"></a>4185<p><a name="luaL_typerror"></a>
4164<hr><h3><code>luaL_typerror</code></h3>4186<hr/><h3><code>luaL_typerror</code></h3>
4165<pre>4187<pre>
4166 int luaL_typerror (lua_State *L, int narg, const char *tname);4188 int luaL_typerror (lua_State *L, int narg, const char *tname);
4167</pre>4189</pre>
4168 4190
4169 4191
4170<p>Generates an error with a message like4192<p>Generates an error with a message like
4171<PRE>4193<pre>
4172&#060;location>: bad argument &#060;narg> to &#060;function> (&#060;tname> expected, got &#060;realt>)4194&#060;location>: bad argument &#060;narg> to &#060;function> (&#060;tname> expected, got &#060;realt>)
4173</PRE>4195</pre>
4174where <code>&#060;location></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,4196where <code>&#060;location></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
4175<code>&#060;function></code> is the name of the current function,4197<code>&#060;function></code> is the name of the current function,
4176and <code>&#060;realt></code> is the type name of the actual argument.4198and <code>&#060;realt></code> is the type name of the actual argument.
4177 4199
4178<p><a name="luaL_unref"></a>4200<p><a name="luaL_unref"></a>
4179<hr><h3><code>luaL_unref</code></h3>4201<hr/><h3><code>luaL_unref</code></h3>
4180<pre>4202<pre>
4181 void luaL_unref (lua_State *L, int t, int ref);4203 void luaL_unref (lua_State *L, int t, int ref);
4182</pre>4204</pre>
@@ -4192,7 +4214,7 @@ The reference <code>ref</code> is also freed to be used again. · 9 unmodified lines
4192<a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.4214<a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
4193 4215
4194<p><a name="luaL_where"></a>4216<p><a name="luaL_where"></a>
4195<hr><h3><code>luaL_where</code></h3>4217<hr/><h3><code>luaL_where</code></h3>
4196<pre>4218<pre>
4197 void luaL_where (lua_State *L, int lvl);4219 void luaL_where (lua_State *L, int lvl);
4198</pre>4220</pre>
@@ -4255,14 +4277,14 @@ If you do not include this library in your application, · 56 unmodified lines
4255you should check carefully whether you need to provide some alternative4277you should check carefully whether you need to provide some alternative
4256implementation for some of its facilities.4278implementation for some of its facilities.
4257 4279
4258<p><a name="pdf-assert"></a><hr><h3><code>assert (v [, message])</code></h3>4280<p><a name="pdf-assert"></a><hr/><h3><code>assert (v [, message])</code></h3>
4259Issues an error when4281Issues an error when
4260the value of its argument <code>v</code> is <B>nil</B> or <B>false</B>;4282the value of its argument <code>v</code> is <b>nil</b> or <b>false</b>;
4261otherwise, returns all its arguments.4283otherwise, returns all its arguments.
4262<code>message</code> is an error message;4284<code>message</code> is an error message;
4263when absent, it defaults to "assertion failed!"4285when absent, it defaults to "assertion failed!"
4264 4286
4265<p><a name="pdf-collectgarbage"></a><hr><h3><code>collectgarbage (opt [, arg])</code></h3>4287<p><a name="pdf-collectgarbage"></a><hr/><h3><code>collectgarbage (opt [, arg])</code></h3>
4266 4288
4267<p>This function is a generic interface to the garbage collector.4289<p>This function is a generic interface to the garbage collector.
4268It performs different functions according to its first argument, <code>opt</code>:4290It performs different functions according to its first argument, <code>opt</code>:
@@ -4276,6 +4298,7 @@ The step "size" is controlled by <code>arg</code> · 7 unmodified lines
4276(larger values mean more steps) in a non-specified way.4298(larger values mean more steps) in a non-specified way.
4277If you want to control the step size4299If you want to control the step size
4278you must tune experimentally the value of <code>arg</code>.4300you must tune experimentally the value of <code>arg</code>.
4301Returns <b>true</b> if that step finished a collection cycle.
4279<li><b>"steppause"</b>4302<li><b>"steppause"</b>
4280sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of4303sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of
4281the collector (see <a href="#GC">2.10</a>).4304the collector (see <a href="#GC">2.10</a>).
@@ -4284,7 +4307,7 @@ sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier< · 2 unmodified lines
4284the collector (see <a href="#GC">2.10</a>).4307the collector (see <a href="#GC">2.10</a>).
4285</ul>4308</ul>
4286 4309
4287<p><a name="pdf-dofile"></a><hr><h3><code>dofile (filename)</code></h3>4310<p><a name="pdf-dofile"></a><hr/><h3><code>dofile (filename)</code></h3>
4288Opens the named file and executes its contents as a Lua chunk.4311Opens the named file and executes its contents as a Lua chunk.
4289When called without arguments,4312When called without arguments,
4290<a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>).4313<a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>).
@@ -4292,7 +4315,7 @@ Returns any value returned by the chunk. · 1 unmodified line
4292In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error4315In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error
4293to its caller (that is, it does not run in protected mode).4316to its caller (that is, it does not run in protected mode).
4294 4317
4295<p><a name="pdf-error"></a><hr><h3><code>error (message [, level])</code></h3>4318<p><a name="pdf-error"></a><hr/><h3><code>error (message [, level])</code></h3>
4296Terminates the last protected function called4319Terminates the last protected function called
4297and returns <code>message</code> as the error message.4320and returns <code>message</code> as the error message.
4298Function <a href="#pdf-error"><code>error</code></a> never returns.4321Function <a href="#pdf-error"><code>error</code></a> never returns.
@@ -4307,14 +4330,14 @@ that called <a href="#pdf-error"><code>error</code></a> was called; and so on. · 8 unmodified lines
4307Passing a level 0 avoids the addition of error position information4330Passing a level 0 avoids the addition of error position information
4308to the message.4331to the message.
4309 4332
4310<p><a name="pdf-_G"></a><hr><h3><code>_G</code></h3>4333<p><a name="pdf-_G"></a><hr/><h3><code>_G</code></h3>
4311A global variable (not a function) that4334A global variable (not a function) that
4312holds the global environment (that is, <code>_G._G = _G</code>).4335holds the global environment (that is, <code>_G._G = _G</code>).
4313Lua itself does not use this variable;4336Lua itself does not use this variable;
4314changing its value does not affect any environment.4337changing its value does not affect any environment.
4315(Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.)4338(Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.)
4316 4339
4317<p><a name="pdf-getfenv"></a><hr><h3><code>getfenv (f)</code></h3>4340<p><a name="pdf-getfenv"></a><hr/><h3><code>getfenv (f)</code></h3>
4318Returns the current environment in use by the function.4341Returns the current environment in use by the function.
4319<code>f</code> can be a Lua function or a number,4342<code>f</code> can be a Lua function or a number,
4320which specifies the function at that stack level:4343which specifies the function at that stack level:
@@ -4324,73 +4347,73 @@ or if <code>f</code> is 0, · 3 unmodified lines
4324<a href="#pdf-getfenv"><code>getfenv</code></a> returns the global environment.4347<a href="#pdf-getfenv"><code>getfenv</code></a> returns the global environment.
4325The default for <code>f</code> is 1.4348The default for <code>f</code> is 1.
4326 4349
4327<p><a name="pdf-getmetatable"></a><hr><h3><code>getmetatable (object)</code></h3>4350<p><a name="pdf-getmetatable"></a><hr/><h3><code>getmetatable (object)</code></h3>
4328 4351
4329<p>If <code>object</code> does not have a metatable, returns <B>nil</B>.4352<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
4330Otherwise,4353Otherwise,
4331if the object's metatable has a <code>"__metatable"</code> field,4354if the object's metatable has a <code>"__metatable"</code> field,
4332returns the associated value.4355returns the associated value.
4333Otherwise, returns the metatable of the given object.4356Otherwise, returns the metatable of the given object.
4334 4357
4335<p><a name="pdf-ipairs"></a><hr><h3><code>ipairs (t)</code></h3>4358<p><a name="pdf-ipairs"></a><hr/><h3><code>ipairs (t)</code></h3>
4336 4359
4337<p>Returns an iterator function, the table <code>t</code>, and 0,4360<p>Returns an iterator function, the table <code>t</code>, and 0,
4338so that the construction4361so that the construction
4339<PRE>4362<pre>
4340 for i,v in ipairs(t) do ... end4363 for i,v in ipairs(t) do ... end
4341</PRE>4364</pre>
4342will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,4365will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
4343up to the first integer key with a nil value in the table.4366up to the first integer key with a nil value in the table.
4344 4367
4345<p><a name="pdf-load"></a><hr><h3><code>load (func [, chunkname])</code></h3>4368<p><a name="pdf-load"></a><hr/><h3><code>load (func [, chunkname])</code></h3>
4346 4369
4347<p>Loads a chunk using function <code>func</code> to get its pieces.4370<p>Loads a chunk using function <code>func</code> to get its pieces.
4348Each call to <code>func</code> must return a string that concatenates4371Each call to <code>func</code> must return a string that concatenates
4349with previous results.4372with previous results.
4350A return of <B>nil</B> (or no value) signals the end of the chunk.4373A return of <b>nil</b> (or no value) signals the end of the chunk.
4351 4374
4352<p>If there are no errors, 4375<p>If there are no errors,
4353returns the compiled chunk as a function;4376returns the compiled chunk as a function;
4354otherwise, returns <B>nil</B> plus the error message.4377otherwise, returns <b>nil</b> plus the error message.
4355The environment of the returned function is the global environment.4378The environment of the returned function is the global environment.
4356 4379
4357<p><code>chunkname</code> is used as the chunk name for error messages4380<p><code>chunkname</code> is used as the chunk name for error messages
4358and debug information.4381and debug information.
4359 4382
4360<p><a name="pdf-loadfile"></a><hr><h3><code>loadfile (filename)</code></h3>4383<p><a name="pdf-loadfile"></a><hr/><h3><code>loadfile (filename)</code></h3>
4361 4384
4362<p>Similar to <a href="#pdf-load"><code>load</code></a>,4385<p>Similar to <a href="#pdf-load"><code>load</code></a>,
4363but gets the chunk from file <code>filename</code>.4386but gets the chunk from file <code>filename</code>.
4364 4387
4365<p><a name="pdf-loadstring"></a><hr><h3><code>loadstring (string [, chunkname])</code></h3>4388<p><a name="pdf-loadstring"></a><hr/><h3><code>loadstring (string [, chunkname])</code></h3>
4366 4389
4367<p>Similar to <a href="#pdf-load"><code>load</code></a>,4390<p>Similar to <a href="#pdf-load"><code>load</code></a>,
4368but gets the chunk from the given string.4391but gets the chunk from the given string.
4369 4392
4370<p>To load and run a given string, use the idiom4393<p>To load and run a given string, use the idiom
4371<PRE>4394<pre>
4372 assert(loadstring(s))()4395 assert(loadstring(s))()
4373</PRE>4396</pre>
4374 4397
4375<p><a name="pdf-next"></a><hr><h3><code>next (table [, index])</code></h3>4398<p><a name="pdf-next"></a><hr/><h3><code>next (table [, index])</code></h3>
4376 4399
4377<p>Allows a program to traverse all fields of a table.4400<p>Allows a program to traverse all fields of a table.
4378Its first argument is a table and its second argument4401Its first argument is a table and its second argument
4379is an index in this table.4402is an index in this table.
4380<a href="#pdf-next"><code>next</code></a> returns the next index of the table and the4403<a href="#pdf-next"><code>next</code></a> returns the next index of the table and the
4381value associated with the index.4404value associated with the index.
4382When called with <B>nil</B> as its second argument,4405When called with <b>nil</b> as its second argument,
4383<a href="#pdf-next"><code>next</code></a> returns the first index4406<a href="#pdf-next"><code>next</code></a> returns the first index
4384of the table and its associated value.4407of the table and its associated value.
4385When called with the last index,4408When called with the last index,
4386or with <B>nil</B> in an empty table,4409or with <b>nil</b> in an empty table,
4387<a href="#pdf-next"><code>next</code></a> returns <B>nil</B>.4410<a href="#pdf-next"><code>next</code></a> returns <b>nil</b>.
4388If the second argument is absent, then it is interpreted as <B>nil</B>.4411If the second argument is absent, then it is interpreted as <b>nil</b>.
4389 4412
4390<p>Lua has no declaration of fields;4413<p>Lua has no declaration of fields;
4391There is no difference between a4414There is no difference between a
4392field not present in a table or a field with value <B>nil</B>.4415field not present in a table or a field with value <b>nil</b>.
4393Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<B>nil</B> values.4416Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<b>nil</b> values.
4394The order in which the indices are enumerated is not specified,4417The order in which the indices are enumerated is not specified,
4395<em>even for numeric indices</em>.4418<em>even for numeric indices</em>.
4396(To traverse a table in numeric order,4419(To traverse a table in numeric order,
@@ -4400,16 +4423,16 @@ use a numerical <b>for</b> or the <a href="#pdf-ipairs"><code>ipairs</code></a> · 3 unmodified lines
4400during the traversal,4423during the traversal,
4401you assign any value to a non-existent field in the table.4424you assign any value to a non-existent field in the table.
4402 4425
4403<p><a name="pdf-pairs"></a><hr><h3><code>pairs (t)</code></h3>4426<p><a name="pdf-pairs"></a><hr/><h3><code>pairs (t)</code></h3>
4404 4427
4405<p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <B>nil</B>),4428<p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <b>nil</b>),
4406so that the construction4429so that the construction
4407<PRE>4430<pre>
4408 for k,v in pairs(t) do ... end4431 for k,v in pairs(t) do ... end
4409</PRE>4432</pre>
4410will iterate over all key&ndash;value pairs of table <code>t</code>.4433will iterate over all key--value pairs of table <code>t</code>.
4411 4434
4412<p><a name="pdf-pcall"></a><hr><h3><code>pcall (f, arg1, arg2, ...)</code></h3>4435<p><a name="pdf-pcall"></a><hr/><h3><code>pcall (f, arg1, arg2, ...)</code></h3>
4413 4436
4414<p>Calls function <code>f</code> with4437<p>Calls function <code>f</code> with
4415the given arguments in protected mode.4438the given arguments in protected mode.
@@ -4420,9 +4443,9 @@ Its first result is the status code (a boolean), · 4 unmodified lines
4420which is true if the call succeeds without errors.4443which is true if the call succeeds without errors.
4421In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call,4444In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call,
4422after this first result.4445after this first result.
4423In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <B>false</B> plus the error message.4446In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <b>false</b> plus the error message.
4424 4447
4425<p><a name="pdf-print"></a><hr><h3><code>print (e1, e2, ...)</code></h3>4448<p><a name="pdf-print"></a><hr/><h3><code>print (e1, e2, ...)</code></h3>
4426Receives any number of arguments,4449Receives any number of arguments,
4427and prints their values in <code>stdout</code>,4450and prints their values in <code>stdout</code>,
4428using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.4451using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.
@@ -4431,32 +4454,32 @@ but only as a quick way to show a value, · 2 unmodified lines
4431typically for debugging.4454typically for debugging.
4432For formatted output, use <code>format</code> (see <a href="#format">5.4</a>).4455For formatted output, use <code>format</code> (see <a href="#format">5.4</a>).
4433 4456
4434<p><a name="pdf-rawequal"></a><hr><h3><code>rawequal (v1, v2)</code></h3>4457<p><a name="pdf-rawequal"></a><hr/><h3><code>rawequal (v1, v2)</code></h3>
4435Checks whether <code>v1</code> is equal to <code>v2</code>,4458Checks whether <code>v1</code> is equal to <code>v2</code>,
4436without invoking any metamethod.4459without invoking any metamethod.
4437Returns a boolean.4460Returns a boolean.
4438 4461
4439<p><a name="pdf-rawget"></a><hr><h3><code>rawget (table, index)</code></h3>4462<p><a name="pdf-rawget"></a><hr/><h3><code>rawget (table, index)</code></h3>
4440Gets the real value of <code>table[index]</code>,4463Gets the real value of <code>table[index]</code>,
4441without invoking any metamethod.4464without invoking any metamethod.
4442<code>table</code> must be a table;4465<code>table</code> must be a table;
4443<code>index</code> is any value different from <B>nil</B>.4466<code>index</code> is any value different from <b>nil</b>.
4444 4467
4445<p><a name="pdf-rawset"></a><hr><h3><code>rawset (table, index, value)</code></h3>4468<p><a name="pdf-rawset"></a><hr/><h3><code>rawset (table, index, value)</code></h3>
4446Sets the real value of <code>table[index]</code> to <code>value</code>,4469Sets the real value of <code>table[index]</code> to <code>value</code>,
4447without invoking any metamethod.4470without invoking any metamethod.
4448<code>table</code> must be a table,4471<code>table</code> must be a table,
4449<code>index</code> is any value different from <B>nil</B>,4472<code>index</code> is any value different from <b>nil</b>,
4450and <code>value</code> is any Lua value.4473and <code>value</code> is any Lua value.
4451 4474
4452<p><a name="pdf-select"></a><hr><h3><code>select (index, ...)</code></h3>4475<p><a name="pdf-select"></a><hr/><h3><code>select (index, ...)</code></h3>
4453 4476
4454<p>If <code>index</code> is a number,4477<p>If <code>index</code> is a number,
4455returns all argument after argument number <code>index</code>.4478returns all argument after argument number <code>index</code>.
4456Otherwise, <code>index</code> must be the string <code>"#"</code>,4479Otherwise, <code>index</code> must be the string <code>"#"</code>,
4457and <code>select</code> returns the total number of extra arguments it received.4480and <code>select</code> returns the total number of extra arguments it received.
4458 4481
4459<p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr><h3><code>setfenv (f, table)</code></h3>4482<p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr/><h3><code>setfenv (f, table)</code></h3>
4460 4483
4461<p>Sets the environment to be used by the given function.4484<p>Sets the environment to be used by the given function.
4462<code>f</code> can be a Lua function or a number,4485<code>f</code> can be a Lua function or a number,
@@ -4468,22 +4491,22 @@ Level 1 is the function calling <a href="#pdf-setfenv"><code>setfenv</code></a>. · 5 unmodified lines
4468the environment of the running thread.4491the environment of the running thread.
4469In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values.4492In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values.
4470 4493
4471<p><a name="pdf-setmetatable"></a><hr><h3><code>setmetatable (table, metatable)</code></h3>4494<p><a name="pdf-setmetatable"></a><hr/><h3><code>setmetatable (table, metatable)</code></h3>
4472 4495
4473<p>Sets the metatable for the given table.4496<p>Sets the metatable for the given table.
4474(You cannot change the metatable of other types from Lua.)4497(You cannot change the metatable of other types from Lua.)
4475If <code>metatable</code> is <B>nil</B>,4498If <code>metatable</code> is <b>nil</b>,
4476removes the metatable of the given table.4499removes the metatable of the given table.
4477If the original metatable has a <code>"__metatable"</code> field,4500If the original metatable has a <code>"__metatable"</code> field,
4478raises an error.4501raises an error.
4479 4502
4480<p>This function returns <code>table</code>.4503<p>This function returns <code>table</code>.
4481 4504
4482<p><a name="pdf-tonumber"></a><hr><h3><code>tonumber (e [, base])</code></h3>4505<p><a name="pdf-tonumber"></a><hr/><h3><code>tonumber (e [, base])</code></h3>
4483Tries to convert its argument to a number.4506Tries to convert its argument to a number.
4484If the argument is already a number or a string convertible4507If the argument is already a number or a string convertible
4485to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number;4508to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number;
4486otherwise, it returns <B>nil</B>.4509otherwise, it returns <b>nil</b>.
4487 4510
4488<p>An optional argument specifies the base to interpret the numeral.4511<p>An optional argument specifies the base to interpret the numeral.
4489The base may be any integer between 2 and 36, inclusive.4512The base may be any integer between 2 and 36, inclusive.
@@ -4494,7 +4517,7 @@ In base 10 (the default), the number may have a decimal part, · 4 unmodified lines
4494as well as an optional exponent part (see <a href="#coercion">2.2.1</a>).4517as well as an optional exponent part (see <a href="#coercion">2.2.1</a>).
4495In other bases, only unsigned integers are accepted.4518In other bases, only unsigned integers are accepted.
4496 4519
4497<p><a name="pdf-tostring"></a><hr><h3><code>tostring (e)</code></h3>4520<p><a name="pdf-tostring"></a><hr/><h3><code>tostring (e)</code></h3>
4498Receives an argument of any type and4521Receives an argument of any type and
4499converts it to a string in a reasonable format.4522converts it to a string in a reasonable format.
4500For complete control of how numbers are converted,4523For complete control of how numbers are converted,
@@ -4505,10 +4528,10 @@ use <a href="#pdf-string.format"><code>string.format</code></a> (see <a href="#f · 4 unmodified lines
4505with <code>e</code> as argument,4528with <code>e</code> as argument,
4506and uses the result of the call as its result.4529and uses the result of the call as its result.
4507 4530
4508<p><a name="pdf-type"></a><hr><h3><code>type (v)</code></h3>4531<p><a name="pdf-type"></a><hr/><h3><code>type (v)</code></h3>
4509Returns the type of its only argument, coded as a string.4532Returns the type of its only argument, coded as a string.
4510The possible results of this function are4533The possible results of this function are
4511<code>"nil"</code> (a string, not the value <B>nil</B>),4534<code>"nil"</code> (a string, not the value <b>nil</b>),
4512<code>"number"</code>,4535<code>"number"</code>,
4513<code>"string"</code>,4536<code>"string"</code>,
4514<code>"boolean</code>,4537<code>"boolean</code>,
@@ -4517,23 +4540,23 @@ The possible results of this function are · 2 unmodified lines
4517<code>"thread"</code>,4540<code>"thread"</code>,
4518and <code>"userdata"</code>.4541and <code>"userdata"</code>.
4519 4542
4520<p><a name="pdf-unpack"></a><hr><h3><code>unpack (list [, i [, j]])</code></h3>4543<p><a name="pdf-unpack"></a><hr/><h3><code>unpack (list [, i [, j]])</code></h3>
4521Returns the elements from the given list.4544Returns the elements from the given list.
4522This function is equivalent to4545This function is equivalent to
4523<PRE>4546<pre>
4524 return list[i], list[i+1], ..., list[j]4547 return list[i], list[i+1], ..., list[j]
4525</PRE>4548</pre>
4526except that the above code can be written only for a fixed number4549except that the above code can be written only for a fixed number
4527of elements.4550of elements.
4528By default, <code>i</code> is 1 and <code>j</code> is the length of the list,4551By default, <code>i</code> is 1 and <code>j</code> is the length of the list,
4529as defined by the length operator.4552as defined by the length operator.
4530 4553
4531<p><a name="pdf-_VERSION"></a><hr><h3><code>_VERSION</code></h3>4554<p><a name="pdf-_VERSION"></a><hr/><h3><code>_VERSION</code></h3>
4532A global variable (not a function) that4555A global variable (not a function) that
4533holds a string containing the current interpreter version.4556holds a string containing the current interpreter version.
4534The current contents of this variable is <code>"Lua 5.1"</code>.4557The current contents of this variable is <code>"Lua 5.1"</code>.
4535 4558
4536<p><a name="pdf-xpcall"></a><hr><h3><code>xpcall (f, err)</code></h3>4559<p><a name="pdf-xpcall"></a><hr/><h3><code>xpcall (f, err)</code></h3>
4537 4560
4538<p>This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,4561<p>This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
4539except that you can set a new error handler.4562except that you can set a new error handler.
@@ -4557,14 +4580,14 @@ In case of any error, · 17 unmodified lines
4557the basic library and come inside the table <code>coroutine</code>.4580the basic library and come inside the table <code>coroutine</code>.
4558See <a href="#coroutine">2.11</a> for a general description of coroutines.4581See <a href="#coroutine">2.11</a> for a general description of coroutines.
4559 4582
4560<p><a name="pdf-coroutine.create"></a><hr><h3><code>coroutine.create (f)</code></h3>4583<p><a name="pdf-coroutine.create"></a><hr/><h3><code>coroutine.create (f)</code></h3>
4561 4584
4562<p>Creates a new coroutine, with body <code>f</code>.4585<p>Creates a new coroutine, with body <code>f</code>.
4563<code>f</code> must be a Lua function.4586<code>f</code> must be a Lua function.
4564Returns this new coroutine,4587Returns this new coroutine,
4565an object with type <code>"thread"</code>.4588an object with type <code>"thread"</code>.
4566 4589
4567<p><a name="pdf-coroutine.resume"></a><hr><h3><code>coroutine.resume (co, val1, ...)</code></h3>4590<p><a name="pdf-coroutine.resume"></a><hr/><h3><code>coroutine.resume (co, val1, ...)</code></h3>
4568 4591
4569<p>Starts or continues the execution of coroutine <code>co</code>.4592<p>Starts or continues the execution of coroutine <code>co</code>.
4570The first time you resume a coroutine,4593The first time you resume a coroutine,
@@ -4575,18 +4598,18 @@ If the coroutine has yielded, · 4 unmodified lines
4575the arguments <code>val1</code>, ... go as the results from the yield.4598the arguments <code>val1</code>, ... go as the results from the yield.
4576 4599
4577<p>If the coroutine runs without any errors,4600<p>If the coroutine runs without any errors,
4578<code>resume</code> returns <B>true</B> plus any values passed to <code>yield</code>4601<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>
4579(if the coroutine yields) or any values returned by the body function4602(if the coroutine yields) or any values returned by the body function
4580(if the coroutine terminates).4603(if the coroutine terminates).
4581If there is any error,4604If there is any error,
4582<code>resume</code> returns <B>false</B> plus the error message.4605<code>resume</code> returns <b>false</b> plus the error message.
4583 4606
4584<p><a name="pdf-coroutine.running"></a><hr><h3><code>coroutine.running ()</code></h3>4607<p><a name="pdf-coroutine.running"></a><hr/><h3><code>coroutine.running ()</code></h3>
4585 4608
4586<p>Returns the running coroutine,4609<p>Returns the running coroutine,
4587or <B>nil</B> when called by the main thread.4610or <b>nil</b> when called by the main thread.
4588 4611
4589<p><a name="pdf-coroutine.status"></a><hr><h3><code>coroutine.status (co)</code></h3>4612<p><a name="pdf-coroutine.status"></a><hr/><h3><code>coroutine.status (co)</code></h3>
4590 4613
4591<p>Returns the status of coroutine <code>co</code>, as a string:4614<p>Returns the status of coroutine <code>co</code>, as a string:
4592<code>"running"</code>,4615<code>"running"</code>,
@@ -4598,7 +4621,7 @@ or if it has not started running yet; · 5 unmodified lines
4598and <code>"dead"</code> if the coroutine has finished its body function,4621and <code>"dead"</code> if the coroutine has finished its body function,
4599or if it has stopped with an error.4622or if it has stopped with an error.
4600 4623
4601<p><a name="pdf-coroutine.wrap"></a><hr><h3><code>coroutine.wrap (f)</code></h3>4624<p><a name="pdf-coroutine.wrap"></a><hr/><h3><code>coroutine.wrap (f)</code></h3>
4602 4625
4603<p>Creates a new coroutine, with body <code>f</code>.4626<p>Creates a new coroutine, with body <code>f</code>.
4604<code>f</code> must be a Lua function.4627<code>f</code> must be a Lua function.
@@ -4609,7 +4632,7 @@ Returns the same values returned by <code>resume</code>, · 4 unmodified lines
4609except the first boolean.4632except the first boolean.
4610In case of error, propagates the error.4633In case of error, propagates the error.
4611 4634
4612<p><a name="pdf-coroutine.yield"></a><hr><h3><code>coroutine.yield (val1, ...)</code></h3>4635<p><a name="pdf-coroutine.yield"></a><hr/><h3><code>coroutine.yield (val1, ...)</code></h3>
4613 4636
4614<p>Suspends the execution of the calling coroutine.4637<p>Suspends the execution of the calling coroutine.
4615The coroutine cannot be running neither a C function,4638The coroutine cannot be running neither a C function,
@@ -4624,7 +4647,7 @@ It exports two of its functions directly in the global environment: · 8 unmodified lines
4624<a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.4647<a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>.
4625Everything else is exported in a table <code>package</code>.4648Everything else is exported in a table <code>package</code>.
4626 4649
4627<p><a name="pdf-module"></a><hr><h3><code>module (name [, ...])</code></h3>4650<p><a name="pdf-module"></a><hr/><h3><code>module (name [, ...])</code></h3>
4628 4651
4629<p>Creates a module.4652<p>Creates a module.
4630If there is a table in <code>package.loaded[name]</code>,4653If there is a table in <code>package.loaded[name]</code>,
@@ -4654,7 +4677,7 @@ field <code>b</code> of global <code>a</code>. · 23 unmodified lines
4654the module name,4677the module name,
4655where each option is a function to be applied over the module.4678where each option is a function to be applied over the module.
4656 4679
4657<p><a name="pdf-require"></a><hr><h3><code>require (modname)</code></h3>4680<p><a name="pdf-require"></a><hr/><h3><code>require (modname)</code></h3>
4658 4681
4659<p>Loads the given module.4682<p>Loads the given module.
4660The function starts by looking into the table <code>package.loaded</code>4683The function starts by looking into the table <code>package.loaded</code>
@@ -4682,9 +4705,9 @@ be used as the loader. · 21 unmodified lines
4682The name of that C function is the string <code>"luaopen_"</code>4705The name of that C function is the string <code>"luaopen_"</code>
4683concatenated with a copy of the module name wherein each dot4706concatenated with a copy of the module name wherein each dot
4684is replaced by an underscore.4707is replaced by an underscore.
4685Moreover, if the module name has a colon,4708Moreover, if the module name has a hyphen,
4686its prefix up to (and including) the first colon is removed.4709its prefix up to (and including) the first hyphen is removed.
4687For instance, if the module name is <code>a.v1:b.c</code>,4710For instance, if the module name is <code>a.v1-b.c</code>,
4688the function name will be <code>luaopen_b_c</code>.4711the function name will be <code>luaopen_b_c</code>.
4689 4712
4690<p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a4713<p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a
@@ -4715,7 +4738,7 @@ final value of <code>package.loaded[modname]</code>. · 24 unmodified lines
4715or if it cannot find any loader for that module,4738or if it cannot find any loader for that module,
4716then <a href="#pdf-require"><code>require</code></a> signals an error. 4739then <a href="#pdf-require"><code>require</code></a> signals an error.
4717 4740
4718<p><a name="pdf-package.cpath"></a><hr><h3><code>package.cpath</code></h3>4741<p><a name="pdf-package.cpath"></a><hr/><h3><code>package.cpath</code></h3>
4719 4742
4720<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader.4743<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader.
4721 4744
@@ -4724,7 +4747,7 @@ it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code · 2 unmodified lines
4724using the environment variable <code>LUA_CPATH</code>4747using the environment variable <code>LUA_CPATH</code>
4725(plus another compiled-defined default path).4748(plus another compiled-defined default path).
4726 4749
4727<p><a name="pdf-package.loaded"></a><hr><h3><code>package.loaded</code></h3>4750<p><a name="pdf-package.loaded"></a><hr/><h3><code>package.loaded</code></h3>
4728 4751
4729<p>A table used by <a href="#pdf-require"><code>require</code></a> to control which4752<p>A table used by <a href="#pdf-require"><code>require</code></a> to control which
4730modules are already loaded.4753modules are already loaded.
@@ -4732,7 +4755,7 @@ When you require a module <code>modname</code> and · 1 unmodified line
4732<code>package.loaded[modname]</code> is not false,4755<code>package.loaded[modname]</code> is not false,
4733<a href="#pdf-require"><code>require</code></a> simply returns the value stored there.4756<a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
4734 4757
4735<p><a name="pdf-package.loadlib"></a><hr><h3><code>package.loadlib (libname, funcname)</code></h3>4758<p><a name="pdf-package.loadlib"></a><hr/><h3><code>package.loadlib (libname, funcname)</code></h3>
4736 4759
4737<p>Links the program with the dynamic C library <code>libname</code>.4760<p>Links the program with the dynamic C library <code>libname</code>.
4738Inside this library, looks for a function <code>funcname</code>4761Inside this library, looks for a function <code>funcname</code>
@@ -4746,7 +4769,7 @@ As such, it is only available on some platforms · 7 unmodified lines
4746(Windows, Linux, Solaris, BSD, plus other Unix systems that4769(Windows, Linux, Solaris, BSD, plus other Unix systems that
4747support the <code>dlfcn</code> standard).4770support the <code>dlfcn</code> standard).
4748 4771
4749<p><a name="pdf-package.path"></a><hr><h3><code>package.path</code></h3>4772<p><a name="pdf-package.path"></a><hr/><h3><code>package.path</code></h3>
4750 4773
4751<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader.4774<p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader.
4752 4775
@@ -4764,20 +4787,20 @@ which is <code>modname</code> with each dot replaced by a · 11 unmodified lines
4764"directory separator" (such as <code>"/"</code> in Unix);4787"directory separator" (such as <code>"/"</code> in Unix);
4765then it will try to load the resulting file name.4788then it will try to load the resulting file name.
4766So, for instance, if the Lua path is4789So, for instance, if the Lua path is
4767<PRE>4790<pre>
4768 "./?.lua;./?.lc;/usr/local/?/init.lua"4791 "./?.lua;./?.lc;/usr/local/?/init.lua"
4769</PRE>4792</pre>
4770the search for a Lua loader for module <code>mod</code>4793the search for a Lua loader for module <code>mod</code>
4771will try to load the files4794will try to load the files
4772<code>./mod.lua</code>, <code>./mod.lc</code>, and4795<code>./mod.lua</code>, <code>./mod.lc</code>, and
4773<code>/usr/local/mod/init.lua</code>, in that order.4796<code>/usr/local/mod/init.lua</code>, in that order.
4774 4797
4775<p><a name="pdf-package.preload"></a><hr><h3><code>package.preload</code></h3>4798<p><a name="pdf-package.preload"></a><hr/><h3><code>package.preload</code></h3>
4776 4799
4777<p>A table to store loaders for specific modules4800<p>A table to store loaders for specific modules
4778(see <a href="#pdf-require"><code>require</code></a>).4801(see <a href="#pdf-require"><code>require</code></a>).
4779 4802
4780<p><a name="pdf-package.seeall"></a><hr><h3><code>package.seeall (module)</code></h3>4803<p><a name="pdf-package.seeall"></a><hr/><h3><code>package.seeall (module)</code></h3>
4781 4804
4782<p>Sets a metatable for <code>module</code> with4805<p>Sets a metatable for <code>module</code> with
4783its <code>__index</code> field refering to the global environment,4806its <code>__index</code> field refering to the global environment,
@@ -4803,7 +4826,7 @@ Therefore, you can use the string function is object-oriented style. · 19 unmodified lines
4803For instance, <code>string.byte(s, i)</code>4826For instance, <code>string.byte(s, i)</code>
4804can be written as <code>s:byte(i)</code>.4827can be written as <code>s:byte(i)</code>.
4805 4828
4806<p><a name="pdf-string.byte"></a><hr><h3><code>string.byte (s [, i [, j]])</code></h3>4829<p><a name="pdf-string.byte"></a><hr/><h3><code>string.byte (s [, i [, j]])</code></h3>
4807Returns the internal numerical codes of the characters <code>s[i]</code>,4830Returns the internal numerical codes of the characters <code>s[i]</code>,
4808<code>s[i+1]</code>, ..., <code>s[j]</code>.4831<code>s[i+1]</code>, ..., <code>s[j]</code>.
4809The default value for <code>i</code> is 1;4832The default value for <code>i</code> is 1;
@@ -4811,7 +4834,7 @@ the default value for <code>j</code> is <code>i</code>. · 1 unmodified line
4811 4834
4812<p>Note that numerical codes are not necessarily portable across platforms.4835<p>Note that numerical codes are not necessarily portable across platforms.
4813 4836
4814<p><a name="pdf-string.char"></a><hr><h3><code>string.char (i1, i2, ...)</code></h3>4837<p><a name="pdf-string.char"></a><hr/><h3><code>string.char (i1, i2, ...)</code></h3>
4815Receives 0 or more integers.4838Receives 0 or more integers.
4816Returns a string with length equal to the number of arguments,4839Returns a string with length equal to the number of arguments,
4817in which each character has the internal numerical code equal4840in which each character has the internal numerical code equal
@@ -4819,29 +4842,34 @@ to its correspondent argument. · 1 unmodified line
4819 4842
4820<p>Note that numerical codes are not necessarily portable across platforms.4843<p>Note that numerical codes are not necessarily portable across platforms.
4821 4844
4822<p><a name="pdf-string.dump"></a><hr><h3><code>string.dump (function)</code></h3>4845<p><a name="pdf-string.dump"></a><hr/><h3><code>string.dump (function)</code></h3>
4823 4846
4824<p>Returns a binary representation of the given function,4847<p>Returns a binary representation of the given function,
4825so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns4848so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns
4826a copy of the function.4849a copy of the function.
4827<code>function</code> must be a Lua function.4850<code>function</code> must be a Lua function.
4828 4851
4829<p><a name="pdf-string.find"></a><hr><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>4852<p><a name="pdf-string.find"></a><hr/><h3><code>string.find (s, pattern [, init [, plain]])</code></h3>
4830Looks for the first <em>match</em> of4853Looks for the first <em>match</em> of
4831<code>pattern</code> in the string <code>s</code>.4854<code>pattern</code> in the string <code>s</code>.
4832If it finds one, then <code>find</code> returns the indices of <code>s</code>4855If it finds one, then <code>find</code> returns the indices of <code>s</code>
4833where this occurrence starts and ends;4856where this occurrence starts and ends;
4834otherwise, it returns <B>nil</B>.4857otherwise, it returns <b>nil</b>.
4835A third, optional numerical argument <code>init</code> specifies4858A third, optional numerical argument <code>init</code> specifies
4836where to start the search;4859where to start the search;
4837its default value is 1 and may be negative.4860its default value is 1 and may be negative.
4838A value of <B>true</B> as a fourth, optional argument <code>plain</code>4861A value of <b>true</b> as a fourth, optional argument <code>plain</code>
4839turns off the pattern matching facilities,4862turns off the pattern matching facilities,
4840so the function does a plain "find substring" operation,4863so the function does a plain "find substring" operation,
4841with no characters in <code>pattern</code> being considered "magic".4864with no characters in <code>pattern</code> being considered "magic".
4842Note that if <code>plain</code> is given, then <code>init</code> must be given too.4865Note that if <code>plain</code> is given, then <code>init</code> must be given too.
4843 4866
4844<p><a name="format"></a><a name="pdf-string.format"></a><hr><h3><code>string.format (formatstring, e1, e2, ...)</code></h3>4867<p>If the pattern has captures,
4868then in a successful match
4869the captured values are also returned,
4870after the two indices.
4871
4872<p><a name="format"></a><a name="pdf-string.format"></a><hr/><h3><code>string.format (formatstring, e1, e2, ...)</code></h3>
4845Returns a formatted version of its variable number of arguments4873Returns a formatted version of its variable number of arguments
4846following the description given in its first argument (which must be a string).4874following the description given in its first argument (which must be a string).
4847The format string follows the same rules as the <code>printf</code> family of4875The format string follows the same rules as the <code>printf</code> family of
@@ -4856,14 +4884,14 @@ The string is written between double quotes, · 8 unmodified lines
4856and all double quotes, newlines, and backslashes in the string4884and all double quotes, newlines, and backslashes in the string
4857are correctly escaped when written.4885are correctly escaped when written.
4858For instance, the call4886For instance, the call
4859<PRE>4887<pre>
4860 string.format('%q', 'a string with "quotes" and \n new line')4888 string.format('%q', 'a string with "quotes" and \n new line')
4861</PRE>4889</pre>
4862will produce the string:4890will produce the string:
4863<PRE>4891<pre>
4864"a string with \"quotes\" and \4892"a string with \"quotes\" and \
4865 new line"4893 new line"
4866</PRE>4894</pre>
4867 4895
4868<p>The options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>,4896<p>The options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>,
4869<code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all4897<code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all
@@ -4873,7 +4901,7 @@ whereas <code>q</code> and <code>s</code> expect a string. · 3 unmodified lines
4873<p>This function does not accept string values4901<p>This function does not accept string values
4874containing embedded zeros.4902containing embedded zeros.
4875 4903
4876<p><a name="pdf-string.gmatch"></a><hr><h3><code>string.gmatch (s, pat)</code></h3>4904<p><a name="pdf-string.gmatch"></a><hr/><h3><code>string.gmatch (s, pat)</code></h3>
4877Returns an iterator function that,4905Returns an iterator function that,
4878each time it is called,4906each time it is called,
4879returns the next captures from pattern <code>pat</code> over string <code>s</code>.4907returns the next captures from pattern <code>pat</code> over string <code>s</code>.
@@ -4882,25 +4910,25 @@ returns the next captures from pattern <code>pat</code> over string <code>s</cod · 2 unmodified lines
4882then the whole match is produced in each call.4910then the whole match is produced in each call.
4883 4911
4884<p>As an example, the following loop4912<p>As an example, the following loop
4885<PRE>4913<pre>
4886 s = "hello world from Lua"4914 s = "hello world from Lua"
4887 for w in string.gmatch(s, "%a+") do4915 for w in string.gmatch(s, "%a+") do
4888 print(w)4916 print(w)
4889 end4917 end
4890</PRE>4918</pre>
4891will iterate over all the words from string <code>s</code>,4919will iterate over all the words from string <code>s</code>,
4892printing one per line.4920printing one per line.
4893The next example collects all pairs <code>key=value</code> from the4921The next example collects all pairs <code>key=value</code> from the
4894given string into a table:4922given string into a table:
4895<PRE>4923<pre>
4896 t = {}4924 t = {}
4897 s = "from=world, to=Lua"4925 s = "from=world, to=Lua"
4898 for k, v in string.gmatch(s, "(%w+)=(%w+)") do4926 for k, v in string.gmatch(s, "(%w+)=(%w+)") do
4899 t[k] = v4927 t[k] = v
4900 end4928 end
4901</PRE>4929</pre>
4902 4930
4903<p><a name="pdf-string.gsub"></a><hr><h3><code>string.gsub (s, pat, repl [, n])</code></h3>4931<p><a name="pdf-string.gsub"></a><hr/><h3><code>string.gsub (s, pat, repl [, n])</code></h3>
4904Returns a copy of <code>s</code>4932Returns a copy of <code>s</code>
4905in which all occurrences of the pattern <code>pat</code> have been4933in which all occurrences of the pattern <code>pat</code> have been
4906replaced by a replacement string specified by <code>repl</code>.4934replaced by a replacement string specified by <code>repl</code>.
@@ -4920,9 +4948,16 @@ match occurs, with all captured substrings passed as arguments, · 13 unmodified lines
4920in order;4948in order;
4921if the pattern specifies no captures,4949if the pattern specifies no captures,
4922then the whole match is passed as a sole argument.4950then the whole match is passed as a sole argument.
4923If the value returned by this function is a string,4951If <code>repl</code> is a table, then this table is queried with the
4952value of the first capture or of the whole match,
4953if the pattern specifies no captures.
4954In both cases,
4955if the value returned by the function or resulted by the query
4956is a string,
4924then it is used as the replacement string;4957then it is used as the replacement string;
4925otherwise, the replacement string is the empty string.4958otherwise, if it is <b>false</b> or <b>nil</b>,
4959then there is no replacement
4960(that is, the original match is kept in the string).
4926 4961
4927<p>The optional last parameter <code>n</code> limits4962<p>The optional last parameter <code>n</code> limits
4928the maximum number of substitutions to occur.4963the maximum number of substitutions to occur.
@@ -4930,7 +4965,7 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 1 unmodified line
4930<code>pat</code> is replaced.4965<code>pat</code> is replaced.
4931 4966
4932<p>Here are some examples:4967<p>Here are some examples:
4933<PRE>4968<pre>
4934 x = string.gsub("hello world", "(%w+)", "%1 %1")4969 x = string.gsub("hello world", "(%w+)", "%1 %1")
4935 --> x="hello hello world world"4970 --> x="hello hello world world"
4936 4971
@@ -4949,44 +4984,42 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 12 unmodified lines
4949 --> x="4+5 = 9"4984 --> x="4+5 = 9"
4950 4985
4951 local t = {name="lua", version="5.0"}4986 local t = {name="lua", version="5.0"}
4952 x = string.gsub("$name_$version.tar.gz", "%$(%w+)", function (v)4987 x = string.gsub("$name_$version.tar.gz", "%$(%w+)", t)
4953 return t[v]
4954 end)
4955 --> x="lua_5.0.tar.gz"4988 --> x="lua_5.0.tar.gz"
4956</PRE>4989</pre>
4957 4990
4958<p><a name="pdf-string.len"></a><hr><h3><code>string.len (s)</code></h3>4991<p><a name="pdf-string.len"></a><hr/><h3><code>string.len (s)</code></h3>
4959Receives a string and returns its length.4992Receives a string and returns its length.
4960The empty string <code>""</code> has length 0.4993The empty string <code>""</code> has length 0.
4961Embedded zeros are counted,4994Embedded zeros are counted,
4962so <code>"a\000bc\000"</code> has length 5.4995so <code>"a\000bc\000"</code> has length 5.
4963 4996
4964<p><a name="pdf-string.lower"></a><hr><h3><code>string.lower (s)</code></h3>4997<p><a name="pdf-string.lower"></a><hr/><h3><code>string.lower (s)</code></h3>
4965Receives a string and returns a copy of that string with all4998Receives a string and returns a copy of that string with all
4966uppercase letters changed to lowercase.4999uppercase letters changed to lowercase.
4967All other characters are left unchanged.5000All other characters are left unchanged.
4968The definition of what is an uppercase letter depends on the current locale.5001The definition of what is an uppercase letter depends on the current locale.
4969 5002
4970<p><a name="pdf-string.match"></a><hr><h3><code>string.match (s, pattern [, init])</code></h3>5003<p><a name="pdf-string.match"></a><hr/><h3><code>string.match (s, pattern [, init])</code></h3>
4971Looks for the first <em>match</em> of5004Looks for the first <em>match</em> of
4972<code>pattern</code> in the string <code>s</code>.5005<code>pattern</code> in the string <code>s</code>.
4973If it finds one, then <code>match</code> returns5006If it finds one, then <code>match</code> returns
4974the captures from the pattern;5007the captures from the pattern;
4975otherwise it returns <B>nil</B>.5008otherwise it returns <b>nil</b>.
4976If <code>pattern</code> specifies no captures,5009If <code>pattern</code> specifies no captures,
4977then the whole match is returned.5010then the whole match is returned.
4978A third, optional numerical argument <code>init</code> specifies5011A third, optional numerical argument <code>init</code> specifies
4979where to start the search;5012where to start the search;
4980its default value is 1 and may be negative.5013its default value is 1 and may be negative.
4981 5014
4982<p><a name="pdf-string.rep"></a><hr><h3><code>string.rep (s, n)</code></h3>5015<p><a name="pdf-string.rep"></a><hr/><h3><code>string.rep (s, n)</code></h3>
4983Returns a string that is the concatenation of <code>n</code> copies of5016Returns a string that is the concatenation of <code>n</code> copies of
4984the string <code>s</code>.5017the string <code>s</code>.
4985 5018
4986<p><a name="pdf-string.reverse"></a><hr><h3><code>string.reverse (s)</code></h3>5019<p><a name="pdf-string.reverse"></a><hr/><h3><code>string.reverse (s)</code></h3>
4987Returns a string that is the string <code>s</code> reversed.5020Returns a string that is the string <code>s</code> reversed.
4988 5021
4989<p><a name="pdf-string.sub"></a><hr><h3><code>string.sub (s, i [, j])</code></h3>5022<p><a name="pdf-string.sub"></a><hr/><h3><code>string.sub (s, i [, j])</code></h3>
4990Returns the substring of <code>s</code> that5023Returns the substring of <code>s</code> that
4991starts at <code>i</code> and continues until <code>j</code>;5024starts at <code>i</code> and continues until <code>j</code>;
4992<code>i</code> and <code>j</code> may be negative.5025<code>i</code> and <code>j</code> may be negative.
@@ -4998,7 +5031,7 @@ with length <code>j</code>, · 5 unmodified lines
4998and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>5031and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>
4999with length <code>i</code>.5032with length <code>i</code>.
5000 5033
5001<p><a name="pdf-string.upper"></a><hr><h3><code>string.upper (s)</code></h3>5034<p><a name="pdf-string.upper"></a><hr/><h3><code>string.upper (s)</code></h3>
5002Receives a string and returns a copy of that string with all5035Receives a string and returns a copy of that string with all
5003lowercase letters changed to uppercase.5036lowercase letters changed to uppercase.
5004All other characters are left unchanged.5037All other characters are left unchanged.
@@ -5012,26 +5045,26 @@ The following combinations are allowed in describing a character class: · 7 unmodified lines
5012<ul>5045<ul>
5013<li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters5046<li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters
5014<code>^$()%.[]*+-?</code>)5047<code>^$()%.[]*+-?</code>)
5015&mdash; represents the character <em>x</em> itself.5048--- represents the character <em>x</em> itself.
5016<li><b><code>.</code></b> &mdash; (a dot) represents all characters.5049<li><b><code>.</code></b> --- (a dot) represents all characters.
5017<li><b><code>%a</code></b> &mdash; represents all letters.5050<li><b><code>%a</code></b> --- represents all letters.
5018<li><b><code>%c</code></b> &mdash; represents all control characters.5051<li><b><code>%c</code></b> --- represents all control characters.
5019<li><b><code>%d</code></b> &mdash; represents all digits.5052<li><b><code>%d</code></b> --- represents all digits.
5020<li><b><code>%l</code></b> &mdash; represents all lowercase letters.5053<li><b><code>%l</code></b> --- represents all lowercase letters.
5021<li><b><code>%p</code></b> &mdash; represents all punctuation characters.5054<li><b><code>%p</code></b> --- represents all punctuation characters.
5022<li><b><code>%s</code></b> &mdash; represents all space characters.5055<li><b><code>%s</code></b> --- represents all space characters.
5023<li><b><code>%u</code></b> &mdash; represents all uppercase letters.5056<li><b><code>%u</code></b> --- represents all uppercase letters.
5024<li><b><code>%w</code></b> &mdash; represents all alphanumeric characters.5057<li><b><code>%w</code></b> --- represents all alphanumeric characters.
5025<li><b><code>%x</code></b> &mdash; represents all hexadecimal digits.5058<li><b><code>%x</code></b> --- represents all hexadecimal digits.
5026<li><b><code>%z</code></b> &mdash; represents the character with representation 0.5059<li><b><code>%z</code></b> --- represents the character with representation 0.
5027<li><b><code>%<em>x</em></code></b> (where <em>x</em> is any non-alphanumeric character) &mdash;5060<li><b><code>%<em>x</em></code></b> (where <em>x</em> is any non-alphanumeric character) ---
5028represents the character <em>x</em>.5061represents the character <em>x</em>.
5029This is the standard way to escape the magic characters.5062This is the standard way to escape the magic characters.
5030Any punctuation character (even the non magic)5063Any punctuation character (even the non magic)
5031can be preceded by a `<code>%</code>&acute;5064can be preceded by a `<code>%</code>&acute;
5032when used to represent itself in a pattern.5065when used to represent itself in a pattern.
5033 5066
5034<p><li><b><code>[<em>set</em>]</code></b> &mdash;5067<p><li><b><code>[<em>set</em>]</code></b> ---
5035represents the class which is the union of all5068represents the class which is the union of all
5036characters in <em>set</em>.5069characters in <em>set</em>.
5037A range of characters may be specified by5070A range of characters may be specified by
@@ -5049,7 +5082,7 @@ the lowercase letters plus the `<code>-</code>&acute; character. · 11 unmodified lines
5049Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>5082Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>
5050have no meaning.5083have no meaning.
5051 5084
5052<p><li><b><code>[^<em>set</em>]</code></b> &mdash;5085<p><li><b><code>[^<em>set</em>]</code></b> ---
5053represents the complement of <em>set</em>,5086represents the complement of <em>set</em>,
5054where <em>set</em> is interpreted as above.5087where <em>set</em> is interpreted as above.
5055</ul>5088</ul>
@@ -5135,30 +5168,14 @@ represents an array or a list. · 79 unmodified lines
5135For those functions, when we talk about "the length" of a table5168For those functions, when we talk about "the length" of a table
5136we mean the result of the length operator.5169we mean the result of the length operator.
5137 5170
5138<p><a name="pdf-table.concat"></a><hr><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3>5171<p><a name="pdf-table.concat"></a><hr/><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3>
5139Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>.5172Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>.
5140The default value for <code>sep</code> is the empty string,5173The default value for <code>sep</code> is the empty string,
5141the default for <code>i</code> is 1,5174the default for <code>i</code> is 1,
5142and the default for <code>j</code> is the length of the table.5175and the default for <code>j</code> is the length of the table.
5143If <code>i</code> is greater than <code>j</code>, returns the empty string.5176If <code>i</code> is greater than <code>j</code>, returns the empty string.
5144 5177
5145<p><a name="pdf-table.sort"></a><hr><h3><code>table.sort (table [, comp])</code></h3>5178<p><a name="pdf-table.insert"></a><hr/><h3><code>table.insert (table, [pos,] value)</code></h3>
5146Sorts table elements in a given order, <em>in-place</em>,
5147from <code>table[1]</code> to <code>table[n]</code>,
5148where <code>n</code> is the length of the table.
5149If <code>comp</code> is given,
5150then it must be a function that receives two table elements,
5151and returns true
5152when the first is less than the second
5153(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).
5154If <code>comp</code> is not given,
5155then the standard Lua operator <code>&#060;</code> is used instead.
5156
5157<p>The sort algorithm is not stable,
5158that is, elements considered equal by the given order
5159may have their relative positions changed by the sort.
5160
5161<p><a name="pdf-table.insert"></a><hr><h3><code>table.insert (table, [pos,] value)</code></h3>
5162 5179
5163<p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>,5180<p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>,
5164shifting up other elements to open space, if necessary.5181shifting up other elements to open space, if necessary.
@@ -5167,7 +5184,12 @@ where <code>n</code> is the length of the table (see <a href="#len-op">2.5.5</a> · 2 unmodified lines
5167so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end5184so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
5168of table <code>t</code>.5185of table <code>t</code>.
5169 5186
5170<p><a name="pdf-table.remove"></a><hr><h3><code>table.remove (table [, pos])</code></h3>5187<p><a name="pdf-table.maxn(table)"></a><hr/><h3><code>table.maxn(table)</code></h3>
5188
5189<p>Returns the largest positive numerical index of the given table,
5190or zero if the table has no positive numerical indices.
5191
5192<p><a name="pdf-table.remove"></a><hr/><h3><code>table.remove (table [, pos])</code></h3>
5171 5193
5172<p>Removes from <code>table</code> the element at position <code>pos</code>,5194<p>Removes from <code>table</code> the element at position <code>pos</code>,
5173shifting down other elements to close the space, if necessary.5195shifting down other elements to close the space, if necessary.
@@ -5177,26 +5199,42 @@ where <code>n</code> is the length of the table, · 3 unmodified lines
5177so that a call <code>table.remove(t)</code> removes the last element5199so that a call <code>table.remove(t)</code> removes the last element
5178of table <code>t</code>.5200of table <code>t</code>.
5179 5201
5202<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>,
5204from <code>table[1]</code> to <code>table[n]</code>,
5205where <code>n</code> is the length of the table.
5206If <code>comp</code> is given,
5207then it must be a function that receives two table elements,
5208and returns true
5209when the first is less than the second
5210(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).
5211If <code>comp</code> is not given,
5212then the standard Lua operator <code>&#060;</code> is used instead.
5213
5214<p>The sort algorithm is not stable,
5215that is, elements considered equal by the given order
5216may have their relative positions changed by the sort.
5217
5180<p><a name="mathlib"></a><a name="5.6"></a><h2>5.6 - Mathematical Functions</h2>5218<p><a name="mathlib"></a><a name="5.6"></a><h2>5.6 - Mathematical Functions</h2>
5181 5219
5182<p>This library is an interface to the standard C math library.5220<p>This library is an interface to the standard C math library.
5183It provides all its functions inside the table <code>math</code>.5221It provides all its functions inside the table <code>math</code>.
5184The library provides the following functions:5222The library provides the following functions:
5185 5223<a name="pdf-math.abs"></a><a name="pdf-math.acos"></a><a name="pdf-math.asin"></a><a name="pdf-math.atan"></a>
5186 5224<a name="pdf-math.atan2"></a><a name="pdf-math.ceil"></a><a name="pdf-math.cos"></a><a name="pdf-math.cosh"></a>
5187 5225<a name="pdf-math.def"></a><a name="pdf-math.exp"></a>
5188 5226<a name="pdf-math.floor"></a><a name="pdf-math.log"></a><a name="pdf-math.log10"></a>
5189 5227<a name="pdf-math.fmod"></a><a name="pdf-math.pow"></a><a name="pdf-math.sin"></a>
5190 5228<a name="pdf-math.sqrt"></a><a name="pdf-math.tan"></a><a name="pdf-math.ldexp"></a>
5191 5229<a name="pdf-math.sinh"></a><a name="pdf-math.tanh"></a>
5192<PRE>5230<pre>
5193 math.abs math.acos math.asin math.atan math.atan25231 math.abs math.acos math.asin math.atan math.atan2
5194 math.ceil math.cosh math.cos math.deg math.exp5232 math.ceil math.cosh math.cos math.deg math.exp
5195 math.floor math.fmod math.frexp math.ldexp math.log5233 math.floor math.fmod math.frexp math.ldexp math.log
5196 math.log10 math.max math.min math.modf math.pow5234 math.log10 math.max math.min math.modf math.pow
5197 math.rad math.random math.randomseed math.sin5235 math.rad math.random math.randomseed math.sin
5198 math.sinh math.sqrt math.tan math.tanh5236 math.sinh math.sqrt math.tan math.tanh
5199</PRE>5237</pre>
5200plus a variable <code>math.pi</code> and5238plus a variable <code>math.pi</code> and
5201a variable <code>math.huge</code>,5239a variable <code>math.huge</code>,
5202with the value <code>HUGE_VAL</code>.5240with the value <code>HUGE_VAL</code>.
@@ -5255,20 +5293,20 @@ three predefined file descriptors with their usual meanings from C: · 52 unmodified lines
5255<code>io.stdin</code>, <code>io.stdout</code>, and <code>io.stderr</code>.5293<code>io.stdin</code>, <code>io.stdout</code>, and <code>io.stderr</code>.
5256 5294
5257<p>Unless otherwise stated,5295<p>Unless otherwise stated,
5258all I/O functions return <B>nil</B> on failure5296all I/O functions return <b>nil</b> on failure
5259(plus an error message as a second result)5297(plus an error message as a second result)
5260and some value different from <B>nil</B> on success.5298and some value different from <b>nil</b> on success.
5261 5299
5262<p><a name="pdf-io.close"></a><hr><h3><code>io.close ([file])</code></h3>5300<p><a name="pdf-io.close"></a><hr/><h3><code>io.close ([file])</code></h3>
5263 5301
5264<p>Equivalent to <code>file:close()</code>.5302<p>Equivalent to <code>file:close()</code>.
5265Without a <code>file</code>, closes the default output file.5303Without a <code>file</code>, closes the default output file.
5266 5304
5267<p><a name="pdf-io.flush"></a><hr><h3><code>io.flush ()</code></h3>5305<p><a name="pdf-io.flush"></a><hr/><h3><code>io.flush ()</code></h3>
5268 5306
5269<p>Equivalent to <code>file:flush</code> over the default output file.5307<p>Equivalent to <code>file:flush</code> over the default output file.
5270 5308
5271<p><a name="pdf-io.input"></a><hr><h3><code>io.input ([file])</code></h3>5309<p><a name="pdf-io.input"></a><hr/><h3><code>io.input ([file])</code></h3>
5272 5310
5273<p>When called with a file name, it opens the named file (in text mode),5311<p>When called with a file name, it opens the named file (in text mode),
5274and sets its handle as the default input file.5312and sets its handle as the default input file.
@@ -5280,31 +5318,31 @@ it returns the current default input file. · 5 unmodified lines
5280<p>In case of errors this function raises the error,5318<p>In case of errors this function raises the error,
5281instead of returning an error code.5319instead of returning an error code.
5282 5320
5283<p><a name="pdf-io.lines"></a><hr><h3><code>io.lines ([filename])</code></h3>5321<p><a name="pdf-io.lines"></a><hr/><h3><code>io.lines ([filename])</code></h3>
5284 5322
5285<p>Opens the given file name in read mode5323<p>Opens the given file name in read mode
5286and returns an iterator function that,5324and returns an iterator function that,
5287each time it is called,5325each time it is called,
5288returns a new line from the file.5326returns a new line from the file.
5289Therefore, the construction5327Therefore, the construction
5290<PRE>5328<pre>
5291 for line in io.lines(filename) do ... end5329 for line in io.lines(filename) do ... end
5292</PRE>5330</pre>
5293will iterate over all lines of the file.5331will iterate over all lines of the file.
5294When the iterator function detects the end of file,5332When the iterator function detects the end of file,
5295it returns <B>nil</B> (to finish the loop) and automatically closes the file.5333it returns <b>nil</b> (to finish the loop) and automatically closes the file.
5296 5334
5297<p>The call <code>io.lines()</code> (without a file name) is equivalent5335<p>The call <code>io.lines()</code> (without a file name) is equivalent
5298to <code>io.input():lines()</code>, that is, it iterates over the5336to <code>io.input():lines()</code>, that is, it iterates over the
5299lines of the default input file.5337lines of the default input file.
5300In that case it does not close the file when the loop ends.5338In that case it does not close the file when the loop ends.
5301 5339
5302<p><a name="pdf-io.open"></a><hr><h3><code>io.open (filename [, mode])</code></h3>5340<p><a name="pdf-io.open"></a><hr/><h3><code>io.open (filename [, mode])</code></h3>
5303 5341
5304<p>This function opens a file,5342<p>This function opens a file,
5305in the mode specified in the string <code>mode</code>.5343in the mode specified in the string <code>mode</code>.
5306It returns a new file handle,5344It returns a new file handle,
5307or, in case of errors, <B>nil</B> plus an error message.5345or, in case of errors, <b>nil</b> plus an error message.
5308 5346
5309<p>The <code>mode</code> string can be any of the following:5347<p>The <code>mode</code> string can be any of the following:
5310<ul>5348<ul>
@@ -5321,11 +5359,11 @@ which is needed in some systems to open the file in binary mode. · 10 unmodified lines
5321This string is exactly what is used in the5359This string is exactly what is used in the
5322standard C function <code>fopen</code>.5360standard C function <code>fopen</code>.
5323 5361
5324<p><a name="pdf-io.output"></a><hr><h3><code>io.output ([file])</code></h3>5362<p><a name="pdf-io.output"></a><hr/><h3><code>io.output ([file])</code></h3>
5325 5363
5326<p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file.5364<p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file.
5327 5365
5328<p><a name="pdf-io.popen"></a><hr><h3><code>io.popen ([prog [, mode]])</code></h3>5366<p><a name="pdf-io.popen"></a><hr/><h3><code>io.popen ([prog [, mode]])</code></h3>
5329 5367
5330<p>Starts program <code>prog</code> in a separated process and returns5368<p>Starts program <code>prog</code> in a separated process and returns
5331a file handle that you can use to read data from that program5369a file handle that you can use to read data from that program
@@ -5336,57 +5374,57 @@ or to write data to that program · 4 unmodified lines
5336<p>This function is system dependent and is not available5374<p>This function is system dependent and is not available
5337in all platforms.5375in all platforms.
5338 5376
5339<p><a name="pdf-io.read"></a><hr><h3><code>io.read (format1, ...)</code></h3>5377<p><a name="pdf-io.read"></a><hr/><h3><code>io.read (format1, ...)</code></h3>
5340 5378
5341<p>Equivalent to <code>io.input():read</code>.5379<p>Equivalent to <code>io.input():read</code>.
5342 5380
5343<p><a name="pdf-io.tmpfile"></a><hr><h3><code>io.tmpfile ()</code></h3>5381<p><a name="pdf-io.tmpfile"></a><hr/><h3><code>io.tmpfile ()</code></h3>
5344 5382
5345<p>Returns a handle for a temporary file.5383<p>Returns a handle for a temporary file.
5346This file is open in update mode5384This file is open in update mode
5347and it is automatically removed when the program ends.5385and it is automatically removed when the program ends.
5348 5386
5349<p><a name="pdf-io.type"></a><hr><h3><code>io.type (obj)</code></h3>5387<p><a name="pdf-io.type"></a><hr/><h3><code>io.type (obj)</code></h3>
5350 5388
5351<p>Checks whether <code>obj</code> is a valid file handle.5389<p>Checks whether <code>obj</code> is a valid file handle.
5352Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,5390Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
5353<code>"closed file"</code> if <code>obj</code> is a closed file handle,5391<code>"closed file"</code> if <code>obj</code> is a closed file handle,
5354and <B>nil</B> if <code>obj</code> is not a file handle.5392and <b>nil</b> if <code>obj</code> is not a file handle.
5355 5393
5356<p><a name="pdf-io.write"></a><hr><h3><code>io.write (value1, ...)</code></h3>5394<p><a name="pdf-io.write"></a><hr/><h3><code>io.write (value1, ...)</code></h3>
5357 5395
5358<p>Equivalent to <code>io.output():write</code>.5396<p>Equivalent to <code>io.output():write</code>.
5359 5397
5360<p><a name="pdf-file:close"></a><hr><h3><code>file:close ()</code></h3>5398<p><a name="pdf-file:close"></a><hr/><h3><code>file:close ()</code></h3>
5361 5399
5362<p>Closes <code>file</code>.5400<p>Closes <code>file</code>.
5363Note that files are automatically closed when garbage collected,5401Note that files are automatically closed when garbage collected,
5364but that takes an unpredictable time to happen.5402but that takes an unpredictable time to happen.
5365 5403
5366<p><a name="flush"></a><a name="pdf-file:flush"></a><hr><h3><code>file:flush ()</code></h3>5404<p><a name="flush"></a><a name="pdf-file:flush"></a><hr/><h3><code>file:flush ()</code></h3>
5367 5405
5368<p>Saves any written data to <code>file</code>.5406<p>Saves any written data to <code>file</code>.
5369 5407
5370<p><a name="pdf-file:lines"></a><hr><h3><code>file:lines ()</code></h3>5408<p><a name="pdf-file:lines"></a><hr/><h3><code>file:lines ()</code></h3>
5371 5409
5372<p>Returns an iterator function that,5410<p>Returns an iterator function that,
5373each time it is called,5411each time it is called,
5374returns a new line from the file.5412returns a new line from the file.
5375Therefore, the construction5413Therefore, the construction
5376<PRE>5414<pre>
5377 for line in file:lines() do ... end5415 for line in file:lines() do ... end
5378</PRE>5416</pre>
5379will iterate over all lines of the file.5417will iterate over all lines of the file.
5380(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file5418(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
5381when the loop ends.)5419when the loop ends.)
5382 5420
5383<p><a name="pdf-file:read"></a><hr><h3><code>file:read (format1, ...)</code></h3>5421<p><a name="pdf-file:read"></a><hr/><h3><code>file:read (format1, ...)</code></h3>
5384 5422
5385<p>Reads the file <code>file</code>,5423<p>Reads the file <code>file</code>,
5386according to the given formats, which specify what to read.5424according to the given formats, which specify what to read.
5387For each format,5425For each format,
5388the function returns a string (or a number) with the characters read,5426the function returns a string (or a number) with the characters read,
5389or <B>nil</B> if it cannot read data with the specified format.5427or <b>nil</b> if it cannot read data with the specified format.
5390When called without formats,5428When called without formats,
5391it uses a default format that reads the entire next line5429it uses a default format that reads the entire next line
5392(see below).5430(see below).
@@ -5398,16 +5436,16 @@ this is the only format that returns a number instead of a string. · 5 unmodified lines
5398<li><b>"*a"</b> reads the whole file, starting at the current position.5436<li><b>"*a"</b> reads the whole file, starting at the current position.
5399On end of file, it returns the empty string.5437On end of file, it returns the empty string.
5400<li><b>"*l"</b> reads the next line (skipping the end of line),5438<li><b>"*l"</b> reads the next line (skipping the end of line),
5401returning <B>nil</B> on end of file.5439returning <b>nil</b> on end of file.
5402This is the default format.5440This is the default format.
5403<li><b><em>number</em></b> reads a string with up to that number of characters,5441<li><b><em>number</em></b> reads a string with up to that number of characters,
5404returning <B>nil</B> on end of file.5442returning <b>nil</b> on end of file.
5405If number is zero,5443If number is zero,
5406it reads nothing and returns an empty string,5444it reads nothing and returns an empty string,
5407or <B>nil</B> on end of file.5445or <b>nil</b> on end of file.
5408</ul>5446</ul>
5409 5447
5410<p><a name="pdf-file:seek"></a><hr><h3><code>file:seek ([whence] [, offset])</code></h3>5448<p><a name="pdf-file:seek"></a><hr/><h3><code>file:seek ([whence] [, offset])</code></h3>
5411 5449
5412<p>Sets and gets the file position,5450<p>Sets and gets the file position,
5413measured from the beginning of the file,5451measured from the beginning of the file,
@@ -5420,7 +5458,7 @@ specified by the string <code>whence</code>, as follows: · 6 unmodified lines
5420</ul>5458</ul>
5421In case of success, function <code>seek</code> returns the final file position,5459In case of success, function <code>seek</code> returns the final file position,
5422measured in bytes from the beginning of the file.5460measured in bytes from the beginning of the file.
5423If this function fails, it returns <B>nil</B>,5461If this function fails, it returns <b>nil</b>,
5424plus a string describing the error.5462plus a string describing the error.
5425 5463
5426<p>The default value for <code>whence</code> is <code>"cur"</code>,5464<p>The default value for <code>whence</code> is <code>"cur"</code>,
@@ -5432,7 +5470,7 @@ beginning of the file (and returns 0); · 5 unmodified lines
5432and the call <code>file:seek("end")</code> sets the position to the5470and the call <code>file:seek("end")</code> sets the position to the
5433end of the file, and returns its size.5471end of the file, and returns its size.
5434 5472
5435<p><a name="pdf-file:setvbuf"></a><hr><h3><code>file:setvbuf (mode [, size])</code></h3>5473<p><a name="pdf-file:setvbuf"></a><hr/><h3><code>file:setvbuf (mode [, size])</code></h3>
5436 5474
5437<p>Sets the buffering mode for an output file.5475<p>Sets the buffering mode for an output file.
5438There are three available modes:5476There are three available modes:
@@ -5448,7 +5486,7 @@ For the last two cases, <code>sizes</code> · 9 unmodified lines
5448specifies the size of the buffer, in bytes.5486specifies the size of the buffer, in bytes.
5449The default is an appropriate size.5487The default is an appropriate size.
5450 5488
5451<p><a name="pdf-file:write"></a><hr><h3><code>file:write (value1, ...)</code></h3>5489<p><a name="pdf-file:write"></a><hr/><h3><code>file:write (value1, ...)</code></h3>
5452 5490
5453<p>Writes the value of each of its arguments to5491<p>Writes the value of each of its arguments to
5454the filehandle <code>file</code>.5492the filehandle <code>file</code>.
@@ -5460,12 +5498,12 @@ use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.fo · 5 unmodified lines
5460 5498
5461<p>This library is implemented through table <code>os</code>.5499<p>This library is implemented through table <code>os</code>.
5462 5500
5463<p><a name="pdf-os.clock"></a><hr><h3><code>os.clock ()</code></h3>5501<p><a name="pdf-os.clock"></a><hr/><h3><code>os.clock ()</code></h3>
5464 5502
5465<p>Returns an approximation of the amount of CPU time5503<p>Returns an approximation of the amount of CPU time
5466used by the program, in seconds.5504used by the program, in seconds.
5467 5505
5468<p><a name="pdf-os.date"></a><hr><h3><code>os.date ([format [, time]])</code></h3>5506<p><a name="pdf-os.date"></a><hr/><h3><code>os.date ([format [, time]])</code></h3>
5469 5507
5470<p>Returns a string or a table containing date and time,5508<p>Returns a string or a table containing date and time,
5471formatted according to the given string <code>format</code>.5509formatted according to the given string <code>format</code>.
@@ -5495,43 +5533,43 @@ formatted according to the same rules as the C function <code>strftime</code>. · 23 unmodified lines
5495the host system and on the current locale5533the host system and on the current locale
5496(that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).5534(that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).
5497 5535
5498<p><a name="pdf-os.difftime"></a><hr><h3><code>os.difftime (t2, t1)</code></h3>5536<p><a name="pdf-os.difftime"></a><hr/><h3><code>os.difftime (t2, t1)</code></h3>
5499 5537
5500<p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>.5538<p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>.
5501In Posix, Windows, and some other systems,5539In Posix, Windows, and some other systems,
5502this value is exactly <code>t2</code><em>-</em><code>t1</code>.5540this value is exactly <code>t2</code><em>-</em><code>t1</code>.
5503 5541
5504<p><a name="pdf-os.execute"></a><hr><h3><code>os.execute (command)</code></h3>5542<p><a name="pdf-os.execute"></a><hr/><h3><code>os.execute (command)</code></h3>
5505 5543
5506<p>This function is equivalent to the C function <code>system</code>.5544<p>This function is equivalent to the C function <code>system</code>.
5507It passes <code>command</code> to be executed by an operating system shell.5545It passes <code>command</code> to be executed by an operating system shell.
5508It returns a status code, which is system-dependent.5546It returns a status code, which is system-dependent.
5509 5547
5510<p><a name="pdf-os.exit"></a><hr><h3><code>os.exit ([code])</code></h3>5548<p><a name="pdf-os.exit"></a><hr/><h3><code>os.exit ([code])</code></h3>
5511 5549
5512<p>Calls the C function <code>exit</code>,5550<p>Calls the C function <code>exit</code>,
5513with an optional <code>code</code>,5551with an optional <code>code</code>,
5514to terminate the host program.5552to terminate the host program.
5515The default value for <code>code</code> is the success code.5553The default value for <code>code</code> is the success code.
5516 5554
5517<p><a name="pdf-os.getenv"></a><hr><h3><code>os.getenv (varname)</code></h3>5555<p><a name="pdf-os.getenv"></a><hr/><h3><code>os.getenv (varname)</code></h3>
5518 5556
5519<p>Returns the value of the process environment variable <code>varname</code>,5557<p>Returns the value of the process environment variable <code>varname</code>,
5520or <B>nil</B> if the variable is not defined.5558or <b>nil</b> if the variable is not defined.
5521 5559
5522<p><a name="pdf-os.remove"></a><hr><h3><code>os.remove (filename)</code></h3>5560<p><a name="pdf-os.remove"></a><hr/><h3><code>os.remove (filename)</code></h3>
5523 5561
5524<p>Deletes the file with the given name.5562<p>Deletes the file with the given name.
5525If this function fails, it returns <B>nil</B>,5563If this function fails, it returns <b>nil</b>,
5526plus a string describing the error.5564plus a string describing the error.
5527 5565
5528<p><a name="pdf-os.rename"></a><hr><h3><code>os.rename (oldname, newname)</code></h3>5566<p><a name="pdf-os.rename"></a><hr/><h3><code>os.rename (oldname, newname)</code></h3>
5529 5567
5530<p>Renames file named <code>oldname</code> to <code>newname</code>.5568<p>Renames file named <code>oldname</code> to <code>newname</code>.
5531If this function fails, it returns <B>nil</B>,5569If this function fails, it returns <b>nil</b>,
5532plus a string describing the error.5570plus a string describing the error.
5533 5571
5534<p><a name="pdf-os.setlocale"></a><hr><h3><code>os.setlocale (locale [, category])</code></h3>5572<p><a name="pdf-os.setlocale"></a><hr/><h3><code>os.setlocale (locale [, category])</code></h3>
5535 5573
5536<p>Sets the current locale of the program.5574<p>Sets the current locale of the program.
5537<code>locale</code> is a string specifying a locale;5575<code>locale</code> is a string specifying a locale;
@@ -5540,9 +5578,9 @@ plus a string describing the error. · 2 unmodified lines
5540<code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;5578<code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;
5541the default category is <code>"all"</code>.5579the default category is <code>"all"</code>.
5542The function returns the name of the new locale,5580The function returns the name of the new locale,
5543or <B>nil</B> if the request cannot be honored.5581or <b>nil</b> if the request cannot be honored.
5544 5582
5545<p><a name="pdf-os.time"></a><hr><h3><code>os.time ([table])</code></h3>5583<p><a name="pdf-os.time"></a><hr/><h3><code>os.time ([table])</code></h3>
5546 5584
5547<p>Returns the current time when called without arguments,5585<p>Returns the current time when called without arguments,
5548or a time representing the date and time specified by the given table.5586or a time representing the date and time specified by the given table.
@@ -5557,7 +5595,7 @@ In other systems, the meaning is not specified, · 8 unmodified lines
5557and the number returned by <code>time</code> can be used only as an argument to5595and the number returned by <code>time</code> can be used only as an argument to
5558<code>date</code> and <code>difftime</code>.5596<code>date</code> and <code>difftime</code>.
5559 5597
5560<p><a name="pdf-os.tmpname"></a><hr><h3><code>os.tmpname ()</code></h3>5598<p><a name="pdf-os.tmpname"></a><hr/><h3><code>os.tmpname ()</code></h3>
5561 5599
5562<p>Returns a string with a file name that can5600<p>Returns a string with a file name that can
5563be used for a temporary file.5601be used for a temporary file.
@@ -5583,7 +5621,7 @@ and therefore can compromise some otherwise secure code. · 19 unmodified lines
5583<p>All functions in this library are provided5621<p>All functions in this library are provided
5584inside a <code>debug</code> table.5622inside a <code>debug</code> table.
5585 5623
5586<p><a name="pdf-debug.debug"></a><hr><h3><code>debug.debug ()</code></h3>5624<p><a name="pdf-debug.debug"></a><hr/><h3><code>debug.debug ()</code></h3>
5587 5625
5588<p>Enters an interactive mode with the user,5626<p>Enters an interactive mode with the user,
5589running each string that the user enters.5627running each string that the user enters.
@@ -5596,17 +5634,17 @@ so that the caller continues its execution. · 6 unmodified lines
5596<p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested5634<p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested
5597with any function, so they have no direct access to local variables.5635with any function, so they have no direct access to local variables.
5598 5636
5599<p><a name="pdf-debug.getfenv"></a><hr><h3><code>debug.getfenv (o)</code></h3>5637<p><a name="pdf-debug.getfenv"></a><hr/><h3><code>debug.getfenv (o)</code></h3>
5600Returns the environment of object <code>o</code>.5638Returns the environment of object <code>o</code>.
5601 5639
5602<p><a name="pdf-debug.gethook"></a><hr><h3><code>debug.gethook ()</code></h3>5640<p><a name="pdf-debug.gethook"></a><hr/><h3><code>debug.gethook ()</code></h3>
5603 5641
5604<p>Returns the current hook settings, as three values:5642<p>Returns the current hook settings, as three values:
5605the current hook function, the current hook mask,5643the current hook function, the current hook mask,
5606and the current hook count5644and the current hook count
5607(as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).5645(as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).
5608 5646
5609<p><a name="pdf-debug.getinfo"></a><hr><h3><code>debug.getinfo (function [, what])</code></h3>5647<p><a name="pdf-debug.getinfo"></a><hr/><h3><code>debug.getinfo (function [, what])</code></h3>
5610 5648
5611<p>This function returns a table with information about a function.5649<p>This function returns a table with information about a function.
5612You can give the function directly,5650You can give the function directly,
@@ -5616,7 +5654,7 @@ Level 0 is the current function (<code>getinfo</code> itself); · 3 unmodified lines
5616level 1 is the function that called <code>getinfo</code>;5654level 1 is the function that called <code>getinfo</code>;
5617and so on.5655and so on.
5618If <code>function</code> is a number larger than the number of active functions,5656If <code>function</code> is a number larger than the number of active functions,
5619then <code>getinfo</code> returns <B>nil</B>.5657then <code>getinfo</code> returns <b>nil</b>.
5620 5658
5621<p>The returned table contains all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>,5659<p>The returned table contains all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>,
5622with the string <code>what</code> describing which fields to fill in.5660with the string <code>what</code> describing which fields to fill in.
@@ -5630,33 +5668,41 @@ the name of the current function, if a reasonable name can be found, · 7 unmodified lines
5630and <code>debug.getinfo(print)</code> returns a table with all available information5668and <code>debug.getinfo(print)</code> returns a table with all available information
5631about the <a href="#pdf-print"><code>print</code></a> function.5669about the <a href="#pdf-print"><code>print</code></a> function.
5632 5670
5633<p><a name="pdf-debug.getlocal"></a><hr><h3><code>debug.getlocal (level, local)</code></h3>5671<p><a name="pdf-debug.getlocal"></a><hr/><h3><code>debug.getlocal (level, local)</code></h3>
5634 5672
5635<p>This function returns the name and the value of the local variable5673<p>This function returns the name and the value of the local variable
5636with index <code>local</code> of the function at level <code>level</code> of the stack.5674with index <code>local</code> of the function at level <code>level</code> of the stack.
5637(The first parameter or local variable has index 1, and so on,5675(The first parameter or local variable has index 1, and so on,
5638until the last active local variable.)5676until the last active local variable.)
5639The function returns <B>nil</B> if there is no local5677The function returns <b>nil</b> if there is no local
5640variable with the given index,5678variable with the given index,
5641and raises an error when called with a <code>level</code> out of range.5679and raises an error when called with a <code>level</code> out of range.
5642(You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.)5680(You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.)
5643 5681
5644<p><a name="pdf-debug.getmetatable"></a><hr><h3><code>debug.getmetatable (object)</code></h3>5682<p>Variable names starting with `<code>(</code>&acute; (open parentheses)
5683represent internal variables
5684(loop control variables, temporaries, and C function locals).
5645 5685
5646<p>If <code>object</code> does not have a metatable, returns <B>nil</B>.5686<p><a name="pdf-debug.getmetatable"></a><hr/><h3><code>debug.getmetatable (object)</code></h3>
5687
5688<p>If <code>object</code> does not have a metatable, returns <b>nil</b>.
5647Otherwise, returns the metatable of the given object.5689Otherwise, returns the metatable of the given object.
5648 5690
5649<p><a name="pdf-debug.getupvalue"></a><hr><h3><code>debug.getupvalue (func, up)</code></h3>5691<p><a name="pdf-debug.getregistry"></a><hr/><h3><code>debug.getregistry ()</code></h3>
5692
5693<p>Returns the registry table (see <a href="#registry">3.5</a>).
5694
5695<p><a name="pdf-debug.getupvalue"></a><hr/><h3><code>debug.getupvalue (func, up)</code></h3>
5650 5696
5651<p>This function returns the name and the value of the upvalue5697<p>This function returns the name and the value of the upvalue
5652with index <code>up</code> of the function <code>func</code>.5698with index <code>up</code> of the function <code>func</code>.
5653The function returns <B>nil</B> if there is no upvalue with the given index.5699The function returns <b>nil</b> if there is no upvalue with the given index.
5654 5700
5655<p><a name="pdf-debug.setfenv"></a><hr><h3><code>debug.setfenv (o, table)</code></h3>5701<p><a name="pdf-debug.setfenv"></a><hr/><h3><code>debug.setfenv (o, table)</code></h3>
5656 5702
5657<p>Sets the environment of the given object.5703<p>Sets the environment of the given object.
5658 5704
5659<p><a name="pdf-debug.sethook"></a><hr><h3><code>debug.sethook (hook, mask [, count])</code></h3>5705<p><a name="pdf-debug.sethook"></a><hr/><h3><code>debug.sethook (hook, mask [, count])</code></h3>
5660 5706
5661<p>Sets the given function as a hook.5707<p>Sets the given function as a hook.
5662The string <code>mask</code> and the number <code>count</code> describe5708The string <code>mask</code> and the number <code>count</code> describe
@@ -5689,29 +5735,29 @@ unless the event is <code>"tail return"</code>. · 26 unmodified lines
5689In this case, Lua is only simulating the return,5735In this case, Lua is only simulating the return,
5690and a call to <code>getinfo</code> will return invalid data.5736and a call to <code>getinfo</code> will return invalid data.
5691 5737
5692<p><a name="pdf-debug.setlocal"></a><hr><h3><code>debug.setlocal (level, local, value)</code></h3>5738<p><a name="pdf-debug.setlocal"></a><hr/><h3><code>debug.setlocal (level, local, value)</code></h3>
5693 5739
5694<p>This function assigns the value <code>value</code> to the local variable5740<p>This function assigns the value <code>value</code> to the local variable
5695with index <code>local</code> of the function at level <code>level</code> of the stack.5741with index <code>local</code> of the function at level <code>level</code> of the stack.
5696The function returns <B>nil</B> if there is no local5742The function returns <b>nil</b> if there is no local
5697variable with the given index,5743variable with the given index,
5698and raises an error when called with a <code>level</code> out of range.5744and raises an error when called with a <code>level</code> out of range.
5699(You can call <code>getinfo</code> to check whether the level is valid.)5745(You can call <code>getinfo</code> to check whether the level is valid.)
5700Otherwise, it returns the name of the local variable.5746Otherwise, it returns the name of the local variable.
5701 5747
5702<p><a name="pdf-debug.setmetatable"></a><hr><h3><code>debug.setmetatable (o, metatable)</code></h3>5748<p><a name="pdf-debug.setmetatable"></a><hr/><h3><code>debug.setmetatable (o, metatable)</code></h3>
5703 5749
5704<p>Sets the metatable for the given object.5750<p>Sets the metatable for the given object.
5705 5751
5706<p><a name="pdf-debug.setupvalue"></a><hr><h3><code>debug.setupvalue (func, up, value)</code></h3>5752<p><a name="pdf-debug.setupvalue"></a><hr/><h3><code>debug.setupvalue (func, up, value)</code></h3>
5707 5753
5708<p>This function assigns the value <code>value</code> to the upvalue5754<p>This function assigns the value <code>value</code> to the upvalue
5709with index <code>up</code> of the function <code>func</code>.5755with index <code>up</code> of the function <code>func</code>.
5710The function returns <B>nil</B> if there is no upvalue5756The function returns <b>nil</b> if there is no upvalue
5711with the given index.5757with the given index.
5712Otherwise, it returns the name of the upvalue.5758Otherwise, it returns the name of the upvalue.
5713 5759
5714<p><a name="pdf-debug.traceback"></a><hr><h3><code>debug.traceback ([message])</code></h3>5760<p><a name="pdf-debug.traceback"></a><hr/><h3><code>debug.traceback ([message])</code></h3>
5715 5761
5716<p>Returns a string with a traceback of the call stack.5762<p>Returns a string with a traceback of the call stack.
5717An optional <code>message</code> string is appended5763An optional <code>message</code> string is appended
@@ -5731,17 +5777,17 @@ is provided with the standard distribution. · 13 unmodified lines
5731The stand-alone interpreter includes5777The stand-alone interpreter includes
5732all standard libraries plus the reflexive debug interface.5778all standard libraries plus the reflexive debug interface.
5733Its usage is:5779Its usage is:
5734<PRE>5780<pre>
5735 lua [options] [script [args]]5781 lua [options] [script [args]]
5736</PRE>5782</pre>
5737The options are:5783The options are:
5738<ul>5784<ul>
5739<li><b><code>-</code> </b> executes <code>stdin</code> as a file;
5740<li><b><code>-e</code> <em>stat</em></b> executes string <em>stat</em>;5785<li><b><code>-e</code> <em>stat</em></b> executes string <em>stat</em>;
5741<li><b><code>-l</code> <em>mod</em></b> "requires" <em>mod</em>;5786<li><b><code>-l</code> <em>mod</em></b> "requires" <em>mod</em>;
5742<li><b><code>-i</code></b> enters interactive mode after running <em>script</em>;5787<li><b><code>-i</code></b> enters interactive mode after running <em>script</em>;
5743<li><b><code>-v</code></b> prints version information;5788<li><b><code>-v</code></b> prints version information;
5744<li><b><code>--</code></b> stop handling options.5789<li><b><code>--</code></b> stops handling options;
5790<li><b><code>-</code> </b> executes <code>stdin</code> as a file and stops handling options.
5745</ul>5791</ul>
5746After handling its options, <code>lua</code> runs the given <em>script</em>,5792After handling its options, <code>lua</code> runs the given <em>script</em>,
5747passing to it the given <em>args</em>.5793passing to it the given <em>args</em>.
@@ -5757,9 +5803,9 @@ Otherwise, lua executes the string itself. · 9 unmodified lines
5757 5803
5758<p>All options are handled in order, except <code>-i</code>.5804<p>All options are handled in order, except <code>-i</code>.
5759For instance, an invocation like5805For instance, an invocation like
5760<PRE>5806<pre>
5761 $ lua -e'a=1' -e 'print(a)' script.lua5807 $ lua -e'a=1' -e 'print(a)' script.lua
5762</PRE>5808</pre>
5763will first set <code>a</code> to 1, then print <code>a</code>,5809will first set <code>a</code> to 1, then print <code>a</code>,
5764and finally run the file <code>script.lua</code>.5810and finally run the file <code>script.lua</code>.
5765(Here <code>$</code> is the shell prompt. Your prompt may be different.)5811(Here <code>$</code> is the shell prompt. Your prompt may be different.)
@@ -5774,15 +5820,15 @@ Any arguments before the script name · 8 unmodified lines
5774(that is, the interpreter name plus the options)5820(that is, the interpreter name plus the options)
5775go to negative indices.5821go to negative indices.
5776For instance, in the call5822For instance, in the call
5777<PRE>5823<pre>
5778 $ lua -la.lua b.lua t1 t25824 $ lua -la.lua b.lua t1 t2
5779</PRE>5825</pre>
5780the interpreter first runs the file <code>a.lua</code>,5826the interpreter first runs the file <code>a.lua</code>,
5781then creates a table5827then creates a table
5782<PRE>5828<pre>
5783 arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua",5829 arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua",
5784 [1] = "t1", [2] = "t2" }5830 [1] = "t1", [2] = "t2" }
5785</PRE>5831</pre>
5786and finally runs the file <code>b.lua</code>.5832and finally runs the file <code>b.lua</code>.
5787The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...5833The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...
5788as arguments;5834as arguments;
@@ -5795,9 +5841,9 @@ the interpreter waits for its completion. · 6 unmodified lines
5795<p>If the global variable <code>_PROMPT</code> is defined as a string,5841<p>If the global variable <code>_PROMPT</code> is defined as a string,
5796then its value is used as the prompt.5842then its value is used as the prompt.
5797Therefore, the prompt can be changed directly on the command line:5843Therefore, the prompt can be changed directly on the command line:
5798<PRE>5844<pre>
5799 $ lua -e"_PROMPT='myprompt> '" -i5845 $ lua -e"_PROMPT='myprompt> '" -i
5800</PRE>5846</pre>
5801(the outer pair of quotes is for the shell,5847(the outer pair of quotes is for the shell,
5802the inner is for Lua),5848the inner is for Lua),
5803or in any Lua programs by assigning to <code>_PROMPT</code>.5849or in any Lua programs by assigning to <code>_PROMPT</code>.
@@ -5811,19 +5857,19 @@ the first line of a chunk if it starts with <code>#</code>. · 7 unmodified lines
5811Therefore, Lua scripts can be made into executable programs5857Therefore, Lua scripts can be made into executable programs
5812by using <code>chmod +x</code> and the <code>#!</code> form,5858by using <code>chmod +x</code> and the <code>#!</code> form,
5813as in5859as in
5814<PRE>5860<pre>
5815#!/usr/local/bin/lua5861#!/usr/local/bin/lua
5816</PRE>5862</pre>
5817(Of course,5863(Of course,
5818the location of the Lua interpreter may be different in your machine.5864the location of the Lua interpreter may be different in your machine.
5819If <code>lua</code> is in your <code>PATH</code>,5865If <code>lua</code> is in your <code>PATH</code>,
5820then 5866then
5821<PRE>5867<pre>
5822#!/usr/bin/env lua5868#!/usr/bin/env lua
5823</PRE>5869</pre>
5824is a more portable solution.) 5870is a more portable solution.)
5825 5871
5826<p><hr>5872<p><hr/>
5827 5873
5828<p><h1>Incompatibilities with Previous Version</h1>5874<p><h1>Incompatibilities with Previous Version</h1>
5829 5875
@@ -5866,6 +5912,13 @@ Use <a href="#pdf-string.match"><code>string.match</code></a> for that. · 36 unmodified lines
5866Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.5912Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.
5867(Option <code>LUA_COMPAT_GFIND</code>)5913(Option <code>LUA_COMPAT_GFIND</code>)
5868 5914
5915<p><li>
5916When <a href="#pdf-string.gsub"><code>string.gsub</code></a> is called with a function as its
5917third argument,
5918whenever that function returns <b>nil</b> or <b>false</b> the
5919replacement string is the whole match,
5920instead of the empty string.
5921
5869<p><li>5922<p><li>
5870Function <code>table.setn</code> was deprecated.5923Function <code>table.setn</code> was deprecated.
5871Function <code>table.getn</code> corresponds5924Function <code>table.getn</code> corresponds
@@ -5924,48 +5977,66 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 52 unmodified lines
5924 5977
5925<p><pre>5978<p><pre>
5926 5979
5927<p> chunk ::= {stat [`<b>;</b>&acute;]}5980 chunk ::= {stat [`<b>;</b>&acute;]} [laststat[`<b>;</b>&acute;]]
5981
5982 block ::= chunk
5928 5983
5929<p> block ::= chunk5984 stat ::= varlist1 `<b>=</b>&acute; explist1 |
5985 functioncall |
5986 <b>do</b> block <b>end</b> |
5987 <b>while</b> exp <b>do</b> block <b>end</b> |
5988 <b>repeat</b> block <b>until</b> exp |
5989 <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> |
5990 <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b> |
5991 <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> |
5992 <b>function</b> funcname funcbody |
5993 <b>local</b> <b>function</b> Name funcbody |
5994 <b>local</b> namelist [init]
5930 5995
5931<p> stat ::= varlist1 `<b>=</b>&acute; explist1 | functioncall | <b>do</b> block <b>end</b> | <b>while</b> exp <b>do</b> block <b>end</b> | <b>repeat</b> block <b>until</b> exp | <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | <b>return</b> [explist1] | <b>break</b> | <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b> | <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | <b>function</b> funcname funcbody | <b>local</b> <b>function</b> Name funcbody | <b>local</b> namelist [init] 5996 laststat ::= <b>return</b> [explist1] | <b>break</b>
5932 5997
5933<p> funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]5998 funcname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]
5999
6000 varlist1 ::= var {`<b>,</b>&acute; var}
5934 6001
5935<p> varlist1 ::= var {`<b>,</b>&acute; var}6002 var ::= Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Name
5936 6003
5937<p> var ::= Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Name 6004 namelist ::= Name {`<b>,</b>&acute; Name}
5938 6005
5939<p> namelist ::= Name {`<b>,</b>&acute; Name}6006 init ::= `<b>=</b>&acute; explist1
5940 6007
5941<p> init ::= `<b>=</b>&acute; explist16008 explist1 ::= {exp `<b>,</b>&acute;} exp
5942 6009
5943<p> explist1 ::= {exp `<b>,</b>&acute;} exp6010 exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>&acute; |
6011 function | prefixexp | tableconstructor | exp binop exp | unop exp
5944 6012
5945<p> exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>&acute; | function | prefixexp | tableconstructor | exp binop exp | unop exp 6013 prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;
5946 6014
5947<p> prefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;6015 functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args
5948 6016
5949<p> functioncall ::= prefixexp args | prefixexp `<b>:</b>&acute; Name args 6017 args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Literal
5950 6018
5951<p> args ::= `<b>(</b>&acute; [explist1] `<b>)</b>&acute; | tableconstructor | Literal 6019 function ::= <b>function</b> funcbody
5952 6020
5953<p> function ::= <b>function</b> funcbody6021 funcbody ::= `<b>(</b>&acute; [parlist1] `<b>)</b>&acute; block <b>end</b>
5954 6022
5955<p> funcbody ::= `<b>(</b>&acute; [parlist1] `<b>)</b>&acute; block <b>end</b>6023 parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;
5956 6024
5957<p> parlist1 ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;6025 tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;
5958 6026
5959<p> tableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;
5960 fieldlist ::= field {fieldsep field} [fieldsep]6027 fieldlist ::= field {fieldsep field} [fieldsep]
5961 field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | name `<b>=</b>&acute; exp | exp
5962 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
5963 6028
5964<p> binop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; | `<b>&#060;</b>&acute; | `<b>&#060;=</b>&acute; | `<b>></b>&acute; | `<b>>=</b>&acute; | `<b>==</b>&acute; | `<b>~=</b>&acute; | <b>and</b> | <b>or</b>6029 field ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | name `<b>=</b>&acute; exp | exp
5965 6030
5966<p> unop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;6031 fieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;
5967 6032
5968<p></pre>6033 binop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; |
6034 `<b>&#060;</b>&acute; | `<b>&#060;=</b>&acute; | `<b>></b>&acute; | `<b>>=</b>&acute; | `<b>==</b>&acute; | `<b>~=</b>&acute; |
6035 <b>and</b> | <b>or</b>
6036
6037 unop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;
6038
6039</pre>
5969 6040
5970<p>6041<p>
5971 6042
@@ -5974,7 +6045,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 2 unmodified lines
5974<HR>6045<HR>
5975<SMALL>6046<SMALL>
5976Last update:6047Last update:
5977Wed Sep 7 13:53:49 BRT 20056048Tue Nov 1 15:20:21 BRST 2005
5978</SMALL>6049</SMALL>
5979 6050
5980</body></html>6051</body></html>
src/lapi.c+19−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lapi.c,v 2.48 2005/09/01 17:42:22 roberto Exp $2** $Id: lapi.c,v 2.51 2005/10/20 11:35:50 roberto Exp $
3** Lua API3** Lua API
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -141,7 +141,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 135 unmodified lines
141 setthvalue(L, L->top, L1);141 setthvalue(L, L->top, L1);
142 api_incr_top(L);142 api_incr_top(L);
143 lua_unlock(L);143 lua_unlock(L);
144 luai_userstateopen(L1);144 luai_userstatethread(L, L1);
145 return L1;145 return L1;
146}146}
147 147
@@ -913,6 +913,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 765 unmodified lines
913 res = cast(int, g->totalbytes >> 10);913 res = cast(int, g->totalbytes >> 10);
914 break;914 break;
915 }915 }
916 case LUA_GCCOUNTB: {
917 res = cast(int, g->totalbytes & 0x3ff);
918 break;
919 }
916 case LUA_GCSTEP: {920 case LUA_GCSTEP: {
917 lu_mem a = (cast(lu_mem, data) << 10);921 lu_mem a = (cast(lu_mem, data) << 10);
918 if (a <= g->totalbytes)922 if (a <= g->totalbytes)
@@ -992,8 +996,20 @@ LUA_API void lua_concat (lua_State *L, int n) { · 73 unmodified lines
992 996
993 997
994LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {998LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
999 lua_Alloc f;
1000 lua_lock(L);
995 if (ud) *ud = G(L)->ud;1001 if (ud) *ud = G(L)->ud;
996 return G(L)->frealloc;1002 f = G(L)->frealloc;
1003 lua_unlock(L);
1004 return f;
1005}
1006
1007
1008LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
1009 lua_lock(L);
1010 G(L)->ud = ud;
1011 G(L)->frealloc = f;
1012 lua_unlock(L);
997}1013}
998 1014
999 1015
src/lauxlib.c+9−10
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lauxlib.c,v 1.152 2005/09/06 17:20:11 roberto Exp $2** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp $
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*/
@@ -176,8 +176,7 @@ LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { · 170 unmodified lines
176 176
177 177
178LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {178LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
179 if (lua_isnoneornil(L, narg)) return def;179 return luaL_opt(L, luaL_checknumber, narg, def);
180 else return luaL_checknumber(L, narg);
181}180}
182 181
183 182
@@ -190,16 +189,16 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { · 6 unmodified lines
190 189
191 190
192LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,191LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
193 lua_Integer def) {192 lua_Integer def) {
194 if (lua_isnoneornil(L, narg)) return def;193 return luaL_opt(L, luaL_checkinteger, narg, def);
195 else return luaL_checkinteger(L, narg);
196}194}
197 195
198 196
199LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {197LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
200 if (!lua_getmetatable(L, obj)) /* no metatable? */198 if (!lua_getmetatable(L, obj)) /* no metatable? */
201 return 0;199 return 0;
202 lua_getfield(L, -1, event);200 lua_pushstring(L, event);
201 lua_rawget(L, -2);
203 if (lua_isnil(L, -1)) {202 if (lua_isnil(L, -1)) {
204 lua_pop(L, 2); /* remove metatable and metafield */203 lua_pop(L, 2); /* remove metatable and metafield */
205 return 0;204 return 0;
@@ -231,7 +230,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, · 25 unmodified lines
231 const luaL_Reg *l, int nup) {230 const luaL_Reg *l, int nup) {
232 if (libname) {231 if (libname) {
233 /* check whether lib already exists */232 /* check whether lib already exists */
234 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");233 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
235 lua_getfield(L, -1, libname); /* get _LOADED[libname] */234 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
236 if (!lua_istable(L, -1)) { /* not found? */235 if (!lua_istable(L, -1)) { /* not found? */
237 lua_pop(L, 1); /* remove previous result */236 lua_pop(L, 1); /* remove previous result */
@@ -305,7 +304,7 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { · 67 unmodified lines
305 if ((n = checkint(L, 2)) >= 0) return n;304 if ((n = checkint(L, 2)) >= 0) return n;
306 lua_getfield(L, t, "n"); /* else try t.n */305 lua_getfield(L, t, "n"); /* else try t.n */
307 if ((n = checkint(L, 1)) >= 0) return n;306 if ((n = checkint(L, 1)) >= 0) return n;
308 return lua_objlen(L, t);307 return (int)lua_objlen(L, t);
309}308}
310 309
311#endif310#endif
@@ -470,7 +469,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { · 158 unmodified lines
470 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */469 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
471 }470 }
472 else { /* no free elements */471 else { /* no free elements */
473 ref = lua_objlen(L, t);472 ref = (int)lua_objlen(L, t);
474 ref++; /* create new reference */473 ref++; /* create new reference */
475 }474 }
476 lua_rawseti(L, t, ref);475 lua_rawseti(L, t, ref);
src/lauxlib.h+2−1
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lauxlib.h,v 1.85 2005/09/06 17:19:51 roberto Exp $2** $Id: lauxlib.h,v 1.86 2005/10/21 13:47:42 roberto Exp $
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*/
@@ -114,6 +114,7 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, · 108 unmodified lines
114 114
115#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))115#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
116 116
117#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
117 118
118/*119/*
119** {======================================================120** {======================================================
src/lbaselib.c+29−19
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lbaselib.c,v 1.182 2005/08/26 17:36:32 roberto Exp $2** $Id: lbaselib.c,v 1.186 2005/10/21 13:47:42 roberto Exp $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -196,9 +196,23 @@ static int luaB_collectgarbage (lua_State *L) { · 190 unmodified lines
196 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,196 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
197 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};197 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};
198 int o = luaL_checkoption(L, 1, "collect", opts);198 int o = luaL_checkoption(L, 1, "collect", opts);
199 int ex = luaL_optinteger(L, 2, 0);199 int ex = luaL_optint(L, 2, 0);
200 lua_pushinteger(L, lua_gc(L, optsnum[o], ex));200 int res = lua_gc(L, optsnum[o], ex);
201 return 1;201 switch (optsnum[o]) {
202 case LUA_GCCOUNT: {
203 int b = lua_gc(L, LUA_GCCOUNTB, 0);
204 lua_pushnumber(L, ((lua_Number)res*1024 + b)/1000);
205 return 1;
206 }
207 case LUA_GCSTEP: {
208 lua_pushboolean(L, res);
209 return 1;
210 }
211 default: {
212 lua_pushnumber(L, res);
213 return 1;
214 }
215 }
202}216}
203 217
204 218
@@ -326,12 +340,10 @@ static int luaB_assert (lua_State *L) { · 121 unmodified lines
326 340
327 341
328static int luaB_unpack (lua_State *L) {342static int luaB_unpack (lua_State *L) {
329 int i = luaL_optint(L, 2, 1);343 int i, e, n;
330 int e = luaL_optint(L, 3, -1);
331 int n;
332 luaL_checktype(L, 1, LUA_TTABLE);344 luaL_checktype(L, 1, LUA_TTABLE);
333 if (e == -1)345 i = luaL_optint(L, 2, 1);
334 e = luaL_getn(L, 1);346 e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
335 n = e - i + 1; /* number of elements */347 n = e - i + 1; /* number of elements */
336 if (n <= 0) return 0; /* empty range */348 if (n <= 0) return 0; /* empty range */
337 luaL_checkstack(L, n, "table too big to unpack");349 luaL_checkstack(L, n, "table too big to unpack");
@@ -349,8 +361,9 @@ static int luaB_select (lua_State *L) { · 11 unmodified lines
349 }361 }
350 else {362 else {
351 int i = luaL_checkint(L, 1);363 int i = luaL_checkint(L, 1);
352 if (i <= 0) i = 1;364 if (i < 0) i = n + i;
353 else if (i >= n) i = n;365 else if (i > n) i = n;
366 luaL_argcheck(L, 1 <= i, 1, "index out of range");
354 return n - i;367 return n - i;
355 }368 }
356}369}
@@ -560,7 +573,7 @@ static int luaB_costatus (lua_State *L) { · 203 unmodified lines
560 lua_pushliteral(L, "dead");573 lua_pushliteral(L, "dead");
561 else574 else
562 lua_pushliteral(L, "suspended"); /* initial state */575 lua_pushliteral(L, "suspended"); /* initial state */
563 break; 576 break;
564 }577 }
565 default: /* some error occured */578 default: /* some error occured */
566 lua_pushliteral(L, "dead");579 lua_pushliteral(L, "dead");
@@ -601,8 +614,11 @@ static void auxopen (lua_State *L, const char *name, · 34 unmodified lines
601 614
602 615
603static void base_open (lua_State *L) {616static void base_open (lua_State *L) {
617 /* set global _G */
604 lua_pushvalue(L, LUA_GLOBALSINDEX);618 lua_pushvalue(L, LUA_GLOBALSINDEX);
605 luaL_register(L, NULL, base_funcs); /* open lib into global table */619 lua_setglobal(L, "_G");
620 /* open lib into global table */
621 luaL_register(L, "_G", base_funcs);
606 lua_pushliteral(L, LUA_VERSION);622 lua_pushliteral(L, LUA_VERSION);
607 lua_setglobal(L, "_VERSION"); /* set global _VERSION */623 lua_setglobal(L, "_VERSION"); /* set global _VERSION */
608 /* `ipairs' and `pairs' need auxliliary functions as upvalues */624 /* `ipairs' and `pairs' need auxliliary functions as upvalues */
@@ -616,12 +632,6 @@ static void base_open (lua_State *L) { · 7 unmodified lines
616 lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */632 lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
617 lua_pushcclosure(L, luaB_newproxy, 1);633 lua_pushcclosure(L, luaB_newproxy, 1);
618 lua_setglobal(L, "newproxy"); /* set global `newproxy' */634 lua_setglobal(L, "newproxy"); /* set global `newproxy' */
619 /* create register._LOADED to track loaded modules */
620 lua_newtable(L);
621 lua_setfield(L, LUA_REGISTRYINDEX, "_LOADED");
622 /* set global _G */
623 lua_pushvalue(L, LUA_GLOBALSINDEX);
624 lua_setglobal(L, "_G");
625}635}
626 636
627 637
src/lcode.c+161−118
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lcode.c,v 2.16 2005/08/29 20:49:21 roberto Exp $2** $Id: lcode.c,v 2.22 2005/11/16 11:55:27 roberto Exp $
3** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -27,16 +27,24 @@ · 21 unmodified lines
27#define hasjumps(e) ((e)->t != (e)->f)27#define hasjumps(e) ((e)->t != (e)->f)
28 28
29 29
30static int isnumeral(expdesc *e) {
31 return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
32}
33
34
30void luaK_nil (FuncState *fs, int from, int n) {35void luaK_nil (FuncState *fs, int from, int n) {
31 Instruction *previous;36 Instruction *previous;
32 if (fs->pc > fs->lasttarget && /* no jumps to current position? */37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
33 GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {38 if (fs->pc == 0) /* function start? */
34 int pfrom = GETARG_A(*previous);39 return; /* positions are already clean */
35 int pto = GETARG_B(*previous);40 if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
36 if (pfrom <= from && from <= pto+1) { /* can connect both? */41 int pfrom = GETARG_A(*previous);
37 if (from+n-1 > pto)42 int pto = GETARG_B(*previous);
38 SETARG_B(*previous, from+n-1);43 if (pfrom <= from && from <= pto+1) { /* can connect both? */
39 return;44 if (from+n-1 > pto)
45 SETARG_B(*previous, from+n-1);
46 return;
47 }
40 }48 }
41 }49 }
42 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */50 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
@@ -115,20 +123,22 @@ static int need_value (FuncState *fs, int list) { · 72 unmodified lines
115}123}
116 124
117 125
118static void patchtestreg (Instruction *i, int reg) {126static int patchtestreg (FuncState *fs, int node, int reg) {
119 if (reg != NO_REG)127 Instruction *i = getjumpcontrol(fs, node);
128 if (GET_OPCODE(*i) != OP_TESTSET)
129 return 0; /* cannot patch other instructions */
130 if (reg != NO_REG && reg != GETARG_B(*i))
120 SETARG_A(*i, reg);131 SETARG_A(*i, reg);
121 else /* no register to put value; change TESTSET to TEST */132 else /* no register to put value or register already has the value */
122 *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));133 *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
134
135 return 1;
123}136}
124 137
125 138
126static void removevalues (FuncState *fs, int list) {139static void removevalues (FuncState *fs, int list) {
127 for (; list != NO_JUMP; list = getjump(fs, list)) {140 for (; list != NO_JUMP; list = getjump(fs, list))
128 Instruction *i = getjumpcontrol(fs, list);141 patchtestreg(fs, list, NO_REG);
129 if (GET_OPCODE(*i) == OP_TESTSET)
130 patchtestreg(i, NO_REG);
131 }
132}142}
133 143
134 144
@@ -136,11 +146,8 @@ static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, · 1 unmodified line
136 int dtarget) {146 int dtarget) {
137 while (list != NO_JUMP) {147 while (list != NO_JUMP) {
138 int next = getjump(fs, list);148 int next = getjump(fs, list);
139 Instruction *i = getjumpcontrol(fs, list);149 if (patchtestreg(fs, list, reg))
140 if (GET_OPCODE(*i) == OP_TESTSET) {
141 patchtestreg(i, reg);
142 fixjump(fs, list, vtarget);150 fixjump(fs, list, vtarget);
143 }
144 else151 else
145 fixjump(fs, list, dtarget); /* jump to default target */152 fixjump(fs, list, dtarget); /* jump to default target */
146 list = next;153 list = next;
@@ -210,7 +217,7 @@ static void freereg (FuncState *fs, int reg) { · 63 unmodified lines
210 217
211static void freeexp (FuncState *fs, expdesc *e) {218static void freeexp (FuncState *fs, expdesc *e) {
212 if (e->k == VNONRELOC)219 if (e->k == VNONRELOC)
213 freereg(fs, e->info);220 freereg(fs, e->u.s.info);
214}221}
215 222
216 223
@@ -280,7 +287,7 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { · 63 unmodified lines
280void luaK_setoneret (FuncState *fs, expdesc *e) {287void luaK_setoneret (FuncState *fs, expdesc *e) {
281 if (e->k == VCALL) { /* expression is an open function call? */288 if (e->k == VCALL) { /* expression is an open function call? */
282 e->k = VNONRELOC;289 e->k = VNONRELOC;
283 e->info = GETARG_A(getcode(fs, e));290 e->u.s.info = GETARG_A(getcode(fs, e));
284 }291 }
285 else if (e->k == VVARARG) {292 else if (e->k == VVARARG) {
286 SETARG_B(getcode(fs, e), 2);293 SETARG_B(getcode(fs, e), 2);
@@ -296,19 +303,19 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 9 unmodified lines
296 break;303 break;
297 }304 }
298 case VUPVAL: {305 case VUPVAL: {
299 e->info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->info, 0);306 e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
300 e->k = VRELOCABLE;307 e->k = VRELOCABLE;
301 break;308 break;
302 }309 }
303 case VGLOBAL: {310 case VGLOBAL: {
304 e->info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->info);311 e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);
305 e->k = VRELOCABLE;312 e->k = VRELOCABLE;
306 break;313 break;
307 }314 }
308 case VINDEXED: {315 case VINDEXED: {
309 freereg(fs, e->aux);316 freereg(fs, e->u.s.aux);
310 freereg(fs, e->info);317 freereg(fs, e->u.s.info);
311 e->info = luaK_codeABC(fs, OP_GETTABLE, 0, e->info, e->aux);318 e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
312 e->k = VRELOCABLE;319 e->k = VRELOCABLE;
313 break;320 break;
314 }321 }
@@ -340,7 +347,11 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { · 25 unmodified lines
340 break;347 break;
341 }348 }
342 case VK: {349 case VK: {
343 luaK_codeABx(fs, OP_LOADK, reg, e->info);350 luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);
351 break;
352 }
353 case VKNUM: {
354 luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));
344 break;355 break;
345 }356 }
346 case VRELOCABLE: {357 case VRELOCABLE: {
@@ -349,8 +360,8 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { · 2 unmodified lines
349 break;360 break;
350 }361 }
351 case VNONRELOC: {362 case VNONRELOC: {
352 if (reg != e->info)363 if (reg != e->u.s.info)
353 luaK_codeABC(fs, OP_MOVE, reg, e->info, 0);364 luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);
354 break;365 break;
355 }366 }
356 default: {367 default: {
@@ -358,7 +369,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { · 1 unmodified line
358 return; /* nothing to do... */369 return; /* nothing to do... */
359 }370 }
360 }371 }
361 e->info = reg;372 e->u.s.info = reg;
362 e->k = VNONRELOC;373 e->k = VNONRELOC;
363}374}
364 375
@@ -374,15 +385,13 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { · 9 unmodified lines
374static void exp2reg (FuncState *fs, expdesc *e, int reg) {385static void exp2reg (FuncState *fs, expdesc *e, int reg) {
375 discharge2reg(fs, e, reg);386 discharge2reg(fs, e, reg);
376 if (e->k == VJMP)387 if (e->k == VJMP)
377 luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */388 luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */
378 if (hasjumps(e)) {389 if (hasjumps(e)) {
379 int final; /* position after whole expression */390 int final; /* position after whole expression */
380 int p_f = NO_JUMP; /* position of an eventual LOAD false */391 int p_f = NO_JUMP; /* position of an eventual LOAD false */
381 int p_t = NO_JUMP; /* position of an eventual LOAD true */392 int p_t = NO_JUMP; /* position of an eventual LOAD true */
382 if (need_value(fs, e->t) || need_value(fs, e->f)) {393 if (need_value(fs, e->t) || need_value(fs, e->f)) {
383 int fj = NO_JUMP; /* first jump (over LOAD ops.) */394 int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
384 if (e->k != VJMP)
385 fj = luaK_jump(fs);
386 p_f = code_label(fs, reg, 0, 1);395 p_f = code_label(fs, reg, 0, 1);
387 p_t = code_label(fs, reg, 1, 0);396 p_t = code_label(fs, reg, 1, 0);
388 luaK_patchtohere(fs, fj);397 luaK_patchtohere(fs, fj);
@@ -392,7 +401,7 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { · 3 unmodified lines
392 patchlistaux(fs, e->t, final, reg, p_t);401 patchlistaux(fs, e->t, final, reg, p_t);
393 }402 }
394 e->f = e->t = NO_JUMP;403 e->f = e->t = NO_JUMP;
395 e->info = reg;404 e->u.s.info = reg;
396 e->k = VNONRELOC;405 e->k = VNONRELOC;
397}406}
398 407
@@ -408,14 +417,14 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { · 9 unmodified lines
408int luaK_exp2anyreg (FuncState *fs, expdesc *e) {417int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
409 luaK_dischargevars(fs, e);418 luaK_dischargevars(fs, e);
410 if (e->k == VNONRELOC) {419 if (e->k == VNONRELOC) {
411 if (!hasjumps(e)) return e->info; /* exp is already in a register */ 420 if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */
412 if (e->info >= fs->nactvar) { /* reg. is not a local? */421 if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */
413 exp2reg(fs, e, e->info); /* put value on it */422 exp2reg(fs, e, e->u.s.info); /* put value on it */
414 return e->info;423 return e->u.s.info;
415 }424 }
416 }425 }
417 luaK_exp2nextreg(fs, e); /* default */426 luaK_exp2nextreg(fs, e); /* default */
418 return e->info;427 return e->u.s.info;
419}428}
420 429
421 430
@@ -430,19 +439,22 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { · 8 unmodified lines
430int luaK_exp2RK (FuncState *fs, expdesc *e) {439int luaK_exp2RK (FuncState *fs, expdesc *e) {
431 luaK_exp2val(fs, e);440 luaK_exp2val(fs, e);
432 switch (e->k) {441 switch (e->k) {
442 case VKNUM:
433 case VTRUE:443 case VTRUE:
434 case VFALSE:444 case VFALSE:
435 case VNIL: {445 case VNIL: {
436 if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */446 if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
437 e->info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));447 e->u.s.info = (e->k == VNIL) ? nilK(fs) :
448 (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
449 boolK(fs, (e->k == VTRUE));
438 e->k = VK;450 e->k = VK;
439 return RKASK(e->info);451 return RKASK(e->u.s.info);
440 }452 }
441 else break;453 else break;
442 }454 }
443 case VK: {455 case VK: {
444 if (e->info <= MAXINDEXRK) /* constant fit in argC? */456 if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */
445 return RKASK(e->info);457 return RKASK(e->u.s.info);
446 else break;458 else break;
447 }459 }
448 default: break;460 default: break;
@@ -456,22 +468,22 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { · 7 unmodified lines
456 switch (var->k) {468 switch (var->k) {
457 case VLOCAL: {469 case VLOCAL: {
458 freeexp(fs, ex);470 freeexp(fs, ex);
459 exp2reg(fs, ex, var->info);471 exp2reg(fs, ex, var->u.s.info);
460 return;472 return;
461 }473 }
462 case VUPVAL: {474 case VUPVAL: {
463 int e = luaK_exp2anyreg(fs, ex);475 int e = luaK_exp2anyreg(fs, ex);
464 luaK_codeABC(fs, OP_SETUPVAL, e, var->info, 0);476 luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
465 break;477 break;
466 }478 }
467 case VGLOBAL: {479 case VGLOBAL: {
468 int e = luaK_exp2anyreg(fs, ex);480 int e = luaK_exp2anyreg(fs, ex);
469 luaK_codeABx(fs, OP_SETGLOBAL, e, var->info);481 luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);
470 break;482 break;
471 }483 }
472 case VINDEXED: {484 case VINDEXED: {
473 int e = luaK_exp2RK(fs, ex);485 int e = luaK_exp2RK(fs, ex);
474 luaK_codeABC(fs, OP_SETTABLE, var->info, var->aux, e);486 luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
475 break;487 break;
476 }488 }
477 default: {489 default: {
@@ -489,15 +501,15 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { · 11 unmodified lines
489 freeexp(fs, e);501 freeexp(fs, e);
490 func = fs->freereg;502 func = fs->freereg;
491 luaK_reserveregs(fs, 2);503 luaK_reserveregs(fs, 2);
492 luaK_codeABC(fs, OP_SELF, func, e->info, luaK_exp2RK(fs, key));504 luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
493 freeexp(fs, key);505 freeexp(fs, key);
494 e->info = func;506 e->u.s.info = func;
495 e->k = VNONRELOC;507 e->k = VNONRELOC;
496}508}
497 509
498 510
499static void invertjump (FuncState *fs, expdesc *e) {511static void invertjump (FuncState *fs, expdesc *e) {
500 Instruction *pc = getjumpcontrol(fs, e->info);512 Instruction *pc = getjumpcontrol(fs, e->u.s.info);
501 lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&513 lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
502 GET_OPCODE(*pc) != OP_TEST);514 GET_OPCODE(*pc) != OP_TEST);
503 SETARG_A(*pc, !(GETARG_A(*pc)));515 SETARG_A(*pc, !(GETARG_A(*pc)));
@@ -515,7 +527,7 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) { · 11 unmodified lines
515 }527 }
516 discharge2anyreg(fs, e);528 discharge2anyreg(fs, e);
517 freeexp(fs, e);529 freeexp(fs, e);
518 return condjump(fs, OP_TESTSET, NO_REG, e->info, cond);530 return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);
519}531}
520 532
521 533
@@ -523,7 +535,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 1 unmodified line
523 int pc; /* pc of last jump */535 int pc; /* pc of last jump */
524 luaK_dischargevars(fs, e);536 luaK_dischargevars(fs, e);
525 switch (e->k) {537 switch (e->k) {
526 case VK: case VTRUE: {538 case VK: case VKNUM: case VTRUE: {
527 pc = NO_JUMP; /* always true; do nothing */539 pc = NO_JUMP; /* always true; do nothing */
528 break;540 break;
529 }541 }
@@ -533,7 +545,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 3 unmodified lines
533 }545 }
534 case VJMP: {546 case VJMP: {
535 invertjump(fs, e);547 invertjump(fs, e);
536 pc = e->info;548 pc = e->u.s.info;
537 break;549 break;
538 }550 }
539 default: {551 default: {
@@ -547,7 +559,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 7 unmodified lines
547}559}
548 560
549 561
550void luaK_goiffalse (FuncState *fs, expdesc *e) {562static void luaK_goiffalse (FuncState *fs, expdesc *e) {
551 int pc; /* pc of last jump */563 int pc; /* pc of last jump */
552 luaK_dischargevars(fs, e);564 luaK_dischargevars(fs, e);
553 switch (e->k) {565 switch (e->k) {
@@ -560,7 +572,7 @@ void luaK_goiffalse (FuncState *fs, expdesc *e) { · 6 unmodified lines
560 break;572 break;
561 }573 }
562 case VJMP: {574 case VJMP: {
563 pc = e->info;575 pc = e->u.s.info;
564 break;576 break;
565 }577 }
566 default: {578 default: {
@@ -581,7 +593,7 @@ static void codenot (FuncState *fs, expdesc *e) { · 14 unmodified lines
581 e->k = VTRUE;593 e->k = VTRUE;
582 break;594 break;
583 }595 }
584 case VK: case VTRUE: {596 case VK: case VKNUM: case VTRUE: {
585 e->k = VFALSE;597 e->k = VFALSE;
586 break;598 break;
587 }599 }
@@ -593,7 +605,7 @@ static void codenot (FuncState *fs, expdesc *e) { · 5 unmodified lines
593 case VNONRELOC: {605 case VNONRELOC: {
594 discharge2anyreg(fs, e);606 discharge2anyreg(fs, e);
595 freeexp(fs, e);607 freeexp(fs, e);
596 e->info = luaK_codeABC(fs, OP_NOT, 0, e->info, 0);608 e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);
597 e->k = VRELOCABLE;609 e->k = VRELOCABLE;
598 break;610 break;
599 }611 }
@@ -610,34 +622,81 @@ static void codenot (FuncState *fs, expdesc *e) { · 10 unmodified lines
610 622
611 623
612void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {624void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
613 t->aux = luaK_exp2RK(fs, k);625 t->u.s.aux = luaK_exp2RK(fs, k);
614 t->k = VINDEXED;626 t->k = VINDEXED;
615}627}
616 628
617 629
630static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
631 lua_Number v1, v2, r;
632 if (!isnumeral(e1) || !isnumeral(e2)) return 0;
633 v1 = e1->u.nval;
634 v2 = e2->u.nval;
635 switch (op) {
636 case OP_ADD: r = luai_numadd(v1, v2); break;
637 case OP_SUB: r = luai_numsub(v1, v2); break;
638 case OP_MUL: r = luai_nummul(v1, v2); break;
639 case OP_DIV:
640 if (v2 == 0) return 0; /* do not attempt to divide by 0 */
641 r = luai_numdiv(v1, v2); break;
642 case OP_MOD:
643 if (v2 == 0) return 0; /* do not attempt to divide by 0 */
644 r = luai_nummod(v1, v2); break;
645 case OP_POW: r = luai_numpow(v1, v2); break;
646 case OP_UNM: r = luai_numunm(v1); break;
647 case OP_LEN: return 0; /* no constant folding for 'len' */
648 default: lua_assert(0); r = 0; break;
649 }
650 if (r != r) return 0; /* do not attempt to produce NaN */
651 e1->u.nval = r;
652 return 1;
653}
654
655
656static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
657 if (constfolding(op, e1, e2))
658 return;
659 else {
660 int o1 = luaK_exp2RK(fs, e1);
661 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
662 freeexp(fs, e2);
663 freeexp(fs, e1);
664 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665 e1->k = VRELOCABLE;
666 }
667}
668
669
670static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
671 expdesc *e2) {
672 int o1 = luaK_exp2RK(fs, e1);
673 int o2 = luaK_exp2RK(fs, e2);
674 freeexp(fs, e2);
675 freeexp(fs, e1);
676 if (cond == 0 && op != OP_EQ) {
677 int temp; /* exchange args to replace by `<' or `<=' */
678 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
679 cond = 1;
680 }
681 e1->u.s.info = condjump(fs, op, cond, o1, o2);
682 e1->k = VJMP;
683}
684
685
618void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {686void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
687 expdesc e2;
688 e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
619 switch (op) {689 switch (op) {
620 case OPR_MINUS: {690 case OPR_MINUS: {
621 luaK_exp2val(fs, e);691 if (e->k == VK)
622 if (e->k == VK && ttisnumber(&fs->f->k[e->info]))692 luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
623 e->info = luaK_numberK(fs, luai_numunm(L, nvalue(&fs->f->k[e->info])));693 codearith(fs, OP_UNM, e, &e2);
624 else {
625 luaK_exp2anyreg(fs, e);
626 freeexp(fs, e);
627 e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0);
628 e->k = VRELOCABLE;
629 }
630 break;
631 }
632 case OPR_NOT: {
633 codenot(fs, e);
634 break;694 break;
635 }695 }
696 case OPR_NOT: codenot(fs, e); break;
636 case OPR_LEN: {697 case OPR_LEN: {
637 luaK_exp2anyreg(fs, e);698 luaK_exp2anyreg(fs, e); /* cannot operate on constants */
638 freeexp(fs, e);699 codearith(fs, OP_LEN, e, &e2);
639 e->info = luaK_codeABC(fs, OP_LEN, 0, e->info, 0);
640 e->k = VRELOCABLE;
641 break;700 break;
642 }701 }
643 default: lua_assert(0);702 default: lua_assert(0);
@@ -660,74 +719,58 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 16 unmodified lines
660 break;719 break;
661 }720 }
662 default: {721 default: {
663 luaK_exp2RK(fs, v);722 if (!isnumeral(v)) luaK_exp2RK(fs, v);
664 break;723 break;
665 }724 }
666 }725 }
667}726}
668 727
669 728
670static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
671 int o1, int o2) {
672 if (op <= OPR_POW) { /* arithmetic operator? */
673 OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); /* ORDER OP */
674 res->info = luaK_codeABC(fs, opc, 0, o1, o2);
675 res->k = VRELOCABLE;
676 }
677 else { /* test operator */
678 static const OpCode ops[] = {OP_EQ, OP_EQ, OP_LT, OP_LE, OP_LT, OP_LE};
679 int cond = 1;
680 if (op >= OPR_GT) { /* `>' or `>='? */
681 int temp; /* exchange args and replace by `<' or `<=' */
682 temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
683 }
684 else if (op == OPR_NE) cond = 0;
685 res->info = condjump(fs, ops[op - OPR_NE], cond, o1, o2);
686 res->k = VJMP;
687 }
688}
689
690
691void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {729void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
692 switch (op) {730 switch (op) {
693 case OPR_AND: {731 case OPR_AND: {
694 lua_assert(e1->t == NO_JUMP); /* list must be closed */732 lua_assert(e1->t == NO_JUMP); /* list must be closed */
695 luaK_dischargevars(fs, e2);733 luaK_dischargevars(fs, e2);
696 luaK_concat(fs, &e1->f, e2->f);734 luaK_concat(fs, &e1->f, e2->f);
697 e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->t = e2->t;735 e1->k = e2->k; e1->u.s.info = e2->u.s.info;
736 e1->u.s.aux = e2->u.s.aux; e1->t = e2->t;
698 break;737 break;
699 }738 }
700 case OPR_OR: {739 case OPR_OR: {
701 lua_assert(e1->f == NO_JUMP); /* list must be closed */740 lua_assert(e1->f == NO_JUMP); /* list must be closed */
702 luaK_dischargevars(fs, e2);741 luaK_dischargevars(fs, e2);
703 luaK_concat(fs, &e1->t, e2->t);742 luaK_concat(fs, &e1->t, e2->t);
704 e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->f = e2->f;743 e1->k = e2->k; e1->u.s.info = e2->u.s.info;
744 e1->u.s.aux = e2->u.s.aux; e1->f = e2->f;
705 break;745 break;
706 }746 }
707 case OPR_CONCAT: {747 case OPR_CONCAT: {
708 luaK_exp2val(fs, e2);748 luaK_exp2val(fs, e2);
709 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {749 if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
710 lua_assert(e1->info == GETARG_B(getcode(fs, e2))-1);750 lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
711 freeexp(fs, e1);751 freeexp(fs, e1);
712 SETARG_B(getcode(fs, e2), e1->info);752 SETARG_B(getcode(fs, e2), e1->u.s.info);
713 e1->k = e2->k; e1->info = e2->info;753 e1->k = e2->k; e1->u.s.info = e2->u.s.info;
714 }754 }
715 else {755 else {
716 luaK_exp2nextreg(fs, e2);756 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
717 freeexp(fs, e2);757 codearith(fs, OP_CONCAT, e1, e2);
718 freeexp(fs, e1);
719 e1->info = luaK_codeABC(fs, OP_CONCAT, 0, e1->info, e2->info);
720 e1->k = VRELOCABLE;
721 }758 }
722 break;759 break;
723 }760 }
724 default: {761 case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
725 int o1 = luaK_exp2RK(fs, e1);762 case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
726 int o2 = luaK_exp2RK(fs, e2);763 case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
727 freeexp(fs, e2);764 case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
728 freeexp(fs, e1);765 case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
729 codebinop(fs, e1, op, o1, o2);766 case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
730 }767 case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
768 case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
769 case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
770 case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
771 case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
772 case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
773 default: lua_assert(0);
731 }774 }
732}775}
733 776
@@ -737,7 +780,7 @@ void luaK_fixline (FuncState *fs, int line) { · 3 unmodified lines
737}780}
738 781
739 782
740int luaK_code (FuncState *fs, Instruction i, int line) {783static int luaK_code (FuncState *fs, Instruction i, int line) {
741 Proto *f = fs->f;784 Proto *f = fs->f;
742 dischargejpc(fs); /* `pc' will change */785 dischargejpc(fs); /* `pc' will change */
743 /* put new instruction in code array */786 /* put new instruction in code array */
src/lcode.h+3−5
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lcode.h,v 1.45 2005/08/29 20:49:21 roberto Exp $2** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp $
3** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -24,7 +24,7 @@ · 18 unmodified lines
24** grep "ORDER OPR" if you change these enums24** grep "ORDER OPR" if you change these enums
25*/25*/
26typedef enum BinOpr {26typedef enum BinOpr {
27 OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_MOD, OPR_POW,27 OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
28 OPR_CONCAT,28 OPR_CONCAT,
29 OPR_NE, OPR_EQ,29 OPR_NE, OPR_EQ,
30 OPR_LT, OPR_LE, OPR_GT, OPR_GE,30 OPR_LT, OPR_LE, OPR_GT, OPR_GE,
@@ -37,13 +37,12 @@ typedef enum BinOpr { · 6 unmodified lines
37typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;37typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
38 38
39 39
40#define getcode(fs,e) ((fs)->f->code[(e)->info])40#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info])
41 41
42#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)42#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
43 43
44#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)44#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
45 45
46LUAI_FUNC int luaK_code (FuncState *fs, Instruction i, int line);
47LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);46LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
48LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);47LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
49LUAI_FUNC void luaK_fixline (FuncState *fs, int line);48LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
@@ -60,7 +59,6 @@ LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); · 10 unmodified lines
60LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);59LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
61LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);60LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
62LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);61LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
63LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
64LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);62LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
65LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);63LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
66LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);64LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
src/ldblib.c+9−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ldblib.c,v 1.101 2005/08/26 17:36:32 roberto Exp $2** $Id: ldblib.c,v 1.103 2005/11/01 16:08:32 roberto Exp $
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*/
@@ -19,6 +19,12 @@ · 13 unmodified lines
19 19
20 20
21 21
22static int db_getregistry (lua_State *L) {
23 lua_pushvalue(L, LUA_REGISTRYINDEX);
24 return 1;
25}
26
27
22static int db_getmetatable (lua_State *L) {28static int db_getmetatable (lua_State *L) {
23 luaL_checkany(L, 1);29 luaL_checkany(L, 1);
24 if (!lua_getmetatable(L, 1)) {30 if (!lua_getmetatable(L, 1)) {
@@ -319,7 +325,7 @@ static int db_errorfb (lua_State *L) { · 294 unmodified lines
319 lua_State *L1 = getthread(L, &arg);325 lua_State *L1 = getthread(L, &arg);
320 lua_Debug ar;326 lua_Debug ar;
321 if (lua_isnumber(L, arg+2)) {327 if (lua_isnumber(L, arg+2)) {
322 level = lua_tointeger(L, arg+2);328 level = (int)lua_tointeger(L, arg+2);
323 lua_pop(L, 1);329 lua_pop(L, 1);
324 }330 }
325 else331 else
@@ -371,6 +377,7 @@ static const luaL_Reg dblib[] = { · 45 unmodified lines
371 {"gethook", db_gethook},377 {"gethook", db_gethook},
372 {"getinfo", db_getinfo},378 {"getinfo", db_getinfo},
373 {"getlocal", db_getlocal},379 {"getlocal", db_getlocal},
380 {"getregistry", db_getregistry},
374 {"getmetatable", db_getmetatable},381 {"getmetatable", db_getmetatable},
375 {"getupvalue", db_getupvalue},382 {"getupvalue", db_getupvalue},
376 {"setfenv", db_setfenv},383 {"setfenv", db_setfenv},
src/ldebug.c+27−28
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ldebug.c,v 2.26 2005/08/04 13:37:38 roberto Exp $2** $Id: ldebug.c,v 2.28 2005/11/01 16:08:52 roberto Exp $
3** Debug Interface3** Debug Interface
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -109,40 +109,39 @@ static Proto *getluaproto (CallInfo *ci) { · 103 unmodified lines
109}109}
110 110
111 111
112LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {112static const char *findlocal (lua_State *L, CallInfo *ci, int n) {
113 const char *name;113 const char *name;
114 CallInfo *ci;114 Proto *fp = getluaproto(ci);
115 Proto *fp;115 if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
116 lua_lock(L);116 return name; /* is a local variable in a Lua function */
117 name = NULL;117 else {
118 ci = L->base_ci + ar->i_ci;118 StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
119 fp = getluaproto(ci);119 if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */
120 if (fp) { /* is a Lua function? */120 return "(*temporary)";
121 name = luaF_getlocalname(fp, n, currentpc(L, ci));121 else
122 if (name)122 return NULL;
123 luaA_pushobject(L, ci->base+(n-1)); /* push value */
124 }123 }
124}
125
126
127LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
128 CallInfo *ci = L->base_ci + ar->i_ci;
129 const char *name = findlocal(L, ci, n);
130 lua_lock(L);
131 if (name)
132 luaA_pushobject(L, ci->base + (n - 1));
125 lua_unlock(L);133 lua_unlock(L);
126 return name;134 return name;
127}135}
128 136
129 137
130LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {138LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
131 const char *name;139 CallInfo *ci = L->base_ci + ar->i_ci;
132 CallInfo *ci;140 const char *name = findlocal(L, ci, n);
133 Proto *fp;
134 lua_lock(L);141 lua_lock(L);
135 name = NULL;142 if (name)
136 ci = L->base_ci + ar->i_ci;143 setobjs2s(L, ci->base + (n - 1), L->top - 1);
137 fp = getluaproto(ci);144 L->top--; /* pop value */
138 L->top--; /* pop new value */
139 if (fp) { /* is a Lua function? */
140 name = luaF_getlocalname(fp, n, currentpc(L, ci));
141 if (!name || name[0] == '(') /* `(' starts private locals */
142 name = NULL;
143 else
144 setobjs2s(L, ci->base+(n-1), L->top);
145 }
146 lua_unlock(L);145 lua_unlock(L);
147 return name;146 return name;
148}147}
@@ -321,7 +320,7 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 172 unmodified lines
321 last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */320 last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */
322 check(precheck(pt));321 check(precheck(pt));
323 for (pc = 0; pc < lastpc; pc++) {322 for (pc = 0; pc < lastpc; pc++) {
324 const Instruction i = pt->code[pc];323 Instruction i = pt->code[pc];
325 OpCode op = GET_OPCODE(i);324 OpCode op = GET_OPCODE(i);
326 int a = GETARG_A(i);325 int a = GETARG_A(i);
327 int b = 0;326 int b = 0;
@@ -348,7 +347,7 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 20 unmodified lines
348 check(0 <= dest && dest < pt->sizecode);347 check(0 <= dest && dest < pt->sizecode);
349 if (dest > 0) {348 if (dest > 0) {
350 /* cannot jump to a setlist count */349 /* cannot jump to a setlist count */
351 const Instruction d = pt->code[dest-1];350 Instruction d = pt->code[dest-1];
352 check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));351 check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
353 }352 }
354 }353 }
src/ldo.c+9−7
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ldo.c,v 2.33 2005/09/09 18:16:28 roberto Exp $2** $Id: ldo.c,v 2.36 2005/10/23 17:52:42 roberto Exp $
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*/
@@ -276,8 +276,11 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 270 unmodified lines
276 Proto *p = cl->p;276 Proto *p = cl->p;
277 luaD_checkstack(L, p->maxstacksize);277 luaD_checkstack(L, p->maxstacksize);
278 func = restorestack(L, funcr);278 func = restorestack(L, funcr);
279 if (!p->is_vararg) /* no varargs? */279 if (!p->is_vararg) { /* no varargs? */
280 base = func + 1;280 base = func + 1;
281 if (L->top > base + p->numparams)
282 L->top = base + p->numparams;
283 }
281 else { /* vararg function */284 else { /* vararg function */
282 int nargs = cast(int, L->top - func) - 1;285 int nargs = cast(int, L->top - func) - 1;
283 base = adjust_varargs(L, p, nargs);286 base = adjust_varargs(L, p, nargs);
@@ -316,14 +319,12 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 32 unmodified lines
316 lua_unlock(L);319 lua_unlock(L);
317 n = (*curr_func(L)->c.f)(L); /* do the actual call */320 n = (*curr_func(L)->c.f)(L); /* do the actual call */
318 lua_lock(L);321 lua_lock(L);
319 if (n >= 0) { /* no yielding? */322 if (n < 0) /* yielding? */
323 return PCRYIELD;
324 else {
320 luaD_poscall(L, L->top - n);325 luaD_poscall(L, L->top - n);
321 return PCRC;326 return PCRC;
322 }327 }
323 else {
324 ci->nresults = nresults;
325 return PCRYIELD;
326 }
327 }328 }
328}329}
329 330
@@ -428,6 +429,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 98 unmodified lines
428 if (status != 0) { /* error? */429 if (status != 0) { /* error? */
429 L->status = cast(lu_byte, status); /* mark thread as `dead' */430 L->status = cast(lu_byte, status); /* mark thread as `dead' */
430 luaD_seterrorobj(L, status, L->top);431 luaD_seterrorobj(L, status, L->top);
432 L->ci->top = L->top;
431 }433 }
432 else434 else
433 status = L->status;435 status = L->status;
src/ldump.c+24−29
@@ -1,6 +1,6 @@
1/*1/*
2** $Id: ldump.c,v 1.12 2005/06/08 14:40:44 lhf Exp $2** $Id: ldump.c,v 1.14 2005/11/11 14:03:13 lhf Exp $
3** save pre-compiled Lua chunks3** save precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
@@ -12,7 +12,6 @@ · 5 unmodified lines
12#include "lua.h"12#include "lua.h"
13 13
14#include "lobject.h"14#include "lobject.h"
15#include "lopcodes.h"
16#include "lstate.h"15#include "lstate.h"
17#include "lundump.h"16#include "lundump.h"
18 17
@@ -24,11 +23,8 @@ typedef struct { · 5 unmodified lines
24 int status;23 int status;
25} DumpState;24} DumpState;
26 25
27#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
28#define DumpLines(f,D) DumpVector(f->lineinfo,f->sizelineinfo,sizeof(int),D)
29#define DumpLiteral(s,D) DumpBlock("" s,(sizeof(s))-1,D)
30#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
31#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)26#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
27#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
32 28
33static void DumpBlock(const void* b, size_t size, DumpState* D)29static void DumpBlock(const void* b, size_t size, DumpState* D)
34{30{
@@ -77,24 +73,7 @@ static void DumpString(const TString* s, DumpState* D) · 42 unmodified lines
77 }73 }
78}74}
79 75
80static void DumpLocals(const Proto* f, DumpState* D)76#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
81{
82 int i,n=f->sizelocvars;
83 DumpInt(n,D);
84 for (i=0; i<n; i++)
85 {
86 DumpString(f->locvars[i].varname,D);
87 DumpInt(f->locvars[i].startpc,D);
88 DumpInt(f->locvars[i].endpc,D);
89 }
90}
91
92static void DumpUpvalues(const Proto* f, DumpState* D)
93{
94 int i,n=f->sizeupvalues;
95 DumpInt(n,D);
96 for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
97}
98 77
99static void DumpFunction(const Proto* f, const TString* p, DumpState* D);78static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
100 79
@@ -129,6 +108,24 @@ static void DumpConstants(const Proto* f, DumpState* D) · 28 unmodified lines
129 for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);108 for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
130}109}
131 110
111static void DumpDebug(const Proto* f, DumpState* D)
112{
113 int i,n;
114 n= (D->strip) ? 0 : f->sizelineinfo;
115 DumpVector(f->lineinfo,n,sizeof(int),D);
116 n= (D->strip) ? 0 : f->sizelocvars;
117 DumpInt(n,D);
118 for (i=0; i<n; i++)
119 {
120 DumpString(f->locvars[i].varname,D);
121 DumpInt(f->locvars[i].startpc,D);
122 DumpInt(f->locvars[i].endpc,D);
123 }
124 n= (D->strip) ? 0 : f->sizeupvalues;
125 DumpInt(n,D);
126 for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
127}
128
132static void DumpFunction(const Proto* f, const TString* p, DumpState* D)129static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
133{130{
134 DumpString((f->source==p) ? NULL : f->source,D);131 DumpString((f->source==p) ? NULL : f->source,D);
@@ -138,11 +135,9 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D) · 3 unmodified lines
138 DumpChar(f->numparams,D);135 DumpChar(f->numparams,D);
139 DumpChar(f->is_vararg,D);136 DumpChar(f->is_vararg,D);
140 DumpChar(f->maxstacksize,D);137 DumpChar(f->maxstacksize,D);
141 if (D->strip) DumpInt(0,D); else DumpLines(f,D);
142 if (D->strip) DumpInt(0,D); else DumpLocals(f,D);
143 if (D->strip) DumpInt(0,D); else DumpUpvalues(f,D);
144 DumpConstants(f,D);
145 DumpCode(f,D);138 DumpCode(f,D);
139 DumpConstants(f,D);
140 DumpDebug(f,D);
146}141}
147 142
148static void DumpHeader(DumpState* D)143static void DumpHeader(DumpState* D)
src/liolib.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: liolib.c,v 2.67 2005/08/26 17:36:32 roberto Exp $2** $Id: liolib.c,v 2.69 2005/10/19 13:05:11 roberto Exp $
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*/
@@ -424,7 +424,7 @@ static int f_seek (lua_State *L) { · 418 unmodified lines
424 static const char *const modenames[] = {"set", "cur", "end", NULL};424 static const char *const modenames[] = {"set", "cur", "end", NULL};
425 FILE *f = tofile(L);425 FILE *f = tofile(L);
426 int op = luaL_checkoption(L, 2, "cur", modenames);426 int op = luaL_checkoption(L, 2, "cur", modenames);
427 lua_Integer offset = luaL_optinteger(L, 3, 0);427 long offset = luaL_optlong(L, 3, 0);
428 op = fseek(f, offset, mode[op]);428 op = fseek(f, offset, mode[op]);
429 if (op)429 if (op)
430 return pushresult(L, 0, NULL); /* error */430 return pushresult(L, 0, NULL); /* error */
@@ -440,7 +440,7 @@ static int f_setvbuf (lua_State *L) { · 9 unmodified lines
440 static const char *const modenames[] = {"no", "full", "line", NULL};440 static const char *const modenames[] = {"no", "full", "line", NULL};
441 FILE *f = tofile(L);441 FILE *f = tofile(L);
442 int op = luaL_checkoption(L, 2, NULL, modenames);442 int op = luaL_checkoption(L, 2, NULL, modenames);
443 lua_Integer sz = luaL_optinteger(L, 3, BUFSIZ);443 lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
444 int res = setvbuf(f, NULL, mode[op], sz);444 int res = setvbuf(f, NULL, mode[op], sz);
445 return pushresult(L, res == 0, NULL);445 return pushresult(L, res == 0, NULL);
446}446}
src/llex.c+16−24
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp $2** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp $
3** Lexical Analyzer3** Lexical Analyzer
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -155,28 +155,23 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 149 unmodified lines
155 155
156 156
157 157
158static int check_next (LexState *ls, const char *set) {
159 if (!strchr(set, ls->current))
160 return 0;
161 save_and_next(ls);
162 return 1;
163}
164
165
158 166
159/* LUA_NUMBER */167/* LUA_NUMBER */
160static void read_numeral (LexState *ls, SemInfo *seminfo) {168static void read_numeral (LexState *ls, SemInfo *seminfo) {
161 while (isdigit(ls->current)) {169 lua_assert(isdigit(ls->current));
170 do {
162 save_and_next(ls);171 save_and_next(ls);
163 }172 } while (isdigit(ls->current) || ls->current == '.');
164 if (ls->current == '.') {173 if (check_next(ls, "Ee")) { /* `E'? */
165 save_and_next(ls);174 check_next(ls, "+-"); /* optional exponent sign */
166 if (ls->current == '.') {
167 save_and_next(ls);
168 luaX_lexerror(ls,
169 "ambiguous syntax (decimal point x string concatenation)",
170 TK_NUMBER);
171 }
172 }
173 while (isdigit(ls->current)) {
174 save_and_next(ls);
175 }
176 if (ls->current == 'e' || ls->current == 'E') {
177 save_and_next(ls); /* read `E' */
178 if (ls->current == '+' || ls->current == '-')
179 save_and_next(ls); /* optional exponent sign */
180 while (isdigit(ls->current)) {175 while (isdigit(ls->current)) {
181 save_and_next(ls);176 save_and_next(ls);
182 }177 }
@@ -375,12 +370,9 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { · 192 unmodified lines
375 }370 }
376 case '.': {371 case '.': {
377 save_and_next(ls);372 save_and_next(ls);
378 if (ls->current == '.') {373 if (check_next(ls, ".")) {
379 next(ls);374 if (check_next(ls, "."))
380 if (ls->current == '.') {
381 next(ls);
382 return TK_DOTS; /* ... */375 return TK_DOTS; /* ... */
383 }
384 else return TK_CONCAT; /* .. */376 else return TK_CONCAT; /* .. */
385 }377 }
386 else if (!isdigit(ls->current)) return '.';378 else if (!isdigit(ls->current)) return '.';
src/loadlib.c+13−12
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: loadlib.c,v 1.44 2005/09/06 17:20:25 roberto Exp $2** $Id: loadlib.c,v 1.48 2005/10/17 18:01:51 roberto Exp $
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**
@@ -97,16 +97,18 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 91 unmodified lines
97 97
98#undef setprogdir98#undef setprogdir
99 99
100void setprogdir (lua_State *L) {100static void setprogdir (lua_State *L) {
101 char buff[MAX_PATH + 1];101 char buff[MAX_PATH + 1];
102 char *lb;102 char *lb;
103 DWORD nsize = sizeof(buff)/sizeof(char);103 DWORD nsize = sizeof(buff)/sizeof(char);
104 DWORD n = GetModuleFileName(NULL, buff, nsize);104 DWORD n = GetModuleFileName(NULL, buff, nsize);
105 if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)105 if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
106 luaL_error(L, "unable to get ModuleFileName");106 luaL_error(L, "unable to get ModuleFileName");
107 *lb = '\0';107 else {
108 luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);108 *lb = '\0';
109 lua_remove(L, -2); /* remove original string */109 luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
110 lua_remove(L, -2); /* remove original string */
111 }
110}112}
111 113
112 114
@@ -440,7 +442,8 @@ static int loader_preload (lua_State *L) { · 327 unmodified lines
440}442}
441 443
442 444
443static const int sentinel = 0;445static const int sentinel_ = 0;
446#define sentinel ((void *)&sentinel_)
444 447
445 448
446static int ll_require (lua_State *L) {449static int ll_require (lua_State *L) {
@@ -450,7 +453,7 @@ static int ll_require (lua_State *L) { · 3 unmodified lines
450 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");453 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
451 lua_getfield(L, 2, name);454 lua_getfield(L, 2, name);
452 if (lua_toboolean(L, -1)) { /* is it there? */455 if (lua_toboolean(L, -1)) { /* is it there? */
453 if (lua_touserdata(L, -1) == &sentinel) /* check loops */456 if (lua_touserdata(L, -1) == sentinel) /* check loops */
454 luaL_error(L, "loop or previous error loading module " LUA_QS, name);457 luaL_error(L, "loop or previous error loading module " LUA_QS, name);
455 return 1; /* package is already loaded */458 return 1; /* package is already loaded */
456 }459 }
@@ -467,14 +470,14 @@ static int ll_require (lua_State *L) { · 10 unmodified lines
467 if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */470 if (lua_isnil(L, -1)) lua_pop(L, 1); /* did not found module */
468 else break; /* module loaded successfully */471 else break; /* module loaded successfully */
469 }472 }
470 lua_pushlightuserdata(L, (void *)&sentinel);473 lua_pushlightuserdata(L, sentinel);
471 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */474 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
472 lua_pushstring(L, name); /* pass name as argument to module */475 lua_pushstring(L, name); /* pass name as argument to module */
473 lua_call(L, 1, 1); /* run loaded module */476 lua_call(L, 1, 1); /* run loaded module */
474 if (!lua_isnil(L, -1)) /* non-nil return? */477 if (!lua_isnil(L, -1)) /* non-nil return? */
475 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */478 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
476 lua_getfield(L, 2, name);479 lua_getfield(L, 2, name);
477 if (lua_touserdata(L, -1) == &sentinel) { /* module did not set a value? */480 if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
478 lua_pushboolean(L, 1); /* use true as result */481 lua_pushboolean(L, 1); /* use true as result */
479 lua_pushvalue(L, -1); /* extra copy to be returned */482 lua_pushvalue(L, -1); /* extra copy to be returned */
480 lua_setfield(L, 2, name); /* _LOADED[name] = true */483 lua_setfield(L, 2, name); /* _LOADED[name] = true */
@@ -623,8 +626,6 @@ LUALIB_API int luaopen_package (lua_State *L) { · 142 unmodified lines
623 lua_getfield(L, -1, "loadlib");626 lua_getfield(L, -1, "loadlib");
624 lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");627 lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
625#endif628#endif
626 lua_pushvalue(L, -1);
627 lua_setfield(L, LUA_REGISTRYINDEX, "_PACKAGE");
628 lua_pushvalue(L, -1);629 lua_pushvalue(L, -1);
629 lua_replace(L, LUA_ENVIRONINDEX);630 lua_replace(L, LUA_ENVIRONINDEX);
630 /* create `loaders' table */631 /* create `loaders' table */
@@ -642,7 +643,7 @@ LUALIB_API int luaopen_package (lua_State *L) { · 11 unmodified lines
642 LUA_EXECDIR "\n" LUA_IGMARK);643 LUA_EXECDIR "\n" LUA_IGMARK);
643 lua_setfield(L, -2, "config");644 lua_setfield(L, -2, "config");
644 /* set field `loaded' */645 /* set field `loaded' */
645 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");646 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
646 lua_setfield(L, -2, "loaded");647 lua_setfield(L, -2, "loaded");
647 /* set field `preload' */648 /* set field `preload' */
648 lua_newtable(L);649 lua_newtable(L);
src/lobject.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lobject.c,v 2.18 2005/08/01 04:22:23 roberto Exp $2** $Id: lobject.c,v 2.19 2005/10/24 17:37:52 roberto Exp $
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*/
@@ -75,7 +75,7 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) { · 69 unmodified lines
75 case LUA_TNIL:75 case LUA_TNIL:
76 return 1;76 return 1;
77 case LUA_TNUMBER:77 case LUA_TNUMBER:
78 return luai_numeq(L, nvalue(t1), nvalue(t2));78 return luai_numeq(nvalue(t1), nvalue(t2));
79 case LUA_TBOOLEAN:79 case LUA_TBOOLEAN:
80 return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */80 return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
81 case LUA_TLIGHTUSERDATA:81 case LUA_TLIGHTUSERDATA:
src/lobject.h+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lobject.h,v 2.17 2005/06/13 14:19:00 roberto Exp $2** $Id: lobject.h,v 2.18 2005/10/24 17:37:33 roberto Exp $
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*/
@@ -353,7 +353,7 @@ typedef struct Table { · 347 unmodified lines
353** `module' operation for hashing (size is always a power of 2)353** `module' operation for hashing (size is always a power of 2)
354*/354*/
355#define lmod(s,size) \355#define lmod(s,size) \
356 check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))356 (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
357 357
358 358
359#define twoto(x) (1<<(x))359#define twoto(x) (1<<(x))
src/lopcodes.c+2−4
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lopcodes.c,v 1.35 2005/08/29 20:49:21 roberto Exp $2** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $
3** See Copyright Notice in lua.h3** See Copyright Notice in lua.h
4*/4*/
5 5
@@ -7,9 +7,7 @@ · 1 unmodified line
7#define lopcodes_c7#define lopcodes_c
8#define LUA_CORE8#define LUA_CORE
9 9
10#include "lua.h"
11 10
12#include "lobject.h"
13#include "lopcodes.h"11#include "lopcodes.h"
14 12
15 13
@@ -88,7 +86,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { · 72 unmodified lines
88 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */86 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
89 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */87 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
90 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */88 ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
91 ,opmode(1, 0, OpArgR, OpArgU, iABC) /* OP_TEST */89 ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */
92 ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */90 ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
93 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */91 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
94 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */92 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
src/lopcodes.h+5−5
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lopcodes.h,v 1.122 2005/08/29 20:49:21 roberto Exp $2** $Id: lopcodes.h,v 1.123 2005/10/23 17:37:55 roberto Exp $
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*/
@@ -193,12 +193,12 @@ OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ · 187 unmodified lines
193OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */193OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
194OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */194OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */
195 195
196OP_FORLOOP,/* A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then pc+=sBx */196OP_FORLOOP,/* A sBx R(A)+=R(A+2);
197 if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
197OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */198OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
198 199
199OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); 200OP_TFORLOOP,/* A C R(A+3), ... ,R(A+3+C) := R(A)(R(A+1), R(A+2));
200 if R(A+2) ~= nil then pc++ */201 if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); } */
201
202OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */202OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
203 203
204OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/204OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
src/loslib.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: loslib.c,v 1.13 2005/09/09 18:22:46 roberto Exp $2** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 roberto Exp $
3** Standard Operating System library3** Standard Operating System library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -125,8 +125,8 @@ static int getfield (lua_State *L, const char *key, int d) { · 119 unmodified lines
125 125
126static int io_date (lua_State *L) {126static int io_date (lua_State *L) {
127 const char *s = luaL_optstring(L, 1, "%c");127 const char *s = luaL_optstring(L, 1, "%c");
128 lua_Number n = luaL_optnumber(L, 2, -1);128 time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
129 time_t t = (n == -1) ? time(NULL) : (time_t)n;129 (time_t)luaL_checknumber(L, 2);
130 struct tm *stm;130 struct tm *stm;
131 if (*s == '!') { /* UTC? */131 if (*s == '!') { /* UTC? */
132 stm = gmtime(&t);132 stm = gmtime(&t);
src/lparser.c+22−21
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lparser.c,v 2.35 2005/08/29 20:49:21 roberto Exp $2** $Id: lparser.c,v 2.38 2005/10/24 17:38:47 roberto Exp $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -144,7 +144,7 @@ static TString *str_checkname (LexState *ls) { · 138 unmodified lines
144static void init_exp (expdesc *e, expkind k, int i) {144static void init_exp (expdesc *e, expkind k, int i) {
145 e->f = e->t = NO_JUMP;145 e->f = e->t = NO_JUMP;
146 e->k = k;146 e->k = k;
147 e->info = i;147 e->u.s.info = i;
148}148}
149 149
150 150
@@ -184,7 +184,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { · 33 unmodified lines
184 184
185static void adjustlocalvars (LexState *ls, int nvars) {185static void adjustlocalvars (LexState *ls, int nvars) {
186 FuncState *fs = ls->fs;186 FuncState *fs = ls->fs;
187 fs->nactvar += nvars;187 fs->nactvar = cast(lu_byte, fs->nactvar + nvars);
188 for (; nvars; nvars--) {188 for (; nvars; nvars--) {
189 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;189 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
190 }190 }
@@ -203,7 +203,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 12 unmodified lines
203 Proto *f = fs->f;203 Proto *f = fs->f;
204 int oldsize = f->sizeupvalues;204 int oldsize = f->sizeupvalues;
205 for (i=0; i<f->nups; i++) {205 for (i=0; i<f->nups; i++) {
206 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->info) {206 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
207 lua_assert(f->upvalues[i] == name);207 lua_assert(f->upvalues[i] == name);
208 return i;208 return i;
209 }209 }
@@ -217,7 +217,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { · 7 unmodified lines
217 luaC_objbarrier(fs->L, f, name);217 luaC_objbarrier(fs->L, f, name);
218 lua_assert(v->k == VLOCAL || v->k == VUPVAL);218 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
219 fs->upvalues[f->nups].k = cast(lu_byte, v->k);219 fs->upvalues[f->nups].k = cast(lu_byte, v->k);
220 fs->upvalues[f->nups].info = cast(lu_byte, v->info);220 fs->upvalues[f->nups].info = cast(lu_byte, v->u.s.info);
221 return f->nups++;221 return f->nups++;
222}222}
223 223
@@ -255,7 +255,7 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { · 31 unmodified lines
255 else { /* not found at current level; try upper one */255 else { /* not found at current level; try upper one */
256 if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)256 if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)
257 return VGLOBAL;257 return VGLOBAL;
258 var->info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */258 var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */
259 var->k = VUPVAL; /* upvalue in this level */259 var->k = VUPVAL; /* upvalue in this level */
260 return VUPVAL;260 return VUPVAL;
261 }261 }
@@ -267,7 +267,7 @@ static void singlevar (LexState *ls, expdesc *var) { · 5 unmodified lines
267 TString *varname = str_checkname(ls);267 TString *varname = str_checkname(ls);
268 FuncState *fs = ls->fs;268 FuncState *fs = ls->fs;
269 if (singlevaraux(fs, varname, var, 1) == VGLOBAL)269 if (singlevaraux(fs, varname, var, 1) == VGLOBAL)
270 var->info = luaK_stringK(fs, varname); /* info points to global name */270 var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */
271}271}
272 272
273 273
@@ -351,7 +351,7 @@ static void open_func (LexState *ls, FuncState *fs) { · 77 unmodified lines
351 fs->L = L;351 fs->L = L;
352 ls->fs = fs;352 ls->fs = fs;
353 fs->pc = 0;353 fs->pc = 0;
354 fs->lasttarget = 0;354 fs->lasttarget = -1;
355 fs->jpc = NO_JUMP;355 fs->jpc = NO_JUMP;
356 fs->freereg = 0;356 fs->freereg = 0;
357 fs->nk = 0;357 fs->nk = 0;
@@ -472,8 +472,8 @@ static void recfield (LexState *ls, struct ConsControl *cc) { · 114 unmodified lines
472 checknext(ls, '=');472 checknext(ls, '=');
473 luaK_exp2RK(fs, &key);473 luaK_exp2RK(fs, &key);
474 expr(ls, &val);474 expr(ls, &val);
475 luaK_codeABC(fs, OP_SETTABLE, cc->t->info, luaK_exp2RK(fs, &key),475 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key),
476 luaK_exp2RK(fs, &val));476 luaK_exp2RK(fs, &val));
477 fs->freereg = reg; /* free registers */477 fs->freereg = reg; /* free registers */
478}478}
479 479
@@ -483,7 +483,7 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) { · 3 unmodified lines
483 luaK_exp2nextreg(fs, &cc->v);483 luaK_exp2nextreg(fs, &cc->v);
484 cc->v.k = VVOID;484 cc->v.k = VVOID;
485 if (cc->tostore == LFIELDS_PER_FLUSH) {485 if (cc->tostore == LFIELDS_PER_FLUSH) {
486 luaK_setlist(fs, cc->t->info, cc->na, cc->tostore); /* flush */486 luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */
487 cc->tostore = 0; /* no more items pending */487 cc->tostore = 0; /* no more items pending */
488 }488 }
489}489}
@@ -493,13 +493,13 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 3 unmodified lines
493 if (cc->tostore == 0) return;493 if (cc->tostore == 0) return;
494 if (hasmultret(cc->v.k)) {494 if (hasmultret(cc->v.k)) {
495 luaK_setmultret(fs, &cc->v);495 luaK_setmultret(fs, &cc->v);
496 luaK_setlist(fs, cc->t->info, cc->na, LUA_MULTRET);496 luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
497 cc->na--; /* do not count last expression (unknown number of elements) */497 cc->na--; /* do not count last expression (unknown number of elements) */
498 }498 }
499 else {499 else {
500 if (cc->v.k != VVOID)500 if (cc->v.k != VVOID)
501 luaK_exp2nextreg(fs, &cc->v);501 luaK_exp2nextreg(fs, &cc->v);
502 luaK_setlist(fs, cc->t->info, cc->na, cc->tostore);502 luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
503 }503 }
504}504}
505 505
@@ -657,7 +657,7 @@ static void funcargs (LexState *ls, expdesc *f) { · 151 unmodified lines
657 }657 }
658 }658 }
659 lua_assert(f->k == VNONRELOC);659 lua_assert(f->k == VNONRELOC);
660 base = f->info; /* base register for call */660 base = f->u.s.info; /* base register for call */
661 if (hasmultret(args.k))661 if (hasmultret(args.k))
662 nparams = LUA_MULTRET; /* open call */662 nparams = LUA_MULTRET; /* open call */
663 else {663 else {
@@ -746,7 +746,8 @@ static void simpleexp (LexState *ls, expdesc *v) { · 82 unmodified lines
746 constructor | FUNCTION body | primaryexp */746 constructor | FUNCTION body | primaryexp */
747 switch (ls->t.token) {747 switch (ls->t.token) {
748 case TK_NUMBER: {748 case TK_NUMBER: {
749 init_exp(v, VK, luaK_numberK(ls->fs, ls->t.seminfo.r));749 init_exp(v, VKNUM, 0);
750 v->u.nval = ls->t.seminfo.r;
750 break;751 break;
751 }752 }
752 case TK_STRING: {753 case TK_STRING: {
@@ -805,7 +806,7 @@ static BinOpr getbinopr (int op) { · 52 unmodified lines
805 switch (op) {806 switch (op) {
806 case '+': return OPR_ADD;807 case '+': return OPR_ADD;
807 case '-': return OPR_SUB;808 case '-': return OPR_SUB;
808 case '*': return OPR_MULT;809 case '*': return OPR_MUL;
809 case '/': return OPR_DIV;810 case '/': return OPR_DIV;
810 case '%': return OPR_MOD;811 case '%': return OPR_MOD;
811 case '^': return OPR_POW;812 case '^': return OPR_POW;
@@ -927,18 +928,18 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { · 115 unmodified lines
927 int conflict = 0;928 int conflict = 0;
928 for (; lh; lh = lh->prev) {929 for (; lh; lh = lh->prev) {
929 if (lh->v.k == VINDEXED) {930 if (lh->v.k == VINDEXED) {
930 if (lh->v.info == v->info) { /* conflict? */931 if (lh->v.u.s.info == v->u.s.info) { /* conflict? */
931 conflict = 1;932 conflict = 1;
932 lh->v.info = extra; /* previous assignment will use safe copy */933 lh->v.u.s.info = extra; /* previous assignment will use safe copy */
933 }934 }
934 if (lh->v.aux == v->info) { /* conflict? */935 if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */
935 conflict = 1;936 conflict = 1;
936 lh->v.aux = extra; /* previous assignment will use safe copy */937 lh->v.u.s.aux = extra; /* previous assignment will use safe copy */
937 }938 }
938 }939 }
939 }940 }
940 if (conflict) {941 if (conflict) {
941 luaK_codeABC(fs, OP_MOVE, fs->freereg, v->info, 0); /* make copy */942 luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */
942 luaK_reserveregs(fs, 1);943 luaK_reserveregs(fs, 1);
943 }944 }
944}945}
src/lparser.h+6−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lparser.h,v 1.55 2005/04/25 19:24:10 roberto Exp $2** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -23,6 +23,7 @@ typedef enum { · 17 unmodified lines
23 VTRUE,23 VTRUE,
24 VFALSE,24 VFALSE,
25 VK, /* info = index of constant in `k' */25 VK, /* info = index of constant in `k' */
26 VKNUM, /* nval = numerical value */
26 VLOCAL, /* info = local register */27 VLOCAL, /* info = local register */
27 VUPVAL, /* info = index of upvalue in `upvalues' */28 VUPVAL, /* info = index of upvalue in `upvalues' */
28 VGLOBAL, /* info = index of table; aux = index of global name in `k' */29 VGLOBAL, /* info = index of table; aux = index of global name in `k' */
@@ -36,7 +37,10 @@ typedef enum { · 7 unmodified lines
36 37
37typedef struct expdesc {38typedef struct expdesc {
38 expkind k;39 expkind k;
39 int info, aux;40 union {
41 struct { int info, aux; } s;
42 lua_Number nval;
43 } u;
40 int t; /* patch list of `exit when true' */44 int t; /* patch list of `exit when true' */
41 int f; /* patch list of `exit when false' */45 int f; /* patch list of `exit when false' */
42} expdesc;46} expdesc;
src/lstate.c+6−4
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lstate.c,v 2.33 2005/08/25 15:39:16 roberto Exp $2** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp $
3** Global State3** Global State
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -71,8 +71,8 @@ static void f_luaopen (lua_State *L, void *ud) { · 65 unmodified lines
71 global_State *g = G(L);71 global_State *g = G(L);
72 UNUSED(ud);72 UNUSED(ud);
73 stack_init(L, L); /* init stack */73 stack_init(L, L); /* init stack */
74 sethvalue(L, gt(L), luaH_new(L, 0, 20)); /* table of globals */74 sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
75 sethvalue(L, registry(L), luaH_new(L, 6, 20)); /* registry */75 sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
76 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */76 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
77 luaT_init(L);77 luaT_init(L);
78 luaX_init(L);78 luaX_init(L);
@@ -134,6 +134,7 @@ lua_State *luaE_newthread (lua_State *L) { · 55 unmodified lines
134void luaE_freethread (lua_State *L, lua_State *L1) {134void luaE_freethread (lua_State *L, lua_State *L1) {
135 luaF_close(L1, L1->stack); /* close all upvalues for this thread */135 luaF_close(L1, L1->stack); /* close all upvalues for this thread */
136 lua_assert(L1->openupval == NULL);136 lua_assert(L1->openupval == NULL);
137 luai_userstatefree(L1);
137 freestack(L, L1);138 freestack(L, L1);
138 luaM_freemem(L, fromstate(L1), state_size(lua_State));139 luaM_freemem(L, fromstate(L1), state_size(lua_State));
139}140}
@@ -196,8 +197,9 @@ static void callallgcTM (lua_State *L, void *ud) { · 56 unmodified lines
196 197
197 198
198LUA_API void lua_close (lua_State *L) {199LUA_API void lua_close (lua_State *L) {
199 lua_lock(L);
200 L = G(L)->mainthread; /* only the main thread can be closed */200 L = G(L)->mainthread; /* only the main thread can be closed */
201 luai_userstateclose(L);
202 lua_lock(L);
201 luaF_close(L, L->stack); /* close all upvalues for this thread */203 luaF_close(L, L->stack); /* close all upvalues for this thread */
202 luaC_separateudata(L, 1); /* separate udata that have GC metamethods */204 luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
203 L->errfunc = 0; /* no error function during GC metamethods */205 L->errfunc = 0; /* no error function during GC metamethods */
src/lstrlib.c+75−58
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lstrlib.c,v 1.123 2005/08/26 17:36:32 roberto Exp $2** $Id: lstrlib.c,v 1.127 2005/10/26 13:28:19 roberto Exp $
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*/
@@ -111,7 +111,9 @@ static int str_byte (lua_State *L) { · 105 unmodified lines
111 if (posi <= 0) posi = 1;111 if (posi <= 0) posi = 1;
112 if ((size_t)pose > l) pose = l;112 if ((size_t)pose > l) pose = l;
113 if (posi > pose) return 0; /* empty interval; return no values */113 if (posi > pose) return 0; /* empty interval; return no values */
114 n = pose - posi + 1;114 n = (int)(pose - posi + 1);
115 if (posi + n <= pose) /* overflow? */
116 luaL_error(L, "string slice too long");
115 luaL_checkstack(L, n, "string slice too long");117 luaL_checkstack(L, n, "string slice too long");
116 for (i=0; i<n; i++)118 for (i=0; i<n; i++)
117 lua_pushinteger(L, uchar(s[posi+i-1]));119 lua_pushinteger(L, uchar(s[posi+i-1]));
@@ -460,28 +462,32 @@ static const char *lmemfind (const char *s1, size_t l1, · 342 unmodified lines
460}462}
461 463
462 464
463static void push_onecapture (MatchState *ms, int i) {465static void push_onecapture (MatchState *ms, int i, const char *s,
464 ptrdiff_t l = ms->capture[i].len;466 const char *e) {
465 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");467 if (i >= ms->level) {
466 if (l == CAP_POSITION)468 if (i == 0) /* ms->level == 0, too */
467 lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);469 lua_pushlstring(ms->L, s, e - s); /* add whole match */
468 else470 else
469 lua_pushlstring(ms->L, ms->capture[i].init, l);471 luaL_error(ms->L, "invalid capture index");
472 }
473 else {
474 ptrdiff_t l = ms->capture[i].len;
475 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
476 if (l == CAP_POSITION)
477 lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
478 else
479 lua_pushlstring(ms->L, ms->capture[i].init, l);
480 }
470}481}
471 482
472 483
473static int push_captures (MatchState *ms, const char *s, const char *e) {484static int push_captures (MatchState *ms, const char *s, const char *e) {
474 int i;485 int i;
475 luaL_checkstack(ms->L, ms->level, "too many captures");486 int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
476 if (ms->level == 0 && s) { /* no explicit captures? */487 luaL_checkstack(ms->L, nlevels, "too many captures");
477 lua_pushlstring(ms->L, s, e-s); /* return whole match */488 for (i = 0; i < nlevels; i++)
478 return 1;489 push_onecapture(ms, i, s, e);
479 }490 return nlevels; /* number of strings pushed */
480 else { /* return all captures */
481 for (i=0; i<ms->level; i++)
482 push_onecapture(ms, i);
483 return ms->level; /* number of strings pushed */
484 }
485}491}
486 492
487 493
@@ -516,12 +522,7 @@ static int str_find_aux (lua_State *L, int find) { · 28 unmodified lines
516 if (find) {522 if (find) {
517 lua_pushinteger(L, s1-s+1); /* start */523 lua_pushinteger(L, s1-s+1); /* start */
518 lua_pushinteger(L, res-s); /* end */524 lua_pushinteger(L, res-s); /* end */
519#if defined(LUA_COMPAT_FIND)
520 return push_captures(&ms, NULL, 0) + 2;525 return push_captures(&ms, NULL, 0) + 2;
521#else
522 return 2;
523#endif
524
525 }526 }
526 else527 else
527 return push_captures(&ms, s1, res);528 return push_captures(&ms, s1, res);
@@ -585,42 +586,61 @@ static int gfind_nodef (lua_State *L) { · 57 unmodified lines
585}586}
586 587
587 588
588static void add_s (MatchState *ms, luaL_Buffer *b,589static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
589 const char *s, const char *e) {590 const char *e) {
590 lua_State *L = ms->L;591 size_t l, i;
591 if (lua_isstring(L, 3)) {592 const char *news = lua_tolstring(ms->L, 3, &l);
592 size_t l;593 for (i = 0; i < l; i++) {
593 const char *news = lua_tolstring(L, 3, &l);594 if (news[i] != L_ESC)
594 size_t i;595 luaL_addchar(b, news[i]);
595 for (i=0; i<l; i++) {596 else {
596 if (news[i] != L_ESC)597 i++; /* skip ESC */
598 if (!isdigit(uchar(news[i])))
597 luaL_addchar(b, news[i]);599 luaL_addchar(b, news[i]);
600 else if (news[i] == '0')
601 luaL_addlstring(b, s, e - s);
598 else {602 else {
599 i++; /* skip ESC */603 push_onecapture(ms, news[i] - '1', s, e);
600 if (!isdigit(uchar(news[i])))604 luaL_addvalue(b); /* add capture to accumulated result */
601 luaL_addchar(b, news[i]);
602 else {
603 if (news[i] == '0')
604 lua_pushlstring(L, s, e - s); /* add whole match */
605 else {
606 int level = check_capture(ms, news[i]);
607 push_onecapture(ms, level);
608 }
609 luaL_addvalue(b); /* add capture to accumulated result */
610 }
611 }605 }
612 }606 }
613 }607 }
614 else { /* is a function */608}
615 int n;609
616 lua_pushvalue(L, 3);610
617 n = push_captures(ms, s, e);611static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
618 lua_call(L, n, 1);612 const char *e) {
619 if (lua_isstring(L, -1))613 lua_State *L = ms->L;
620 luaL_addvalue(b); /* add return to accumulated result */614 switch (lua_type(L, 3)) {
621 else615 case LUA_TNUMBER:
622 lua_pop(L, 1); /* function result is not a string: pop it */616 case LUA_TSTRING: {
617 add_s(ms, b, s, e);
618 return;
619 }
620 case LUA_TFUNCTION: {
621 int n;
622 lua_pushvalue(L, 3);
623 n = push_captures(ms, s, e);
624 lua_call(L, n, 1);
625 break;
626 }
627 case LUA_TTABLE: {
628 push_onecapture(ms, 0, s, e);
629 lua_gettable(L, 3);
630 break;
631 }
632 default: {
633 luaL_argerror(L, 3, "string/function/table expected");
634 return;
635 }
636 }
637 if (!lua_toboolean(L, -1)) { /* nil or false? */
638 lua_pop(L, 1);
639 lua_pushlstring(L, s, e - s); /* keep original text */
623 }640 }
641 else if (!lua_isstring(L, -1))
642 luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
643 luaL_addvalue(b); /* add result to accumulator */
624}644}
625 645
626 646
@@ -633,9 +653,6 @@ static int str_gsub (lua_State *L) { · 6 unmodified lines
633 int n = 0;653 int n = 0;
634 MatchState ms;654 MatchState ms;
635 luaL_Buffer b;655 luaL_Buffer b;
636 luaL_argcheck(L,
637 lua_gettop(L) >= 3 && (lua_isstring(L, 3) || lua_isfunction(L, 3)),
638 3, "string or function expected");
639 luaL_buffinit(L, &b);656 luaL_buffinit(L, &b);
640 ms.L = L;657 ms.L = L;
641 ms.src_init = src;658 ms.src_init = src;
@@ -646,7 +663,7 @@ static int str_gsub (lua_State *L) { · 4 unmodified lines
646 e = match(&ms, src, p);663 e = match(&ms, src, p);
647 if (e) {664 if (e) {
648 n++;665 n++;
649 add_s(&ms, &b, src, e);666 add_value(&ms, &b, src, e);
650 }667 }
651 if (e && e>src) /* non empty match? */668 if (e && e>src) /* non empty match? */
652 src = e; /* skip it */669 src = e; /* skip it */
src/ltable.c+5−5
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ltable.c,v 2.26 2005/07/11 14:01:37 roberto Exp $2** $Id: ltable.c,v 2.27 2005/10/24 17:37:52 roberto Exp $
3** Lua tables (hash)3** Lua tables (hash)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -120,7 +120,7 @@ static int arrayindex (const TValue *key) { · 114 unmodified lines
120 lua_Number n = nvalue(key);120 lua_Number n = nvalue(key);
121 int k;121 int k;
122 lua_number2int(k, n);122 lua_number2int(k, n);
123 if (luai_numeq(L, cast(lua_Number, k), nvalue(key)))123 if (luai_numeq(cast(lua_Number, k), nvalue(key)))
124 return k;124 return k;
125 }125 }
126 return -1; /* `key' did not match some condition */126 return -1; /* `key' did not match some condition */
@@ -437,7 +437,7 @@ const TValue *luaH_getnum (Table *t, int key) { · 310 unmodified lines
437 lua_Number nk = cast(lua_Number, key);437 lua_Number nk = cast(lua_Number, key);
438 Node *n = hashnum(t, nk);438 Node *n = hashnum(t, nk);
439 do { /* check whether `key' is somewhere in the chain */439 do { /* check whether `key' is somewhere in the chain */
440 if (ttisnumber(gkey(n)) && luai_numeq(L, nvalue(gkey(n)), nk))440 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
441 return gval(n); /* that's it */441 return gval(n); /* that's it */
442 else n = gnext(n);442 else n = gnext(n);
443 } while (n);443 } while (n);
@@ -471,7 +471,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 27 unmodified lines
471 int k;471 int k;
472 lua_Number n = nvalue(key);472 lua_Number n = nvalue(key);
473 lua_number2int(k, n);473 lua_number2int(k, n);
474 if (luai_numeq(L, cast(lua_Number, k), nvalue(key))) /* index is int? */474 if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */
475 return luaH_getnum(t, k); /* use specialized version */475 return luaH_getnum(t, k); /* use specialized version */
476 /* else go through */476 /* else go through */
477 }477 }
@@ -495,7 +495,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { · 17 unmodified lines
495 return cast(TValue *, p);495 return cast(TValue *, p);
496 else {496 else {
497 if (ttisnil(key)) luaG_runerror(L, "table index is nil");497 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
498 else if (ttisnumber(key) && !luai_numeq(L, nvalue(key), nvalue(key)))498 else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key)))
499 luaG_runerror(L, "table index is NaN");499 luaG_runerror(L, "table index is NaN");
500 return newkey(L, t, key);500 return newkey(L, t, key);
501 }501 }
src/ltablib.c+40−18
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ltablib.c,v 1.35 2005/08/26 17:36:32 roberto Exp $2** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $
3** Library for Table Manipulation3** Library for Table Manipulation
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -40,9 +40,7 @@ static int foreach (lua_State *L) { · 34 unmodified lines
40 luaL_checktype(L, 1, LUA_TTABLE);40 luaL_checktype(L, 1, LUA_TTABLE);
41 luaL_checktype(L, 2, LUA_TFUNCTION);41 luaL_checktype(L, 2, LUA_TFUNCTION);
42 lua_pushnil(L); /* first key */42 lua_pushnil(L); /* first key */
43 for (;;) {43 while (lua_next(L, 1)) {
44 if (lua_next(L, 1) == 0)
45 return 0;
46 lua_pushvalue(L, 2); /* function */44 lua_pushvalue(L, 2); /* function */
47 lua_pushvalue(L, -3); /* key */45 lua_pushvalue(L, -3); /* key */
48 lua_pushvalue(L, -3); /* value */46 lua_pushvalue(L, -3); /* value */
@@ -51,6 +49,23 @@ static int foreach (lua_State *L) { · 2 unmodified lines
51 return 1;49 return 1;
52 lua_pop(L, 2); /* remove value and result */50 lua_pop(L, 2); /* remove value and result */
53 }51 }
52 return 0;
53}
54
55
56static int maxn (lua_State *L) {
57 lua_Number max = 0;
58 luaL_checktype(L, 1, LUA_TTABLE);
59 lua_pushnil(L); /* first key */
60 while (lua_next(L, 1)) {
61 lua_pop(L, 1); /* remove value */
62 if (lua_type(L, -1) == LUA_TNUMBER) {
63 lua_Number v = lua_tonumber(L, -1);
64 if (v > max) max = v;
65 }
66 }
67 lua_pushnumber(L, max);
68 return 1;
54}69}
55 70
56 71
@@ -75,16 +90,23 @@ static int setn (lua_State *L) { · 18 unmodified lines
75static int tinsert (lua_State *L) {90static int tinsert (lua_State *L) {
76 int e = aux_getn(L, 1) + 1; /* first empty element */91 int e = aux_getn(L, 1) + 1; /* first empty element */
77 int pos; /* where to insert new element */92 int pos; /* where to insert new element */
78 if (lua_isnone(L, 3)) /* called with only 2 arguments */93 switch (lua_gettop(L)) {
79 pos = e; /* insert new element at the end */94 case 2: { /* called with only 2 arguments */
80 else {95 pos = e; /* insert new element at the end */
81 int i;96 break;
82 pos = luaL_checkint(L, 2); /* 2nd argument is the position */97 }
83 if (pos > e) e = pos; /* `grow' array if necessary */98 case 3: {
84 lua_settop(L, 3); /* function may be called with more than 3 args */99 int i;
85 for (i = e; i > pos; i--) { /* move up elements */100 pos = luaL_checkint(L, 2); /* 2nd argument is the position */
86 lua_rawgeti(L, 1, i-1);101 if (pos > e) e = pos; /* `grow' array if necessary */
87 lua_rawseti(L, 1, i); /* t[i] = t[i-1] */102 for (i = e; i > pos; i--) { /* move up elements */
103 lua_rawgeti(L, 1, i-1);
104 lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
105 }
106 break;
107 }
108 default: {
109 return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
88 }110 }
89 }111 }
90 luaL_setn(L, 1, e); /* new size */112 luaL_setn(L, 1, e); /* new size */
@@ -112,12 +134,11 @@ static int tremove (lua_State *L) { · 21 unmodified lines
112static int tconcat (lua_State *L) {134static int tconcat (lua_State *L) {
113 luaL_Buffer b;135 luaL_Buffer b;
114 size_t lsep;136 size_t lsep;
137 int i, last;
115 const char *sep = luaL_optlstring(L, 2, "", &lsep);138 const char *sep = luaL_optlstring(L, 2, "", &lsep);
116 int i = luaL_optint(L, 3, 1);
117 int last = luaL_optint(L, 4, -2);
118 luaL_checktype(L, 1, LUA_TTABLE);139 luaL_checktype(L, 1, LUA_TTABLE);
119 if (last == -2)140 i = luaL_optint(L, 3, 1);
120 last = luaL_getn(L, 1);141 last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));
121 luaL_buffinit(L, &b);142 luaL_buffinit(L, &b);
122 for (; i <= last; i++) {143 for (; i <= last; i++) {
123 lua_rawgeti(L, 1, i);144 lua_rawgeti(L, 1, i);
@@ -241,6 +262,7 @@ static const luaL_Reg tab_funcs[] = { · 117 unmodified lines
241 {"foreach", foreach},262 {"foreach", foreach},
242 {"foreachi", foreachi},263 {"foreachi", foreachi},
243 {"getn", getn},264 {"getn", getn},
265 {"maxn", maxn},
244 {"insert", tinsert},266 {"insert", tinsert},
245 {"remove", tremove},267 {"remove", tremove},
246 {"setn", setn},268 {"setn", setn},
src/lua.c+96−90
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lua.c,v 1.150 2005/09/06 17:19:33 roberto Exp $2** $Id: lua.c,v 1.154 2005/10/24 17:38:47 roberto Exp $
3** Lua stand-alone interpreter3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -43,12 +43,13 @@ static void print_usage (void) { · 37 unmodified lines
43 fprintf(stderr,43 fprintf(stderr,
44 "usage: %s [options] [script [args]].\n"44 "usage: %s [options] [script [args]].\n"
45 "Available options are:\n"45 "Available options are:\n"
46 " - execute stdin as a file\n"
47 " -e stat execute string " LUA_QL("stat") "\n"46 " -e stat execute string " LUA_QL("stat") "\n"
48 " -i enter interactive mode after executing " LUA_QL("script") "\n"
49 " -l name require library " LUA_QL("name") "\n"47 " -l name require library " LUA_QL("name") "\n"
48 " -i enter interactive mode after executing " LUA_QL("script") "\n"
50 " -v show version information\n"49 " -v show version information\n"
51 " -- stop handling options\n" ,50 " -- stop handling options\n"
51 " - execute stdin and stop handling options\n"
52 ,
52 progname);53 progname);
53 fflush(stderr);54 fflush(stderr);
54}55}
@@ -99,6 +100,8 @@ static int docall (lua_State *L, int narg, int clear) { · 44 unmodified lines
99 status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);100 status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
100 signal(SIGINT, SIG_DFL);101 signal(SIGINT, SIG_DFL);
101 lua_remove(L, base); /* remove traceback function */102 lua_remove(L, base); /* remove traceback function */
103 /* force a complete garbage collection in case of errors */
104 if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
102 return status;105 return status;
103}106}
104 107
@@ -108,9 +111,12 @@ static void print_version (void) { · 3 unmodified lines
108}111}
109 112
110 113
111static int getargs (lua_State *L, int argc, char **argv, int n) {114static int getargs (lua_State *L, char **argv, int n) {
112 int narg = argc - (n + 1); /* number of arguments to the script */115 int narg;
113 int i;116 int i;
117 int argc = 0;
118 while (argv[argc]) argc++; /* count total number of arguments */
119 narg = argc - (n + 1); /* number of arguments to the script */
114 luaL_checkstack(L, narg + 3, "too many arguments to script");120 luaL_checkstack(L, narg + 3, "too many arguments to script");
115 for (i=n+1; i < argc; i++)121 for (i=n+1; i < argc; i++)
116 lua_pushstring(L, argv[i]);122 lua_pushstring(L, argv[i]);
@@ -229,86 +235,71 @@ static void dotty (lua_State *L) { · 112 unmodified lines
229}235}
230 236
231 237
232#define clearinteractive(i) (*i &= 2)238static int handle_script (lua_State *L, char **argv, int n) {
239 int status;
240 const char *fname;
241 int narg = getargs(L, argv, n); /* collect arguments */
242 lua_setglobal(L, "arg");
243 fname = argv[n];
244 if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
245 fname = NULL; /* stdin */
246 status = luaL_loadfile(L, fname);
247 lua_insert(L, -(narg+1));
248 if (status == 0)
249 status = docall(L, narg, 0);
250 else
251 lua_pop(L, narg);
252 return report(L, status);
253}
233 254
234static int handle_argv (lua_State *L, int argc, char **argv, int *interactive) {255
235 if (argv[1] == NULL) { /* no arguments? */256static int collectargs (char **argv, int *pi, int *pv, int *pe) {
236 *interactive = 0;257 int i;
237 if (lua_stdin_is_tty())258 for (i = 1; argv[i] != NULL; i++) {
238 dotty(L);259 if (argv[i][0] != '-') /* not an option? */
239 else260 return i;
240 dofile(L, NULL); /* executes stdin as a file */261 switch (argv[i][1]) { /* option */
241 }262 case '-': return (argv[i+1] != NULL ? i+1 : 0);
242 else { /* other arguments; loop over them */263 case '\0': return i;
243 int i;264 case 'i': *pi = 1; break;
244 for (i = 1; argv[i] != NULL; i++) {265 case 'v': *pv = 1; break;
245 if (argv[i][0] != '-') break; /* not an option? */266 case 'e': *pe = 1; /* go through */
246 switch (argv[i][1]) { /* option */267 case 'l':
247 case '-': { /* `--' */268 if (argv[i][2] == '\0') {
248 if (argv[i][2] != '\0') {269 i++;
249 print_usage();270 if (argv[i] == NULL) return -1;
250 return 1;
251 }
252 i++; /* skip this argument */
253 goto endloop; /* stop handling arguments */
254 }
255 case '\0': {
256 clearinteractive(interactive);
257 dofile(L, NULL); /* executes stdin as a file */
258 break;
259 }
260 case 'i': {
261 *interactive = 2; /* force interactive mode after arguments */
262 break;
263 }
264 case 'v': {
265 clearinteractive(interactive);
266 print_version();
267 break;
268 }
269 case 'e': {
270 const char *chunk = argv[i] + 2;
271 clearinteractive(interactive);
272 if (*chunk == '\0') chunk = argv[++i];
273 if (chunk == NULL) {
274 print_usage();
275 return 1;
276 }
277 if (dostring(L, chunk, "=(command line)") != 0)
278 return 1;
279 break;
280 }
281 case 'l': {
282 const char *filename = argv[i] + 2;
283 if (*filename == '\0') filename = argv[++i];
284 if (filename == NULL) {
285 print_usage();
286 return 1;
287 }
288 if (dolibrary(L, filename))
289 return 1; /* stop if file fails */
290 break;
291 }271 }
292 default: {272 break;
293 clearinteractive(interactive);273 default: return -1; /* invalid option */
294 print_usage();274 }
275 }
276 return 0;
277}
278
279
280static int runargs (lua_State *L, char **argv, int n) {
281 int i;
282 for (i = 1; i < n; i++) {
283 if (argv[i] == NULL) continue;
284 lua_assert(argv[i][0] == '-');
285 switch (argv[i][1]) { /* option */
286 case 'e': {
287 const char *chunk = argv[i] + 2;
288 if (*chunk == '\0') chunk = argv[++i];
289 lua_assert(chunk != NULL);
290 if (dostring(L, chunk, "=(command line)") != 0)
295 return 1;291 return 1;
296 }292 break;
297 }293 }
298 } endloop:294 case 'l': {
299 if (argv[i] != NULL) {295 const char *filename = argv[i] + 2;
300 int status;296 if (*filename == '\0') filename = argv[++i];
301 const char *filename = argv[i];297 lua_assert(filename != NULL);
302 int narg = getargs(L, argc, argv, i); /* collect arguments */298 if (dolibrary(L, filename))
303 lua_setglobal(L, "arg");299 return 1; /* stop if file fails */
304 clearinteractive(interactive);300 break;
305 status = luaL_loadfile(L, filename);301 }
306 lua_insert(L, -(narg+1));302 default: break;
307 if (status == 0)
308 status = docall(L, narg, 0);
309 else
310 lua_pop(L, narg);
311 return report(L, status);
312 }303 }
313 }304 }
314 return 0;305 return 0;
@@ -334,17 +325,32 @@ struct Smain { · 19 unmodified lines
334 325
335static int pmain (lua_State *L) {326static int pmain (lua_State *L) {
336 struct Smain *s = (struct Smain *)lua_touserdata(L, 1);327 struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
337 int status;328 char **argv = s->argv;
338 int interactive = 1;329 int script;
339 if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];330 int has_i = 0, has_v = 0, has_e = 0;
340 globalL = L;331 globalL = L;
332 if (argv[0] && argv[0][0]) progname = argv[0];
341 luaL_openlibs(L); /* open libraries */333 luaL_openlibs(L); /* open libraries */
342 status = handle_luainit(L);334 s->status = handle_luainit(L);
343 if (status == 0) {335 if (s->status != 0) return 0;
344 status = handle_argv(L, s->argc, s->argv, &interactive);336 script = collectargs(argv, &has_i, &has_v, &has_e);
345 if (status == 0 && interactive) dotty(L);337 if (script < 0) { /* invalid args? */
338 print_usage();
339 s->status = 1;
340 return 0;
341 }
342 if (has_v) print_version();
343 s->status = runargs(L, argv, (script > 0) ? script : s->argc);
344 if (s->status != 0) return 0;
345 if (script)
346 s->status = handle_script(L, argv, script);
347 if (s->status != 0) return 0;
348 if (has_i)
349 dotty(L);
350 else if (script == 0 && !has_e && !has_v) {
351 if (lua_stdin_is_tty()) dotty(L);
352 else dofile(L, NULL); /* executes stdin as a file */
346 }353 }
347 s->status = status;
348 return 0;354 return 0;
349}355}
350 356
src/lua.h+7−5
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lua.h,v 1.212 2005/08/25 20:02:08 roberto Exp $2** $Id: lua.h,v 1.214 2005/10/20 11:35:50 roberto Exp $
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,7 +16,7 @@ · 10 unmodified lines
16#include "luaconf.h"16#include "luaconf.h"
17 17
18 18
19#define LUA_VERSION "Lua 5.1 (alpha)"19#define LUA_VERSION "Lua 5.1 (beta)"
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-2005 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"
@@ -221,9 +221,10 @@ LUA_API int (lua_status) (lua_State *L); · 198 unmodified lines
221#define LUA_GCRESTART 1221#define LUA_GCRESTART 1
222#define LUA_GCCOLLECT 2222#define LUA_GCCOLLECT 2
223#define LUA_GCCOUNT 3223#define LUA_GCCOUNT 3
224#define LUA_GCSTEP 4224#define LUA_GCCOUNTB 4
225#define LUA_GCSETPAUSE 5225#define LUA_GCSTEP 5
226#define LUA_GCSETSTEPMUL 6226#define LUA_GCSETPAUSE 6
227#define LUA_GCSETSTEPMUL 7
227 228
228LUA_API int (lua_gc) (lua_State *L, int what, int data);229LUA_API int (lua_gc) (lua_State *L, int what, int data);
229 230
@@ -239,6 +240,7 @@ LUA_API int (lua_next) (lua_State *L, int idx); · 9 unmodified lines
239LUA_API void (lua_concat) (lua_State *L, int n);240LUA_API void (lua_concat) (lua_State *L, int n);
240 241
241LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);242LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
243LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
242 244
243 245
244 246
src/luac.c+7−12
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: luac.c,v 1.51 2005/06/02 13:39:23 lhf Exp $2** $Id: luac.c,v 1.52 2005/11/11 14:03:13 lhf Exp $
3** Lua compiler (saves bytecodes to files; also list bytecodes)3** Lua compiler (saves bytecodes to files; also list bytecodes)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -23,13 +23,8 @@ · 17 unmodified lines
23#include "lstring.h"23#include "lstring.h"
24#include "lundump.h"24#include "lundump.h"
25 25
26#ifndef PROGNAME
27#define PROGNAME "luac" /* default program name */26#define PROGNAME "luac" /* default program name */
28#endif27#define OUTPUT PROGNAME ".out" /* default output file */
29
30#ifndef OUTPUT
31#define OUTPUT "luac.out" /* default output file */
32#endif
33 28
34static int listing=0; /* list bytecodes? */29static int listing=0; /* list bytecodes? */
35static int dumping=1; /* dump bytecodes? */30static int dumping=1; /* dump bytecodes? */
@@ -152,15 +147,15 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 116 unmodified lines
152}147}
153 148
154struct Smain {149struct Smain {
155 int argc;150 int argc;
156 char **argv;151 char** argv;
157};152};
158 153
159static int pmain(lua_State *L)154static int pmain(lua_State* L)
160{155{
161 struct Smain *s = (struct Smain *)lua_touserdata(L, 1);156 struct Smain* s = (struct Smain*)lua_touserdata(L, 1);
162 int argc=s->argc;157 int argc=s->argc;
163 char **argv=s->argv;158 char** argv=s->argv;
164 Proto* f;159 Proto* f;
165 int i;160 int i;
166 if (!lua_checkstack(L,argc)) fatal("too many input files");161 if (!lua_checkstack(L,argc)) fatal("too many input files");
src/luaconf.h+95−73
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: luaconf.h,v 1.65 2005/09/09 18:24:42 roberto Exp $2** $Id: luaconf.h,v 1.74 2005/11/16 16:24:28 roberto Exp $
3** Configuration file for Lua3** Configuration file for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -19,8 +19,6 @@ · 13 unmodified lines
19*/19*/
20 20
21 21
22
23
24/*22/*
25@@ LUA_ANSI controls the use of non-ansi features.23@@ LUA_ANSI controls the use of non-ansi features.
26** CHANGE it (define it) if you want Lua to avoid the use of any24** CHANGE it (define it) if you want Lua to avoid the use of any
@@ -30,6 +28,31 @@ · 3 unmodified lines
30#define LUA_ANSI28#define LUA_ANSI
31#endif29#endif
32 30
31#if defined(LUA_USE_LINUX)
32#define LUA_USE_POSIX
33#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
34#define LUA_USE_READLINE /* needs some extra libraries */
35#endif
36
37#if defined(LUA_USE_MACOSX)
38#define LUA_USE_POSIX
39#define LUA_DL_DYLD /* does not need extra library */
40#endif
41
42
43
44/*
45@@ LUA_USE_POSIX includes all functionallity listed as X/Open System
46@* Interfaces Extension (XSI).
47** CHANGE it (define it) if your system is XSI compatible.
48*/
49#if defined(LUA_USE_POSIX)
50#define LUA_USE_MKSTEMP
51#define LUA_USE_ISATTY
52#define LUA_USE_POPEN
53#define LUA_USE_ULONGJMP
54#endif
55
33 56
34/*57/*
35@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for58@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@@ -92,7 +115,7 @@ · 56 unmodified lines
92#define LUA_PATHSEP ";"115#define LUA_PATHSEP ";"
93#define LUA_PATH_MARK "?"116#define LUA_PATH_MARK "?"
94#define LUA_EXECDIR "!"117#define LUA_EXECDIR "!"
95#define LUA_IGMARK ":"118#define LUA_IGMARK "-"
96 119
97 120
98/*121/*
@@ -141,10 +164,12 @@ · 42 unmodified lines
141#if defined(luaall_c)164#if defined(luaall_c)
142#define LUAI_FUNC static165#define LUAI_FUNC static
143#define LUAI_DATA /* empty */166#define LUAI_DATA /* empty */
167
144#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \168#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
145 defined(__ELF__)169 defined(__ELF__)
146#define LUAI_FUNC __attribute__((visibility("hidden"))) extern170#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
147#define LUAI_DATA LUAI_FUNC171#define LUAI_DATA LUAI_FUNC
172
148#else173#else
149#define LUAI_FUNC extern174#define LUAI_FUNC extern
150#define LUAI_DATA extern175#define LUAI_DATA extern
@@ -189,7 +214,7 @@ · 38 unmodified lines
189** CHANGE it if you have a better definition for non-POSIX/non-Windows214** CHANGE it if you have a better definition for non-POSIX/non-Windows
190** systems.215** systems.
191*/216*/
192#if !defined(LUA_ANSI) && defined(_POSIX_C_SOURCE)217#if defined(LUA_USE_ISATTY)
193#include <unistd.h>218#include <unistd.h>
194#define lua_stdin_is_tty() isatty(0)219#define lua_stdin_is_tty() isatty(0)
195#elif !defined(LUA_ANSI) && defined(_WIN32)220#elif !defined(LUA_ANSI) && defined(_WIN32)
@@ -239,17 +264,17 @@ · 43 unmodified lines
239#include <stdio.h>264#include <stdio.h>
240#include <readline/readline.h>265#include <readline/readline.h>
241#include <readline/history.h>266#include <readline/history.h>
242#define lua_readline(L,b,p) (((b)=readline(p)) != NULL)267#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
243#define lua_saveline(L,idx) \268#define lua_saveline(L,idx) \
244 if (lua_strlen(L,idx) > 0) /* non-empty line? */ \269 if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
245 add_history(lua_tostring(L, idx)); /* add it to history */270 add_history(lua_tostring(L, idx)); /* add it to history */
246#define lua_freeline(L,b) free(b)271#define lua_freeline(L,b) ((void)L, free(b))
247#else272#else
248#define lua_readline(L,b,p) \273#define lua_readline(L,b,p) \
249 (fputs(p, stdout), fflush(stdout), /* show prompt */ \274 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
250 fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */275 fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
251#define lua_saveline(L,idx) ((void)0)276#define lua_saveline(L,idx) { (void)L; (void)idx; }
252#define lua_freeline(L,b) ((void)0)277#define lua_freeline(L,b) { (void)L; (void)b; }
253#endif278#endif
254 279
255#endif280#endif
@@ -315,13 +340,6 @@ · 59 unmodified lines
315*/340*/
316#define LUA_COMPAT_LSTR 1341#define LUA_COMPAT_LSTR 1
317 342
318/*
319@@ LUA_COMPAT_FIND controls compatibility with old 'string.find' behavior.
320** CHANGE it to undefined as soon as your programs use 'string.find' only
321** to find patterns.
322*/
323#define LUA_COMPAT_FIND
324
325/*343/*
326@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.344@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
327** CHANGE it to undefined as soon as you rename 'string.gfind' to345** CHANGE it to undefined as soon as you rename 'string.gfind' to
@@ -329,7 +347,6 @@ · 1 unmodified line
329*/347*/
330#define LUA_COMPAT_GFIND348#define LUA_COMPAT_GFIND
331 349
332
333/*350/*
334@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'351@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
335@* behavior.352@* behavior.
@@ -349,10 +366,10 @@ · 13 unmodified lines
349*/366*/
350#if defined(LUA_USE_APICHECK)367#if defined(LUA_USE_APICHECK)
351#include <assert.h>368#include <assert.h>
352#define luai_apicheck(L,o) assert(o)369#define luai_apicheck(L,o) { (void)L; assert(o); }
353#else370#else
354/* (By default lua_assert is empty, so luai_apicheck is also empty.) */371/* (By default lua_assert is empty, so luai_apicheck is also empty.) */
355#define luai_apicheck(L,o) lua_assert(o)372#define luai_apicheck(L,o) { (void)L; lua_assert(o); }
356#endif373#endif
357 374
358 375
@@ -464,31 +481,6 @@ · 105 unmodified lines
464 481
465 482
466 483
467/*
468@@ lua_number2int is a macro to convert lua_Number to int.
469@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
470** CHANGE them if you know a faster way to convert a lua_Number to
471** int (with any rounding method and without throwing errors) in your
472** system. In Pentium machines, a naive typecast from double to int
473** in C is extremely slow, so any alternative is worth trying.
474*/
475
476/* On a Pentium, resort to a trick */
477#if !defined(LUA_ANSI) && !defined(__SSE2__) && \
478 (defined(__i386) || defined (_M_IX86))
479union luai_Cast { double l_d; long l_l; };
480#define lua_number2int(i,d) \
481 { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
482#define lua_number2integer(i,n) lua_number2int(i, n)
483
484/* this option always works, but may be slow */
485#else
486#define lua_number2int(i,d) ((i)=(int)(d))
487#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
488
489#endif
490
491
492 484
493/*485/*
494** {==================================================================486** {==================================================================
@@ -525,16 +517,44 @@ union luai_Cast { double l_d; long l_l; }; · 30 unmodified lines
525/*517/*
526@@ The luai_num* macros define the primitive operations over numbers.518@@ The luai_num* macros define the primitive operations over numbers.
527*/519*/
528#define luai_numadd(L,a,b) ((a)+(b))520#if defined(LUA_CORE)
529#define luai_numsub(L,a,b) ((a)-(b))521#include <math.h>
530#define luai_nummul(L,a,b) ((a)*(b))522#define luai_numadd(a,b) ((a)+(b))
531#define luai_numdiv(L,a,b) ((a)/(b))523#define luai_numsub(a,b) ((a)-(b))
532#define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))524#define luai_nummul(a,b) ((a)*(b))
533#define luai_numpow(L,a,b) pow(a,b)525#define luai_numdiv(a,b) ((a)/(b))
534#define luai_numunm(L,a) (-(a))526#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
535#define luai_numeq(L,a,b) ((a)==(b))527#define luai_numpow(a,b) (pow(a,b))
536#define luai_numlt(L,a,b) ((a)<(b))528#define luai_numunm(a) (-(a))
537#define luai_numle(L,a,b) ((a)<=(b))529#define luai_numeq(a,b) ((a)==(b))
530#define luai_numlt(a,b) ((a)<(b))
531#define luai_numle(a,b) ((a)<=(b))
532#endif
533
534
535/*
536@@ lua_number2int is a macro to convert lua_Number to int.
537@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
538** CHANGE them if you know a faster way to convert a lua_Number to
539** int (with any rounding method and without throwing errors) in your
540** system. In Pentium machines, a naive typecast from double to int
541** in C is extremely slow, so any alternative is worth trying.
542*/
543
544/* On a Pentium, resort to a trick */
545#if !defined(LUA_ANSI) && !defined(__SSE2__) && \
546 (defined(__i386) || defined (_M_IX86) || defined(__i386__))
547union luai_Cast { double l_d; long l_l; };
548#define lua_number2int(i,d) \
549 { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
550#define lua_number2integer(i,n) lua_number2int(i, n)
551
552/* this option always works, but may be slow */
553#else
554#define lua_number2int(i,d) ((i)=(int)(d))
555#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
556
557#endif
538 558
539/* }================================================================== */559/* }================================================================== */
540 560
@@ -597,7 +617,7 @@ union luai_Cast { double l_d; long l_l; }; · 56 unmodified lines
597*/617*/
598#if defined(loslib_c) || defined(luaall_c)618#if defined(loslib_c) || defined(luaall_c)
599 619
600#if !defined(LUA_ANSI) && defined(_POSIX_C_SOURCE)620#if defined(LUA_USE_MKSTEMP)
601#include <unistd.h>621#include <unistd.h>
602#define LUA_TMPNAMBUFSIZE 32622#define LUA_TMPNAMBUFSIZE 32
603#define lua_tmpnam(b,e) { \623#define lua_tmpnam(b,e) { \
@@ -605,6 +625,7 @@ union luai_Cast { double l_d; long l_l; }; · 1 unmodified line
605 e = mkstemp(b); \625 e = mkstemp(b); \
606 if (e != -1) close(e); \626 if (e != -1) close(e); \
607 e = (e == -1); }627 e = (e == -1); }
628
608#else629#else
609#define LUA_TMPNAMBUFSIZE L_tmpnam630#define LUA_TMPNAMBUFSIZE L_tmpnam
610#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }631#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
@@ -618,21 +639,21 @@ union luai_Cast { double l_d; long l_l; }; · 7 unmodified lines
618@* the file streams.639@* the file streams.
619** CHANGE it if you have a way to implement it in your system.640** CHANGE it if you have a way to implement it in your system.
620*/641*/
621#if !defined(LUA_ANSI) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 2642#if defined(LUA_USE_POPEN)
622 643
623#define lua_popen(L,c,m) popen(c,m)644#define lua_popen(L,c,m) ((void)L, popen(c,m))
624#define lua_pclose(L,file) (pclose(file) != -1)645#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
625 646
626#elif !defined(LUA_ANSI) && defined(_WIN32)647#elif !defined(LUA_ANSI) && defined(_WIN32)
627 648
628#define lua_popen(L,c,m) _popen(c,m)649#define lua_popen(L,c,m) ((void)L, _popen(c,m))
629#define lua_pclose(L,file) (_pclose(file) != -1)650#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
630 651
631#else652#else
632 653
633#define lua_popen(L,c,m) \654#define lua_popen(L,c,m) \
634 ((void)c, (void)m, luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)655 ((void)c, (void)m, luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
635#define lua_pclose(L,file) ((void)file, 0)656#define lua_pclose(L,file) ((void)L, (void)file, 0)
636 657
637#endif658#endif
638 659
@@ -647,16 +668,15 @@ union luai_Cast { double l_d; long l_l; }; · 8 unmodified lines
647** automatically. (When you change the makefile to add -ldl, you must668** automatically. (When you change the makefile to add -ldl, you must
648** also add -DLUA_USE_DLOPEN.)669** also add -DLUA_USE_DLOPEN.)
649** If you do not want any kind of dynamic library, undefine all these670** If you do not want any kind of dynamic library, undefine all these
650** options (or just remove these definitions).671** options.
672** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
651*/673*/
652#if !defined(LUA_ANSI) 674#if defined(LUA_USE_DLOPEN)
653#if defined(_WIN32)
654#define LUA_DL_DLL
655#elif defined(__APPLE__) && defined(__MACH__)
656#define LUA_DL_DYLD
657#elif defined(LUA_USE_DLOPEN)
658#define LUA_DL_DLOPEN675#define LUA_DL_DLOPEN
659#endif676#endif
677
678#if !defined(LUA_ANSI) && defined(_WIN32)
679#define LUA_DL_DLL
660#endif680#endif
661 681
662 682
@@ -674,10 +694,12 @@ union luai_Cast { double l_d; long l_l; }; · 11 unmodified lines
674** CHANGE them if you defined LUAI_EXTRASPACE and need to do something694** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
675** extra when a thread is created/deleted/resumed/yielded.695** extra when a thread is created/deleted/resumed/yielded.
676*/696*/
677#define luai_userstateopen(L) ((void)0)697#define luai_userstateopen(L) ((void)L)
678#define luai_userstatefree(L) ((void)0)698#define luai_userstateclose(L) ((void)L)
679#define luai_userstateresume(L,n) ((void)0)699#define luai_userstatethread(L,L1) ((void)L)
680#define luai_userstateyield(L,n) ((void)0)700#define luai_userstatefree(L) ((void)L)
701#define luai_userstateresume(L,n) ((void)L)
702#define luai_userstateyield(L,n) ((void)L)
681 703
682 704
683 705
src/lundump.c+41−108
@@ -1,6 +1,6 @@
1/*1/*
2** $Id: lundump.c,v 1.58 2005/09/02 01:54:47 lhf Exp $2** $Id: lundump.c,v 1.59 2005/11/11 14:03:13 lhf Exp $
3** load pre-compiled Lua chunks3** load precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
@@ -15,42 +15,34 @@ · 8 unmodified lines
15#include "ldo.h"15#include "ldo.h"
16#include "lfunc.h"16#include "lfunc.h"
17#include "lmem.h"17#include "lmem.h"
18#include "lopcodes.h"18#include "lobject.h"
19#include "lstring.h"19#include "lstring.h"
20#include "lundump.h"20#include "lundump.h"
21#include "lzio.h"21#include "lzio.h"
22 22
23#ifdef LUAC_TRUST_BINARIES
24#define IF(c,s)
25#else
26#define IF(c,s) if (c) error(S,s)
27#endif
28
29typedef struct {23typedef struct {
30 lua_State* L;24 lua_State* L;
31 ZIO* Z;25 ZIO* Z;
32 Mbuffer* b;26 Mbuffer* b;
33 const char* name;27 const char* name;
34#ifdef LUAC_SWAP_ON_LOAD
35 int swap;
36#endif
37} LoadState;28} LoadState;
38 29
39#ifdef LUAC_SWAP_ON_LOAD30#ifdef LUAC_TRUST_BINARIES
40static void LoadMem (LoadState* S, void* b, int n, size_t size);31#define IF(c,s)
41#else32#else
42#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))33#define IF(c,s) if (c) error(S,s)
43#endif
44
45#define LoadByte(S) (lu_byte)LoadChar(S)
46#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
47#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
48 34
49static void error(LoadState* S, const char* why)35static void error(LoadState* S, const char* why)
50{36{
51 luaO_pushfstring(S->L,"%s: %s",S->name,why);37 luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
52 luaD_throw(S->L,LUA_ERRSYNTAX);38 luaD_throw(S->L,LUA_ERRSYNTAX);
53}39}
40#endif
41
42#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
43#define LoadByte(S) (lu_byte)LoadChar(S)
44#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
45#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
54 46
55static void LoadBlock(LoadState* S, void* b, size_t size)47static void LoadBlock(LoadState* S, void* b, size_t size)
56{48{
@@ -102,39 +94,6 @@ static void LoadCode(LoadState* S, Proto* f) · 45 unmodified lines
102 LoadVector(S,f->code,n,sizeof(Instruction));94 LoadVector(S,f->code,n,sizeof(Instruction));
103}95}
104 96
105static void LoadLocals(LoadState* S, Proto* f)
106{
107 int i,n;
108 n=LoadInt(S);
109 f->locvars=luaM_newvector(S->L,n,LocVar);
110 f->sizelocvars=n;
111 for (i=0; i<n; i++) f->locvars[i].varname=NULL;
112 for (i=0; i<n; i++)
113 {
114 f->locvars[i].varname=LoadString(S);
115 f->locvars[i].startpc=LoadInt(S);
116 f->locvars[i].endpc=LoadInt(S);
117 }
118}
119
120static void LoadLines(LoadState* S, Proto* f)
121{
122 int n=LoadInt(S);
123 f->lineinfo=luaM_newvector(S->L,n,int);
124 f->sizelineinfo=n;
125 LoadVector(S,f->lineinfo,n,sizeof(int));
126}
127
128static void LoadUpvalues(LoadState* S, Proto* f)
129{
130 int i,n;
131 n=LoadInt(S);
132 f->upvalues=luaM_newvector(S->L,n,TString*);
133 f->sizeupvalues=n;
134 for (i=0; i<n; i++) f->upvalues[i]=NULL;
135 for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
136}
137
138static Proto* LoadFunction(LoadState* S, TString* p);97static Proto* LoadFunction(LoadState* S, TString* p);
139 98
140static void LoadConstants(LoadState* S, Proto* f)99static void LoadConstants(LoadState* S, Proto* f)
@@ -174,6 +133,30 @@ static void LoadConstants(LoadState* S, Proto* f) · 33 unmodified lines
174 for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);133 for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
175}134}
176 135
136static void LoadDebug(LoadState* S, Proto* f)
137{
138 int i,n;
139 n=LoadInt(S);
140 f->lineinfo=luaM_newvector(S->L,n,int);
141 f->sizelineinfo=n;
142 LoadVector(S,f->lineinfo,n,sizeof(int));
143 n=LoadInt(S);
144 f->locvars=luaM_newvector(S->L,n,LocVar);
145 f->sizelocvars=n;
146 for (i=0; i<n; i++) f->locvars[i].varname=NULL;
147 for (i=0; i<n; i++)
148 {
149 f->locvars[i].varname=LoadString(S);
150 f->locvars[i].startpc=LoadInt(S);
151 f->locvars[i].endpc=LoadInt(S);
152 }
153 n=LoadInt(S);
154 f->upvalues=luaM_newvector(S->L,n,TString*);
155 f->sizeupvalues=n;
156 for (i=0; i<n; i++) f->upvalues[i]=NULL;
157 for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
158}
159
177static Proto* LoadFunction(LoadState* S, TString* p)160static Proto* LoadFunction(LoadState* S, TString* p)
178{161{
179 Proto* f=luaF_newproto(S->L);162 Proto* f=luaF_newproto(S->L);
@@ -185,11 +168,9 @@ static Proto* LoadFunction(LoadState* S, TString* p) · 5 unmodified lines
185 f->numparams=LoadByte(S);168 f->numparams=LoadByte(S);
186 f->is_vararg=LoadByte(S);169 f->is_vararg=LoadByte(S);
187 f->maxstacksize=LoadByte(S);170 f->maxstacksize=LoadByte(S);
188 LoadLines(S,f);
189 LoadLocals(S,f);
190 LoadUpvalues(S,f);
191 LoadConstants(S,f);
192 LoadCode(S,f);171 LoadCode(S,f);
172 LoadConstants(S,f);
173 LoadDebug(S,f);
193 IF (!luaG_checkcode(f), "bad code");174 IF (!luaG_checkcode(f), "bad code");
194 S->L->top--;175 S->L->top--;
195 return f;176 return f;
@@ -201,9 +182,6 @@ static void LoadHeader(LoadState* S) · 5 unmodified lines
201 char s[LUAC_HEADERSIZE];182 char s[LUAC_HEADERSIZE];
202 luaU_header(h);183 luaU_header(h);
203 LoadBlock(S,s,LUAC_HEADERSIZE);184 LoadBlock(S,s,LUAC_HEADERSIZE);
204#ifdef LUAC_SWAP_ON_LOAD
205 S->swap=(s[6]!=h[6]); s[6]=h[6];
206#endif
207 IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");185 IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
208}186}
209 187
@@ -236,55 +214,10 @@ void luaU_header (char* h) · 26 unmodified lines
236 h+=sizeof(LUA_SIGNATURE)-1;214 h+=sizeof(LUA_SIGNATURE)-1;
237 *h++=(char)LUAC_VERSION;215 *h++=(char)LUAC_VERSION;
238 *h++=(char)LUAC_FORMAT;216 *h++=(char)LUAC_FORMAT;
239 *h++=(char)*(char*)&x;217 *h++=(char)*(char*)&x; /* endianness */
240 *h++=(char)sizeof(int);218 *h++=(char)sizeof(int);
241 *h++=(char)sizeof(size_t);219 *h++=(char)sizeof(size_t);
242 *h++=(char)sizeof(Instruction);220 *h++=(char)sizeof(Instruction);
243 *h++=(char)sizeof(lua_Number);221 *h++=(char)sizeof(lua_Number);
244 *h++=(char)(((lua_Number)0.5)==0);222 *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
245}
246
247#ifdef LUAC_SWAP_ON_LOAD
248static void LoadMem (LoadState* S, void* b, int n, size_t size)
249{
250 LoadBlock(S,b,n*size);
251 if (S->swap)
252 {
253 char* p=(char*) b;
254 char c;
255 switch (size)
256 {
257 case 1:
258 break;
259 case 2:
260 while (n--)
261 {
262 c=p[0]; p[0]=p[1]; p[1]=c;
263 p+=2;
264 }
265 break;
266 case 4:
267 while (n--)
268 {
269 c=p[0]; p[0]=p[3]; p[3]=c;
270 c=p[1]; p[1]=p[2]; p[2]=c;
271 p+=4;
272 }
273 break;
274 case 8:
275 while (n--)
276 {
277 c=p[0]; p[0]=p[7]; p[7]=c;
278 c=p[1]; p[1]=p[6]; p[6]=c;
279 c=p[2]; p[2]=p[5]; p[5]=c;
280 c=p[3]; p[3]=p[4]; p[4]=c;
281 p+=8;
282 }
283 break;
284 default:
285 IF(1, "bad size");
286 break;
287 }
288 }
289}223}
290#endif
src/lundump.h+4−30
@@ -1,6 +1,6 @@
1/*1/*
2** $Id: lundump.h,v 1.38 2005/09/02 01:54:47 lhf Exp $2** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $
3** load pre-compiled Lua chunks3** load precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
@@ -10,12 +10,6 @@ · 3 unmodified lines
10#include "lobject.h"10#include "lobject.h"
11#include "lzio.h"11#include "lzio.h"
12 12
13/* make it work with Lua 5.0 */
14#ifndef LUA_VERSION_NUM
15#define LUAI_FUNC
16#define lua_Writer lua_Chunkwriter
17#endif
18
19/* load one chunk; from lundump.c */13/* load one chunk; from lundump.c */
20LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);14LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
21 15
@@ -25,8 +19,10 @@ LUAI_FUNC void luaU_header (char* h); · 3 unmodified lines
25/* dump one chunk; from ldump.c */19/* dump one chunk; from ldump.c */
26LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);20LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
27 21
22#ifdef luac_c
28/* print one chunk; from print.c */23/* print one chunk; from print.c */
29LUAI_FUNC void luaU_print (const Proto* f, int full);24LUAI_FUNC void luaU_print (const Proto* f, int full);
25#endif
30 26
31/* for header of binary files -- this is Lua 5.1 */27/* for header of binary files -- this is Lua 5.1 */
32#define LUAC_VERSION 0x5128#define LUAC_VERSION 0x51
@@ -37,26 +33,4 @@ LUAI_FUNC void luaU_print (const Proto* f, int full); · 4 unmodified lines
37/* size of header of binary files */33/* size of header of binary files */
38#define LUAC_HEADERSIZE 1234#define LUAC_HEADERSIZE 12
39 35
40/* make it work with Lua 5.0 */
41#ifndef LUA_VERSION_NUM
42#define LUA_SIGNATURE "\033Lua"
43#define TValue TObject
44#define rawtsvalue tsvalue
45#define linedefined lineDefined
46#define lastlinedefined lineDefined
47#define setptvalue2s(L,t,f)
48#undef setsvalue2n
49#define setsvalue2n(L,x,y) setsvalue(x,y)
50#define LUA_QL(x) "'" x "'"
51#define LUA_QS LUA_QL("%s")
52#undef LUAC_VERSION
53#define LUAC_VERSION 0x50
54#ifdef lapi_c
55#define luaU_dump(L,f,w,d) (luaU_dump)(L,f,w,d,0)
56#endif
57#ifdef ldo_c
58#define luaU_undump(L,z,b) (luaU_undump)(L,z,b,z->name)
59#endif
60#endif
61
62#endif36#endif
src/lvm.c+43−75
@@ -1,11 +1,10 @@
1/*1/*
2** $Id: lvm.c,v 2.55 2005/09/09 18:23:35 roberto Exp $2** $Id: lvm.c,v 2.59 2005/11/01 16:08:45 roberto Exp $
3** Lua virtual machine3** Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
6 6
7 7
8#include <math.h>
9#include <stdio.h>8#include <stdio.h>
10#include <stdlib.h>9#include <stdlib.h>
11#include <string.h>10#include <string.h>
@@ -66,7 +65,6 @@ static void traceexec (lua_State *L, const Instruction *pc) { · 54 unmodified lines
66 if (L->hookcount == 0) {65 if (L->hookcount == 0) {
67 resethookcount(L);66 resethookcount(L);
68 luaD_callhook(L, LUA_HOOKCOUNT, -1);67 luaD_callhook(L, LUA_HOOKCOUNT, -1);
69 return;
70 }68 }
71 }69 }
72 if (mask & LUA_MASKLINE) {70 if (mask & LUA_MASKLINE) {
@@ -226,7 +224,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 153 unmodified lines
226 if (ttype(l) != ttype(r))224 if (ttype(l) != ttype(r))
227 return luaG_ordererror(L, l, r);225 return luaG_ordererror(L, l, r);
228 else if (ttisnumber(l))226 else if (ttisnumber(l))
229 return luai_numlt(L, nvalue(l), nvalue(r));227 return luai_numlt(nvalue(l), nvalue(r));
230 else if (ttisstring(l))228 else if (ttisstring(l))
231 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;229 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
232 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)230 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
@@ -240,7 +238,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { · 7 unmodified lines
240 if (ttype(l) != ttype(r))238 if (ttype(l) != ttype(r))
241 return luaG_ordererror(L, l, r);239 return luaG_ordererror(L, l, r);
242 else if (ttisnumber(l))240 else if (ttisnumber(l))
243 return luai_numle(L, nvalue(l), nvalue(r));241 return luai_numle(nvalue(l), nvalue(r));
244 else if (ttisstring(l))242 else if (ttisstring(l))
245 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;243 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
246 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */244 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
@@ -256,7 +254,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { · 9 unmodified lines
256 lua_assert(ttype(t1) == ttype(t2));254 lua_assert(ttype(t1) == ttype(t2));
257 switch (ttype(t1)) {255 switch (ttype(t1)) {
258 case LUA_TNIL: return 1;256 case LUA_TNIL: return 1;
259 case LUA_TNUMBER: return luai_numeq(L, nvalue(t1), nvalue(t2));257 case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
260 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */258 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
261 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);259 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
262 case LUA_TUSERDATA: {260 case LUA_TUSERDATA: {
@@ -319,13 +317,13 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, · 56 unmodified lines
319 (c = luaV_tonumber(rc, &tempc)) != NULL) {317 (c = luaV_tonumber(rc, &tempc)) != NULL) {
320 lua_Number nb = nvalue(b), nc = nvalue(c);318 lua_Number nb = nvalue(b), nc = nvalue(c);
321 switch (op) {319 switch (op) {
322 case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break;320 case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
323 case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break;321 case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
324 case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break;322 case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
325 case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break;323 case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
326 case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break;324 case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
327 case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break;325 case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
328 case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break;326 case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
329 default: lua_assert(0); break;327 default: lua_assert(0); break;
330 }328 }
331 }329 }
@@ -358,6 +356,19 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, · 26 unmodified lines
358#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }356#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }
359 357
360 358
359#define arith_op(op,tm) { \
360 TValue *rb = RKB(i); \
361 TValue *rc = RKC(i); \
362 if (ttisnumber(rb) && ttisnumber(rc)) { \
363 lua_Number nb = nvalue(rb), nc = nvalue(rc); \
364 setnvalue(ra, op(nb, nc)); \
365 } \
366 else \
367 Protect(Arith(L, ra, rb, rc, tm)); \
368 }
369
370
371
361void luaV_execute (lua_State *L, int nexeccalls) {372void luaV_execute (lua_State *L, int nexeccalls) {
362 LClosure *cl;373 LClosure *cl;
363 StkId base;374 StkId base;
@@ -455,76 +466,34 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 91 unmodified lines
455 continue;466 continue;
456 }467 }
457 case OP_ADD: {468 case OP_ADD: {
458 TValue *rb = RKB(i);469 arith_op(luai_numadd, TM_ADD);
459 TValue *rc = RKC(i);
460 if (ttisnumber(rb) && ttisnumber(rc)) {
461 lua_Number nb = nvalue(rb), nc = nvalue(rc);
462 setnvalue(ra, luai_numadd(L, nb, nc));
463 }
464 else
465 Protect(Arith(L, ra, rb, rc, TM_ADD));
466 continue;470 continue;
467 }471 }
468 case OP_SUB: {472 case OP_SUB: {
469 TValue *rb = RKB(i);473 arith_op(luai_numsub, TM_SUB);
470 TValue *rc = RKC(i);
471 if (ttisnumber(rb) && ttisnumber(rc)) {
472 lua_Number nb = nvalue(rb), nc = nvalue(rc);
473 setnvalue(ra, luai_numsub(L, nb, nc));
474 }
475 else
476 Protect(Arith(L, ra, rb, rc, TM_SUB));
477 continue;474 continue;
478 }475 }
479 case OP_MUL: {476 case OP_MUL: {
480 TValue *rb = RKB(i);477 arith_op(luai_nummul, TM_MUL);
481 TValue *rc = RKC(i);
482 if (ttisnumber(rb) && ttisnumber(rc)) {
483 lua_Number nb = nvalue(rb), nc = nvalue(rc);
484 setnvalue(ra, luai_nummul(L, nb, nc));
485 }
486 else
487 Protect(Arith(L, ra, rb, rc, TM_MUL));
488 continue;478 continue;
489 }479 }
490 case OP_DIV: {480 case OP_DIV: {
491 TValue *rb = RKB(i);481 arith_op(luai_numdiv, TM_DIV);
492 TValue *rc = RKC(i);
493 if (ttisnumber(rb) && ttisnumber(rc)) {
494 lua_Number nb = nvalue(rb), nc = nvalue(rc);
495 setnvalue(ra, luai_numdiv(L, nb, nc));
496 }
497 else
498 Protect(Arith(L, ra, rb, rc, TM_DIV));
499 continue;482 continue;
500 }483 }
501 case OP_MOD: {484 case OP_MOD: {
502 TValue *rb = RKB(i);485 arith_op(luai_nummod, TM_MOD);
503 TValue *rc = RKC(i);
504 if (ttisnumber(rb) && ttisnumber(rc)) {
505 lua_Number nb = nvalue(rb), nc = nvalue(rc);
506 setnvalue(ra, luai_nummod(L, nb, nc));
507 }
508 else
509 Protect(Arith(L, ra, rb, rc, TM_MOD));
510 continue;486 continue;
511 }487 }
512 case OP_POW: {488 case OP_POW: {
513 TValue *rb = RKB(i);489 arith_op(luai_numpow, TM_POW);
514 TValue *rc = RKC(i);
515 if (ttisnumber(rb) && ttisnumber(rc)) {
516 lua_Number nb = nvalue(rb), nc = nvalue(rc);
517 setnvalue(ra, luai_numpow(L, nb, nc));
518 }
519 else
520 Protect(Arith(L, ra, rb, rc, TM_POW));
521 continue;490 continue;
522 }491 }
523 case OP_UNM: {492 case OP_UNM: {
524 TValue *rb = RB(i);493 TValue *rb = RB(i);
525 if (ttisnumber(rb)) {494 if (ttisnumber(rb)) {
526 lua_Number nb = nvalue(rb);495 lua_Number nb = nvalue(rb);
527 setnvalue(ra, luai_numunm(L, nb));496 setnvalue(ra, luai_numunm(nb));
528 }497 }
529 else {498 else {
530 Protect(Arith(L, ra, rb, rb, TM_UNM));499 Protect(Arith(L, ra, rb, rb, TM_UNM));
@@ -594,18 +563,18 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 63 unmodified lines
594 continue;563 continue;
595 }564 }
596 case OP_TEST: {565 case OP_TEST: {
597 if (l_isfalse(ra) == GETARG_C(i)) pc++;566 if (l_isfalse(ra) != GETARG_C(i))
598 else567 dojump(L, pc, GETARG_sBx(*pc));
599 dojump(L, pc, GETARG_sBx(*pc) + 1);568 pc++;
600 continue;569 continue;
601 }570 }
602 case OP_TESTSET: {571 case OP_TESTSET: {
603 TValue *rb = RB(i);572 TValue *rb = RB(i);
604 if (l_isfalse(rb) == GETARG_C(i)) pc++;573 if (l_isfalse(rb) != GETARG_C(i)) {
605 else {
606 setobjs2s(L, ra, rb);574 setobjs2s(L, ra, rb);
607 dojump(L, pc, GETARG_sBx(*pc) + 1);575 dojump(L, pc, GETARG_sBx(*pc));
608 }576 }
577 pc++;
609 continue;578 continue;
610 }579 }
611 case OP_CALL: {580 case OP_CALL: {
@@ -678,9 +647,9 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 66 unmodified lines
678 }647 }
679 case OP_FORLOOP: {648 case OP_FORLOOP: {
680 lua_Number step = nvalue(ra+2);649 lua_Number step = nvalue(ra+2);
681 lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */650 lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
682 lua_Number limit = nvalue(ra+1);651 lua_Number limit = nvalue(ra+1);
683 if (step > 0 ? luai_numle(L, idx, limit) : luai_numle(L, limit, idx)) {652 if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) {
684 dojump(L, pc, GETARG_sBx(i)); /* jump back */653 dojump(L, pc, GETARG_sBx(i)); /* jump back */
685 setnvalue(ra, idx); /* update internal index... */654 setnvalue(ra, idx); /* update internal index... */
686 setnvalue(ra+3, idx); /* ...and external index */655 setnvalue(ra+3, idx); /* ...and external index */
@@ -698,7 +667,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 11 unmodified lines
698 luaG_runerror(L, LUA_QL("for") " limit must be a number");667 luaG_runerror(L, LUA_QL("for") " limit must be a number");
699 else if (!tonumber(pstep, ra+2))668 else if (!tonumber(pstep, ra+2))
700 luaG_runerror(L, LUA_QL("for") " step must be a number");669 luaG_runerror(L, LUA_QL("for") " step must be a number");
701 setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));670 setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
702 dojump(L, pc, GETARG_sBx(i));671 dojump(L, pc, GETARG_sBx(i));
703 continue;672 continue;
704 }673 }
@@ -711,12 +680,11 @@ void luaV_execute (lua_State *L, int nexeccalls) { · 6 unmodified lines
711 Protect(luaD_call(L, cb, GETARG_C(i)));680 Protect(luaD_call(L, cb, GETARG_C(i)));
712 L->top = L->ci->top;681 L->top = L->ci->top;
713 cb = RA(i) + 3; /* previous call may change the stack */682 cb = RA(i) + 3; /* previous call may change the stack */
714 if (ttisnil(cb)) /* break loop? */683 if (!ttisnil(cb)) { /* continue loop? */
715 pc++; /* skip jump (break loop) */
716 else {
717 setobjs2s(L, cb-1, cb); /* save control variable */684 setobjs2s(L, cb-1, cb); /* save control variable */
718 dojump(L, pc, GETARG_sBx(*pc) + 1); /* jump back */685 dojump(L, pc, GETARG_sBx(*pc)); /* jump back */
719 }686 }
687 pc++;
720 continue;688 continue;
721 }689 }
722 case OP_SETLIST: {690 case OP_SETLIST: {
src/print.c+6−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: print.c,v 1.52 2005/06/08 14:40:44 lhf Exp $2** $Id: print.c,v 1.53 2005/11/11 14:03:13 lhf Exp $
3** print bytecodes3** print bytecodes
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -7,6 +7,7 @@ · 1 unmodified line
7#include <ctype.h>7#include <ctype.h>
8#include <stdio.h>8#include <stdio.h>
9 9
10#define luac_c
10#define LUA_CORE11#define LUA_CORE
11 12
12#include "ldebug.h"13#include "ldebug.h"
@@ -14,6 +15,8 @@ · 1 unmodified line
14#include "lopcodes.h"15#include "lopcodes.h"
15#include "lundump.h"16#include "lundump.h"
16 17
18#define PrintFunction luaU_print
19
17#define Sizeof(x) ((int)sizeof(x))20#define Sizeof(x) ((int)sizeof(x))
18#define VOID(p) ((const void*)(p))21#define VOID(p) ((const void*)(p))
19 22
@@ -203,7 +206,7 @@ static void PrintUpvalues(const Proto* f) · 183 unmodified lines
203 }206 }
204}207}
205 208
206void luaU_print(const Proto* f, int full)209void PrintFunction(const Proto* f, int full)
207{210{
208 int i,n=f->sizep;211 int i,n=f->sizep;
209 PrintHeader(f);212 PrintHeader(f);
@@ -214,5 +217,5 @@ void luaU_print(const Proto* f, int full) · 4 unmodified lines
214 PrintLocals(f);217 PrintLocals(f);
215 PrintUpvalues(f);218 PrintUpvalues(f);
216 }219 }
217 for (i=0; i<n; i++) luaU_print(f->p[i],full);220 for (i=0; i<n; i++) PrintFunction(f->p[i],full);
218}221}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

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

Repository code

Go to file
t