History

Lua 5.2.0-rc1

Lua Team committed 14 years ago

Commit d74d0e51 parent 8203bab51 files · +1861 −1136Browse files

Unified · Split

51 files
  1. Makefile +2 −2
  2. README +1 −1
  3. doc/alert.png +0 −0
  4. doc/contents.html +9 −11
  5. doc/lua.1 +116 −0
  6. doc/lua.css +2 −3
  7. doc/luac.1 +118 −0
  8. doc/manual.css +5 −2
  9. doc/manual.html +588 −438
  10. doc/readme.html +61 −49
  11. src/Makefile +1 −0
  12. src/lapi.c +88 −37
  13. src/lauxlib.c +31 −10
  14. src/lauxlib.h +31 −2
  15. src/lbaselib.c +45 −35
  16. src/lcode.c +12 −10
  17. src/lcode.h +2 −1
  18. src/lcorolib.c +2 −2
  19. src/lctype.c +4 −1
  20. src/lctype.h +2 −2
  21. src/ldblib.c +4 −7
  22. src/ldebug.c +104 −96
  23. src/ldebug.h +10 −10
  24. src/ldo.c +17 −17
  25. src/ldo.h +2 −2
  26. src/ldump.c +3 −3
  27. src/lgc.c +96 −46
  28. src/lgc.h +1 −5
  29. src/liolib.c +74 −30
  30. src/llex.c +40 −47
  31. src/llimits.h +16 −4
  32. src/lmem.c +2 −2
  33. src/loadlib.c +71 −33
  34. src/lobject.c +6 −4
  35. src/lobject.h +46 −22
  36. src/lopcodes.h +2 −2
  37. src/lparser.c +90 −70
  38. src/lparser.h +6 −7
  39. src/lstate.c +5 −8
  40. src/lstate.h +2 −4
  41. src/lstrlib.c +15 −6
  42. src/ltable.c +25 −36
  43. src/ltable.h +5 −3
  44. src/ltablib.c +2 −2
  45. src/lua.c +39 −12
  46. src/lua.h +7 −10
  47. src/luac.c +3 −4
  48. src/luaconf.h +16 −11
  49. src/lvm.c +29 −20
  50. src/lzio.c +2 −2
  51. src/lzio.h +2 −6
Makefile+2−2
@@ -62,13 +62,13 @@ install: dummy · 61 unmodified lines
6262 cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
6363 cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
6464 cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
65− #cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
65+ cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
6666
6767 uninstall:
6868 cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)
6969 cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)
7070 cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)
71− #cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)
71+ cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)
7272
7373 local:
7474 $(MAKE) install INSTALL_TOP=../install
README+1−1
@@ -1,5 +1,5 @@
11
2−This is Lua 5.2 (beta), released on 05 Jul 2011.
2+This is Lua 5.2, released on 24 Nov 2011.
33
44 For installation instructions, license details, and
55 further information about Lua, see doc/readme.html.
doc/alert.png+0−0

Binary file not shown.

doc/contents.html+9−11
@@ -20,11 +20,6 @@ ul { · 19 unmodified lines
2020 Lua 5.2 Reference Manual
2121 </H1>
2222
23−<P>
24−<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
25−<EM>This is a beta version of Lua 5.2.
26−Some details may change in the final version.</EM>
27−
2823 <P>
2924 The reference manual is the official definition of the Lua language.
3025 For a complete introduction to Lua programming, see the book
@@ -95,7 +90,7 @@ Freely available under the terms of the · 64 unmodified lines
9590 <UL>
9691 <LI><A HREF="manual.html#4.1">4.1 &ndash; The Stack</A>
9792 <LI><A HREF="manual.html#4.2">4.2 &ndash; Stack Size</A>
98−<LI><A HREF="manual.html#4.3">4.3 &ndash; Pseudo-Indices</A>
93+<LI><A HREF="manual.html#4.3">4.3 &ndash; Valid and Acceptable Indices</A>
9994 <LI><A HREF="manual.html#4.4">4.4 &ndash; C Closures</A>
10095 <LI><A HREF="manual.html#4.5">4.5 &ndash; Registry</A>
10196 <LI><A HREF="manual.html#4.6">4.6 &ndash; Error Handling in C</A>
@@ -154,8 +149,8 @@ Freely available under the terms of the · 52 unmodified lines
154149 <A HREF="manual.html#pdf-error">error</A><BR>
155150 <A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
156151 <A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
157−<A HREF="manual.html#pdf-load">load</A><BR>
158152 <A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
153+<A HREF="manual.html#pdf-load">load</A><BR>
159154 <A HREF="manual.html#pdf-next">next</A><BR>
160155 <A HREF="manual.html#pdf-pairs">pairs</A><BR>
161156 <A HREF="manual.html#pdf-pcall">pcall</A><BR>
@@ -406,6 +401,8 @@ Freely available under the terms of the · 244 unmodified lines
406401 <A HREF="manual.html#lua_rawlen">lua_rawlen</A><BR>
407402 <A HREF="manual.html#lua_rawset">lua_rawset</A><BR>
408403 <A HREF="manual.html#lua_rawseti">lua_rawseti</A><BR>
404+<A HREF="manual.html#lua_rawgetp">lua_rawgetp</A><BR>
405+<A HREF="manual.html#lua_rawsetp">lua_rawsetp</A><BR>
409406 <A HREF="manual.html#lua_register">lua_register</A><BR>
410407 <A HREF="manual.html#lua_remove">lua_remove</A><BR>
411408 <A HREF="manual.html#lua_replace">lua_replace</A><BR>
@@ -463,8 +460,8 @@ Freely available under the terms of the · 51 unmodified lines
463460 <A HREF="manual.html#luaL_buffinitsize">luaL_buffinitsize</A><BR>
464461 <A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>
465462 <A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>
466−<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
467463 <A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>
464+<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
468465 <A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>
469466 <A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>
470467 <A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>
@@ -487,14 +484,15 @@ Freely available under the terms of the · 16 unmodified lines
487484 <A HREF="manual.html#luaL_len">luaL_len</A><BR>
488485 <A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
489486 <A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
487+<A HREF="manual.html#luaL_loadfilex">luaL_loadfilex</A><BR>
490488 <A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
491489 <A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR>
492490 <A HREF="manual.html#luaL_newlibtable">luaL_newlibtable</A><BR>
493491 <A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
494492 <A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
495493 <A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR>
496−<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
497494 <A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
495+<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
498496 <A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>
499497 <A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
500498 <A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
@@ -522,10 +520,10 @@ Freely available under the terms of the · 21 unmodified lines
522520 <HR>
523521 <SMALL CLASS="footer">
524522 Last update:
525−Tue Jun 28 14:53:13 BRT 2011
523+Wed Nov 23 16:14:28 BRST 2011
526524 </SMALL>
527525 <!--
528−Last change: revised for Lua 5.2.0 (beta)
526+Last change: revised for Lua 5.2.0
529527 -->
530528
531529 </BODY>
doc/lua.1+116−0
@@ -0,0 +1,116 @@
1+.\" $Id: lua.man,v 1.13 2011/11/16 17:16:53 lhf Exp $
2+.TH LUA 1 "$Date: 2011/11/16 17:16:53 $"
3+.SH NAME
4+lua \- Lua interpreter
5+.SH SYNOPSIS
6+.B lua
7+[
8+.I options
9+]
10+[
11+.I script
12+[
13+.I args
14+]
15+]
16+.SH DESCRIPTION
17+.B lua
18+is the standalone Lua interpreter.
19+It loads and executes Lua programs,
20+either in textual source form or
21+in precompiled binary form.
22+(Precompiled binaries are output by
23+.BR luac ,
24+the Lua compiler.)
25+.B lua
26+can be used as a batch interpreter and also interactively.
27+.LP
28+The given
29+.I options
30+are handled in order and then
31+the Lua program in file
32+.I script
33+is loaded and executed.
34+The given
35+.I args
36+are available to
37+.I script
38+as strings in a global table named
39+.BR arg .
40+If no options or arguments are given,
41+then
42+.B "\-v \-i"
43+is assumed when the standard input is a terminal;
44+otherwise,
45+.B "\-"
46+is assumed.
47+.LP
48+In interactive mode,
49+.B lua
50+prompts the user,
51+reads lines from the standard input,
52+and executes them as they are read.
53+If a line does not contain a complete statement,
54+then a secondary prompt is displayed and
55+lines are read until a complete statement is formed or
56+a syntax error is found.
57+If a line starts with
58+.BR '=' ,
59+then
60+.B lua
61+evaluates and displays
62+the values of the expressions in the remainder of the line.
63+.LP
64+At the very start,
65+before even handling the command line,
66+.B lua
67+checks the contents of the environment variables
68+.B LUA_INIT_5_2
69+or
70+.BR LUA_INIT ,
71+in that order.
72+If the contents is of the form
73+.RI '@ filename ',
74+then
75+.I filename
76+is executed.
77+Otherwise, the string is assumed to be a Lua statement and is executed.
78+.SH OPTIONS
79+.TP
80+.BI \-e " stat"
81+execute statement
82+.IR stat .
83+.TP
84+.B \-i
85+enter interactive mode after executing
86+.IR script .
87+.TP
88+.BI \-l " name"
89+execute the equivalent of
90+.IB name =require(' name ')
91+before executing
92+.IR script .
93+.TP
94+.B \-v
95+show version information.
96+.TP
97+.B \-E
98+ignore environment variables.
99+.TP
100+.B \-\-
101+stop handling options.
102+.TP
103+.B \-
104+stop handling options and execute the standard input as a file.
105+.SH "SEE ALSO"
106+.BR luac (1)
107+.br
108+The documentation at lua.org,
109+especially section 7 of the reference manual.
110+.SH DIAGNOSTICS
111+Error messages should be self explanatory.
112+.SH AUTHORS
113+R. Ierusalimschy,
114+L. H. de Figueiredo,
115+W. Celes
116+.\" EOF
doc/lua.css+2−3
@@ -1,7 +1,6 @@
11 body {
22 color: #000000 ;
33 background-color: #FFFFFF ;
4− font-family: sans-serif ;
54 font-family: Helvetica, Arial, sans-serif ;
65 text-align: justify ;
76 margin-right: 20px ;
@@ -18,12 +17,13 @@ h2 { · 10 unmodified lines
1817 padding-top: 0.4em ;
1918 padding-bottom: 0.4em ;
2019 padding-left: 20px ;
20+ padding-right: 20px ;
2121 margin-left: -20px ;
2222 background-color: #E0E0FF ;
2323 }
2424
2525 h3 {
26− padding-left: 8px ;
26+ padding-left: 0.5em ;
2727 border-left: solid #E0E0FF 1em ;
2828 }
2929
@@ -76,7 +76,6 @@ input[type=text] { · 46 unmodified lines
7676 -moz-border-radius: 2em ;
7777 background-image: url('images/search.png') ;
7878 background-repeat: no-repeat;
79− background-position: left center ;
8079 background-position: 4px center ;
8180 padding-left: 20px ;
8281 height: 2em ;
doc/luac.1+118−0
@@ -0,0 +1,118 @@
1+.\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $
2+.TH LUAC 1 "$Date: 2011/11/16 13:53:40 $"
3+.SH NAME
4+luac \- Lua compiler
5+.SH SYNOPSIS
6+.B luac
7+[
8+.I options
9+] [
10+.I filenames
11+]
12+.SH DESCRIPTION
13+.B luac
14+is the Lua compiler.
15+It translates programs written in the Lua programming language
16+into binary files containing precompiled chunks
17+that can be later loaded and executed.
18+.LP
19+The main advantages of precompiling chunks are:
20+faster loading,
21+protecting source code from accidental user changes,
22+and
23+off-line syntax checking.
24+Precompiling does not imply faster execution
25+because in Lua chunks are always compiled into bytecodes before being executed.
26+.B luac
27+simply allows those bytecodes to be saved in a file for later execution.
28+Precompiled chunks are not necessarily smaller than the corresponding source.
29+The main goal in precompiling is faster loading.
30+.LP
31+In the command line,
32+you can mix
33+text files containing Lua source and
34+binary files containing precompiled chunks.
35+.B luac
36+produces a single output file containing the combined bytecodes
37+for all files given.
38+Executing the combined file is equivalent to executing the given files.
39+By default,
40+the output file is named
41+.BR luac.out ,
42+but you can change this with the
43+.B \-o
44+option.
45+.LP
46+Precompiled chunks are
47+.I not
48+portable across different architectures.
49+Moreover,
50+the internal format of precompiled chunks
51+is likely to change when a new version of Lua is released.
52+Make sure you save the source files of all Lua programs that you precompile.
53+.LP
54+.SH OPTIONS
55+.TP
56+.B \-l
57+produce a listing of the compiled bytecode for Lua's virtual machine.
58+Listing bytecodes is useful to learn about Lua's virtual machine.
59+If no files are given, then
60+.B luac
61+loads
62+.B luac.out
63+and lists its contents.
64+Use
65+.B \-l \-l
66+for a full listing.
67+.TP
68+.BI \-o " file"
69+output to
70+.IR file ,
71+instead of the default
72+.BR luac.out .
73+(You can use
74+.B "'\-'"
75+for standard output,
76+but not on platforms that open standard output in text mode.)
77+The output file may be one of the given files because
78+all files are loaded before the output file is written.
79+Be careful not to overwrite precious files.
80+.TP
81+.B \-p
82+load files but do not generate any output file.
83+Used mainly for syntax checking and for testing precompiled chunks:
84+corrupted files will probably generate errors when loaded.
85+If no files are given, then
86+.B luac
87+loads
88+.B luac.out
89+and tests its contents.
90+No messages are displayed if the file loads without errors.
91+.TP
92+.B \-s
93+strip debug information before writing the output file.
94+This saves some space in very large chunks,
95+but if errors occur when running a stripped chunk,
96+then the error messages may not contain the full information they usually do.
97+In particular,
98+line numbers and names of local variables are lost.
99+.TP
100+.B \-v
101+show version information.
102+.TP
103+.B \-\-
104+stop handling options.
105+.TP
106+.B \-
107+stop handling options and process standard input.
108+.SH "SEE ALSO"
109+.BR lua (1)
110+.br
111+The documentation at lua.org.
112+.SH DIAGNOSTICS
113+Error messages should be self explanatory.
114+.SH AUTHORS
115+R. Ierusalimschy,
116+L. H. de Figueiredo,
117+W. Celes
118+.\" EOF
doc/manual.css+5−2
@@ -2,13 +2,16 @@ h3 code { · 1 unmodified line
22 font-family: inherit ;
33 }
44
5−pre {
6− font-size: 105% ;
5+pre, code {
6+ font-size: 12pt ;
77 }
88
99 span.apii {
1010 float: right ;
1111 font-family: inherit ;
12+ font-style: normal ;
13+ font-size: small ;
14+ color: gray ;
1215 }
1316
1417 p+h1, ul+h1 {
doc/manual.html+588−438
@@ -16,11 +16,6 @@ · 15 unmodified lines
1616 Lua 5.2 Reference Manual
1717 </h1>
1818
19−<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
20−<EM>This is a beta version of Lua 5.2.
21−Some details may change in the final version.</EM>
22−<P>
23−
2419 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
2520 <p>
2621 <small>
@@ -38,7 +33,7 @@ Freely available under the terms of the · 11 unmodified lines
3833 <!-- ====================================================================== -->
3934 <p>
4035
41−<!-- $Id: manual.of,v 1.86 2011/07/08 20:00:45 roberto Exp $ -->
36+<!-- $Id: manual.of,v 1.88 2011/11/24 13:23:53 roberto Exp $ -->
4237
4338
4439
@@ -51,8 +46,8 @@ general procedural programming with data description · 6 unmodified lines
5146 facilities.
5247 It also offers good support for object-oriented programming,
5348 functional programming, and data-driven programming.
54−Lua is intended to be used as a powerful, light-weight
55−scripting language for any program that needs one.
49+Lua is intended to be used as a powerful, lightweight,
50+embeddable scripting language for any program that needs one.
5651 Lua is implemented as a library, written in <em>clean C</em>,
5752 the common subset of Standard&nbsp;C and C++.
5853
@@ -86,14 +81,14 @@ this document is dry in places. · 27 unmodified lines
8681 For a discussion of the decisions behind the design of Lua,
8782 see the technical papers available at Lua's web site.
8883 For a detailed introduction to programming in Lua,
89−see Roberto's book, <em>Programming in Lua</em> (second edition).
84+see Roberto's book, <em>Programming in Lua</em>.
9085
9186
9287
9388 <h1>2 &ndash; <a name="2">Basic Concepts</a></h1>
9489
9590 <p>
96−This section describes some basic concepts of the language.
91+This section describes the basic concepts of the language.
9792
9893
9994
@@ -148,11 +143,14 @@ functions written in C · 48 unmodified lines
148143 <p>
149144 The type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to
150145 be stored in Lua variables.
151−This type corresponds to a block of raw memory
152−and has no pre-defined operations in Lua,
146+A userdata value is a pointer to a block of raw memory.
147+There are two kinds of userdata:
148+full userdata, where the block of memory is managed by Lua,
149+and light userdata, where the block of memory is managed by the host.
150+Userdata has no predefined operations in Lua,
153151 except assignment and identity test.
154−However, by using <em>metatables</em>,
155−the programmer can define operations for userdata values
152+By using <em>metatables</em>,
153+the programmer can define operations for full userdata values
156154 (see <a href="#2.4">&sect;2.4</a>).
157155 Userdata values cannot be created or modified in Lua,
158156 only through the C&nbsp;API.
@@ -200,7 +198,7 @@ which is called the length of the sequence (see <a href="#3.4.6">&sect;3.4.6</a> · 41 unmodified lines
200198
201199 <p>
202200 Like indices,
203−the value of a table field can be of any type.
201+the values of table fields can be of any type.
204202 In particular,
205203 because functions are first-class values,
206204 table fields can contain functions.
@@ -227,7 +225,7 @@ these operations do not imply any kind of copy. · 20 unmodified lines
227225
228226 <p>
229227 The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type
230−of a given value.
228+of a given value (see <a href="#6.1">&sect;6.1</a>).
231229
232230
233231
@@ -239,8 +237,8 @@ of a given value. · 5 unmodified lines
239237 As will be discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
240238 any reference to a global name <code>var</code> is syntactically translated
241239 to <code>_ENV.var</code>.
242−Moreover, every chunk is compiled in the scope of an external
243−variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>),
240+Moreover, every chunk is compiled in the scope of
241+an external local variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>),
244242 so <code>_ENV</code> itself is never a global name in a chunk.
245243
246244
@@ -252,12 +250,11 @@ In particular, · 5 unmodified lines
252250 you can define new variables and parameters with that name.
253251 Each reference to a global name uses the <code>_ENV</code> that is
254252 visible at that point in the program,
255−following the usual visibility rules of Lua.
253+following the usual visibility rules of Lua (see <a href="#3.5">&sect;3.5</a>).
256254
257255
258256 <p>
259−Any table used as the value of <code>_ENV</code> is usually called
260−an <em>environment</em>.
257+Any table used as the value of <code>_ENV</code> is called an <em>environment</em>.
261258
262259
263260 <p>
@@ -268,13 +265,14 @@ In Lua, the variable <a href="#pdf-_G"><code>_G</code></a> is initialized with t · 4 unmodified lines
268265
269266 <p>
270267 When Lua compiles a chunk,
271−it initializes the value of its <code>_ENV</code> variable
268+it initializes the value of its <code>_ENV</code> upvalue
272269 with the global environment (see <a href="#pdf-load"><code>load</code></a>).
273270 Therefore, by default,
274271 global variables in Lua code refer to entries in the global environment.
275−Moreover, all standard libraries are loaded in the global environment,
272+Moreover, all standard libraries are loaded in the global environment
276273 and several functions there operate on that environment.
277−You can use <a href="#pdf-load"><code>load</code></a> to load a chunk with a different environment.
274+You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</code></a>)
275+to load a chunk with a different environment.
278276 (In C, you have to load the chunk and then change the value
279277 of its first upvalue.)
280278
@@ -325,7 +323,7 @@ any value for the error object. · 44 unmodified lines
325323
326324 <p>
327325 When you use <a href="#pdf-xpcall"><code>xpcall</code></a> or <a href="#lua_pcall"><code>lua_pcall</code></a>,
328−you may give an <em>message handler</em>
326+you may give a <em>message handler</em>
329327 to be called in case of errors.
330328 This function is called with the original error message
331329 and returns a new error message.
@@ -389,8 +387,8 @@ but the string library sets a metatable for the string type (see <a href="#6.4"> · 57 unmodified lines
389387 <p>
390388 A metatable controls how an object behaves in arithmetic operations,
391389 order comparisons, concatenation, length operation, and indexing.
392−A metatable also can define a function to be called when a userdata
393−is garbage collected.
390+A metatable also can define a function to be called
391+when a userdata or a table is garbage collected.
394392 When Lua performs one of these operations over a value,
395393 it checks whether this value has a metatable with the corresponding event.
396394 If so, the value associated with that key (the metamethod)
@@ -427,8 +425,8 @@ This should be read as · 30 unmodified lines
427425 rawget(getmetatable(obj) or {}, event)
428426 </pre><p>
429427
430−That is, the access to a metamethod does not invoke other metamethods,
431−and the access to objects with no metatables does not fail
428+This means that the access to a metamethod does not invoke other metamethods,
429+and access to objects with no metatables does not fail
432430 (it simply results in <b>nil</b>).
433431
434432
@@ -590,13 +588,17 @@ The function <code>getequalhandler</code> defines how Lua chooses a metamethod · 155 unmodified lines
590588 for equality.
591589 A metamethod is selected only when both values
592590 being compared have the same type
593−and the same metamethod for the selected operation.
591+and the same metamethod for the selected operation,
592+and the values are either tables or full userdata.
594593
595594 <pre>
596− function getequalhandler (op1, op2, event)
597− if type(op1) ~= type(op2) then return nil end
598− local mm1 = metatable(op1)[event]
599− local mm2 = metatable(op2)[event]
595+ function getequalhandler (op1, op2)
596+ if type(op1) ~= type(op2) or
597+ (type(op1) ~= "table" and type(op1) ~= "userdata") then
598+ return nil -- different values
599+ end
600+ local mm1 = metatable(op1).__eq
601+ local mm2 = metatable(op2).__eq
600602 if mm1 == mm2 then return mm1 else return nil end
601603 end
602604 </pre><p>
@@ -604,21 +606,19 @@ The "eq" event is defined as follows: · 1 unmodified line
604606
605607 <pre>
606608 function eq_event (op1, op2)
607− if type(op1) ~= type(op2) then -- different types?
608− return false -- different values
609− end
610609 if op1 == op2 then -- primitive equal?
611610 return true -- values are equal
612611 end
613612 -- try metamethod
614− local h = getequalhandler(op1, op2, "__eq")
613+ local h = getequalhandler(op1, op2)
615614 if h then
616− return (h(op1, op2))
615+ return not not h(op1, op2)
617616 else
618617 return false
619618 end
620619 end
621620 </pre><p>
621+Note that the result is always a boolean.
622622 </li>
623623
624624 <li><b>"lt": </b>
@@ -634,13 +634,14 @@ the <code>&lt;</code> operation. · 9 unmodified lines
634634 else
635635 local h = getbinhandler(op1, op2, "__lt")
636636 if h then
637− return (h(op1, op2))
637+ return not not h(op1, op2)
638638 else
639639 error(&middot;&middot;&middot;)
640640 end
641641 end
642642 end
643643 </pre><p>
644+Note that the result is always a boolean.
644645 </li>
645646
646647 <li><b>"le": </b>
@@ -656,7 +657,7 @@ the <code>&lt;=</code> operation. · 9 unmodified lines
656657 else
657658 local h = getbinhandler(op1, op2, "__le")
658659 if h then
659− return (h(op1, op2))
660+ return not not h(op1, op2)
660661 else
661662 h = getbinhandler(op1, op2, "__lt")
662663 if h then
@@ -671,6 +672,11 @@ the <code>&lt;=</code> operation. · 8 unmodified lines
671672 Note that, in the absence of a "le" metamethod,
672673 Lua tries the "lt", assuming that <code>a &lt;= b</code> is
673674 equivalent to <code>not (b &lt; a)</code>.
675+
676+
677+<p>
678+As with the other comparison operators,
679+the result is always a boolean.
674680 </li>
675681
676682 <li><b>"index": </b>
@@ -770,7 +776,7 @@ Lua manages memory automatically by running · 93 unmodified lines
770776 a <em>garbage collector</em> to collect all <em>dead objects</em>
771777 (that is, objects that are no longer accessible from Lua).
772778 All memory used by Lua is subject to automatic management:
773−tables, userdata, functions, threads, strings, etc.
779+strings, tables, userdata, functions, threads, internal structures, etc.
774780
775781
776782 <p>
@@ -819,10 +825,25 @@ memory usage. · 42 unmodified lines
819825 <p>
820826 You can change these numbers by calling <a href="#lua_gc"><code>lua_gc</code></a> in C
821827 or <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> in Lua.
822−With these functions you can also control
828+You can also use these functions to control
823829 the collector directly (e.g., stop and restart it).
824830
825831
832+<p>
833+As an experimental feature in Lua 5.2,
834+you can change the collector's operation mode
835+from incremental to <em>generational</em>.
836+A <em>generational collector</em> assumes that most objects die young,
837+and therefore it traverses only young (recently created) objects.
838+This behavior can reduce the time used by the collector,
839+but also increases memory usage (as old dead objects may accumulate).
840+To mitigate this second problem,
841+from time to time the generational collector performs a full collection.
842+Remember that this is an experimental feature;
843+you are welcome to try it,
844+but check your gains.
845+
846+
826847
827848 <h3>2.5.1 &ndash; <a name="2.5.1">Garbage-Collection Metamethods</a></h3>
828849
@@ -879,11 +900,17 @@ the execution of the regular code. · 50 unmodified lines
879900
880901
881902 <p>
882−Because the object being collected must still be used by the finalizer
883−and even <em>resurrected</em>
884−(e.g., stored by the finalizer in a global variable),
885−the object memory is freed only when it becomes completely inaccessible
886−(that is, in the next garbage-collection cycle unless it was resurrected).
903+Because the object being collected must still be used by the finalizer,
904+it (and other objects accessible only through it)
905+must be <em>resurrected</em> by Lua.
906+Usually, this resurrection is transient,
907+and the object memory is freed in the next garbage-collection cycle.
908+However, if the finalizer stores the object in some global place
909+(e.g., a global variable),
910+then there is a permanent resurrection.
911+In any case,
912+the object memory is freed only when it becomes completely inaccessible;
913+its finalizer will never be called twice.
887914
888915
889916
@@ -927,32 +954,42 @@ the pair is removed. · 37 unmodified lines
927954
928955
929956 <p>
930−After you use a table as a metatable,
931−you should not change the value of its <code>__mode</code> field.
932−Otherwise, the weak behavior of the tables controlled by this
933−metatable is undefined.
957+Any change in the weakness of a table may take effect only
958+at the next collect cycle.
959+In particular, if you change the weakness to a stronger mode,
960+Lua may still collect some items from that table
961+before the change takes effect.
934962
935963
936964 <p>
937965 Only objects that have an explicit construction
938−can be removed from weak tables.
939−Values, such as numbers and booleans,
966+are removed from weak tables.
967+Values, such as numbers and light C functions,
940968 are not subject to garbage collection,
941969 and therefore are not removed from weak tables
942970 (unless its associated value is collected).
943−Lua treats strings and light C functions as non-object values.
971+Although strings are subject to garbage collection,
972+they do not have an explicit construction,
973+and therefore are not removed from weak tables.
944974
945975
946976 <p>
947−Objects marked for finalization have a special behavior in weak tables.
948−When a marked object is a value in a weak table,
949−it is removed from the table before running its finalizer.
950−However, when it is a key,
951−it is removed from the table only after running its finalizer.
977+Resurrected objects
978+(that is, objects being finalized
979+and objects accessible only through objects being finalized)
980+have a special behavior in weak tables.
981+They are removed from weak values before running their finalizers,
982+but are removed from weak keys only in the next collection
983+after running their finalizers, when such objects are actually freed.
952984 This behavior allows the finalizer to access properties
953985 associated with the object through weak tables.
954986
955987
988+<p>
989+If a weak table is among the resurrected objects in a collection cycle,
990+it may not be properly cleared until the next cycle.
991+
992+
956993
957994
958995
@@ -1060,7 +1097,6 @@ When you run it, it produces the following output: · 101 unmodified lines
10601097 <pre>
10611098 co-body 1 10
10621099 foo 2
1063−
10641100 main true 4
10651101 co-body r
10661102 main true 11 -9
@@ -1090,7 +1126,7 @@ and what their combinations mean. · 23 unmodified lines
10901126
10911127
10921128 <p>
1093−The language constructs will be explained using the usual extended BNF notation,
1129+Language constructs will be explained using the usual extended BNF notation,
10941130 in which
10951131 {<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and
10961132 [<em>a</em>]&nbsp;means an optional <em>a</em>.
@@ -1176,7 +1212,7 @@ into the string contents. · 79 unmodified lines
11761212
11771213
11781214 <p>
1179−A character in a literal string can also be specified by its numerical value.
1215+A byte in a literal string can also be specified by its numerical value.
11801216 This can be done with the escape sequence <code>\x<em>XX</em></code>,
11811217 where <em>XX</em> is a sequence of exactly two hexadecimal digits,
11821218 or with the escape sequence <code>\<em>ddd</em></code>,
@@ -1407,13 +1443,13 @@ even if it does not use that variable. · 224 unmodified lines
14071443 <p>
14081444 A chunk can be stored in a file or in a string inside the host program.
14091445 To execute a chunk,
1410−Lua first pre-compiles the chunk into instructions for a virtual machine,
1446+Lua first precompiles the chunk into instructions for a virtual machine,
14111447 and then it executes the compiled code
14121448 with an interpreter for the virtual machine.
14131449
14141450
14151451 <p>
1416−Chunks can also be pre-compiled into binary form;
1452+Chunks can also be precompiled into binary form;
14171453 see program <code>luac</code> for details.
14181454 Programs in source and compiled forms are interchangeable;
14191455 Lua automatically detects the file type and acts accordingly.
@@ -1555,7 +1591,7 @@ enter into the scope of a local variable. · 135 unmodified lines
15551591
15561592
15571593 <p>
1558−Both labels and empty statements are called <em>void statements</em>,
1594+Labels and empty statements are called <em>void statements</em>,
15591595 as they perform no actions.
15601596
15611597
@@ -1806,14 +1842,13 @@ and the unary <em>length operator</em> (see <a href="#3.4.6">&sect;3.4.6</a>). · 244 unmodified lines
18061842
18071843 <p>
18081844 Both function calls and vararg expressions can result in multiple values.
1809−If an expression is used as a statement
1810−(only possible for function calls (see <a href="#3.3.6">&sect;3.3.6</a>)),
1845+If a function call is used as a statement (see <a href="#3.3.6">&sect;3.3.6</a>),
18111846 then its return list is adjusted to zero elements,
18121847 thus discarding all returned values.
18131848 If an expression is used as the last (or the only) element
18141849 of a list of expressions,
18151850 then no adjustment is made
1816−(unless the call is enclosed in parentheses).
1851+(unless the expression is enclosed in parentheses).
18171852 In all other contexts,
18181853 Lua adjusts the result list to one element,
18191854 discarding all values except the first one.
@@ -1881,8 +1916,7 @@ Lua provides automatic conversion between · 61 unmodified lines
18811916 string and number values at run time.
18821917 Any arithmetic operation applied to a string tries to convert
18831918 this string to a number, following the rules of the Lua lexer.
1884−(The string may have leading and trailing spaces,
1885−plus an optional sign.)
1919+(The string may have leading and trailing spaces and a sign.)
18861920 Conversely, whenever a number is used where a string is expected,
18871921 the number is converted to a string, in a reasonable format.
18881922 For complete control over how numbers are converted to strings,
@@ -2254,8 +2288,8 @@ contains references to <code>f</code>.) · 365 unmodified lines
22542288 <p>
22552289 A function definition is an executable expression,
22562290 whose value has type <em>function</em>.
2257−When Lua pre-compiles a chunk,
2258−all its function bodies are pre-compiled too.
2291+When Lua precompiles a chunk,
2292+all its function bodies are precompiled too.
22592293 Then, whenever Lua executes the function definition,
22602294 the function is <em>instantiated</em> (or <em>closed</em>).
22612295 This function instance (or <em>closure</em>)
@@ -2272,9 +2306,9 @@ initialized with the argument values: · 10 unmodified lines
22722306 When a function is called,
22732307 the list of arguments is adjusted to
22742308 the length of the list of parameters,
2275−unless the function is a variadic or <em>vararg function</em>,
2276−which is
2277−indicated by three dots ('<code>...</code>') at the end of its parameter list.
2309+unless the function is a <em>vararg function</em>,
2310+which is indicated by three dots ('<code>...</code>')
2311+at the end of its parameter list.
22782312 A vararg function does not adjust its argument list;
22792313 instead, it collects all extra arguments and supplies them
22802314 to the function through a <em>vararg expression</em>,
@@ -2425,7 +2459,8 @@ are declared in the header file <a name="pdf-lua.h"><code>lua.h</code></a>. · 144 unmodified lines
24252459 <p>
24262460 Even when we use the term "function",
24272461 any facility in the API may be provided as a macro instead.
2428−All such macros use each of their arguments exactly once
2462+Except where stated otherwise,
2463+all such macros use each of their arguments exactly once
24292464 (except for the first argument, which is always a Lua state),
24302465 and so do not generate any hidden side-effects.
24312466
@@ -2434,8 +2469,7 @@ and so do not generate any hidden side-effects. · 2 unmodified lines
24342469 As in most C&nbsp;libraries,
24352470 the Lua API functions do not check their arguments for validity or consistency.
24362471 However, you can change this behavior by compiling Lua
2437−with a proper definition for the macro <a name="pdf-luai_apicheck"><code>luai_apicheck</code></a>,
2438−in file <code>luaconf.h</code>.
2472+with the macro <a name="pdf-LUA_USE_APICHECK"><code>LUA_USE_APICHECK</code></a> defined.
24392473
24402474
24412475
@@ -2472,10 +2506,6 @@ index&nbsp;<em>n</em> represents the last element; · 30 unmodified lines
24722506 index&nbsp;-1 also represents the last element
24732507 (that is, the element at the&nbsp;top)
24742508 and index <em>-n</em> represents the first element.
2475−We say that an index is <em>valid</em>
2476−if it lies between&nbsp;1 and the stack top
2477−(that is, if <code>1 &le; abs(index) &le; top</code>).
2478−
24792509
24802510
24812511
@@ -2494,7 +2524,7 @@ to ensure that the stack has extra slots when pushing new elements. · 12 unmodified lines
24942524
24952525 <p>
24962526 Whenever Lua calls C,
2497−it ensures that at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> stack positions are available.
2527+it ensures that the stack has at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> extra slots.
24982528 <code>LUA_MINSTACK</code> is defined as 20,
24992529 so that usually you do not have to worry about stack space
25002530 unless your code has loops pushing elements onto the stack.
@@ -2509,33 +2539,66 @@ So, before pushing anything in the stack after such a call · 8 unmodified lines
25092539 you should use <a href="#lua_checkstack"><code>lua_checkstack</code></a>.
25102540
25112541
2542+
2543+
2544+
2545+<h2>4.3 &ndash; <a name="4.3">Valid and Acceptable Indices</a></h2>
2546+
25122547 <p>
2513−Most query functions accept as indices any value inside the
2514−available stack space, that is, indices up to the maximum stack size
2515−that you have set through <a href="#lua_checkstack"><code>lua_checkstack</code></a>.
2516−Such indices are called <em>acceptable indices</em>.
2517−More formally, we define an <em>acceptable index</em>
2548+Any function in the API that receives stack indices
2549+works only with <em>valid indices</em> or <em>acceptable indices</em>.
2550+
2551+
2552+<p>
2553+A <em>valid index</em> is an index that refers to a
2554+valid position within the stack, that is,
2555+it lies between&nbsp;1 and the stack top
2556+(<code>1 &le; abs(index) &le; top</code>).
2557+
2558+Usually, functions that need a specific stack position
2559+(e.g., <a href="#lua_remove"><code>lua_remove</code></a>) require valid indices.
2560+
2561+
2562+<p>
2563+Functions that do not need a specific stack position,
2564+but only a value in the stack (e.g., query functions),
2565+can be called with acceptable indices.
2566+An <em>acceptable index</em> refers to a position within
2567+the space allocated for the stack,
2568+that is, indices up to the stack size.
2569+More formally, we define an acceptable index
25182570 as follows:
25192571
25202572 <pre>
25212573 (index &lt; 0 &amp;&amp; abs(index) &lt;= top) ||
2522− (index &gt; 0 &amp;&amp; index &lt;= stackspace)
2574+ (index &gt; 0 &amp;&amp; index &lt;= stack size)
25232575 </pre><p>
2524−Note that 0 is never an acceptable index.
2576+(Note that 0 is never an acceptable index.)
2577+When a function is called,
2578+its stack size is <code>top + LUA_MINSTACK</code>.
2579+You can change its stack size through function <a href="#lua_checkstack"><code>lua_checkstack</code></a>.
25252580
25262581
2582+<p>
2583+Acceptable indices serve to avoid extra tests
2584+against the stack top when querying the stack.
2585+For instance, a C&nbsp;function can query its third argument
2586+without the need to first check whether there is a third argument,
2587+that is, without the need to check whether 3 is a valid index.
25272588
25282589
2590+<p>
2591+For functions that can be called with acceptable indices,
2592+any non-valid index is treated as if it
2593+contains a value of a virtual type <a name="pdf-LUA_TNONE"><code>LUA_TNONE</code></a>.
25292594
2530−<h2>4.3 &ndash; <a name="4.3">Pseudo-Indices</a></h2>
25312595
25322596 <p>
25332597 Unless otherwise noted,
25342598 any function that accepts valid indices also accepts <em>pseudo-indices</em>,
25352599 which represent some Lua values that are accessible to C&nbsp;code
25362600 but which are not in the stack.
2537−Pseudo-indices are used to access
2538−the registry
2601+Pseudo-indices are used to access the registry
25392602 and the upvalues of a C&nbsp;function (see <a href="#4.4">&sect;4.4</a>).
25402603
25412604
@@ -2547,10 +2610,10 @@ and the upvalues of a C&nbsp;function (see <a href="#4.4">&sect;4.4</a>). · 5 unmodified lines
25472610 <p>
25482611 When a C&nbsp;function is created,
25492612 it is possible to associate some values with it,
2550−thus creating a <em>C&nbsp;closure</em>;
2613+thus creating a <em>C&nbsp;closure</em>
2614+(see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>);
25512615 these values are called <em>upvalues</em> and are
2552−accessible to the function whenever it is called
2553−(see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>).
2616+accessible to the function whenever it is called.
25542617
25552618
25562619 <p>
@@ -2573,12 +2636,13 @@ produces an acceptable (but invalid) index. · 16 unmodified lines
25732636
25742637 <p>
25752638 Lua provides a <em>registry</em>,
2576−a pre-defined table that can be used by any C&nbsp;code to
2577−store whatever Lua value it needs to store.
2578−This table is always located at pseudo-index
2639+a predefined table that can be used by any C&nbsp;code to
2640+store whatever Lua values it needs to store.
2641+The registry table is always located at pseudo-index
25792642 <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>.
25802643 Any C&nbsp;library can store data into this table,
2581−but it should take care to choose keys different from those used
2644+but it should take care to choose keys
2645+that are different from those used
25822646 by other libraries, to avoid collisions.
25832647 Typically, you should use as key a string containing your library name,
25842648 or a light userdata with the address of a C&nbsp;object in your code,
@@ -2610,7 +2674,6 @@ the main thread of the state. · 25 unmodified lines
26102674
26112675 <li><b><a name="pdf-LUA_RIDX_GLOBALS"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has
26122676 the global environment.
2613−This is the C&nbsp;equivalent to the <a href="#pdf-_G"><code>_G</code></a> global variable.
26142677 </li>
26152678 </ul>
26162679
@@ -2629,8 +2692,8 @@ and runtime errors) · 12 unmodified lines
26292692 it <em>raises</em> an error;
26302693 that is, it does a long jump.
26312694 A <em>protected environment</em> uses <code>setjmp</code>
2632−to set a recover point;
2633−any error jumps to the most recent active recover point.
2695+to set a recovery point;
2696+any error jumps to the most recent active recovery point.
26342697
26352698
26362699 <p>
@@ -2639,7 +2702,8 @@ Lua calls a <em>panic function</em> (see <a href="#lua_atpanic"><code>lua_atpani · 2 unmodified lines
26392702 and then calls <code>abort</code>,
26402703 thus exiting the host application.
26412704 Your panic function can avoid this exit by
2642−never returning (e.g., doing a long jump).
2705+never returning
2706+(e.g., doing a long jump to your own recovery point outside Lua).
26432707
26442708
26452709 <p>
@@ -2677,8 +2741,7 @@ All those functions receive a <em>continuation function</em> · 31 unmodified lines
26772741
26782742
26792743 <p>
2680−To explain continuations,
2681−let us set some terminology.
2744+We need to set some terminology to explain continuations.
26822745 We have a C function called from Lua which we will call
26832746 the <em>original function</em>.
26842747 This original function then calls one of those three functions in the C API,
@@ -2704,7 +2767,7 @@ of the original function. · 19 unmodified lines
27042767
27052768
27062769 <p>
2707−Lua treats the continuation function as if it was the original function.
2770+Lua treats the continuation function as if it were the original function.
27082771 The continuation function receives the same Lua stack
27092772 from the original function,
27102773 in the same state it would be if the callee function had returned.
@@ -2712,7 +2775,7 @@ in the same state it would be if the callee function had returned. · 1 unmodified line
27122775 after a <a href="#lua_callk"><code>lua_callk</code></a> the function and its arguments are
27132776 removed from the stack and replaced by the results from the call.)
27142777 It also has the same upvalues.
2715−Whatever it returns is handled by Lua as if it was the return
2778+Whatever it returns is handled by Lua as if it were the return
27162779 of the original function.
27172780
27182781
@@ -2749,15 +2812,14 @@ by looking only at its arguments · 30 unmodified lines
27492812 The third field, <code>x</code>,
27502813 tells whether the function may throw errors:
27512814 '<code>-</code>' means the function never throws any error;
2752−'<code>m</code>' means the function may throw an error
2753−only due to not enough memory;
2815+'<code>m</code>' means the function may throw only memory allocation errors;
27542816 '<code>e</code>' means the function may throw other kinds of errors;
27552817 '<code>v</code>' means the function may throw an error on purpose.
27562818
27572819
27582820
27592821 <hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p>
2760−<span class="apii">[-0, +0, <em>-</em>]</span>
2822+<span class="apii">[-0, +0, &ndash;]</span>
27612823 <pre>int lua_absindex (lua_State *L, int idx);</pre>
27622824
27632825 <p>
@@ -2795,7 +2857,7 @@ that is, the size given when it was allocated or reallocated. · 31 unmodified lines
27952857
27962858 <p>
27972859 When <code>ptr</code> is <code>NULL</code>,
2798−<code>osize</code> codes the kind of object that Lua is allocating.
2860+<code>osize</code> encodes the kind of object that Lua is allocating.
27992861 <code>osize</code> is any of
28002862 <a href="#pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>, <a href="#pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, <a href="#pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>,
28012863 <a href="#pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, or <a href="#pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a> when (and only when)
@@ -2818,7 +2880,7 @@ and return <code>NULL</code>. · 16 unmodified lines
28182880 When <code>nsize</code> is not zero,
28192881 the allocator should behave like <code>realloc</code>.
28202882 The allocator returns <code>NULL</code>
2821−if and only if it cannot fill the request.
2883+if and only if it cannot fulfill the request.
28222884 Lua assumes that the allocator never fails when
28232885 <code>osize &gt;= nsize</code>.
28242886
@@ -2843,8 +2905,8 @@ Note that Standard&nbsp;C ensures · 18 unmodified lines
28432905 that <code>free(NULL)</code> has no effect and that
28442906 <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
28452907 This code assumes that <code>realloc</code> does not fail when shrinking a block.
2846−Standard&nbsp;C does not ensure this behavior,
2847−but it seems a safe assumption.
2908+(Although Standard&nbsp;C does not ensure this behavior,
2909+it seems to be a safe assumption.)
28482910
28492911
28502912
@@ -2883,7 +2945,7 @@ The value of <code>op</code> must be one of the following constants: · 32 unmodified lines
28832945
28842946
28852947 <hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p>
2886−<span class="apii">[-0, +0, <em>-</em>]</span>
2948+<span class="apii">[-0, +0, &ndash;]</span>
28872949 <pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>
28882950
28892951 <p>
@@ -2901,7 +2963,7 @@ In particular, the error message is at the top of the stack. · 11 unmodified lines
29012963
29022964
29032965 <hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p>
2904−<span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span>
2966+<span class="apii">[-(nargs+1), +nresults, <em>e</em>]</span>
29052967 <pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>
29062968
29072969 <p>
@@ -3025,12 +3087,12 @@ of numerical arguments and returns their average and sum: · 117 unmodified lines
30253087
30263088
30273089 <hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p>
3028−<span class="apii">[-0, +0, <em>-</em>]</span>
3090+<span class="apii">[-0, +0, &ndash;]</span>
30293091 <pre>int lua_checkstack (lua_State *L, int extra);</pre>
30303092
30313093 <p>
30323094 Ensures that there are at least <code>extra</code> free stack slots in the stack.
3033−It returns false if it cannot grant the request,
3095+It returns false if it cannot fulfill the request,
30343096 because it would cause the stack to be larger than a fixed maximum size
30353097 (typically at least a few thousand elements) or
30363098 because it cannot allocate memory for the new stack size.
@@ -3043,7 +3105,7 @@ it is left unchanged. · 6 unmodified lines
30433105
30443106
30453107 <hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p>
3046−<span class="apii">[-0, +0, <em>-</em>]</span>
3108+<span class="apii">[-0, +0, &ndash;]</span>
30473109 <pre>void lua_close (lua_State *L);</pre>
30483110
30493111 <p>
@@ -3052,10 +3114,9 @@ Destroys all objects in the given Lua state · 2 unmodified lines
30523114 and frees all dynamic memory used by this state.
30533115 On several platforms, you may not need to call this function,
30543116 because all resources are naturally released when the host program ends.
3055−On the other hand, long-running programs,
3056−such as a daemon or a web server,
3057−might need to release states as soon as they are not needed,
3058−to avoid growing too large.
3117+On the other hand, long-running programs that create multiple states,
3118+such as daemons or web servers,
3119+might need to close states as soon as they are not needed.
30593120
30603121
30613122
@@ -3066,6 +3127,7 @@ to avoid growing too large. · 4 unmodified lines
30663127 <pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre>
30673128
30683129 <p>
3130+Compares two Lua values.
30693131 Returns 1 if the value at acceptable index <code>index1</code> satisfies <code>op</code>
30703132 when compared with the value at acceptable index <code>index2</code>,
30713133 following the semantics of the corresponding Lua operator
@@ -3106,7 +3168,7 @@ Concatenation is performed following the usual semantics of Lua · 34 unmodified lines
31063168
31073169
31083170 <hr><h3><a name="lua_copy"><code>lua_copy</code></a></h3><p>
3109−<span class="apii">[-0, +0, <em>-</em>]</span>
3171+<span class="apii">[-0, +0, &ndash;]</span>
31103172 <pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre>
31113173
31123174 <p>
@@ -3176,7 +3238,7 @@ Generates a Lua error. · 63 unmodified lines
31763238 The error message (which can actually be a Lua value of any type)
31773239 must be on the stack top.
31783240 This function does a long jump,
3179−and therefore never returns.
3241+and therefore never returns
31803242 (see <a href="#luaL_error"><code>luaL_error</code></a>).
31813243
31823244
@@ -3245,10 +3307,20 @@ returns a boolean that tells whether the collector is running · 62 unmodified lines
32453307 (i.e., not stopped).
32463308 </li>
32473309
3310+<li><b><code>LUA_GCGEN</code>: </b>
3311+changes the collector to generational mode
3312+(see <a href="#2.5">&sect;2.5</a>).
3313+</li>
3314+
3315+<li><b><code>LUA_GCINC</code>: </b>
3316+changes the collector to incremental mode.
3317+This is the default mode.
3318+</li>
3319+
32483320 </ul>
32493321
32503322 <p>
3251−For more details about some options,
3323+For more details about these options,
32523324 see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>.
32533325
32543326
@@ -3256,7 +3328,7 @@ see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>. · 1 unmodified line
32563328
32573329
32583330 <hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p>
3259−<span class="apii">[-0, +0, <em>-</em>]</span>
3331+<span class="apii">[-0, +0, &ndash;]</span>
32603332 <pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>
32613333
32623334 <p>
@@ -3269,7 +3341,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 6 unmodified lines
32693341
32703342
32713343 <hr><h3><a name="lua_getctx"><code>lua_getctx</code></a></h3><p>
3272−<span class="apii">[-0, +0, <em>-</em>]</span>
3344+<span class="apii">[-0, +0, &ndash;]</span>
32733345 <pre>int lua_getctx (lua_State *L, int *ctx);</pre>
32743346
32753347 <p>
@@ -3293,7 +3365,7 @@ When the callee is <a href="#lua_pcallk"><code>lua_pcallk</code></a>, · 17 unmodified lines
32933365 Lua may also call its continuation function
32943366 to handle errors during the call.
32953367 That is, upon an error in the function called by <a href="#lua_pcallk"><code>lua_pcallk</code></a>,
3296−Lua may not return <a href="#lua_pcallk"><code>lua_pcallk</code></a>
3368+Lua may not return to the original function
32973369 but instead may call the continuation function.
32983370 In that case, a call to <a href="#lua_getctx"><code>lua_getctx</code></a> will return the error code
32993371 (the value that would be returned by <a href="#lua_pcallk"><code>lua_pcallk</code></a>);
@@ -3324,21 +3396,19 @@ for the "index" event (see <a href="#2.4">&sect;2.4</a>). · 24 unmodified lines
33243396
33253397 <p>
33263398 Pushes onto the stack the value of the global <code>name</code>.
3327−It is defined as a macro.
33283399
33293400
33303401
33313402
33323403
33333404 <hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p>
3334−<span class="apii">[-0, +(0|1), <em>-</em>]</span>
3405+<span class="apii">[-0, +(0|1), &ndash;]</span>
33353406 <pre>int lua_getmetatable (lua_State *L, int index);</pre>
33363407
33373408 <p>
33383409 Pushes onto the stack the metatable of the value at the given
33393410 acceptable index.
3340−If the index is not valid,
3341−or if the value does not have a metatable,
3411+If the value does not have a metatable,
33423412 the function returns&nbsp;0 and pushes nothing on the stack.
33433413
33443414
@@ -3366,7 +3436,7 @@ for the "index" event (see <a href="#2.4">&sect;2.4</a>). · 21 unmodified lines
33663436
33673437
33683438 <hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p>
3369−<span class="apii">[-0, +0, <em>-</em>]</span>
3439+<span class="apii">[-0, +0, &ndash;]</span>
33703440 <pre>int lua_gettop (lua_State *L);</pre>
33713441
33723442 <p>
@@ -3380,7 +3450,7 @@ this result is equal to the number of elements in the stack · 7 unmodified lines
33803450
33813451
33823452 <hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p>
3383−<span class="apii">[-0, +1, <em>-</em>]</span>
3453+<span class="apii">[-0, +1, &ndash;]</span>
33843454 <pre>void lua_getuservalue (lua_State *L, int index);</pre>
33853455
33863456 <p>
@@ -3393,7 +3463,7 @@ This Lua value must be a table or <b>nil</b>. · 6 unmodified lines
33933463
33943464
33953465 <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p>
3396−<span class="apii">[-1, +1, <em>-</em>]</span>
3466+<span class="apii">[-1, +1, &ndash;]</span>
33973467 <pre>void lua_insert (lua_State *L, int index);</pre>
33983468
33993469 <p>
@@ -3423,11 +3493,11 @@ which is usually the largest signed integral type the machine handles · 23 unmodified lines
34233493
34243494
34253495 <hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p>
3426−<span class="apii">[-0, +0, <em>-</em>]</span>
3496+<span class="apii">[-0, +0, &ndash;]</span>
34273497 <pre>int lua_isboolean (lua_State *L, int index);</pre>
34283498
34293499 <p>
3430−Returns 1 if the value at the given acceptable index has type boolean,
3500+Returns 1 if the value at the given acceptable index is a boolean,
34313501 and 0&nbsp;otherwise.
34323502
34333503
@@ -3435,7 +3505,7 @@ and 0&nbsp;otherwise. · 1 unmodified line
34353505
34363506
34373507 <hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p>
3438−<span class="apii">[-0, +0, <em>-</em>]</span>
3508+<span class="apii">[-0, +0, &ndash;]</span>
34393509 <pre>int lua_iscfunction (lua_State *L, int index);</pre>
34403510
34413511 <p>
@@ -3447,7 +3517,7 @@ and 0&nbsp;otherwise. · 5 unmodified lines
34473517
34483518
34493519 <hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p>
3450−<span class="apii">[-0, +0, <em>-</em>]</span>
3520+<span class="apii">[-0, +0, &ndash;]</span>
34513521 <pre>int lua_isfunction (lua_State *L, int index);</pre>
34523522
34533523 <p>
@@ -3459,7 +3529,7 @@ Returns 1 if the value at the given acceptable index is a function · 5 unmodified lines
34593529
34603530
34613531 <hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p>
3462−<span class="apii">[-0, +0, <em>-</em>]</span>
3532+<span class="apii">[-0, +0, &ndash;]</span>
34633533 <pre>int lua_islightuserdata (lua_State *L, int index);</pre>
34643534
34653535 <p>
@@ -3471,7 +3541,7 @@ and 0&nbsp;otherwise. · 5 unmodified lines
34713541
34723542
34733543 <hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p>
3474−<span class="apii">[-0, +0, <em>-</em>]</span>
3544+<span class="apii">[-0, +0, &ndash;]</span>
34753545 <pre>int lua_isnil (lua_State *L, int index);</pre>
34763546
34773547 <p>
@@ -3483,7 +3553,7 @@ and 0&nbsp;otherwise. · 5 unmodified lines
34833553
34843554
34853555 <hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p>
3486−<span class="apii">[-0, +0, <em>-</em>]</span>
3556+<span class="apii">[-0, +0, &ndash;]</span>
34873557 <pre>int lua_isnone (lua_State *L, int index);</pre>
34883558
34893559 <p>
@@ -3496,7 +3566,7 @@ and 0&nbsp;otherwise. · 6 unmodified lines
34963566
34973567
34983568 <hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p>
3499−<span class="apii">[-0, +0, <em>-</em>]</span>
3569+<span class="apii">[-0, +0, &ndash;]</span>
35003570 <pre>int lua_isnoneornil (lua_State *L, int index);</pre>
35013571
35023572 <p>
@@ -3510,7 +3580,7 @@ and 0&nbsp;otherwise. · 7 unmodified lines
35103580
35113581
35123582 <hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p>
3513−<span class="apii">[-0, +0, <em>-</em>]</span>
3583+<span class="apii">[-0, +0, &ndash;]</span>
35143584 <pre>int lua_isnumber (lua_State *L, int index);</pre>
35153585
35163586 <p>
@@ -3523,7 +3593,7 @@ and 0&nbsp;otherwise. · 6 unmodified lines
35233593
35243594
35253595 <hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p>
3526−<span class="apii">[-0, +0, <em>-</em>]</span>
3596+<span class="apii">[-0, +0, &ndash;]</span>
35273597 <pre>int lua_isstring (lua_State *L, int index);</pre>
35283598
35293599 <p>
@@ -3536,7 +3606,7 @@ and 0&nbsp;otherwise. · 6 unmodified lines
35363606
35373607
35383608 <hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p>
3539−<span class="apii">[-0, +0, <em>-</em>]</span>
3609+<span class="apii">[-0, +0, &ndash;]</span>
35403610 <pre>int lua_istable (lua_State *L, int index);</pre>
35413611
35423612 <p>
@@ -3548,7 +3618,7 @@ and 0&nbsp;otherwise. · 5 unmodified lines
35483618
35493619
35503620 <hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p>
3551−<span class="apii">[-0, +0, <em>-</em>]</span>
3621+<span class="apii">[-0, +0, &ndash;]</span>
35523622 <pre>int lua_isthread (lua_State *L, int index);</pre>
35533623
35543624 <p>
@@ -3560,7 +3630,7 @@ and 0&nbsp;otherwise. · 5 unmodified lines
35603630
35613631
35623632 <hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p>
3563−<span class="apii">[-0, +0, <em>-</em>]</span>
3633+<span class="apii">[-0, +0, &ndash;]</span>
35643634 <pre>int lua_isuserdata (lua_State *L, int index);</pre>
35653635
35663636 <p>
@@ -3585,7 +3655,7 @@ The result is pushed on the stack. · 18 unmodified lines
35853655
35863656
35873657 <hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p>
3588−<span class="apii">[-0, +1, <em>-</em>]</span>
3658+<span class="apii">[-0, +1, &ndash;]</span>
35893659 <pre>int lua_load (lua_State *L,
35903660 lua_Reader reader,
35913661 void *data,
@@ -3601,13 +3671,13 @@ The return values of <a href="#lua_load"><code>lua_load</code></a> are: · 9 unmodified lines
36013671
36023672 <ul>
36033673
3604−<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> no errors;</li>
3674+<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a>: </b> no errors;</li>
36053675
36063676 <li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b>
3607−syntax error during pre-compilation;</li>
3677+syntax error during precompilation;</li>
36083678
36093679 <li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
3610−memory allocation error.</li>
3680+memory allocation error;</li>
36113681
36123682 <li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
36133683 error while running a <code>__gc</code> metamethod.
@@ -3623,7 +3693,7 @@ it does not run it. · 9 unmodified lines
36233693
36243694
36253695 <p>
3626−<a href="#lua_load"><code>lua_load</code></a> automatically detects whether the chunk is text or binary,
3696+<a href="#lua_load"><code>lua_load</code></a> automatically detects whether the chunk is text or binary
36273697 and loads it accordingly (see program <code>luac</code>).
36283698
36293699
@@ -3642,25 +3712,25 @@ which is used for error messages and in debug information (see <a href="#4.9">&s · 12 unmodified lines
36423712 If the resulting function has one upvalue,
36433713 this upvalue is set to the value of the global environment
36443714 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">&sect;4.5</a>).
3645−(When loading main chunks,
3646−this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).)
3715+When loading main chunks,
3716+this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).
36473717
36483718
36493719
36503720
36513721
36523722 <hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p>
3653−<span class="apii">[-0, +0, <em>-</em>]</span>
3723+<span class="apii">[-0, +0, &ndash;]</span>
36543724 <pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>
36553725
36563726 <p>
36573727 Creates a new thread running in a new, independent state.
3658−Returns <code>NULL</code> if cannot create the thread/state
3728+Returns <code>NULL</code> if cannot create the thread or the state
36593729 (due to lack of memory).
36603730 The argument <code>f</code> is the allocator function;
36613731 Lua does all memory allocation for this state through this function.
36623732 The second argument, <code>ud</code>, is an opaque pointer that Lua
3663−simply passes to the allocator in every call.
3733+passes to the allocator in every call.
36643734
36653735
36663736
@@ -3686,7 +3756,7 @@ It is equivalent to <code>lua_createtable(L, 0, 0)</code>. · 19 unmodified lines
36863756 Creates a new thread, pushes it on the stack,
36873757 and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread.
36883758 The new thread returned by this function shares with the original thread
3689−all global objects (such as tables),
3759+its global environment,
36903760 but has an independent execution stack.
36913761
36923762
@@ -3707,15 +3777,7 @@ like any Lua object. · 14 unmodified lines
37073777 This function allocates a new block of memory with the given size,
37083778 pushes onto the stack a new full userdata with the block address,
37093779 and returns this address.
3710−
3711−
3712−<p>
3713−Userdata represent C&nbsp;values in Lua.
3714−A <em>full userdata</em> represents a block of memory.
3715−It is an object (like a table):
3716−you must create it, it can have its own metatable,
3717−and you can detect when it is being collected.
3718−A full userdata is only equal to itself (under raw equality).
3780+The host program can freely use this memory.
37193781
37203782
37213783
@@ -3780,7 +3842,7 @@ Lua to operate with another type for numbers (e.g., float or long). · 58 unmodified lines
37803842
37813843
37823844 <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p>
3783−<span class="apii">[-(nargs + 1), +(nresults|1), <em>-</em>]</span>
3845+<span class="apii">[-(nargs + 1), +(nresults|1), &ndash;]</span>
37843846 <pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre>
37853847
37863848 <p>
@@ -3855,9 +3917,13 @@ It is generated by the garbage collector.) · 68 unmodified lines
38553917
38563918
38573919 <hr><h3><a name="lua_pcallk"><code>lua_pcallk</code></a></h3><p>
3858−<span class="apii">[-(nargs + 1), +(nresults|1), <em>-</em>]</span>
3859−<pre>int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
3860− int ctx, lua_CFunction k);</pre>
3920+<span class="apii">[-(nargs + 1), +(nresults|1), &ndash;]</span>
3921+<pre>int lua_pcallk (lua_State *L,
3922+ int nargs,
3923+ int nresults,
3924+ int errfunc,
3925+ int ctx,
3926+ lua_CFunction k);</pre>
38613927
38623928 <p>
38633929 This function behaves exactly like <a href="#lua_pcall"><code>lua_pcall</code></a>,
@@ -3868,7 +3934,7 @@ but allows the called function to yield (see <a href="#4.7">&sect;4.7</a>). · 4 unmodified lines
38683934
38693935
38703936 <hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p>
3871−<span class="apii">[-n, +0, <em>-</em>]</span>
3937+<span class="apii">[-n, +0, &ndash;]</span>
38723938 <pre>void lua_pop (lua_State *L, int n);</pre>
38733939
38743940 <p>
@@ -3879,7 +3945,7 @@ Pops <code>n</code> elements from the stack. · 4 unmodified lines
38793945
38803946
38813947 <hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p>
3882−<span class="apii">[-0, +1, <em>-</em>]</span>
3948+<span class="apii">[-0, +1, &ndash;]</span>
38833949 <pre>void lua_pushboolean (lua_State *L, int b);</pre>
38843950
38853951 <p>
@@ -3920,14 +3986,14 @@ The maximum value for <code>n</code> is 255. · 34 unmodified lines
39203986 When <code>n</code> is zero,
39213987 this function creates a <em>light C function</em>,
39223988 which is just a pointer to the C&nbsp;function.
3923−In that case, it cannot throw a memory error.
3989+In that case, it never throws a memory error.
39243990
39253991
39263992
39273993
39283994
39293995 <hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p>
3930−<span class="apii">[-0, +1, <em>-</em>]</span>
3996+<span class="apii">[-0, +1, &ndash;]</span>
39313997 <pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>
39323998
39333999 <p>
@@ -3948,7 +4014,9 @@ and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code>< · 14 unmodified lines
39484014
39494015 <pre>
39504016 #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
3951−</pre>
4017+</pre><p>
4018+Note that <code>f</code> is used twice.
4019+
39524020
39534021
39544022
@@ -3980,7 +4048,7 @@ The conversion specifiers can only be · 25 unmodified lines
39804048 '<code>%f</code>' (inserts a <a href="#lua_Number"><code>lua_Number</code></a>),
39814049 '<code>%p</code>' (inserts a pointer as a hexadecimal numeral),
39824050 '<code>%d</code>' (inserts an <code>int</code>), and
3983−'<code>%c</code>' (inserts an <code>int</code> as a character).
4051+'<code>%c</code>' (inserts an <code>int</code> as a byte).
39844052 </li>
39854053
39864054 </ul>
@@ -3989,7 +4057,7 @@ The conversion specifiers can only be · 2 unmodified lines
39894057
39904058
39914059 <hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p>
3992−<span class="apii">[-0, +1, <em>-</em>]</span>
4060+<span class="apii">[-0, +1, &ndash;]</span>
39934061 <pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>
39944062
39954063 <p>
@@ -4000,7 +4068,7 @@ Pushes a number with value <code>n</code> onto the stack. · 4 unmodified lines
40004068
40014069
40024070 <hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p>
4003−<span class="apii">[-0, +1, <em>-</em>]</span>
4071+<span class="apii">[-0, +1, &ndash;]</span>
40044072 <pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>
40054073
40064074 <p>
@@ -4027,7 +4095,7 @@ light userdata with the same C&nbsp;address. · 20 unmodified lines
40274095 <p>
40284096 This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>,
40294097 but can be used only when <code>s</code> is a literal string.
4030−In these cases, it automatically provides the string length.
4098+It automatically provides the string length.
40314099
40324100
40334101
@@ -4055,7 +4123,7 @@ Returns a pointer to the internal copy of the string. · 21 unmodified lines
40554123
40564124
40574125 <hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p>
4058−<span class="apii">[-0, +1, <em>-</em>]</span>
4126+<span class="apii">[-0, +1, &ndash;]</span>
40594127 <pre>void lua_pushnil (lua_State *L);</pre>
40604128
40614129 <p>
@@ -4066,7 +4134,7 @@ Pushes a nil value onto the stack. · 4 unmodified lines
40664134
40674135
40684136 <hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p>
4069−<span class="apii">[-0, +1, <em>-</em>]</span>
4137+<span class="apii">[-0, +1, &ndash;]</span>
40704138 <pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>
40714139
40724140 <p>
@@ -4100,7 +4168,7 @@ If <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL · 27 unmodified lines
41004168
41014169
41024170 <hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p>
4103−<span class="apii">[-0, +1, <em>-</em>]</span>
4171+<span class="apii">[-0, +1, &ndash;]</span>
41044172 <pre>int lua_pushthread (lua_State *L);</pre>
41054173
41064174 <p>
@@ -4112,7 +4180,7 @@ Returns 1 if this thread is the main thread of its state. · 5 unmodified lines
41124180
41134181
41144182 <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p>
4115−<span class="apii">[-0, +1, <em>-</em>]</span>
4183+<span class="apii">[-0, +1, &ndash;]</span>
41164184 <pre>void lua_pushvalue (lua_State *L, int index);</pre>
41174185
41184186 <p>
@@ -4138,7 +4206,7 @@ instead of a variable number of arguments. · 19 unmodified lines
41384206
41394207
41404208 <hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p>
4141−<span class="apii">[-0, +0, <em>-</em>]</span>
4209+<span class="apii">[-0, +0, &ndash;]</span>
41424210 <pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>
41434211
41444212 <p>
@@ -4153,7 +4221,7 @@ Also returns&nbsp;0 if any of the indices are non valid. · 8 unmodified lines
41534221
41544222
41554223 <hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p>
4156−<span class="apii">[-1, +1, <em>-</em>]</span>
4224+<span class="apii">[-1, +1, &ndash;]</span>
41574225 <pre>void lua_rawget (lua_State *L, int index);</pre>
41584226
41594227 <p>
@@ -4165,7 +4233,7 @@ Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw · 5 unmodified lines
41654233
41664234
41674235 <hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p>
4168−<span class="apii">[-0, +1, <em>-</em>]</span>
4236+<span class="apii">[-0, +1, &ndash;]</span>
41694237 <pre>void lua_rawgeti (lua_State *L, int index, int n);</pre>
41704238
41714239 <p>
@@ -4178,8 +4246,23 @@ that is, it does not invoke metamethods. · 6 unmodified lines
41784246
41794247
41804248
4249+<hr><h3><a name="lua_rawgetp"><code>lua_rawgetp</code></a></h3><p>
4250+<span class="apii">[-0, +1, &ndash;]</span>
4251+<pre>void lua_rawgetp (lua_State *L, int index, const void *p);</pre>
4252+
4253+<p>
4254+Pushes onto the stack the value <code>t[k]</code>,
4255+where <code>t</code> is the table at the given valid index and
4256+<code>k</code> is the pointer <code>p</code> represented as a light userdata.
4257+The access is raw;
4258+that is, it does not invoke metamethods.
4259+
4260+
4261+
4262+
4263+
41814264 <hr><h3><a name="lua_rawlen"><code>lua_rawlen</code></a></h3><p>
4182−<span class="apii">[-0, +0, <em>-</em>]</span>
4265+<span class="apii">[-0, +0, &ndash;]</span>
41834266 <pre>size_t lua_rawlen (lua_State *L, int index);</pre>
41844267
41854268 <p>
@@ -4226,6 +4309,26 @@ that is, it does not invoke metamethods. · 40 unmodified lines
42264309
42274310
42284311
4312+<hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p>
4313+<span class="apii">[-1, +0, <em>m</em>]</span>
4314+<pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre>
4315+
4316+<p>
4317+Does the equivalent of <code>t[k] = v</code>,
4318+where <code>t</code> is the table at the given valid index,
4319+<code>k</code> is the pointer <code>p</code> represented as a light userdata,
4320+and <code>v</code> is the value at the top of the stack.
4321+
4322+
4323+<p>
4324+This function pops the value from the stack.
4325+The assignment is raw;
4326+that is, it does not invoke metamethods.
4327+
4328+
4329+
4330+
4331+
42294332 <hr><h3><a name="lua_Reader"><code>lua_Reader</code></a></h3>
42304333 <pre>typedef const char * (*lua_Reader) (lua_State *L,
42314334 void *data,
@@ -4250,9 +4353,7 @@ The reader function may return pieces of any size greater than zero. · 18 unmodified lines
42504353
42514354 <hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p>
42524355 <span class="apii">[-0, +0, <em>e</em>]</span>
4253−<pre>void lua_register (lua_State *L,
4254− const char *name,
4255− lua_CFunction f);</pre>
4356+<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>
42564357
42574358 <p>
42584359 Sets the C function <code>f</code> as the new value of global <code>name</code>.
@@ -4267,7 +4368,7 @@ It is defined as a macro: · 8 unmodified lines
42674368
42684369
42694370 <hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p>
4270−<span class="apii">[-1, +0, <em>-</em>]</span>
4371+<span class="apii">[-1, +0, &ndash;]</span>
42714372 <pre>void lua_remove (lua_State *L, int index);</pre>
42724373
42734374 <p>
@@ -4281,7 +4382,7 @@ because a pseudo-index is not an actual stack position. · 7 unmodified lines
42814382
42824383
42834384 <hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p>
4284−<span class="apii">[-1, +0, <em>-</em>]</span>
4385+<span class="apii">[-1, +0, &ndash;]</span>
42854386 <pre>void lua_replace (lua_State *L, int index);</pre>
42864387
42874388 <p>
@@ -4295,8 +4396,8 @@ and then pops the top element. · 7 unmodified lines
42954396
42964397
42974398 <hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p>
4298−<span class="apii">[-?, +?, <em>-</em>]</span>
4299−<pre>int lua_resume (lua_State *L, int narg);</pre>
4399+<span class="apii">[-?, +?, &ndash;]</span>
4400+<pre>int lua_resume (lua_State *L, lua_State *from, int narg);</pre>
43004401
43014402 <p>
43024403 Starts and resumes a coroutine in a given thread.
@@ -4330,11 +4431,17 @@ be passed as results from <code>yield</code>, · 27 unmodified lines
43304431 and then call <a href="#lua_resume"><code>lua_resume</code></a>.
43314432
43324433
4434+<p>
4435+The parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.
4436+If there is no such coroutine,
4437+this parameter can be <code>NULL</code>.
4438+
4439+
43334440
43344441
43354442
43364443 <hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p>
4337−<span class="apii">[-0, +0, <em>-</em>]</span>
4444+<span class="apii">[-0, +0, &ndash;]</span>
43384445 <pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>
43394446
43404447 <p>
@@ -4371,14 +4478,13 @@ for the "newindex" event (see <a href="#2.4">&sect;2.4</a>). · 30 unmodified lines
43714478 <p>
43724479 Pops a value from the stack and
43734480 sets it as the new value of global <code>name</code>.
4374−It is defined as a macro.
43754481
43764482
43774483
43784484
43794485
43804486 <hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p>
4381−<span class="apii">[-1, +0, <em>-</em>]</span>
4487+<span class="apii">[-1, +0, &ndash;]</span>
43824488 <pre>void lua_setmetatable (lua_State *L, int index);</pre>
43834489
43844490 <p>
@@ -4411,7 +4517,7 @@ for the "newindex" event (see <a href="#2.4">&sect;2.4</a>). · 26 unmodified lines
44114517
44124518
44134519 <hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p>
4414−<span class="apii">[-?, +?, <em>-</em>]</span>
4520+<span class="apii">[-?, +?, &ndash;]</span>
44154521 <pre>void lua_settop (lua_State *L, int index);</pre>
44164522
44174523 <p>
@@ -4426,7 +4532,7 @@ If <code>index</code> is&nbsp;0, then all stack elements are removed. · 8 unmodified lines
44264532
44274533
44284534 <hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p>
4429−<span class="apii">[-1, +0, <em>-</em>]</span>
4535+<span class="apii">[-1, +0, &ndash;]</span>
44304536 <pre>void lua_setuservalue (lua_State *L, int index);</pre>
44314537
44324538 <p>
@@ -4457,7 +4563,7 @@ which creates a Lua state from scratch. · 24 unmodified lines
44574563
44584564
44594565 <hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p>
4460−<span class="apii">[-0, +0, <em>-</em>]</span>
4566+<span class="apii">[-0, +0, &ndash;]</span>
44614567 <pre>int lua_status (lua_State *L);</pre>
44624568
44634569 <p>
@@ -4482,7 +4588,7 @@ You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> · 18 unmodified lines
44824588
44834589
44844590 <hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p>
4485−<span class="apii">[-0, +0, <em>-</em>]</span>
4591+<span class="apii">[-0, +0, &ndash;]</span>
44864592 <pre>int lua_toboolean (lua_State *L, int index);</pre>
44874593
44884594 <p>
@@ -4501,7 +4607,7 @@ use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's · 12 unmodified lines
45014607
45024608
45034609 <hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p>
4504−<span class="apii">[-0, +0, <em>-</em>]</span>
4610+<span class="apii">[-0, +0, &ndash;]</span>
45054611 <pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>
45064612
45074613 <p>
@@ -4514,18 +4620,18 @@ otherwise, returns <code>NULL</code>. · 6 unmodified lines
45144620
45154621
45164622 <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p>
4517−<span class="apii">[-0, +0, <em>-</em>]</span>
4623+<span class="apii">[-0, +0, &ndash;]</span>
45184624 <pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>
45194625
45204626 <p>
4521−A macro equivalent to <code>lua_tointegerx(L, index, NULL)</code>.
4627+Equivalent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>.
45224628
45234629
45244630
45254631
45264632
45274633 <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p>
4528−<span class="apii">[-0, +0, <em>-</em>]</span>
4634+<span class="apii">[-0, +0, &ndash;]</span>
45294635 <pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>
45304636
45314637 <p>
@@ -4533,7 +4639,7 @@ Converts the Lua value at the given acceptable index · 1 unmodified line
45334639 to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>.
45344640 The Lua value must be a number or a string convertible to a number
45354641 (see <a href="#3.4.2">&sect;3.4.2</a>);
4536−otherwise, <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> returns&nbsp;0.
4642+otherwise, <code>lua_tointegerx</code> returns&nbsp;0.
45374643
45384644
45394645 <p>
@@ -4542,7 +4648,7 @@ it is truncated in some non-specified way. · 2 unmodified lines
45424648
45434649
45444650 <p>
4545−If <code>isnum</code> is different from <code>NULL</code>,
4651+If <code>isnum</code> is not <code>NULL</code>,
45464652 its referent is assigned a boolean value that
45474653 indicates whether the operation succeeded.
45484654
@@ -4561,20 +4667,20 @@ it also sets <code>*len</code> with the string length. · 12 unmodified lines
45614667 The Lua value must be a string or a number;
45624668 otherwise, the function returns <code>NULL</code>.
45634669 If the value is a number,
4564−then <a href="#lua_tolstring"><code>lua_tolstring</code></a> also
4670+then <code>lua_tolstring</code> also
45654671 <em>changes the actual value in the stack to a string</em>.
45664672 (This change confuses <a href="#lua_next"><code>lua_next</code></a>
4567−when <a href="#lua_tolstring"><code>lua_tolstring</code></a> is applied to keys during a table traversal.)
4673+when <code>lua_tolstring</code> is applied to keys during a table traversal.)
45684674
45694675
45704676 <p>
4571−<a href="#lua_tolstring"><code>lua_tolstring</code></a> returns a fully aligned pointer
4677+<code>lua_tolstring</code> returns a fully aligned pointer
45724678 to a string inside the Lua state.
45734679 This string always has a zero ('<code>\0</code>')
45744680 after its last character (as in&nbsp;C),
45754681 but can contain other zeros in its body.
45764682 Because Lua has garbage collection,
4577−there is no guarantee that the pointer returned by <a href="#lua_tolstring"><code>lua_tolstring</code></a>
4683+there is no guarantee that the pointer returned by <code>lua_tolstring</code>
45784684 will be valid after the corresponding value is removed from the stack.
45794685
45804686
@@ -4582,18 +4688,18 @@ will be valid after the corresponding value is removed from the stack. · 1 unmodified line
45824688
45834689
45844690 <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p>
4585−<span class="apii">[-0, +0, <em>-</em>]</span>
4691+<span class="apii">[-0, +0, &ndash;]</span>
45864692 <pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>
45874693
45884694 <p>
4589−A macro equivalent to <code>lua_tonumberx(L, index, NULL)</code>.
4695+Equivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>.
45904696
45914697
45924698
45934699
45944700
45954701 <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p>
4596−<span class="apii">[-0, +0, <em>-</em>]</span>
4702+<span class="apii">[-0, +0, &ndash;]</span>
45974703 <pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>
45984704
45994705 <p>
@@ -4605,7 +4711,7 @@ otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns&nbsp; · 5 unmodified lines
46054711
46064712
46074713 <p>
4608−If <code>isnum</code> is different from <code>NULL</code>,
4714+If <code>isnum</code> is not <code>NULL</code>,
46094715 its referent is assigned a boolean value that
46104716 indicates whether the operation succeeded.
46114717
@@ -4614,14 +4720,14 @@ indicates whether the operation succeeded. · 2 unmodified lines
46144720
46154721
46164722 <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p>
4617−<span class="apii">[-0, +0, <em>-</em>]</span>
4723+<span class="apii">[-0, +0, &ndash;]</span>
46184724 <pre>const void *lua_topointer (lua_State *L, int index);</pre>
46194725
46204726 <p>
46214727 Converts the value at the given acceptable index to a generic
46224728 C&nbsp;pointer (<code>void*</code>).
46234729 The value can be a userdata, a table, a thread, or a function;
4624−otherwise, <a href="#lua_topointer"><code>lua_topointer</code></a> returns <code>NULL</code>.
4730+otherwise, <code>lua_topointer</code> returns <code>NULL</code>.
46254731 Different objects will give different pointers.
46264732 There is no way to convert the pointer back to its original value.
46274733
@@ -4645,7 +4751,7 @@ Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code · 17 unmodified lines
46454751
46464752
46474753 <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p>
4648−<span class="apii">[-0, +0, <em>-</em>]</span>
4754+<span class="apii">[-0, +0, &ndash;]</span>
46494755 <pre>lua_State *lua_tothread (lua_State *L, int index);</pre>
46504756
46514757 <p>
@@ -4659,18 +4765,18 @@ otherwise, the function returns <code>NULL</code>. · 7 unmodified lines
46594765
46604766
46614767 <hr><h3><a name="lua_tounsigned"><code>lua_tounsigned</code></a></h3><p>
4662−<span class="apii">[-0, +0, <em>-</em>]</span>
4768+<span class="apii">[-0, +0, &ndash;]</span>
46634769 <pre>lua_Unsigned lua_tounsigned (lua_State *L, int index);</pre>
46644770
46654771 <p>
4666−A macro equivalent to <code>lua_tounsignedx(L, index, NULL)</code>.
4772+Equivalent to <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> with <code>isnum</code> equal to <code>NULL</code>.
46674773
46684774
46694775
46704776
46714777
46724778 <hr><h3><a name="lua_tounsignedx"><code>lua_tounsignedx</code></a></h3><p>
4673−<span class="apii">[-0, +0, <em>-</em>]</span>
4779+<span class="apii">[-0, +0, &ndash;]</span>
46744780 <pre>lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);</pre>
46754781
46764782 <p>
@@ -4678,7 +4784,7 @@ Converts the Lua value at the given acceptable index · 1 unmodified line
46784784 to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
46794785 The Lua value must be a number or a string convertible to a number
46804786 (see <a href="#3.4.2">&sect;3.4.2</a>);
4681−otherwise, <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> returns&nbsp;0.
4787+otherwise, <code>lua_tounsignedx</code> returns&nbsp;0.
46824788
46834789
46844790 <p>
@@ -4690,7 +4796,7 @@ one more than the maximum representable value. · 5 unmodified lines
46904796
46914797
46924798 <p>
4693−If <code>isnum</code> is different from <code>NULL</code>,
4799+If <code>isnum</code> is not <code>NULL</code>,
46944800 its referent is assigned a boolean value that
46954801 indicates whether the operation succeeded.
46964802
@@ -4699,7 +4805,7 @@ indicates whether the operation succeeded. · 2 unmodified lines
46994805
47004806
47014807 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
4702−<span class="apii">[-0, +0, <em>-</em>]</span>
4808+<span class="apii">[-0, +0, &ndash;]</span>
47034809 <pre>void *lua_touserdata (lua_State *L, int index);</pre>
47044810
47054811 <p>
@@ -4714,13 +4820,12 @@ Otherwise, returns <code>NULL</code>. · 8 unmodified lines
47144820
47154821
47164822 <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p>
4717−<span class="apii">[-0, +0, <em>-</em>]</span>
4823+<span class="apii">[-0, +0, &ndash;]</span>
47184824 <pre>int lua_type (lua_State *L, int index);</pre>
47194825
47204826 <p>
47214827 Returns the type of the value in the given acceptable index,
4722−or <code>LUA_TNONE</code> for a non-valid index
4723−(that is, an index to an "empty" stack position).
4828+or <code>LUA_TNONE</code> for a non-valid index.
47244829 The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following constants
47254830 defined in <code>lua.h</code>:
47264831 <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>,
@@ -4739,7 +4844,7 @@ and · 12 unmodified lines
47394844
47404845
47414846 <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p>
4742−<span class="apii">[-0, +0, <em>-</em>]</span>
4847+<span class="apii">[-0, +0, &ndash;]</span>
47434848 <pre>const char *lua_typename (lua_State *L, int tp);</pre>
47444849
47454850 <p>
@@ -4807,11 +4912,11 @@ calling the writer again. · 61 unmodified lines
48074912
48084913
48094914 <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p>
4810−<span class="apii">[-?, +?, <em>-</em>]</span>
4915+<span class="apii">[-?, +?, &ndash;]</span>
48114916 <pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>
48124917
48134918 <p>
4814−Exchange values between different threads of the same global state.
4919+Exchange values between different threads of the same state.
48154920
48164921
48174922 <p>
@@ -4823,7 +4928,7 @@ and pushes them onto the stack <code>to</code>. · 5 unmodified lines
48234928
48244929
48254930 <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p>
4826−<span class="apii">[-?, +?, <em>-</em>]</span>
4931+<span class="apii">[-?, +?, &ndash;]</span>
48274932 <pre>int lua_yield (lua_State *L, int nresults);</pre>
48284933
48294934 <p>
@@ -4838,7 +4943,7 @@ the function calling <code>lua_yield</code>. · 8 unmodified lines
48384943
48394944
48404945 <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p>
4841−<span class="apii">[-?, +?, <em>-</em>]</span>
4946+<span class="apii">[-?, +?, &ndash;]</span>
48424947 <pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);</pre>
48434948
48444949 <p>
@@ -4850,7 +4955,7 @@ This function should only be called as the · 5 unmodified lines
48504955 return expression of a C&nbsp;function, as follows:
48514956
48524957 <pre>
4853− return lua_yield (L, nresults, i, k);
4958+ return lua_yieldk (L, n, i, k);
48544959 </pre><p>
48554960 When a C&nbsp;function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a> in that way,
48564961 the running coroutine suspends its execution,
@@ -4928,7 +5033,7 @@ If <code>source</code> starts with a '<code>@</code>', · 71 unmodified lines
49285033 it means that the function was defined in a file where
49295034 the file name follows the '<code>@</code>'.
49305035 If <code>source</code> starts with a '<code>=</code>',
4931−the rest of it should describe the source in a user-dependent manner.
5036+the remainder of its contents describe the source in a user-dependent manner.
49325037 Otherwise,
49335038 the function was defined in a string where
49345039 <code>source</code> is that string.
@@ -4994,7 +5099,7 @@ the number of fixed parameters of the function · 59 unmodified lines
49945099 </li>
49955100
49965101 <li><b><code>isvararg</code>: </b>
4997−whether the function is a vararg function
5102+true if the function is a vararg function
49985103 (always true for C&nbsp;functions).
49995104 </li>
50005105
@@ -5004,7 +5109,7 @@ whether the function is a vararg function · 3 unmodified lines
50045109
50055110
50065111 <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p>
5007−<span class="apii">[-0, +0, <em>-</em>]</span>
5112+<span class="apii">[-0, +0, &ndash;]</span>
50085113 <pre>lua_Hook lua_gethook (lua_State *L);</pre>
50095114
50105115 <p>
@@ -5015,7 +5120,7 @@ Returns the current hook function. · 4 unmodified lines
50155120
50165121
50175122 <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p>
5018−<span class="apii">[-0, +0, <em>-</em>]</span>
5123+<span class="apii">[-0, +0, &ndash;]</span>
50195124 <pre>int lua_gethookcount (lua_State *L);</pre>
50205125
50215126 <p>
@@ -5026,7 +5131,7 @@ Returns the current hook count. · 4 unmodified lines
50265131
50275132
50285133 <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p>
5029−<span class="apii">[-0, +0, <em>-</em>]</span>
5134+<span class="apii">[-0, +0, &ndash;]</span>
50305135 <pre>int lua_gethookmask (lua_State *L);</pre>
50315136
50325137 <p>
@@ -5115,7 +5220,7 @@ This function returns 0 on error · 82 unmodified lines
51155220
51165221
51175222 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p>
5118−<span class="apii">[-0, +(0|1), <em>-</em>]</span>
5223+<span class="apii">[-0, +(0|1), &ndash;]</span>
51195224 <pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>
51205225
51215226 <p>
@@ -5156,7 +5261,7 @@ the number of active local variables. · 34 unmodified lines
51565261
51575262
51585263 <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p>
5159−<span class="apii">[-0, +0, <em>-</em>]</span>
5264+<span class="apii">[-0, +0, &ndash;]</span>
51605265 <pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>
51615266
51625267 <p>
@@ -5179,7 +5284,7 @@ it returns 0. · 16 unmodified lines
51795284
51805285
51815286 <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p>
5182−<span class="apii">[-0, +(0|1), <em>-</em>]</span>
5287+<span class="apii">[-0, +(0|1), &ndash;]</span>
51835288 <pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>
51845289
51855290 <p>
@@ -5241,7 +5346,7 @@ this execution occurs without any calls to hooks. · 55 unmodified lines
52415346
52425347
52435348 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p>
5244−<span class="apii">[-0, +0, <em>-</em>]</span>
5349+<span class="apii">[-0, +0, &ndash;]</span>
52455350 <pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>
52465351
52475352 <p>
@@ -5294,7 +5399,7 @@ A hook is disabled by setting <code>mask</code> to zero. · 46 unmodified lines
52945399
52955400
52965401 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p>
5297−<span class="apii">[-(0|1), +0, <em>-</em>]</span>
5402+<span class="apii">[-(0|1), +0, &ndash;]</span>
52985403 <pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre>
52995404
53005405 <p>
@@ -5316,7 +5421,7 @@ the number of active local variables. · 15 unmodified lines
53165421
53175422
53185423 <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p>
5319−<span class="apii">[-(0|1), +0, <em>-</em>]</span>
5424+<span class="apii">[-(0|1), +0, &ndash;]</span>
53205425 <pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>
53215426
53225427 <p>
@@ -5337,7 +5442,7 @@ when the index is greater than the number of upvalues. · 14 unmodified lines
53375442
53385443
53395444 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p>
5340−<span class="apii">[-0, +0, <em>-</em>]</span>
5445+<span class="apii">[-0, +0, &ndash;]</span>
53415446 <pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>
53425447
53435448 <p>
@@ -5386,7 +5491,7 @@ common tasks. · 42 unmodified lines
53865491
53875492
53885493 <p>
5389−All functions from the auxiliary library
5494+All functions and types from the auxiliary library
53905495 are defined in header file <code>lauxlib.h</code> and
53915496 have a prefix <code>luaL_</code>.
53925497
@@ -5395,6 +5500,8 @@ have a prefix <code>luaL_</code>. · 2 unmodified lines
53955500 All functions in the auxiliary library are built on
53965501 top of the basic API,
53975502 and so they provide nothing that cannot be done with that API.
5503+Nevertheless, the use of the auxiliary library ensures
5504+more consistency to your code.
53985505
53995506
54005507 <p>
@@ -5432,7 +5539,7 @@ in alphabetical order. · 31 unmodified lines
54325539 <pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>
54335540
54345541 <p>
5435−Adds the character <code>c</code> to the buffer <code>B</code>
5542+Adds the byte <code>c</code> to the buffer <code>B</code>
54365543 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
54375544
54385545
@@ -5474,7 +5581,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>). · 35 unmodified lines
54745581 Adds the zero-terminated string pointed to by <code>s</code>
54755582 to the buffer <code>B</code>
54765583 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
5477−The string should not contain embedded zeros.
5584+The string cannot contain embedded zeros.
54785585
54795586
54805587
@@ -5509,12 +5616,8 @@ which is the value to be added to the buffer. · 28 unmodified lines
55095616
55105617 <p>
55115618 Checks whether <code>cond</code> is true.
5512−If not, raises an error with the following message,
5513−where <code>func</code> is retrieved from the call stack:
5619+If not, raises an error with a standard message.
55145620
5515−<pre>
5516− bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
5517−</pre>
55185621
55195622
55205623
@@ -5524,12 +5627,9 @@ where <code>func</code> is retrieved from the call stack: · 3 unmodified lines
55245627 <pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre>
55255628
55265629 <p>
5527−Raises an error with the following message,
5528−where <code>func</code> is retrieved from the call stack:
5630+Raises an error with a standard message
5631+that includes <code>extramsg</code> as a comment.
55295632
5530−<pre>
5531− bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
5532−</pre>
55335633
55345634 <p>
55355635 This function never returns,
@@ -5553,17 +5653,17 @@ Its pattern of use is as follows: · 17 unmodified lines
55535653
55545654 <ul>
55555655
5556−<li>First you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li>
5656+<li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li>
55575657
5558−<li>Then you initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>
5658+<li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>
55595659
55605660 <li>
5561−Then you add string pieces to the buffer calling any of
5661+Then add string pieces to the buffer calling any of
55625662 the <code>luaL_add*</code> functions.
55635663 </li>
55645664
55655665 <li>
5566−You finish by calling <code>luaL_pushresult(&amp;b)</code>.
5666+Finish by calling <code>luaL_pushresult(&amp;b)</code>.
55675667 This call leaves the final string on the top of the stack.
55685668 </li>
55695669
@@ -5575,15 +5675,15 @@ you can use the buffer like this: · 5 unmodified lines
55755675
55765676 <ul>
55775677
5578−<li>First you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li>
5678+<li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li>
55795679
5580−<li>Then you initialize it and preallocate a space of
5680+<li>Then initialize it and preallocate a space of
55815681 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>
55825682
5583−<li>Then you copy the string into that space.</li>
5683+<li>Then copy the string into that space.</li>
55845684
55855685 <li>
5586−You finish by calling <code>luaL_pushresult(&amp;b, sz)</code>,
5686+Finish by calling <code>luaL_pushresult(&amp;b, sz)</code>,
55875687 where <code>sz</code> is the total size of the resulting string
55885688 copied into that space.
55895689 </li>
@@ -5611,7 +5711,7 @@ plus the final string on its top. · 21 unmodified lines
56115711
56125712
56135713 <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p>
5614−<span class="apii">[-0, +0, <em>-</em>]</span>
5714+<span class="apii">[-0, +0, &ndash;]</span>
56155715 <pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>
56165716
56175717 <p>
@@ -5647,7 +5747,7 @@ Calls a metamethod. · 29 unmodified lines
56475747 <p>
56485748 If the object at index <code>obj</code> has a metatable and this
56495749 metatable has a field <code>e</code>,
5650−this function calls this field and passes the object as its only argument.
5750+this function calls this field passing the object as its only argument.
56515751 In this case this function returns true and pushes onto the
56525752 stack the value returned by the call.
56535753 If there is no metatable or no metamethod,
@@ -5755,7 +5855,7 @@ if the string cannot be found. · 101 unmodified lines
57555855 <p>
57565856 If <code>def</code> is not <code>NULL</code>,
57575857 the function uses <code>def</code> as a default value when
5758−there is no argument <code>narg</code> or if this argument is <b>nil</b>.
5858+there is no argument <code>narg</code> or when this argument is <b>nil</b>.
57595859
57605860
57615861 <p>
@@ -5836,7 +5936,7 @@ and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</co · 74 unmodified lines
58365936
58375937
58385938 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
5839−<span class="apii">[-0, +0, <em>-</em>]</span>
5939+<span class="apii">[-0, +0, &ndash;]</span>
58405940 <pre>void luaL_checkversion (lua_State *L);</pre>
58415941
58425942 <p>
@@ -5870,7 +5970,7 @@ or true in case of errors. · 27 unmodified lines
58705970
58715971
58725972 <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p>
5873−<span class="apii">[-0, +?, <em>-</em>]</span>
5973+<span class="apii">[-0, +?, &ndash;]</span>
58745974 <pre>int luaL_dostring (lua_State *L, const char *str);</pre>
58755975
58765976 <p>
@@ -5952,7 +6052,7 @@ returns false and pushes nothing. · 75 unmodified lines
59526052
59536053
59546054 <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p>
5955−<span class="apii">[-0, +1, <em>-</em>]</span>
6055+<span class="apii">[-0, +1, &ndash;]</span>
59566056 <pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre>
59576057
59586058 <p>
@@ -6012,7 +6112,7 @@ Raises an error if the result of the operation is not a number. · 53 unmodified lines
60126112
60136113
60146114 <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p>
6015−<span class="apii">[-0, +1, <em>-</em>]</span>
6115+<span class="apii">[-0, +1, &ndash;]</span>
60166116 <pre>int luaL_loadbuffer (lua_State *L,
60176117 const char *buff,
60186118 size_t sz,
@@ -6035,7 +6135,16 @@ used for debug information and error messages. · 16 unmodified lines
60356135
60366136 <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p>
60376137 <span class="apii">[-0, +1, <em>m</em>]</span>
6038−<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>
6138+<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre><p>
6139+Equivalent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>.
6140+
6141+
6142+
6143+
6144+<hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p>
6145+<span class="apii">[-0, +1, <em>m</em>]</span>
6146+<pre>int luaL_loadfilex (lua_State *L, const char *filename,
6147+ const char *mode);</pre>
60396148
60406149 <p>
60416150 Loads a file as a Lua chunk.
@@ -6046,10 +6155,16 @@ then it loads from the standard input. · 4 unmodified lines
60466155 The first line in the file is ignored if it starts with a <code>#</code>.
60476156
60486157
6158+<p>
6159+The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>,
6160+with the addition that
6161+a <code>NULL</code> value is equivalent to the string "<code>bt</code>".
6162+
6163+
60496164 <p>
60506165 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>,
60516166 but it has an extra error code <a name="pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a>
6052−if it cannot open/read the file.
6167+if it cannot open/read the file or the file has a wrong mode.
60536168
60546169
60556170 <p>
@@ -6061,7 +6176,7 @@ it does not run it. · 5 unmodified lines
60616176
60626177
60636178 <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p>
6064−<span class="apii">[-0, +1, <em>-</em>]</span>
6179+<span class="apii">[-0, +1, &ndash;]</span>
60656180 <pre>int luaL_loadstring (lua_State *L, const char *s);</pre>
60666181
60676182 <p>
@@ -6141,7 +6256,7 @@ with <code>tname</code> in the registry. · 73 unmodified lines
61416256
61426257
61436258 <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p>
6144−<span class="apii">[-0, +0, <em>-</em>]</span>
6259+<span class="apii">[-0, +0, &ndash;]</span>
61456260 <pre>lua_State *luaL_newstate (void);</pre>
61466261
61476262 <p>
@@ -6434,7 +6549,7 @@ These values are popped from the stack after the registration. · 286 unmodified lines
64346549
64356550
64366551 <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
6437−<span class="apii">[-0, +0, <em>-</em>]</span>
6552+<span class="apii">[-0, +0, &ndash;]</span>
64386553 <pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>
64396554
64406555 <p>
@@ -6499,7 +6614,7 @@ to start the traceback. · 58 unmodified lines
64996614
65006615
65016616 <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p>
6502−<span class="apii">[-0, +0, <em>-</em>]</span>
6617+<span class="apii">[-0, +0, &ndash;]</span>
65036618 <pre>const char *luaL_typename (lua_State *L, int index);</pre>
65046619
65056620 <p>
@@ -6510,7 +6625,7 @@ Returns the name of the type of the value at the given index. · 4 unmodified lines
65106625
65116626
65126627 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
6513−<span class="apii">[-0, +0, <em>-</em>]</span>
6628+<span class="apii">[-0, +0, &ndash;]</span>
65146629 <pre>void luaL_unref (lua_State *L, int t, int ref);</pre>
65156630
65166631 <p>
@@ -6575,28 +6690,28 @@ Currently, Lua has the following standard libraries: · 58 unmodified lines
65756690
65766691 <ul>
65776692
6578−<li>basic library;</li>
6693+<li>basic library (<a href="#6.1">&sect;6.1</a>);</li>
65796694
6580−<li>package library;</li>
6695+<li>coroutine library (<a href="#6.2">&sect;6.2</a>);</li>
65816696
6582−<li>coroutine library;</li>
6697+<li>package library (<a href="#6.3">&sect;6.3</a>);</li>
65836698
6584−<li>string manipulation;</li>
6699+<li>string manipulation (<a href="#6.4">&sect;6.4</a>);</li>
65856700
6586−<li>table manipulation;</li>
6701+<li>table manipulation (<a href="#6.5">&sect;6.5</a>);</li>
65876702
6588−<li>mathematical functions (sin, log, etc.);</li>
6703+<li>mathematical functions (<a href="#6.6">&sect;6.6</a>) (sin, log, etc.);</li>
65896704
6590−<li>bitwise operations;</li>
6705+<li>bitwise operations (<a href="#6.7">&sect;6.7</a>);</li>
65916706
6592−<li>input and output;</li>
6707+<li>input and output (<a href="#6.8">&sect;6.8</a>);</li>
65936708
6594−<li>operating system facilities;</li>
6709+<li>operating system facilities (<a href="#6.9">&sect;6.9</a>);</li>
65956710
6596−<li>debug facilities.</li>
6711+<li>debug facilities (<a href="#6.10">&sect;6.10</a>).</li>
65976712
65986713 </ul><p>
6599−Except for the basic and package libraries,
6714+Except for the basic and the package libraries,
66006715 each library provides all its functions as fields of a global table
66016716 or as methods of its objects.
66026717
@@ -6627,7 +6742,7 @@ e.g., by using <a href="#lua_call"><code>lua_call</code></a>. · 24 unmodified lines
66276742 <h2>6.1 &ndash; <a name="6.1">Basic Functions</a></h2>
66286743
66296744 <p>
6630−The basic library provides some core functions to Lua.
6745+The basic library provides core functions to Lua.
66316746 If you do not include this library in your application,
66326747 you should check carefully whether you need to provide
66336748 implementations for some of its facilities.
@@ -6660,13 +6775,13 @@ This is the default option. · 26 unmodified lines
66606775 </li>
66616776
66626777 <li><b>"<code>stop</code>": </b>
6663−stops automatic invocation of the garbage collector.
6664−The collector will run only when explcitly invoked,
6778+stops automatic execution of the garbage collector.
6779+The collector will run only when explicitly invoked,
66656780 until a call to restart it.
66666781 </li>
66676782
66686783 <li><b>"<code>restart</code>": </b>
6669−restarts automatic invocation the garbage collector.
6784+restarts automatic execution of the garbage collector.
66706785 </li>
66716786
66726787 <li><b>"<code>count</code>": </b>
@@ -6709,6 +6824,16 @@ returns a boolean that tells whether the collector is running · 36 unmodified lines
67096824 (i.e., not stopped).
67106825 </li>
67116826
6827+<li><b>"<code>generational</code>": </b>
6828+changes the collector to generational mode.
6829+This is an experimental feature (see <a href="#2.5">&sect;2.5</a>).
6830+</li>
6831+
6832+<li><b>"<code>incremental</code>": </b>
6833+changes the collector to incremental mode.
6834+This is the default mode.
6835+</li>
6836+
67126837 </ul>
67136838
67146839
@@ -6789,7 +6914,7 @@ so that the construction · 74 unmodified lines
67896914 <pre>
67906915 for i,v in ipairs(t) do <em>body</em> end
67916916 </pre><p>
6792−will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middot;&middot;&middot;,
6917+will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
67936918 up to the first integer key absent from the table.
67946919
67956920
@@ -6823,8 +6948,8 @@ If the resulting function has upvalues, · 27 unmodified lines
68236948 the first upvalue is set to the value of the
68246949 global environment or to <code>env</code>,
68256950 if that parameter is given.
6826−(When loading main chunks,
6827−the first upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).)
6951+When loading main chunks,
6952+the first upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).
68286953
68296954
68306955 <p>
@@ -6832,21 +6957,22 @@ the first upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&se · 1 unmodified line
68326957 and debug information (see <a href="#4.9">&sect;4.9</a>).
68336958 When absent,
68346959 it defaults to <code>ld</code>, if <code>ld</code> is a string,
6835−or to "<code>=(load)</code>".
6960+or to "<code>=(load)</code>" otherwise.
68366961
68376962
68386963 <p>
68396964 The string <code>mode</code> controls whether the chunk can be text or binary
68406965 (that is, a precompiled chunk).
6841−A letter '<code>t</code>' in <code>mode</code> allows a text chunk;
6842−a letter '<code>b</code>' allows a binary chunk.
6966+It may be the string "<code>b</code>" (only binary chunks),
6967+"<code>t</code>" (only text chunks),
6968+or "<code>bt</code>" (both binary and text).
68436969 The default is "<code>bt</code>".
68446970
68456971
68466972
68476973
68486974 <p>
6849−<hr><h3><a name="pdf-loadfile"><code>loadfile ([filename])</code></a></h3>
6975+<hr><h3><a name="pdf-loadfile"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>
68506976
68516977
68526978 <p>
@@ -6945,13 +7071,14 @@ In case of any error, <code>pcall</code> returns <b>false</b> plus the error mes · 92 unmodified lines
69457071
69467072 <p>
69477073 <hr><h3><a name="pdf-print"><code>print (&middot;&middot;&middot;)</code></a></h3>
6948−Receives any number of arguments,
7074+Receives any number of arguments
69497075 and prints their values to <code>stdout</code>,
6950−using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings.
7076+using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert each argument to a string.
69517077 <code>print</code> is not intended for formatted output,
69527078 but only as a quick way to show a value,
6953−typically for debugging.
6954−For formatted output, use <a href="#pdf-string.format"><code>string.format</code></a>.
7079+for instance for debugging.
7080+For complete control over the output,
7081+use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>io.write</code></a>.
69557082
69567083
69577084
@@ -6990,7 +7117,7 @@ Returns an integer number. · 32 unmodified lines
69907117 Sets the real value of <code>table[index]</code> to <code>value</code>,
69917118 without invoking any metamethod.
69927119 <code>table</code> must be a table,
6993−<code>index</code> any value different from <b>nil</b>,
7120+<code>index</code> any value different from <b>nil</b> and NaN,
69947121 and <code>value</code> any Lua value.
69957122
69967123
@@ -7035,37 +7162,43 @@ This function returns <code>table</code>. · 38 unmodified lines
70357162
70367163 <p>
70377164 <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3>
7038−Tries to convert its argument to a number.
7039−If the argument is already a number or a string convertible
7040−to a number, then <code>tonumber</code> returns this number;
7165+
7166+
7167+<p>
7168+When called with no <code>base</code>,
7169+<code>tonumber</code> tries to convert its argument to a number.
7170+If the argument is already a number or
7171+a string convertible to a number (see <a href="#3.4.2">&sect;3.4.2</a>),
7172+then <code>tonumber</code> returns this number;
70417173 otherwise, it returns <b>nil</b>.
70427174
70437175
70447176 <p>
7045−An optional argument specifies the base to interpret the numeral.
7177+When called with <code>base</code>,
7178+then <code>e</code> should be a string to be interpreted as
7179+an integer numeral in that base.
70467180 The base may be any integer between 2 and 36, inclusive.
70477181 In bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)
70487182 represents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,
70497183 with '<code>Z</code>' representing 35.
7050−In base 10 (the default),
7051−the numeral is converted following the coercion rules (see <a href="#3.4.2">&sect;3.4.2</a>).
7052−In other bases, only integers are accepted.
7184+If the string <code>e</code> is not a valid numeral in the given base,
7185+the function returns <b>nil</b>.
70537186
70547187
70557188
70567189
70577190 <p>
7058−<hr><h3><a name="pdf-tostring"><code>tostring (e)</code></a></h3>
7059−Receives an argument of any type and
7191+<hr><h3><a name="pdf-tostring"><code>tostring (v)</code></a></h3>
7192+Receives a value of any type and
70607193 converts it to a string in a reasonable format.
7061−For complete control of how numbers are converted,
7062−use <a href="#pdf-string.format"><code>string.format</code></a>.
7194+(For complete control of how numbers are converted,
7195+use <a href="#pdf-string.format"><code>string.format</code></a>.)
70637196
70647197
70657198 <p>
7066−If the metatable of <code>e</code> has a <code>"__tostring"</code> field,
7199+If the metatable of <code>v</code> has a <code>"__tostring"</code> field,
70677200 then <code>tostring</code> calls the corresponding value
7068−with <code>e</code> as argument,
7201+with <code>v</code> as argument,
70697202 and uses the result of the call as its result.
70707203
70717204
@@ -7139,11 +7272,11 @@ an object with type <code>"thread"</code>. · 67 unmodified lines
71397272 Starts or continues the execution of coroutine <code>co</code>.
71407273 The first time you resume a coroutine,
71417274 it starts running its body.
7142−The values <code>val1</code>, &middot;&middot;&middot; are passed
7275+The values <code>val1</code>, ... are passed
71437276 as the arguments to the body function.
71447277 If the coroutine has yielded,
71457278 <code>resume</code> restarts it;
7146−the values <code>val1</code>, &middot;&middot;&middot; are passed
7279+the values <code>val1</code>, ... are passed
71477280 as the results from the yield.
71487281
71497282
@@ -7280,7 +7413,7 @@ final value of <code>package.loaded[modname]</code>. · 130 unmodified lines
72807413 <p>
72817414 If there is any error loading or running the module,
72827415 or if it cannot find any loader for the module,
7283−then <code>require</code> signals an error.
7416+then <code>require</code> raises an error.
72847417
72857418
72867419
@@ -7309,8 +7442,8 @@ Default is '<code>?</code>'.</li> · 22 unmodified lines
73097442 is replaced by the executable's directory.
73107443 Default is '<code>!</code>'.</li>
73117444
7312−<li>The fifth line is a mark to ignore all before it when building the
7313−<code>luaopen_</code> function name.
7445+<li>The fifth line is a mark to ignore all text before it
7446+when building the <code>luaopen_</code> function name.
73147447 Default is '<code>-</code>'.</li>
73157448
73167449 </ul>
@@ -7372,7 +7505,7 @@ available to other dynamically linked libraries. · 55 unmodified lines
73727505 Otherwise,
73737506 it looks for a function <code>funcname</code> inside the library
73747507 and returns this function as a C&nbsp;function.
7375−(So, <code>funcname</code> must follow the protocol (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>)).
7508+(So, <code>funcname</code> must follow the prototype <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
73767509
73777510
73787511 <p>
@@ -7409,7 +7542,7 @@ At start-up, Lua initializes this variable with · 30 unmodified lines
74097542 the value of the environment variable <a name="pdf-LUA_PATH_5_2"><code>LUA_PATH_5_2</code></a> or
74107543 the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or
74117544 with a default path defined in <code>luaconf.h</code>,
7412−if the environment variable is not defined.
7545+if those environment variables are not defined.
74137546 Any "<code>;;</code>" in the value of the environment variable
74147547 is replaced by the default path.
74157548
@@ -7511,7 +7644,7 @@ with each submodule keeping its original open function. · 95 unmodified lines
75117644
75127645
75137646 <p>
7514−All searchers except the first (preload) return as the extra value
7647+All searchers except the first one (preload) return as the extra value
75157648 the file name where the module was found,
75167649 as returned by <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
75177650 The first searcher returns no extra value.
@@ -7520,7 +7653,7 @@ The first searcher returns no extra value. · 2 unmodified lines
75207653
75217654
75227655 <p>
7523−<hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep])</code></a></h3>
7656+<hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3>
75247657
75257658
75267659 <p>
@@ -7528,17 +7661,16 @@ Searches for the given <code>name</code> in the given <code>path</code>. · 1 unmodified line
75287661
75297662
75307663 <p>
7531−A path is string containing a sequence of
7664+A path is a string containing a sequence of
75327665 <em>templates</em> separated by semicolons.
75337666 For each template,
7534−the function changes each interrogation
7535−mark in the template by a copy of <code>name</code>
7667+the function replaces each interrogation mark (if any)
7668+in the template with a copy of <code>name</code>
75367669 wherein all occurrences of <code>sep</code>
75377670 (a dot, by default)
7538−were replaced by the system's directory separator,
7671+were replaced by <code>rep</code>
7672+(the system's directory separator, by default),
75397673 and then tries to open the resulting file name.
7540−If <code>sep</code> is the empty string,
7541−the replacement is not done.
75427674
75437675
75447676 <p>
@@ -7583,7 +7715,7 @@ The string library provides all its functions inside the table · 38 unmodified lines
75837715 It also sets a metatable for strings
75847716 where the <code>__index</code> field points to the <code>string</code> table.
75857717 Therefore, you can use the string functions in object-oriented style.
7586−For instance, <code>string.byte(s, i)</code>
7718+For instance, <code>string.byte(s,i)</code>
75877719 can be written as <code>s:byte(i)</code>.
75887720
75897721
@@ -7594,13 +7726,15 @@ The string library assumes one-byte character encodings. · 4 unmodified lines
75947726 <p>
75957727 <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3>
75967728 Returns the internal numerical codes of the characters <code>s[i]</code>,
7597−<code>s[i+1]</code>, &middot;&middot;&middot;, <code>s[j]</code>.
7729+<code>s[i+1]</code>, ..., <code>s[j]</code>.
75987730 The default value for <code>i</code> is&nbsp;1;
75997731 the default value for <code>j</code> is&nbsp;<code>i</code>.
7732+These indices are corrected
7733+following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>.
76007734
76017735
76027736 <p>
7603−Note that numerical codes are not necessarily portable across platforms.
7737+Numerical codes are not necessarily portable across platforms.
76047738
76057739
76067740
@@ -7614,7 +7748,7 @@ to its corresponding argument. · 7 unmodified lines
76147748
76157749
76167750 <p>
7617−Note that numerical codes are not necessarily portable across platforms.
7751+Numerical codes are not necessarily portable across platforms.
76187752
76197753
76207754
@@ -7709,7 +7843,7 @@ it is converted to one following the same rules of <a href="#pdf-tostring"><code · 88 unmodified lines
77097843 <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3>
77107844 Returns an iterator function that,
77117845 each time it is called,
7712−returns the next captures from <code>pattern</code> over string <code>s</code>.
7846+returns the next captures from <code>pattern</code> over the string <code>s</code>.
77137847 If <code>pattern</code> specifies no captures,
77147848 then the whole match is produced in each call.
77157849
@@ -7737,7 +7871,7 @@ given string into a table: · 21 unmodified lines
77377871 </pre>
77387872
77397873 <p>
7740−For this function, a '<code>^</code>' at the start of a pattern does not
7874+For this function, a caret '<code>^</code>' at the start of a pattern does not
77417875 work as an anchor, as this would prevent the iteration.
77427876
77437877
@@ -7884,6 +8018,17 @@ and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> · 140 unmodified lines
78848018 with length <code>i</code>.
78858019
78868020
8021+<p>
8022+If, after the translation of negative indices,
8023+<code>i</code> is less than zero,
8024+it is corrected to zero.
8025+If <code>j</code> is greater than the string length,
8026+it is corrected to that length.
8027+If, after these corrections,
8028+<code>i</code> is greater than <code>j</code>,
8029+the function returns the empty string.
8030+
8031+
78878032
78888033
78898034 <p>
@@ -8050,7 +8195,7 @@ they were the character '<code>\0</code>'. · 160 unmodified lines
80508195
80518196 <h4>Pattern:</h4><p>
80528197 A <em>pattern</em> is a sequence of pattern items.
8053−A '<code>^</code>' at the beginning of a pattern anchors the match at the
8198+A caret '<code>^</code>' at the beginning of a pattern anchors the match at the
80548199 beginning of the subject string.
80558200 A '<code>$</code>' at the end of a pattern anchors the match at the
80568201 end of the subject string.
@@ -8589,7 +8734,7 @@ result in zero or <code>0xFFFFFFFF</code> (all original bits are shifted out). · 532 unmodified lines
85898734
85908735
85918736 <p>
8592−Returns the bitwise and of its operands.
8737+Returns the bitwise <em>and</em> of its operands.
85938738
85948739
85958740
@@ -8614,7 +8759,7 @@ the following identity holds: · 18 unmodified lines
86148759
86158760
86168761 <p>
8617−Returns the bitwise or of its operands.
8762+Returns the bitwise <em>or</em> of its operands.
86188763
86198764
86208765
@@ -8625,7 +8770,7 @@ Returns the bitwise or of its operands. · 4 unmodified lines
86258770
86268771 <p>
86278772 Returns a boolean signaling
8628−whether the bitwise and of its operands is different from zero.
8773+whether the bitwise <em>and</em> of its operands is different from zero.
86298774
86308775
86318776
@@ -8635,7 +8780,7 @@ whether the bitwise and of its operands is different from zero. · 3 unmodified lines
86358780
86368781
86378782 <p>
8638−Returns the bitwise exclusive or of its operands.
8783+Returns the bitwise <em>exclusive or</em> of its operands.
86398784
86408785
86418786
@@ -8845,7 +8990,7 @@ instead of returning an error code. · 203 unmodified lines
88458990
88468991
88478992 <p>
8848−<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] &middot;&middot;&middot;)</code></a></h3>
8993+<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename &middot;&middot;&middot;])</code></a></h3>
88498994
88508995
88518996 <p>
@@ -8863,6 +9008,11 @@ that is, it iterates over the lines of the default input file. · 11 unmodified lines
88639008 In this case it does not close the file when the loop ends.
88649009
88659010
9011+<p>
9012+In case of errors this function raises the error,
9013+instead of returning an error code.
9014+
9015+
88669016
88679017
88689018 <p>
@@ -9007,15 +9157,20 @@ each time it is called, · 138 unmodified lines
90079157 reads the file according to the given formats.
90089158 When no format is given,
90099159 uses "*l" as a default.
9010−Therefore, the construction
9160+As an example, the construction
90119161
90129162 <pre>
90139163 for c in file:lines(1) do <em>body</em> end
90149164 </pre><p>
90159165 will iterate over all characters of the file,
90169166 starting at the current position.
9017−(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
9018−when the loop ends.)
9167+Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
9168+when the loop ends.
9169+
9170+
9171+<p>
9172+In case of errors this function raises the error,
9173+instead of returning an error code.
90199174
90209175
90219176
@@ -9062,7 +9217,7 @@ returning <b>nil</b> on end of file. · 40 unmodified lines
90629217 </li>
90639218
90649219 <li><b><em>number</em>: </b>
9065−reads a string with up to this number of characters,
9220+reads a string with up to this number of bytes,
90669221 returning <b>nil</b> on end of file.
90679222 If number is zero,
90689223 it reads nothing and returns an empty string,
@@ -9088,9 +9243,9 @@ specified by the string <code>whence</code>, as follows: · 19 unmodified lines
90889243 <li><b>"<code>cur</code>": </b> base is current position;</li>
90899244 <li><b>"<code>end</code>": </b> base is end of file;</li>
90909245 </ul><p>
9091−In case of success, function <code>seek</code> returns the final file position,
9246+In case of success, <code>seek</code> returns the final file position,
90929247 measured in bytes from the beginning of the file.
9093−If this function fails, it returns <b>nil</b>,
9248+If <code>seek</code> fails, it returns <b>nil</b>,
90949249 plus a string describing the error.
90959250
90969251
@@ -9123,8 +9278,8 @@ no buffering; the result of any output operation appears immediately. · 26 unmodified lines
91239278
91249279 <li><b>"<code>full</code>": </b>
91259280 full buffering; output operation is performed only
9126−when the buffer is full (or when you explicitly <code>flush</code> the file
9127−(see <a href="#pdf-io.flush"><code>io.flush</code></a>)).
9281+when the buffer is full or when
9282+you explicitly <code>flush</code> the file (see <a href="#pdf-io.flush"><code>io.flush</code></a>).
91289283 </li>
91299284
91309285 <li><b>"<code>line</code>": </b>
@@ -9146,11 +9301,8 @@ The default is an appropriate size. · 15 unmodified lines
91469301
91479302
91489303 <p>
9149−Writes the value of each of its arguments to
9150−the <code>file</code>.
9304+Writes the value of each of its arguments to <code>file</code>.
91519305 The arguments must be strings or numbers.
9152−To write other values,
9153−use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.format"><code>string.format</code></a> before <code>write</code>.
91549306
91559307
91569308 <p>
@@ -9202,8 +9354,8 @@ then the date is formatted in Coordinated Universal Time. · 45 unmodified lines
92029354 After this optional character,
92039355 if <code>format</code> is the string "<code>*t</code>",
92049356 then <code>date</code> returns a table with the following fields:
9205−<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),
9206−<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),
9357+<code>year</code> (four digits), <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),
9358+<code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59), <code>sec</code> (0&ndash;61),
92079359 <code>wday</code> (weekday, Sunday is&nbsp;1),
92089360 <code>yday</code> (day of the year),
92099361 and <code>isdst</code> (daylight saving flag, a boolean).
@@ -9314,7 +9466,7 @@ or <b>nil</b> if the variable is not defined. · 104 unmodified lines
93149466 Deletes the file (or empty directory, on POSIX systems)
93159467 with the given name.
93169468 If this function fails, it returns <b>nil</b>,
9317−plus a string describing the error.
9469+plus a string describing the error and the error code.
93189470
93199471
93209472
@@ -9326,7 +9478,7 @@ plus a string describing the error. · 5 unmodified lines
93269478 <p>
93279479 Renames file or directory named <code>oldname</code> to <code>newname</code>.
93289480 If this function fails, it returns <b>nil</b>,
9329−plus a string describing the error.
9481+plus a string describing the error and the error code.
93309482
93319483
93329484
@@ -9337,7 +9489,7 @@ plus a string describing the error. · 4 unmodified lines
93379489
93389490 <p>
93399491 Sets the current locale of the program.
9340−<code>locale</code> is a string specifying a locale;
9492+<code>locale</code> is a system-dependent string specifying a locale;
93419493 <code>category</code> is an optional string describing which category to change:
93429494 <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>,
93439495 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;
@@ -9369,8 +9521,12 @@ for the given category. · 25 unmodified lines
93699521 Returns the current time when called without arguments,
93709522 or a time representing the date and time specified by the given table.
93719523 This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,
9372−and may have fields <code>hour</code>, <code>min</code>, <code>sec</code>, and <code>isdst</code>
9373−(for a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function).
9524+and may have fields
9525+<code>hour</code> (default is 12),
9526+<code>min</code> (default is 0),
9527+<code>sec</code> (default is 0),
9528+and <code>isdst</code> (default is <b>nil</b>).
9529+For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function.
93749530
93759531
93769532 <p>
@@ -9380,7 +9536,7 @@ this number counts the number · 3 unmodified lines
93809536 of seconds since some given start time (the "epoch").
93819537 In other systems, the meaning is not specified,
93829538 and the number returned by <code>time</code> can be used only as an argument to
9383−<code>date</code> and <code>difftime</code>.
9539+<a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</code></a>.
93849540
93859541
93869542
@@ -9421,9 +9577,9 @@ which automatically removes the file when the program ends. · 34 unmodified lines
94219577
94229578 <p>
94239579 This library provides
9424−the functionality of the debug interface to Lua programs.
9580+the functionality of the debug interface (<a href="#4.9">&sect;4.9</a>) to Lua programs.
94259581 You should exert care when using this library.
9426−Several of these functions
9582+Several of its functions
94279583 violate basic assumptions about Lua code
94289584 (e.g., that variables local to a function
94299585 cannot be accessed from outside;
@@ -9458,7 +9614,7 @@ so that the caller continues its execution. · 28 unmodified lines
94589614
94599615 <p>
94609616 Note that commands for <code>debug.debug</code> are not lexically nested
9461−within any function, and so have no direct access to local variables.
9617+within any function and so have no direct access to local variables.
94629618
94639619
94649620
@@ -9477,20 +9633,20 @@ and the current hook count · 12 unmodified lines
94779633
94789634
94799635 <p>
9480−<hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] function [, what])</code></a></h3>
9636+<hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>
94819637
94829638
94839639 <p>
94849640 Returns a table with information about a function.
9485−You can give the function directly,
9486−or you can give a number as the value of <code>function</code>,
9487−which means the function running at level <code>function</code> of the call stack
9641+You can give the function directly
9642+or you can give a number as the value of <code>f</code>,
9643+which means the function running at level <code>f</code> of the call stack
94889644 of the given thread:
94899645 level&nbsp;0 is the current function (<code>getinfo</code> itself);
94909646 level&nbsp;1 is the function that called <code>getinfo</code>
94919647 (except for tail calls, which do not count on the stack);
94929648 and so on.
9493−If <code>function</code> is a number larger than the number of active functions,
9649+If <code>f</code> is a number larger than the number of active functions,
94949650 then <code>getinfo</code> returns <b>nil</b>.
94959651
94969652
@@ -9554,11 +9710,11 @@ In that case, <code>getlocal</code> returns only the name of function parameters · 57 unmodified lines
95549710
95559711
95569712 <p>
9557−<hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (object)</code></a></h3>
9713+<hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3>
95589714
95599715
95609716 <p>
9561−Returns the metatable of the given <code>object</code>
9717+Returns the metatable of the given <code>value</code>
95629718 or <b>nil</b> if it does not have a metatable.
95639719
95649720
@@ -9575,12 +9731,12 @@ Returns the registry table (see <a href="#4.5">&sect;4.5</a>). · 10 unmodified lines
95759731
95769732
95779733 <p>
9578−<hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (func, up)</code></a></h3>
9734+<hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3>
95799735
95809736
95819737 <p>
95829738 This function returns the name and the value of the upvalue
9583−with index <code>up</code> of the function <code>func</code>.
9739+with index <code>up</code> of the function <code>f</code>.
95849740 The function returns <b>nil</b> if there is no upvalue with the given index.
95859741
95869742
@@ -9662,24 +9818,24 @@ variable indices and names. · 75 unmodified lines
96629818
96639819
96649820 <p>
9665−<hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (object, table)</code></a></h3>
9821+<hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3>
96669822
96679823
96689824 <p>
9669−Sets the metatable for the given <code>object</code> to the given <code>table</code>
9825+Sets the metatable for the given <code>value</code> to the given <code>table</code>
96709826 (which can be <b>nil</b>).
9671−Returns <code>object</code>.
9827+Returns <code>value</code>.
96729828
96739829
96749830
96759831
96769832 <p>
9677−<hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (func, up, value)</code></a></h3>
9833+<hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3>
96789834
96799835
96809836 <p>
96819837 This function assigns the value <code>value</code> to the upvalue
9682−with index <code>up</code> of the function <code>func</code>.
9838+with index <code>up</code> of the function <code>f</code>.
96839839 The function returns <b>nil</b> if there is no upvalue
96849840 with the given index.
96859841 Otherwise, it returns the name of the upvalue.
@@ -9723,7 +9879,7 @@ to start the traceback · 37 unmodified lines
97239879
97249880
97259881 <p>
9726−<hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (function, n)</code></a></h3>
9882+<hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3>
97279883
97289884
97299885 <p>
@@ -9743,12 +9899,12 @@ will return identical ids for those upvalue indices. · 13 unmodified lines
97439899
97449900
97459901 <p>
9746−<hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (func1, n1, func2, n2)</code></a></h3>
9902+<hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>
97479903
97489904
97499905 <p>
9750−Make the <code>n1</code>-th upvalue of the Lua closure <code>func1</code>
9751−refer to the <code>n2</code>-th upvalue of the Lua closure <code>func2</code>.
9906+Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>
9907+refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.
97529908
97539909
97549910
@@ -9779,6 +9935,7 @@ The options are: · 24 unmodified lines
97799935 <li><b><code>-l <em>mod</em></code>: </b> "requires" <em>mod</em>;</li>
97809936 <li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li>
97819937 <li><b><code>-v</code>: </b> prints version information;</li>
9938+<li><b><code>-E</code>: </b> ignores environment variables;</li>
97829939 <li><b><code>--</code>: </b> stops handling options;</li>
97839940 <li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li>
97849941 </ul><p>
@@ -9791,24 +9948,34 @@ and as <code>lua -</code> otherwise. · 6 unmodified lines
97919948
97929949
97939950 <p>
9794−Before running any argument,
9951+When called without option <code>-E</code>,
97959952 the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_2"><code>LUA_INIT_5_2</code></a>
9796−(or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined).
9797−If its format is <code>@<em>filename</em></code>,
9953+(or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined)
9954+before running any argument.
9955+If the variable content has the format <code>@<em>filename</em></code>,
97989956 then <code>lua</code> executes the file.
97999957 Otherwise, <code>lua</code> executes the string itself.
98009958
98019959
98029960 <p>
9803−All options are handled in order, except <code>-i</code>.
9961+When called with option <code>-E</code>,
9962+besides ignoring <code>LUA_INIT</code>,
9963+the interpreter also resets the values of
9964+<a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><code>package.cpath</code></a>
9965+with the default paths defined in <code>luaconf.h</code>,
9966+in effect ignoring the values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>.
9967+
9968+
9969+<p>
9970+All options are handled in order, except <code>-i</code> and <code>-E</code>.
98049971 For instance, an invocation like
98059972
98069973 <pre>
98079974 $ lua -e'a=1' -e 'print(a)' script.lua
98089975 </pre><p>
9809−will first set <code>a</code> to 1, then print the value of <code>a</code> (which is '<code>1</code>'),
9976+will first set <code>a</code> to 1, then print the value of <code>a</code>,
98109977 and finally run the file <code>script.lua</code> with no arguments.
9811−(Here <code>$</code> is the shell prompt. Your prompt can be different.)
9978+(Here <code>$</code> is the shell prompt. Your prompt may be different.)
98129979
98139980
98149981 <p>
@@ -9835,7 +10002,7 @@ then creates a table · 20 unmodified lines
983510002 [1] = "t1", [2] = "t2" }
983610003 </pre><p>
983710004 and finally runs the file <code>b.lua</code>.
9838−The script is called with <code>arg[1]</code>, <code>arg[2]</code>, &middot;&middot;&middot;
10005+The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ...
983910006 as arguments;
984010007 it can also access these arguments with the vararg expression '<code>...</code>'.
984110008
@@ -9862,29 +10029,8 @@ the interpreter does not report the error. · 20 unmodified lines
986210029 When finishing normally,
986310030 the interpreter closes its main Lua state
986410031 (see <a href="#lua_close"><code>lua_close</code></a>).
9865−The script can avoid this step by terminating
9866−through <a href="#pdf-os.exit"><code>os.exit</code></a>.
9867−
9868−
9869−<p>
9870−If the global variable <a name="pdf-_PROMPT"><code>_PROMPT</code></a> contains a string,
9871−then its value is used as the prompt.
9872−Similarly, if the global variable <a name="pdf-_PROMPT2"><code>_PROMPT2</code></a> contains a string,
9873−its value is used as the secondary prompt
9874−(issued during incomplete statements).
9875−Therefore, both prompts can be changed directly on the command line
9876−or in any Lua programs by assigning to <code>_PROMPT</code>.
9877−See the next example:
9878−
9879−<pre>
9880− $ lua -e"_PROMPT='myprompt&gt; '" -i
9881−</pre><p>
9882−(The outer pair of quotes is for the shell,
9883−the inner pair is for Lua.)
9884−Note the use of <code>-i</code> to enter interactive mode;
9885−otherwise,
9886−the program would just end silently
9887−right after the assignment to <code>_PROMPT</code>.
10032+The script can avoid this step by
10033+calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate.
988810034
988910035
989010036 <p>
@@ -9900,7 +10046,7 @@ as in · 9 unmodified lines
990010046 #!/usr/local/bin/lua
990110047 </pre><p>
990210048 (Of course,
9903−the location of the Lua interpreter can be different in your machine.
10049+the location of the Lua interpreter may be different in your machine.
990410050 If <code>lua</code> is in your <code>PATH</code>,
990510051 then
990610052
@@ -9914,9 +10060,9 @@ is a more portable solution.) · 7 unmodified lines
991410060 <h1>8 &ndash; <a name="8">Incompatibilities with the Previous Version</a></h1>
991510061
991610062 <p>
9917−Here we list the incompatibilities that you can find when moving a program
10063+Here we list the incompatibilities that you may find when moving a program
991810064 from Lua&nbsp;5.1 to Lua&nbsp;5.2.
9919−You can avoid some incompatibilities compiling Lua with
10065+You can avoid some incompatibilities by compiling Lua with
992010066 appropriate options (see file <code>luaconf.h</code>).
992110067 However,
992210068 all these compatibility options will be removed in the next version of Lua.
@@ -9934,7 +10080,7 @@ use the variable <code>_ENV</code> or the function <a href="#pdf-load"><code>loa · 11 unmodified lines
993410080
993510081
993610082 <p>
9937−C functions do not have environments any more.
10083+C functions no longer have environments.
993810084 Use an upvalue with a shared table if you need to keep
993910085 shared state among several C functions.
994010086 (You may use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> to open a C library
@@ -9964,8 +10110,8 @@ Weak tables with weak keys now perform like <em>ephemeron tables</em>. · 23 unmodified lines
996410110 <li>
996510111 The event <em>tail return</em> in debug hooks was removed.
996610112 Instead, tail calls generate a special new event,
9967−<em>tail call</em>, so that the debugger can know there will
9968−not be a corresponding return event.
10113+<em>tail call</em>, so that the debugger can know that
10114+there will not be a corresponding return event.
996910115 </li>
997010116
997110117 <li>
@@ -9985,8 +10131,8 @@ observable difference to the new function. · 13 unmodified lines
998510131
998610132 <li>
998710133 Function <code>module</code> is deprecated.
9988−Modules are not expected to set global variables anymore,
9989−and it is easy to set up a module with regular Lua code.
10134+It is easy to set up a module with regular Lua code.
10135+Modules are not expected to set global variables.
999010136 </li>
999110137
999210138 <li>
@@ -10036,12 +10182,17 @@ So, all functions that load code · 43 unmodified lines
1003610182 (<a href="#pdf-load"><code>load</code></a> and <a href="#pdf-loadfile"><code>loadfile</code></a>)
1003710183 are potentially insecure when loading untrusted binary data.
1003810184 (Actually, those functions were already insecure because
10039−of bugs in the verification algorithm.)
10185+of flaws in the verification algorithm.)
1004010186 When in doubt,
1004110187 use the <code>mode</code> argument in function <a href="#pdf-load"><code>load</code></a>
1004210188 to restrict it to loading textual chunks.
1004310189 </li>
1004410190
10191+<li>
10192+The standard paths in the official distribution may
10193+change between versions.
10194+</li>
10195+
1004510196 </ul>
1004610197
1004710198
@@ -10060,13 +10211,12 @@ You must get the global environment from the registry · 12 unmodified lines
1006010211 Pseudoindex <code>LUA_ENVIRONINDEX</code>
1006110212 and functions <code>lua_getfenv</code>/<code>lua_setfenv</code>
1006210213 were removed,
10063−as C&nbsp;functions do not have environments any more.
10214+as C&nbsp;functions no longer have environments.
1006410215 </li>
1006510216
1006610217 <li>
1006710218 Function <code>luaL_register</code> is deprecated.
10068−Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not
10069−create globals anymore.
10219+Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not create globals.
1007010220 (Modules are not expected to set global variables anymore.)
1007110221 </li>
1007210222
@@ -10081,7 +10231,7 @@ the block is new. · 8 unmodified lines
1008110231
1008210232 <li>
1008310233 Finalizers (<code>__gc</code> metamethods) for userdata are called in the
10084−reverse order that they were marked,
10234+reverse order that they were marked for finalization,
1008510235 not that they were created (see <a href="#2.5.1">&sect;2.5.1</a>).
1008610236 (Most userdata are marked immediately after they are created.)
1008710237 Moreover,
@@ -10202,10 +10352,10 @@ Here is the complete syntax of Lua in extended BNF. · 114 unmodified lines
1020210352 <HR>
1020310353 <SMALL CLASS="footer">
1020410354 Last update:
10205−Fri Jul 8 17:11:02 BRT 2011
10355+Thu Nov 24 11:54:31 BRST 2011
1020610356 </SMALL>
1020710357 <!--
10208−Last change: revised for Lua 5.2.0 (beta)
10358+Last change: revised for Lua 5.2.0
1020910359 -->
1021010360
1021110361 </body></html>
doc/readme.html+61−49
@@ -6,18 +6,21 @@ · 5 unmodified lines
66 <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
77 <STYLE TYPE="text/css">
88 blockquote, .display {
9− color: black ;
10− padding: 8px ;
119 border: solid #a0a0a0 2px ;
12− xbackground-color: #EFEFFF ;
13− margin-left: 0px ;
10+ padding: 1em ;
11+ margin: 0px ;
12+}
13+
14+.display {
15+ word-spacing: 0.25em ;
16+}
17+
18+dl.display dd {
19+ padding-bottom: 0.2em ;
1420 }
1521
1622 tt, kbd, code {
17− font-size: 120% ;
18− xcolor: black ;
19− xpadding: 4px ;
20− xbackground-color: #E0E0E0 ;
23+ font-size: 12pt ;
2124 }
2225 </STYLE>
2326 </HEAD>
@@ -27,14 +30,9 @@ tt, kbd, code { · 3 unmodified lines
2730 <HR>
2831 <H1>
2932 <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
30−Welcome to Lua 5.2 (beta)
33+Welcome to Lua 5.2
3134 </H1>
3235
33−<P>
34−<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
35−<EM>This is a beta version of Lua 5.2.
36−Some details may change in the final version.</EM>
37−
3836 <P>
3937 <A HREF="#about">about</A>
4038 &middot;
@@ -86,7 +84,7 @@ form. · 45 unmodified lines
8684 You need to build it before using it.
8785 Building Lua should be straightforward
8886 because
89−Lua is implemented in pure ANSI C, and compiles unmodified in all known
87+Lua is implemented in pure ANSI C and compiles unmodified in all known
9088 platforms that have an ANSI C compiler.
9189 Lua also compiles unmodified as C++.
9290 The instructions given below for building Lua are for Unix-like platforms.
@@ -120,15 +118,16 @@ Here are the details. · 27 unmodified lines
120118 <OL>
121119 <LI>
122120 Open a terminal window and move to
123−the top-level directory, which is named lua-5.2.0.
121+the top-level directory, which is named <TT>lua-5.2.0</TT>.
124122 The Makefile there controls both the build process and the installation process.
125123 <P>
126124 <LI>
127125 Do "<KBD>make</KBD>" and see if your platform is listed.
128126 The platforms currently supported are:
129−<BLOCKQUOTE>
130− aix ansi bsd freebsd generic linux macosx mingw posix solaris
131−</BLOCKQUOTE>
127+<P>
128+<P CLASS="display">
129+ aix ansi bsd freebsd generic linux macosx mingw posix solaris
130+</P>
132131 <P>
133132 If your platform is listed, just do "<KBD>make xxx</KBD>", where xxx
134133 is your platform name.
@@ -138,7 +137,7 @@ The Makefile there controls both the build process and the installation process. · 3 unmodified lines
138137 <P>
139138 <LI>
140139 The compilation takes only a few moments
141−and produces three files in the src directory:
140+and produces three files in the <TT>src</TT> directory:
142141 lua (the interpreter),
143142 luac (the compiler),
144143 and liblua.a (the library).
@@ -147,12 +146,15 @@ and liblua.a (the library). · 2 unmodified lines
147146 To check that Lua has been built correctly, do "<KBD>make test</KBD>"
148147 after building Lua. This will run the interpreter and print its version string.
149148 </OL>
149+<P>
150+If you're running Linux and get compilation errors,
151+make sure you have installed the <TT>readline</TT> development package.
150152
151153 <H3>Installing Lua</H3>
152154 <P>
153155 Once you have built Lua, you may want to install it in an official
154156 place in your system. In this case, do "<KBD>make install</KBD>". The official
155− place and the way to install files are defined in Makefile. You'll
157+ place and the way to install files are defined in the Makefile. You'll
156158 probably need the right permissions to install files.
157159
158160 <P>
@@ -198,9 +200,9 @@ and liblua.a (the library). · 39 unmodified lines
198200 <P>
199201 Three kinds of things can be customized by editing a file:
200202 <UL>
201− <LI> Where and how to install Lua &mdash; edit Makefile.
202− <LI> How to build Lua &mdash; edit src/Makefile.
203− <LI> Lua features &mdash; edit src/luaconf.h.
203+ <LI> Where and how to install Lua &mdash; edit <TT>Makefile</TT>.
204+ <LI> How to build Lua &mdash; edit <TT>src/Makefile</TT>.
205+ <LI> Lua features &mdash; edit <TT>src/luaconf.h</TT>.
204206 </UL>
205207
206208 <P>
@@ -211,13 +213,13 @@ and liblua.a (the library). · 4 unmodified lines
211213
212214 <P>
213215 On the other hand, if you need to customize some Lua features, you'll need
214− to edit src/luaconf.h before building and installing Lua.
216+ to edit <TT>src/luaconf.h</TT> before building and installing Lua.
215217 The edited file will be the one installed, and
216218 it will be used by any Lua clients that you build, to ensure consistency.
217219 Further customization is available to experts by editing the Lua sources.
218220
219221 <P>
220− We strongly recommend that you enable dynamic loading in src/luaconf.h.
222+ We strongly recommend that you enable dynamic loading in <TT>src/luaconf.h</TT>.
221223 This is done automatically for all platforms listed above that have
222224 this feature and also for Windows.
223225
@@ -238,7 +240,6 @@ lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c · 14 unmodified lines
238240 ltm.c lundump.c lvm.c lzio.c
239241 lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c
240242 lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c
241−
242243 <DT>
243244 interpreter:
244245 <DD>
@@ -257,11 +258,11 @@ compiler: · 12 unmodified lines
257258 those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library
258259 into each dynamic library. For Unix, we recommend that the Lua library
259260 be linked statically into the host program and its symbols exported for
260− dynamic linking; src/Makefile does this for the Lua interpreter.
261+ dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.
261262 For Windows, we recommend that the Lua library be a DLL.
262263
263264 <P>
264− As mentioned above, you may edit src/luaconf.h to customize
265+ As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize
265266 some features before building Lua.
266267
267268 <H2><A NAME="changes">Changes since Lua 5.1</A></H2>
@@ -290,7 +291,7 @@ Here are the other changes introduced in Lua 5.2: · 22 unmodified lines
290291 <UL>
291292 <LI> no more fenv for threads or functions
292293 <LI> tables honor the <CODE>__len</CODE> metamethod
293−<LI> hex and <CODE>\*</CODE> escapes in strings
294+<LI> hex and <CODE>\z</CODE> escapes in strings
294295 <LI> support for hexadecimal floats
295296 <LI> order metamethods work for different types
296297 <LI> no more verification of opcode consistency
@@ -302,8 +303,8 @@ Here are the other changes introduced in Lua 5.2: · 5 unmodified lines
302303 <H3>Libraries</H3>
303304 <UL>
304305 <LI> arguments for function called through <CODE>xpcall</CODE>
305−<LI> optional 'mode' argument to load (to control binary x text)
306−<LI> optional 'env' argument to load (environment for loaded chunk)
306+<LI> optional 'mode' argument to load and loadfile (to control binary x text)
307+<LI> optional 'env' argument to load and loadfile (environment for loaded chunk)
307308 <LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL)
308309 <LI> new function <CODE>package.searchpath</CODE>
309310 <LI> modules receive their paths when loaded
@@ -324,15 +325,23 @@ Here are the other changes introduced in Lua 5.2: · 14 unmodified lines
324325 <H3>C API</H3>
325326 <UL>
326327 <LI> main thread predefined in the registry
327−<LI> new constants <CODE>LUA_OK</CODE> and <CODE>LUA_ERRGCMM</CODE>
328−<LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE>
329−<LI> new <CODE>lua_version</CODE> and <CODE>luaL_checkversion</CODE>
328+<LI> new functions
329+<CODE>lua_absindex</CODE>,
330+<CODE>lua_arith</CODE>,
331+<CODE>lua_compare</CODE>,
332+<CODE>lua_copy</CODE>,
333+<CODE>lua_len</CODE>,
334+<CODE>lua_rawgetp</CODE>,
335+<CODE>lua_rawsetp</CODE>,
336+<CODE>lua_upvalueid</CODE>,
337+<CODE>lua_upvaluejoin</CODE>,
338+<CODE>lua_version</CODE>.
339+<LI> new functions
340+<CODE>luaL_checkversion</CODE>,
341+<CODE>luaL_setmetatable</CODE>,
342+<CODE>luaL_testudata</CODE>,
343+<CODE>luaL_tolstring</CODE>.
330344 <LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
331−<LI> new <CODE>luaL_testudata</CODE> and <CODE>luaL_setmetatable</CODE>
332−<LI> new <CODE>luaL_tolstring</CODE>
333−<LI> new <CODE>lua_copy</CODE>
334−<LI> new <CODE>lua_absindex</CODE>
335−<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
336345 <LI> <CODE>nparams</CODE> and <CODE>isvararg</CODE> available in debug API
337346 <LI> new <CODE>lua_Unsigned</CODE>
338347 </UL>
@@ -340,15 +349,17 @@ Here are the other changes introduced in Lua 5.2: · 1 unmodified line
340349 <H3>Implementation</H3>
341350 <UL>
342351 <LI> max constants per function raised to 2<SUP>26</SUP>
352+<LI> generational mode for garbage collection (experimental)
353+<LI> NaN trick (experimental)
343354 <LI> internal (immutable) version of ctypes
344355 <LI> simpler implementation for string buffers
345−<LI> udata with finalizers are kept in a separated list for the GC
346−<LI> <CODE>CallInfo</CODE> stack now is a linked list
347356 <LI> parser uses much less C-stack space (no more auto arrays)
348−<LI> new hash for floats
349−<LI> handling of non-string error messages in the standalone interpreter
350−<LI> generational mode for garbage collection (experimental)
351−<LI> NaN trick (experimental)
357+</UL>
358+
359+<H3>Lua standalone interpreter</H3>
360+<UL>
361+<LI> new <CODE>-E</CODE> option to avoid environment variables
362+<LI> handling of non-string error messages
352363 </UL>
353364
354365 <H2><A NAME="license">License</A></H2>
@@ -369,7 +380,7 @@ then you should give us credit by including the appropriate copyright notice som · 14 unmodified lines
369380 For details, see
370381 <A HREF="http://www.lua.org/license.html">this</A>.
371382
372−<BLOCKQUOTE>
383+<BLOCKQUOTE STYLE="padding-bottom: 0em">
373384 Copyright &copy; 1994&ndash;2011 Lua.org, PUC-Rio.
374385
375386 <P>
@@ -393,14 +404,15 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, · 17 unmodified lines
393404 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
394405 THE SOFTWARE.
395406 </BLOCKQUOTE>
407+<P>
396408
397409 <HR>
398410 <SMALL CLASS="footer">
399411 Last update:
400−Fri Jun 24 11:30:57 BRT 2011
412+Wed Nov 23 16:17:22 BRST 2011
401413 </SMALL>
402414 <!--
403−Last change: revised for Lua 5.2.0 (beta)
415+Last change: revised for Lua 5.2.0
404416 -->
405417
406418 </BODY>
src/Makefile+1−0
@@ -112,6 +112,7 @@ mingw: · 111 unmodified lines
112112 $(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \
113113 "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
114114 "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
115+ $(MAKE) "LUAC_T=luac.exe" luac.exe
115116
116117 posix:
117118 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
src/lapi.c+88−37
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.149 2011/06/13 14:13:06 roberto Exp $
2+** $Id: lapi.c,v 2.157 2011/11/16 18:51:36 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -34,9 +34,13 @@ const char lua_ident[] = · 28 unmodified lines
3434 "$LuaAuthors: " LUA_AUTHORS " $";
3535
3636
37+/* value at a non-valid index */
38+#define NONVALIDVALUE cast(TValue *, luaO_nilobject)
3739
38−#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject, \
39− "invalid index")
40+/* corresponding test */
41+#define isvalid(o) ((o) != luaO_nilobject)
42+
43+#define api_checkvalidindex(L, i) api_check(L, isvalid(i), "invalid index")
4044
4145
4246 static TValue *index2addr (lua_State *L, int idx) {
@@ -44,7 +48,7 @@ static TValue *index2addr (lua_State *L, int idx) { · 1 unmodified line
4448 if (idx > 0) {
4549 TValue *o = ci->func + idx;
4650 api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index");
47− if (o >= L->top) return cast(TValue *, luaO_nilobject);
51+ if (o >= L->top) return NONVALIDVALUE;
4852 else return o;
4953 }
5054 else if (idx > LUA_REGISTRYINDEX) {
@@ -57,12 +61,10 @@ static TValue *index2addr (lua_State *L, int idx) { · 6 unmodified lines
5761 idx = LUA_REGISTRYINDEX - idx;
5862 api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
5963 if (ttislcf(ci->func)) /* light C function? */
60− return cast(TValue *, luaO_nilobject); /* it has no upvalues */
64+ return NONVALIDVALUE; /* it has no upvalues */
6165 else {
6266 CClosure *func = clCvalue(ci->func);
63− return (idx <= func->nupvalues)
64− ? &func->upvalue[idx-1]
65− : cast(TValue *, luaO_nilobject);
67+ return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;
6668 }
6769 }
6870 }
@@ -237,7 +239,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 168 unmodified lines
237239
238240 LUA_API int lua_type (lua_State *L, int idx) {
239241 StkId o = index2addr(L, idx);
240− return (o == luaO_nilobject) ? LUA_TNONE : ttypenv(o);
242+ return (isvalid(o) ? ttypenv(o) : LUA_TNONE);
241243 }
242244
243245
@@ -275,8 +277,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { · 31 unmodified lines
275277 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
276278 StkId o1 = index2addr(L, index1);
277279 StkId o2 = index2addr(L, index2);
278− return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
279− : luaV_rawequalobj(o1, o2);
280+ return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;
280281 }
281282
282283
@@ -305,17 +306,17 @@ LUA_API void lua_arith (lua_State *L, int op) { · 22 unmodified lines
305306
306307 LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
307308 StkId o1, o2;
308− int i;
309+ int i = 0;
309310 lua_lock(L); /* may call tag method */
310311 o1 = index2addr(L, index1);
311312 o2 = index2addr(L, index2);
312− if (o1 == luaO_nilobject || o2 == luaO_nilobject)
313− i = 0;
314− else switch (op) {
315− case LUA_OPEQ: i = equalobj(L, o1, o2); break;
316− case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
317− case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
318− default: api_check(L, 0, "invalid option"); i = 0;
313+ if (isvalid(o1) && isvalid(o2)) {
314+ switch (op) {
315+ case LUA_OPEQ: i = equalobj(L, o1, o2); break;
316+ case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
317+ case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
318+ default: api_check(L, 0, "invalid option");
319+ }
319320 }
320321 lua_unlock(L);
321322 return i;
@@ -595,6 +596,17 @@ LUA_API int lua_pushthread (lua_State *L) { · 273 unmodified lines
595596 */
596597
597598
599+LUA_API void lua_getglobal (lua_State *L, const char *var) {
600+ Table *reg = hvalue(&G(L)->l_registry);
601+ const TValue *gt; /* global table */
602+ lua_lock(L);
603+ gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
604+ setsvalue2s(L, L->top++, luaS_new(L, var));
605+ luaV_gettable(L, gt, L->top - 1, L->top - 1);
606+ lua_unlock(L);
607+}
608+
609+
598610 LUA_API void lua_gettable (lua_State *L, int idx) {
599611 StkId t;
600612 lua_lock(L);
@@ -628,11 +640,24 @@ LUA_API void lua_rawget (lua_State *L, int idx) { · 27 unmodified lines
628640
629641
630642 LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
631− StkId o;
643+ StkId t;
632644 lua_lock(L);
633− o = index2addr(L, idx);
634− api_check(L, ttistable(o), "table expected");
635− setobj2s(L, L->top, luaH_getint(hvalue(o), n));
645+ t = index2addr(L, idx);
646+ api_check(L, ttistable(t), "table expected");
647+ setobj2s(L, L->top, luaH_getint(hvalue(t), n));
648+ api_incr_top(L);
649+ lua_unlock(L);
650+}
651+
652+
653+LUA_API void lua_rawgetp (lua_State *L, int idx, const void *p) {
654+ StkId t;
655+ TValue k;
656+ lua_lock(L);
657+ t = index2addr(L, idx);
658+ api_check(L, ttistable(t), "table expected");
659+ setpvalue(&k, cast(void *, p));
660+ setobj2s(L, L->top, luaH_get(hvalue(t), &k));
636661 api_incr_top(L);
637662 lua_unlock(L);
638663 }
@@ -700,6 +725,19 @@ LUA_API void lua_getuservalue (lua_State *L, int idx) { · 61 unmodified lines
700725 */
701726
702727
728+LUA_API void lua_setglobal (lua_State *L, const char *var) {
729+ Table *reg = hvalue(&G(L)->l_registry);
730+ const TValue *gt; /* global table */
731+ lua_lock(L);
732+ api_checknelems(L, 1);
733+ gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
734+ setsvalue2s(L, L->top++, luaS_new(L, var));
735+ luaV_settable(L, gt, L->top - 1, L->top - 2);
736+ L->top -= 2; /* pop value and key */
737+ lua_unlock(L);
738+}
739+
740+
703741 LUA_API void lua_settable (lua_State *L, int idx) {
704742 StkId t;
705743 lua_lock(L);
@@ -732,6 +770,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { · 26 unmodified lines
732770 t = index2addr(L, idx);
733771 api_check(L, ttistable(t), "table expected");
734772 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
773+ invalidateTMcache(hvalue(t));
735774 luaC_barrierback(L, gcvalue(t), L->top-1);
736775 L->top -= 2;
737776 lua_unlock(L);
@@ -739,13 +778,28 @@ LUA_API void lua_rawset (lua_State *L, int idx) { · 1 unmodified line
739778
740779
741780 LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
742− StkId o;
781+ StkId t;
743782 lua_lock(L);
744783 api_checknelems(L, 1);
745− o = index2addr(L, idx);
746− api_check(L, ttistable(o), "table expected");
747− setobj2t(L, luaH_setint(L, hvalue(o), n), L->top-1);
748− luaC_barrierback(L, gcvalue(o), L->top-1);
784+ t = index2addr(L, idx);
785+ api_check(L, ttistable(t), "table expected");
786+ luaH_setint(L, hvalue(t), n, L->top - 1);
787+ luaC_barrierback(L, gcvalue(t), L->top-1);
788+ L->top--;
789+ lua_unlock(L);
790+}
791+
792+
793+LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
794+ StkId t;
795+ TValue k;
796+ lua_lock(L);
797+ api_checknelems(L, 1);
798+ t = index2addr(L, idx);
799+ api_check(L, ttistable(t), "table expected");
800+ setpvalue(&k, cast(void *, p));
801+ setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
802+ luaC_barrierback(L, gcvalue(t), L->top - 1);
749803 L->top--;
750804 lua_unlock(L);
751805 }
@@ -1128,7 +1182,6 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { · 376 unmodified lines
11281182
11291183
11301184
1131−
11321185 static const char *aux_upvalue (StkId fi, int n, TValue **val,
11331186 GCObject **owner) {
11341187 switch (ttype(fi)) {
@@ -1141,15 +1194,13 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, · 6 unmodified lines
11411194 }
11421195 case LUA_TLCL: { /* Lua closure */
11431196 LClosure *f = clLvalue(fi);
1144− const char *name;
1197+ TString *name;
11451198 Proto *p = f->p;
11461199 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
11471200 *val = f->upvals[n-1]->v;
11481201 if (owner) *owner = obj2gco(f->upvals[n - 1]);
1149− name = getstr(p->upvalues[n-1].name);
1150− if (name == NULL) /* no debug information? */
1151− name = "";
1152− return name;
1202+ name = p->upvalues[n-1].name;
1203+ return (name == NULL) ? "" : getstr(name);
11531204 }
11541205 default: return NULL; /* not a closure */
11551206 }
@@ -1158,7 +1209,7 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, · 2 unmodified lines
11581209
11591210 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
11601211 const char *name;
1161− TValue *val;
1212+ TValue *val = NULL; /* initialized to avoid warnings */
11621213 lua_lock(L);
11631214 name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL);
11641215 if (name) {
@@ -1172,8 +1223,8 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { · 7 unmodified lines
11721223
11731224 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
11741225 const char *name;
1175− TValue *val;
1176− GCObject *owner;
1226+ TValue *val = NULL; /* initialized to avoid warnings */
1227+ GCObject *owner = NULL; /* initialized to avoid warnings */
11771228 StkId fi;
11781229 lua_lock(L);
11791230 fi = index2addr(L, funcindex);
src/lauxlib.c+31−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.233 2011/06/16 14:11:04 roberto Exp $
2+** $Id: lauxlib.c,v 1.236 2011/11/14 17:10:24 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -41,11 +41,10 @@ · 35 unmodified lines
4141 ** return 1 + string at top if find a good name.
4242 */
4343 static int findfield (lua_State *L, int objidx, int level) {
44− int found = 0;
4544 if (level == 0 || !lua_istable(L, -1))
4645 return 0; /* not found */
4746 lua_pushnil(L); /* start 'next' loop */
48− while (!found && lua_next(L, -2)) { /* for each pair in table */
47+ while (lua_next(L, -2)) { /* for each pair in table */
4948 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
5049 if (lua_rawequal(L, objidx, -1)) { /* found object? */
5150 lua_pop(L, 1); /* remove value (but keep name) */
@@ -86,7 +85,7 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) { · 34 unmodified lines
8685 lua_pushfstring(L, "function " LUA_QS, ar->name);
8786 else if (*ar->what == 'm') /* main? */
8887 lua_pushfstring(L, "main chunk");
89− else if (*ar->what == 'C' || *ar->what == 't') {
88+ else if (*ar->what == 'C') {
9089 if (pushglobalfuncname(L, ar)) {
9190 lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
9291 lua_remove(L, -2); /* remove name */
@@ -331,7 +330,9 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, · 238 unmodified lines
331330
332331
333332 LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {
334− if (!lua_checkstack(L, space)) {
333+ /* keep some extra space to run error routines, if needed */
334+ const int extra = LUA_MINSTACK;
335+ if (!lua_checkstack(L, space + extra)) {
335336 if (msg)
336337 luaL_error(L, "stack overflow (%s)", msg);
337338 else
@@ -591,6 +592,16 @@ static int errfile (lua_State *L, const char *what, int fnameindex) { · 253 unmodified lines
591592 }
592593
593594
595+static int checkmode (lua_State *L, const char *mode, const char *x) {
596+ if (mode && strchr(mode, x[0]) == NULL) {
597+ lua_pushfstring(L,
598+ "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode);
599+ return LUA_ERRFILE;
600+ }
601+ else return LUA_OK;
602+}
603+
604+
594605 static int skipBOM (LoadF *lf) {
595606 const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
596607 int c;
@@ -623,7 +634,8 @@ static int skipcomment (LoadF *lf, int *cp) { · 26 unmodified lines
623634 }
624635
625636
626−LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
637+LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
638+ const char *mode) {
627639 LoadF lf;
628640 int status, readstatus;
629641 int c;
@@ -639,14 +651,23 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { · 9 unmodified lines
639651 }
640652 if (skipcomment(&lf, &c)) /* read initial portion */
641653 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
642− if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
643− lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
644− if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
645− skipcomment(&lf, &c); /* re-read initial portion */
654+ if (c == LUA_SIGNATURE[0]) { /* binary file? */
655+ if ((status = checkmode(L, mode, "binary")) != LUA_OK)
656+ goto closefile;
657+ if (filename) {
658+ lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
659+ if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
660+ skipcomment(&lf, &c); /* re-read initial portion */
661+ }
662+ }
663+ else { /* text file */
664+ if ((status = checkmode(L, mode, "text")) != LUA_OK)
665+ goto closefile;
646666 }
647667 if (c != EOF)
648668 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
649669 status = lua_load(L, getF, &lf, lua_tostring(L, -1));
670+ closefile:
650671 readstatus = ferror(lf.f);
651672 if (filename) fclose(lf.f); /* close file (even in case of errors) */
652673 if (readstatus) {
src/lauxlib.h+31−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.117 2011/06/16 14:10:12 roberto Exp $
2+** $Id: lauxlib.h,v 1.119 2011/11/14 17:10:24 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -72,7 +72,11 @@ LUALIB_API int (luaL_execresult) (lua_State *L, int stat); · 66 unmodified lines
7272 LUALIB_API int (luaL_ref) (lua_State *L, int t);
7373 LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
7474
75−LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
75+LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
76+ const char *mode);
77+
78+#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
79+
7680 LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
7781 const char *name);
7882 LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
@@ -163,6 +167,31 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); · 84 unmodified lines
163167 /* }====================================================== */
164168
165169
170+
171+/*
172+** {======================================================
173+** File handles for IO library
174+** =======================================================
175+*/
176+
177+/*
178+** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
179+** initial structure 'luaL_Stream' (it may contain other fields
180+** after that initial structure).
181+*/
182+
183+#define LUA_FILEHANDLE "FILE*"
184+
185+
186+typedef struct luaL_Stream {
187+ FILE *f; /* stream (NULL for incompletely created streams) */
188+ lua_CFunction closef; /* to close stream (NULL for closed streams) */
189+} luaL_Stream;
190+
191+/* }====================================================== */
192+
193+
194+
166195 /* compatibility with old module system */
167196 #if defined(LUA_COMPAT_MODULE)
168197
src/lbaselib.c+45−35
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.264 2011/07/05 12:49:35 roberto Exp $
2+** $Id: lbaselib.c,v 1.270 2011/11/23 17:29:04 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -46,20 +46,22 @@ static int luaB_print (lua_State *L) { · 40 unmodified lines
4646 #define SPACECHARS " \f\n\r\t\v"
4747
4848 static int luaB_tonumber (lua_State *L) {
49− int base = luaL_optint(L, 2, 10);
50− luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
51− if (base == 10) { /* standard conversion */
52− luaL_checkany(L, 1);
53− if (lua_isnumber(L, 1)) {
54− lua_pushnumber(L, lua_tonumber(L, 1));
49+ if (lua_isnoneornil(L, 2)) { /* standard conversion */
50+ int isnum;
51+ lua_Number n = lua_tonumberx(L, 1, &isnum);
52+ if (isnum) {
53+ lua_pushnumber(L, n);
5554 return 1;
56− } /* else not a number */
55+ } /* else not a number; must be something */
56+ luaL_checkany(L, 1);
5757 }
5858 else {
5959 size_t l;
6060 const char *s = luaL_checklstring(L, 1, &l);
6161 const char *e = s + l; /* end point for 's' */
62+ int base = luaL_checkint(L, 2);
6263 int neg = 0;
64+ luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
6365 s += strspn(s, SPACECHARS); /* skip initial spaces */
6466 if (*s == '-') { s++; neg = 1; } /* handle signal */
6567 else if (*s == '+') s++;
@@ -158,7 +160,7 @@ static int luaB_rawset (lua_State *L) { · 92 unmodified lines
158160 static int luaB_collectgarbage (lua_State *L) {
159161 static const char *const opts[] = {"stop", "restart", "collect",
160162 "count", "step", "setpause", "setstepmul",
161− "setmajorinc", "isrunning", "gen", "inc", NULL};
163+ "setmajorinc", "isrunning", "generational", "incremental", NULL};
162164 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
163165 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
164166 LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
@@ -253,7 +255,14 @@ static int load_aux (lua_State *L, int status) { · 88 unmodified lines
253255
254256 static int luaB_loadfile (lua_State *L) {
255257 const char *fname = luaL_optstring(L, 1, NULL);
256− return load_aux(L, luaL_loadfile(L, fname));
258+ const char *mode = luaL_optstring(L, 2, NULL);
259+ int env = !lua_isnone(L, 3); /* 'env' parameter? */
260+ int status = luaL_loadfilex(L, fname, mode);
261+ if (status == LUA_OK && env) { /* 'env' parameter? */
262+ lua_pushvalue(L, 3);
263+ lua_setupvalue(L, -2, 1); /* set it as 1st upvalue of loaded chunk */
264+ }
265+ return load_aux(L, status);
257266 }
258267
259268
@@ -265,7 +274,6 @@ static int luaB_loadfile (lua_State *L) { · 5 unmodified lines
265274
266275
267276 typedef struct {
268−char c;
269277 const char *mode;
270278 } loaddata;
271279
@@ -276,11 +284,11 @@ char c; · 4 unmodified lines
276284 ** pushed on the stack) in case of errors.
277285 */
278286 static const char *checkrights (lua_State *L, const char *mode, const char *s) {
279− if (strchr(mode, 'b') == NULL && *s == LUA_SIGNATURE[0])
280− return lua_pushstring(L, "attempt to load a binary chunk");
281− if (strchr(mode, 't') == NULL && *s != LUA_SIGNATURE[0])
282− return lua_pushstring(L, "attempt to load a text chunk");
283− return NULL; /* chunk in allowed format */
287+ const char *x = (*s == LUA_SIGNATURE[0]) ? "binary" : "text";
288+ if (strchr(mode, x[0]) == NULL)
289+ return lua_pushfstring(L,
290+ "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode);
291+ else return NULL;
284292 }
285293
286294
@@ -390,27 +398,32 @@ static int luaB_select (lua_State *L) { · 103 unmodified lines
390398 }
391399
392400
393−static int pcallcont (lua_State *L) {
394− int errfunc = 0; /* =0 to avoid warnings */
395− int status = lua_getctx(L, &errfunc);
396− lua_assert(status != LUA_OK);
397− lua_pushboolean(L, (status == LUA_YIELD)); /* first result (status) */
398− if (errfunc) /* came from xpcall? */
399− lua_replace(L, 1); /* put first result in place of error function */
400− else /* came from pcall */
401− lua_insert(L, 1); /* open space for first result */
401+static int finishpcall (lua_State *L, int status) {
402+ if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */
403+ lua_settop(L, 0); /* create space for return values */
404+ lua_pushboolean(L, 0);
405+ lua_pushstring(L, "stack overflow");
406+ return 2; /* return false, msg */
407+ }
408+ lua_pushboolean(L, status); /* first result (status) */
409+ lua_replace(L, 1); /* put first result in first slot */
402410 return lua_gettop(L);
403411 }
404412
405413
414+static int pcallcont (lua_State *L) {
415+ int status = lua_getctx(L, NULL);
416+ return finishpcall(L, (status == LUA_YIELD));
417+}
418+
419+
406420 static int luaB_pcall (lua_State *L) {
407421 int status;
408422 luaL_checkany(L, 1);
409− status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, pcallcont);
410− luaL_checkstack(L, 1, NULL);
411− lua_pushboolean(L, (status == LUA_OK));
412− lua_insert(L, 1);
413− return lua_gettop(L); /* return status + all results */
423+ lua_pushnil(L);
424+ lua_insert(L, 1); /* create space for status result */
425+ status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);
426+ return finishpcall(L, (status == LUA_OK));
414427 }
415428
416429
@@ -421,11 +434,8 @@ static int luaB_xpcall (lua_State *L) { · 4 unmodified lines
421434 lua_pushvalue(L, 1); /* exchange function... */
422435 lua_copy(L, 2, 1); /* ...and error handler */
423436 lua_replace(L, 2);
424− status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont);
425− luaL_checkstack(L, 1, NULL);
426− lua_pushboolean(L, (status == LUA_OK));
427− lua_replace(L, 1);
428− return lua_gettop(L); /* return status + all results */
437+ status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);
438+ return finishpcall(L, (status == LUA_OK));
429439 }
430440
431441
src/lcode.c+12−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.56 2011/05/31 18:27:56 roberto Exp $
2+** $Id: lcode.c,v 2.60 2011/08/30 16:26:41 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -44,8 +44,8 @@ void luaK_nil (FuncState *fs, int from, int n) { · 38 unmodified lines
4444 int pl = pfrom + GETARG_B(*previous);
4545 if ((pfrom <= from && from <= pl + 1) ||
4646 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
47− if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
48− if (pl > l) l = pl; /* l = max(l, pl) */
47+ if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
48+ if (pl > l) l = pl; /* l = max(l, pl) */
4949 SETARG_A(*previous, from);
5050 SETARG_B(*previous, l - from);
5151 return;
@@ -213,11 +213,11 @@ static int luaK_code (FuncState *fs, Instruction i) { · 161 unmodified lines
213213 Proto *f = fs->f;
214214 dischargejpc(fs); /* `pc' will change */
215215 /* put new instruction in code array */
216− luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
216+ luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
217217 MAX_INT, "opcodes");
218218 f->code[fs->pc] = i;
219219 /* save corresponding line information */
220− luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
220+ luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
221221 MAX_INT, "opcodes");
222222 f->lineinfo[fs->pc] = fs->ls->lastline;
223223 return fs->pc++;
@@ -289,7 +289,7 @@ static void freeexp (FuncState *fs, expdesc *e) { · 65 unmodified lines
289289
290290
291291 static int addk (FuncState *fs, TValue *key, TValue *v) {
292− lua_State *L = fs->L;
292+ lua_State *L = fs->ls->L;
293293 TValue *idx = luaH_set(L, fs->h, key);
294294 Proto *f = fs->f;
295295 int k, oldsize;
@@ -304,6 +304,8 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { · 8 unmodified lines
304304 /* constant not found; create a new entry */
305305 oldsize = f->sizek;
306306 k = fs->nk;
307+ /* numerical value does not need GC barrier;
308+ table has no metatable, so it does not need to invalidate cache */
307309 setnvalue(idx, cast_num(k));
308310 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
309311 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
@@ -316,14 +318,14 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { · 6 unmodified lines
316318
317319 int luaK_stringK (FuncState *fs, TString *s) {
318320 TValue o;
319− setsvalue(fs->L, &o, s);
321+ setsvalue(fs->ls->L, &o, s);
320322 return addk(fs, &o, &o);
321323 }
322324
323325
324326 int luaK_numberK (FuncState *fs, lua_Number r) {
325327 int n;
326− lua_State *L = fs->L;
328+ lua_State *L = fs->ls->L;
327329 TValue o;
328330 setnvalue(&o, r);
329331 if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */
@@ -350,7 +352,7 @@ static int nilK (FuncState *fs) { · 20 unmodified lines
350352 TValue k, v;
351353 setnilvalue(&v);
352354 /* cannot use nil as key; instead use table itself to represent nil */
353− sethvalue(fs->L, &k, fs->h);
355+ sethvalue(fs->ls->L, &k, fs->h);
354356 return addk(fs, &k, &v);
355357 }
356358
@@ -641,7 +643,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 284 unmodified lines
641643 }
642644
643645
644−static void luaK_goiffalse (FuncState *fs, expdesc *e) {
646+void luaK_goiffalse (FuncState *fs, expdesc *e) {
645647 int pc; /* pc of last jump */
646648 luaK_dischargevars(fs, e);
647649 switch (e->k) {
src/lcode.h+2−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.h,v 1.57 2011/04/07 18:14:12 roberto Exp $
2+** $Id: lcode.h,v 1.58 2011/08/30 16:26:41 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -62,6 +62,7 @@ LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); · 56 unmodified lines
6262 LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
6363 LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
6464 LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
65+LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
6566 LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
6667 LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
6768 LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
src/lcorolib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcorolib.c,v 1.2 2010/07/02 11:38:13 roberto Exp $
2+** $Id: lcorolib.c,v 1.3 2011/08/23 17:24:34 roberto Exp $
33 ** Coroutine Library
44 ** See Copyright Notice in lua.h
55 */
@@ -28,7 +28,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { · 22 unmodified lines
2828 return -1; /* error flag */
2929 }
3030 lua_xmove(L, co, narg);
31− status = lua_resume(co, narg);
31+ status = lua_resume(co, L, narg);
3232 if (status == LUA_OK || status == LUA_YIELD) {
3333 int nres = lua_gettop(co);
3434 if (!lua_checkstack(L, nres + 1)) {
src/lctype.c+4−1
@@ -1,9 +1,12 @@
11 /*
2−** $Id: lctype.c,v 1.10 2011/06/24 12:25:33 roberto Exp $
2+** $Id: lctype.c,v 1.11 2011/10/03 16:19:23 roberto Exp $
33 ** 'ctype' functions for Lua
44 ** See Copyright Notice in lua.h
55 */
66
7+#define lctype_c
8+#define LUA_CORE
9+
710 #include "lctype.h"
811
912 #if !LUA_USE_CTYPE /* { */
src/lctype.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp $
2+** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $
33 ** 'ctype' functions for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -11,7 +11,7 @@ · 5 unmodified lines
1111
1212
1313 /*
14−** WARNING: the functions defined here do not necessarily correspond
14+** WARNING: the functions defined here do not necessarily correspond
1515 ** to the similar functions in the standard C ctype.h. They are
1616 ** optimized for the specific needs of Lua
1717 */
src/ldblib.c+4−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.130 2011/04/08 19:17:36 roberto Exp $
2+** $Id: ldblib.c,v 1.131 2011/10/24 14:54:05 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -260,8 +260,7 @@ static void hookf (lua_State *L, lua_Debug *ar) { · 254 unmodified lines
260260 static const char *const hooknames[] =
261261 {"call", "return", "line", "count", "tail call"};
262262 gethooktable(L);
263− lua_pushlightuserdata(L, L);
264− lua_rawget(L, -2);
263+ lua_rawgetp(L, -1, L);
265264 if (lua_isfunction(L, -1)) {
266265 lua_pushstring(L, hooknames[(int)ar->event]);
267266 if (ar->currentline >= 0)
@@ -308,9 +307,8 @@ static int db_sethook (lua_State *L) { · 40 unmodified lines
308307 func = hookf; mask = makemask(smask, count);
309308 }
310309 gethooktable(L);
311− lua_pushlightuserdata(L, L1);
312310 lua_pushvalue(L, arg+1);
313− lua_rawset(L, -3); /* set new hook */
311+ lua_rawsetp(L, -2, L1); /* set new hook */
314312 lua_pop(L, 1); /* remove hook table */
315313 lua_sethook(L1, func, mask, count); /* set hooks */
316314 return 0;
@@ -327,8 +325,7 @@ static int db_gethook (lua_State *L) { · 10 unmodified lines
327325 lua_pushliteral(L, "external hook");
328326 else {
329327 gethooktable(L);
330− lua_pushlightuserdata(L, L1);
331− lua_rawget(L, -2); /* get hook */
328+ lua_rawgetp(L, -1, L1); /* get hook */
332329 lua_remove(L, -2); /* remove hook table */
333330 }
334331 lua_pushstring(L, unmakemask(mask, buff));
src/ldebug.c+104−96
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.82 2011/06/02 19:31:40 roberto Exp $
2+** $Id: ldebug.c,v 2.87 2011/10/07 20:45:19 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -94,6 +94,13 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 88 unmodified lines
9494 }
9595
9696
97+static const char *upvalname (Proto *p, int uv) {
98+ TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
99+ if (s == NULL) return "?";
100+ else return getstr(s);
101+}
102+
103+
97104 static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
98105 int nparams = clLvalue(ci->func)->p->numparams;
99106 if (n >= ci->u.l.base - ci->func - nparams)
@@ -190,12 +197,14 @@ static void collectvalidlines (lua_State *L, Closure *f) { · 90 unmodified lines
190197 }
191198 else {
192199 int i;
200+ TValue v;
193201 int *lineinfo = f->l.p->lineinfo;
194− Table *t = luaH_new(L);
195− sethvalue(L, L->top, t);
202+ Table *t = luaH_new(L); /* new table to store active lines */
203+ sethvalue(L, L->top, t); /* push it on stack */
196204 incr_top(L);
197− for (i=0; i<f->l.p->sizelineinfo; i++)
198− setbvalue(luaH_setint(L, t, lineinfo[i]), 1);
205+ setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
206+ for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
207+ luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
199208 }
200209 }
201210
@@ -230,7 +239,11 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, · 28 unmodified lines
230239 break;
231240 }
232241 case 'n': {
233− ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
242+ /* calling function is a known Lua function? */
243+ if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
244+ ar->namewhat = getfuncname(L, ci->previous, &ar->name);
245+ else
246+ ar->namewhat = NULL;
234247 if (ar->namewhat == NULL) {
235248 ar->namewhat = ""; /* not found */
236249 ar->name = NULL;
@@ -284,17 +297,16 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { · 47 unmodified lines
284297 ** =======================================================
285298 */
286299
287−static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
300+static const char *getobjname (Proto *p, int lastpc, int reg,
288301 const char **name);
289302
290303
291304 /*
292305 ** find a "name" for the RK value 'c'
293306 */
294−static void kname (lua_State *L, CallInfo *ci, int c, int oreg,
295− const char *what, const char **name) {
307+static void kname (Proto *p, int pc, int c, const char **name) {
296308 if (ISK(c)) { /* is 'c' a constant? */
297− TValue *kvalue = &ci_func(ci)->p->k[INDEXK(c)];
309+ TValue *kvalue = &p->k[INDEXK(c)];
298310 if (ttisstring(kvalue)) { /* literal constant? */
299311 *name = svalue(kvalue); /* it is its own name */
300312 return;
@@ -302,8 +314,7 @@ static void kname (lua_State *L, CallInfo *ci, int c, int oreg, · 1 unmodified line
302314 /* else no reasonable name found */
303315 }
304316 else { /* 'c' is a register */
305− if (c != oreg) /* not the original register? */
306− what = getobjname(L, ci, c, name); /* search for 'c' */
317+ const char *what = getobjname(p, pc, c, name); /* search for 'c' */
307318 if (what && *what == 'c') { /* found a constant name? */
308319 return; /* 'name' already filled */
309320 }
@@ -313,85 +324,30 @@ static void kname (lua_State *L, CallInfo *ci, int c, int oreg, · 3 unmodified lines
313324 }
314325
315326
316−static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
317− const char **name) {
318− Proto *p = ci_func(ci)->p;
319− const char *what = NULL;
320− int lastpc = currentpc(ci);
327+/*
328+** try to find last instruction before 'lastpc' that modified register 'reg'
329+*/
330+static int findsetreg (Proto *p, int lastpc, int reg) {
321331 int pc;
322− *name = luaF_getlocalname(p, reg + 1, lastpc);
323− if (*name) /* is a local? */
324− return "local";
325− /* else try symbolic execution */
332+ int setreg = -1; /* keep last instruction that changed 'reg' */
326333 for (pc = 0; pc < lastpc; pc++) {
327334 Instruction i = p->code[pc];
328335 OpCode op = GET_OPCODE(i);
329336 int a = GETARG_A(i);
330337 switch (op) {
331− case OP_MOVE: {
332− if (reg == a) {
333− int b = GETARG_B(i); /* move from 'b' to 'a' */
334− if (b < a)
335− what = getobjname(L, ci, b, name); /* get name for 'b' */
336− else what = NULL;
337− }
338− break;
339− }
340− case OP_GETTABUP:
341− case OP_GETTABLE: {
342− if (reg == a) {
343− int k = GETARG_C(i); /* key index */
344− int t = GETARG_B(i);
345− const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
346− ? luaF_getlocalname(p, t + 1, pc)
347− : getstr(p->upvalues[t].name);
348− kname(L, ci, k, a, what, name);
349− what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
350− }
351− break;
352− }
353− case OP_GETUPVAL: {
354− if (reg == a) {
355− int u = GETARG_B(i); /* upvalue index */
356− TString *tn = p->upvalues[u].name;
357− *name = tn ? getstr(tn) : "?";
358− what = "upvalue";
359− }
360− break;
361− }
362− case OP_LOADK:
363− case OP_LOADKX: {
364− if (reg == a) {
365− int b = (op == OP_LOADK) ? GETARG_Bx(i)
366− : GETARG_Ax(p->code[pc + 1]);
367− if (ttisstring(&p->k[b])) {
368− what = "constant";
369− *name = svalue(&p->k[b]);
370− }
371− }
372− break;
373− }
374338 case OP_LOADNIL: {
375339 int b = GETARG_B(i);
376340 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
377− what = NULL;
378− break;
379− }
380− case OP_SELF: {
381− if (reg == a) {
382− int k = GETARG_C(i); /* key index */
383− kname(L, ci, k, a, what, name);
384− what = "method";
385− }
341+ setreg = pc;
386342 break;
387343 }
388344 case OP_TFORCALL: {
389− if (reg >= a + 2) what = NULL; /* affect all regs above its base */
345+ if (reg >= a + 2) setreg = pc; /* affect all regs above its base */
390346 break;
391347 }
392348 case OP_CALL:
393349 case OP_TAILCALL: {
394− if (reg >= a) what = NULL; /* affect all registers above base */
350+ if (reg >= a) setreg = pc; /* affect all registers above base */
395351 break;
396352 }
397353 case OP_JMP: {
@@ -403,35 +359,87 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, · 5 unmodified lines
403359 break;
404360 }
405361 case OP_TEST: {
406− if (reg == a) what = NULL; /* jumped code can change 'a' */
362+ if (reg == a) setreg = pc; /* jumped code can change 'a' */
407363 break;
408364 }
409365 default:
410− if (testAMode(op) && reg == a) what = NULL;
366+ if (testAMode(op) && reg == a) /* any instruction that set A */
367+ setreg = pc;
411368 break;
412369 }
413370 }
414− return what;
371+ return setreg;
372+}
373+
374+
375+static const char *getobjname (Proto *p, int lastpc, int reg,
376+ const char **name) {
377+ int pc;
378+ *name = luaF_getlocalname(p, reg + 1, lastpc);
379+ if (*name) /* is a local? */
380+ return "local";
381+ /* else try symbolic execution */
382+ pc = findsetreg(p, lastpc, reg);
383+ if (pc != -1) { /* could find instruction? */
384+ Instruction i = p->code[pc];
385+ OpCode op = GET_OPCODE(i);
386+ switch (op) {
387+ case OP_MOVE: {
388+ int b = GETARG_B(i); /* move from 'b' to 'a' */
389+ if (b < GETARG_A(i))
390+ return getobjname(p, pc, b, name); /* get name for 'b' */
391+ break;
392+ }
393+ case OP_GETTABUP:
394+ case OP_GETTABLE: {
395+ int k = GETARG_C(i); /* key index */
396+ int t = GETARG_B(i); /* table index */
397+ const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
398+ ? luaF_getlocalname(p, t + 1, pc)
399+ : upvalname(p, t);
400+ kname(p, pc, k, name);
401+ return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
402+ }
403+ case OP_GETUPVAL: {
404+ *name = upvalname(p, GETARG_B(i));
405+ return "upvalue";
406+ }
407+ case OP_LOADK:
408+ case OP_LOADKX: {
409+ int b = (op == OP_LOADK) ? GETARG_Bx(i)
410+ : GETARG_Ax(p->code[pc + 1]);
411+ if (ttisstring(&p->k[b])) {
412+ *name = svalue(&p->k[b]);
413+ return "constant";
414+ }
415+ break;
416+ }
417+ case OP_SELF: {
418+ int k = GETARG_C(i); /* key index */
419+ kname(p, pc, k, name);
420+ return "method";
421+ }
422+ default: break; /* go through to return NULL */
423+ }
424+ }
425+ return NULL; /* could not find reasonable name */
415426 }
416427
417428
418429 static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
419430 TMS tm;
420− Instruction i;
421− if ((ci->callstatus & CIST_TAIL) || !isLua(ci->previous))
422− return NULL; /* calling function is not Lua (or is unknown) */
423− ci = ci->previous; /* calling function */
424− i = ci_func(ci)->p->code[currentpc(ci)];
425− if (GET_OPCODE(i) == OP_EXTRAARG) /* extra argument? */
426− i = ci_func(ci)->p->code[currentpc(ci) - 1]; /* get 'real' instruction */
431+ Proto *p = ci_func(ci)->p; /* calling function */
432+ int pc = currentpc(ci); /* calling instruction index */
433+ Instruction i = p->code[pc]; /* calling instruction */
427434 switch (GET_OPCODE(i)) {
428435 case OP_CALL:
429− case OP_TAILCALL:
430− return getobjname(L, ci, GETARG_A(i), name);
431− case OP_TFORCALL: {
436+ case OP_TAILCALL: /* get function name */
437+ return getobjname(p, pc, GETARG_A(i), name);
438+ case OP_TFORCALL: { /* for iterator */
432439 *name = "for iterator";
433440 return "for iterator";
434441 }
442+ /* all other instructions can call only through metamethods */
435443 case OP_SELF:
436444 case OP_GETTABUP:
437445 case OP_GETTABLE: tm = TM_INDEX; break;
@@ -473,12 +481,12 @@ static int isinstack (CallInfo *ci, const TValue *o) { · 35 unmodified lines
473481
474482
475483 static const char *getupvalname (CallInfo *ci, const TValue *o,
476− const char **name) {
484+ const char **name) {
477485 LClosure *c = ci_func(ci);
478486 int i;
479487 for (i = 0; i < c->nupvalues; i++) {
480488 if (c->upvals[i]->v == o) {
481− *name = getstr(c->p->upvalues[i].name);
489+ *name = upvalname(c->p, i);
482490 return "upvalue";
483491 }
484492 }
@@ -494,7 +502,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 9 unmodified lines
494502 if (isLua(ci)) {
495503 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
496504 if (!kind && isinstack(ci, o)) /* no? try a register */
497− kind = getobjname(L, ci, cast_int(o - ci->u.l.base), &name);
505+ kind = getobjname(ci_func(ci)->p, currentpc(ci),
506+ cast_int(o - ci->u.l.base), &name);
498507 }
499508 if (kind)
500509 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
@@ -511,7 +520,7 @@ void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { · 10 unmodified lines
511520 }
512521
513522
514−void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
523+l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
515524 TValue temp;
516525 if (luaV_tonumber(p1, &temp) == NULL)
517526 p2 = p1; /* first operand is wrong */
@@ -519,14 +528,13 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { · 1 unmodified line
519528 }
520529
521530
522−int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
531+l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
523532 const char *t1 = objtypename(p1);
524533 const char *t2 = objtypename(p2);
525534 if (t1 == t2)
526535 luaG_runerror(L, "attempt to compare two %s values", t1);
527536 else
528537 luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
529− return 0;
530538 }
531539
532540
@@ -546,7 +554,7 @@ static void addinfo (lua_State *L, const char *msg) { · 13 unmodified lines
546554 }
547555
548556
549−void luaG_errormsg (lua_State *L) {
557+l_noret luaG_errormsg (lua_State *L) {
550558 if (L->errfunc != 0) { /* is there an error handling function? */
551559 StkId errfunc = restorestack(L, L->errfunc);
552560 if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
@@ -559,7 +567,7 @@ void luaG_errormsg (lua_State *L) { · 6 unmodified lines
559567 }
560568
561569
562−void luaG_runerror (lua_State *L, const char *fmt, ...) {
570+l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
563571 va_list argp;
564572 va_start(argp, fmt);
565573 addinfo(L, luaO_pushvfstring(L, fmt, argp));
src/ldebug.h+10−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.h,v 2.6 2011/06/02 19:31:40 roberto Exp $
2+** $Id: ldebug.h,v 2.7 2011/10/07 20:45:19 roberto Exp $
33 ** Auxiliary functions from Debug Interface module
44 ** See Copyright Notice in lua.h
55 */
@@ -21,14 +21,14 @@ · 15 unmodified lines
2121 #define ci_func(ci) (clLvalue((ci)->func))
2222
2323
24−LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
25− const char *opname);
26−LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
27−LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
28− const TValue *p2);
29−LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
30− const TValue *p2);
31−LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
32−LUAI_FUNC void luaG_errormsg (lua_State *L);
24+LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,
25+ const char *opname);
26+LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2);
27+LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1,
28+ const TValue *p2);
29+LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
30+ const TValue *p2);
31+LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
32+LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
3333
3434 #endif
src/ldo.c+17−17
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.98 2011/06/28 15:42:04 roberto Exp $
2+** $Id: ldo.c,v 2.101 2011/10/07 20:45:19 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -100,7 +100,7 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 94 unmodified lines
100100 }
101101
102102
103−void luaD_throw (lua_State *L, int errcode) {
103+l_noret luaD_throw (lua_State *L, int errcode) {
104104 if (L->errorJmp) { /* thread has an error handler? */
105105 L->errorJmp->status = errcode; /* set status */
106106 LUAI_THROW(L, L->errorJmp); /* jump to it */
@@ -123,7 +123,7 @@ void luaD_throw (lua_State *L, int errcode) { · 16 unmodified lines
123123
124124
125125 int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
126− unsigned short oldnCcalls = G(L)->nCcalls;
126+ unsigned short oldnCcalls = L->nCcalls;
127127 struct lua_longjmp lj;
128128 lj.status = LUA_OK;
129129 lj.previous = L->errorJmp; /* chain new error handler */
@@ -132,7 +132,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 2 unmodified lines
132132 (*f)(L, ud);
133133 );
134134 L->errorJmp = lj.previous; /* restore old error handler */
135− G(L)->nCcalls = oldnCcalls;
135+ L->nCcalls = oldnCcalls;
136136 return lj.status;
137137 }
138138
@@ -344,7 +344,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 205 unmodified lines
344344 }
345345 default: { /* not a function */
346346 func = tryfuncTM(L, func); /* retry with 'function' tag method */
347− return luaD_precall(L, func, nresults);
347+ return luaD_precall(L, func, nresults); /* now it must be a function */
348348 }
349349 }
350350 }
@@ -382,18 +382,17 @@ int luaD_poscall (lua_State *L, StkId firstResult) { · 31 unmodified lines
382382 ** function position.
383383 */
384384 void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) {
385− global_State *g = G(L);
386− if (++g->nCcalls >= LUAI_MAXCCALLS) {
387− if (g->nCcalls == LUAI_MAXCCALLS)
385+ if (++L->nCcalls >= LUAI_MAXCCALLS) {
386+ if (L->nCcalls == LUAI_MAXCCALLS)
388387 luaG_runerror(L, "C stack overflow");
389− else if (g->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
388+ else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
390389 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
391390 }
392391 if (!allowyield) L->nny++;
393392 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */
394393 luaV_execute(L); /* call it */
395394 if (!allowyield) L->nny--;
396− g->nCcalls--;
395+ L->nCcalls--;
397396 luaC_checkGC(L);
398397 }
399398
@@ -404,7 +403,7 @@ static void finishCcall (lua_State *L) { · 4 unmodified lines
404403 lua_assert(ci->u.c.k != NULL); /* must have a continuation */
405404 lua_assert(L->nny == 0);
406405 /* finish 'luaD_call' */
407− G(L)->nCcalls--;
406+ L->nCcalls--;
408407 /* finish 'lua_callk' */
409408 adjustresults(L, ci->nresults);
410409 /* call continuation function */
@@ -473,7 +472,7 @@ static int recover (lua_State *L, int status) { · 62 unmodified lines
473472 ** coroutine itself. (Such errors should not be handled by any coroutine
474473 ** error handler and should not kill the coroutine.)
475474 */
476−static void resume_error (lua_State *L, const char *msg, StkId firstArg) {
475+static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {
477476 L->top = firstArg; /* remove args from the stack */
478477 setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */
479478 incr_top(L);
@@ -487,7 +486,7 @@ static void resume_error (lua_State *L, const char *msg, StkId firstArg) { · 7 unmodified lines
487486 static void resume (lua_State *L, void *ud) {
488487 StkId firstArg = cast(StkId, ud);
489488 CallInfo *ci = L->ci;
490− if (G(L)->nCcalls >= LUAI_MAXCCALLS)
489+ if (L->nCcalls >= LUAI_MAXCCALLS)
491490 resume_error(L, "C stack overflow", firstArg);
492491 if (L->status == LUA_OK) { /* may be starting a coroutine */
493492 if (ci != &L->base_ci) /* not in base level? */
@@ -514,7 +513,7 @@ static void resume (lua_State *L, void *ud) { · 20 unmodified lines
514513 api_checknelems(L, n);
515514 firstArg = L->top - n; /* yield results come from continuation */
516515 }
517− G(L)->nCcalls--; /* finish 'luaD_call' */
516+ L->nCcalls--; /* finish 'luaD_call' */
518517 luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
519518 }
520519 unroll(L, NULL);
@@ -522,11 +521,11 @@ static void resume (lua_State *L, void *ud) { · 1 unmodified line
522521 }
523522
524523
525−LUA_API int lua_resume (lua_State *L, int nargs) {
524+LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {
526525 int status;
527526 lua_lock(L);
528527 luai_userstateresume(L, nargs);
529− ++G(L)->nCcalls; /* count resume */
528+ L->nCcalls = (from) ? from->nCcalls + 1 : 1;
530529 L->nny = 0; /* allow yields */
531530 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
532531 status = luaD_rawrunprotected(L, resume, L->top - nargs);
@@ -546,7 +545,8 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 13 unmodified lines
546545 lua_assert(status == L->status);
547546 }
548547 L->nny = 1; /* do not allow yields */
549− --G(L)->nCcalls;
548+ L->nCcalls--;
549+ lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
550550 lua_unlock(L);
551551 return status;
552552 }
src/ldo.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.h,v 2.18 2009/12/17 12:28:57 roberto Exp $
2+** $Id: ldo.h,v 2.19 2011/10/07 20:45:19 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -38,7 +38,7 @@ LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); · 32 unmodified lines
3838 LUAI_FUNC void luaD_growstack (lua_State *L, int n);
3939 LUAI_FUNC void luaD_shrinkstack (lua_State *L);
4040
41−LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
41+LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
4242 LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
4343
4444 #endif
src/ldump.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldump.c,v 1.18 2011/05/06 13:35:17 lhf Exp $
2+** $Id: ldump.c,v 1.19 2011/11/23 17:48:18 lhf Exp $
33 ** save precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -111,8 +111,8 @@ static void DumpUpvalues(const Proto* f, DumpState* D) · 105 unmodified lines
111111 DumpInt(n,D);
112112 for (i=0; i<n; i++)
113113 {
114− DumpChar(f->upvalues[i].instack, D);
115− DumpChar(f->upvalues[i].idx, D);
114+ DumpChar(f->upvalues[i].instack,D);
115+ DumpChar(f->upvalues[i].idx,D);
116116 }
117117 }
118118
src/lgc.c+96−46
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.109 2011/05/05 19:42:25 roberto Exp $
2+** $Id: lgc.c,v 2.114 2011/10/03 17:54:25 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -100,12 +100,13 @@ static void reallymarkobject (global_State *g, GCObject *o); · 94 unmodified lines
100100
101101
102102 /*
103−** mark a table entry as dead (therefore removing it from the table)
103+** if key is not marked, mark its entry as dead (therefore removing it
104+** from the table)
104105 */
105106 static void removeentry (Node *n) {
106107 lua_assert(ttisnil(gval(n)));
107− if (iscollectable(gkey(n)))
108− setdeadvalue(gkey(n)); /* dead key; remove it */
108+ if (valiswhite(gkey(n)))
109+ setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */
109110 }
110111
111112
@@ -116,13 +117,13 @@ static void removeentry (Node *n) { · 4 unmodified lines
116117 ** other objects: if really collected, cannot keep them; for objects
117118 ** being finalized, keep them in keys, but not in values
118119 */
119−static int iscleared (const TValue *o, int iskey) {
120+static int iscleared (const TValue *o) {
120121 if (!iscollectable(o)) return 0;
121122 else if (ttisstring(o)) {
122123 stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
123124 return 0;
124125 }
125− else return iswhite(gcvalue(o)) || (!iskey && isfinalized(gcvalue(o)));
126+ else return iswhite(gcvalue(o));
126127 }
127128
128129
@@ -152,7 +153,7 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { · 23 unmodified lines
152153 */
153154 void luaC_barrierback_ (lua_State *L, GCObject *o) {
154155 global_State *g = G(L);
155− lua_assert(isblack(o) && !isdead(g, o));
156+ lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE);
156157 black2gray(o); /* make object gray (again) */
157158 gco2t(o)->gclist = g->grayagain;
158159 g->grayagain = o;
@@ -342,6 +343,9 @@ static void markroot (global_State *g) { · 183 unmodified lines
342343
343344 static void traverseweakvalue (global_State *g, Table *h) {
344345 Node *n, *limit = gnode(h, sizenode(h));
346+ /* if there is array part, assume it may have white values (do not
347+ traverse it just to check) */
348+ int hasclears = (h->sizearray > 0);
345349 for (n = gnode(h, 0); n < limit; n++) {
346350 checkdeadkey(n);
347351 if (ttisnil(gval(n))) /* entry is empty? */
@@ -349,15 +353,21 @@ static void traverseweakvalue (global_State *g, Table *h) { · 1 unmodified line
349353 else {
350354 lua_assert(!ttisnil(gkey(n)));
351355 markvalue(g, gkey(n)); /* mark key */
356+ if (!hasclears && iscleared(gval(n))) /* is there a white value? */
357+ hasclears = 1; /* table will have to be cleared */
352358 }
353359 }
354− linktable(h, &g->weak); /* link into appropriate list */
360+ if (hasclears)
361+ linktable(h, &g->weak); /* has to be cleared later */
362+ else /* no white values */
363+ linktable(h, &g->grayagain); /* no need to clean */
355364 }
356365
357366
358367 static int traverseephemeron (global_State *g, Table *h) {
359368 int marked = 0; /* true if an object is marked in this traversal */
360− int hasclears = 0; /* true if table has unmarked pairs */
369+ int hasclears = 0; /* true if table has white keys */
370+ int prop = 0; /* true if table has entry "white-key -> white-value" */
361371 Node *n, *limit = gnode(h, sizenode(h));
362372 int i;
363373 /* traverse array part (numeric keys are 'strong') */
@@ -372,19 +382,22 @@ static int traverseephemeron (global_State *g, Table *h) { · 8 unmodified lines
372382 checkdeadkey(n);
373383 if (ttisnil(gval(n))) /* entry is empty? */
374384 removeentry(n); /* remove it */
385+ else if (iscleared(gkey(n))) { /* key is not marked (yet)? */
386+ hasclears = 1; /* table must be cleared */
387+ if (valiswhite(gval(n))) /* value not marked yet? */
388+ prop = 1; /* must propagate again */
389+ }
375390 else if (valiswhite(gval(n))) { /* value not marked yet? */
376− if (iscleared(gkey(n), 1)) /* key is not marked (yet)? */
377− hasclears = 1; /* may have to propagate mark from key to value */
378− else { /* key is marked, so mark value */
379− marked = 1; /* value was not marked */
380− reallymarkobject(g, gcvalue(gval(n)));
381− }
391+ marked = 1;
392+ reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
382393 }
383394 }
384− if (hasclears) /* does table have unmarked pairs? */
385− linktable(h, &g->ephemeron); /* will have to propagate again */
386− else /* nothing to propagate */
387− linktable(h, &g->weak); /* avoid convergence phase */
395+ if (prop)
396+ linktable(h, &g->ephemeron); /* have to propagate again */
397+ else if (hasclears) /* does table have white keys? */
398+ linktable(h, &g->allweak); /* may have to clean white keys */
399+ else /* no white keys */
400+ linktable(h, &g->grayagain); /* no need to clean */
388401 return marked;
389402 }
390403
@@ -526,11 +539,26 @@ static void propagateall (global_State *g) { · 135 unmodified lines
526539 }
527540
528541
529−static void traverselistofgrays (global_State *g, GCObject **l) {
542+static void propagatelist (global_State *g, GCObject *l) {
530543 lua_assert(g->gray == NULL); /* no grays left */
531− g->gray = *l; /* now 'l' is new gray list */
532− *l = NULL;
533− propagateall(g);
544+ g->gray = l;
545+ propagateall(g); /* traverse all elements from 'l' */
546+}
547+
548+/*
549+** retraverse all gray lists. Because tables may be reinserted in other
550+** lists when traversed, traverse the original lists to avoid traversing
551+** twice the same table (which is not wrong, but inefficient)
552+*/
553+static void retraversegrays (global_State *g) {
554+ GCObject *weak = g->weak; /* save original lists */
555+ GCObject *grayagain = g->grayagain;
556+ GCObject *ephemeron = g->ephemeron;
557+ g->weak = g->grayagain = g->ephemeron = NULL;
558+ propagateall(g); /* traverse main gray list */
559+ propagatelist(g, grayagain);
560+ propagatelist(g, weak);
561+ propagatelist(g, ephemeron);
534562 }
535563
536564
@@ -562,21 +590,39 @@ static void convergeephemerons (global_State *g) { · 25 unmodified lines
562590
563591
564592 /*
565−** clear collected entries from all weaktables in list 'l'
593+** clear entries with unmarked keys from all weaktables in list 'l' up
594+** to element 'f'
595+*/
596+static void clearkeys (GCObject *l, GCObject *f) {
597+ for (; l != f; l = gco2t(l)->gclist) {
598+ Table *h = gco2t(l);
599+ Node *n, *limit = gnode(h, sizenode(h));
600+ for (n = gnode(h, 0); n < limit; n++) {
601+ if (!ttisnil(gval(n)) && (iscleared(gkey(n)))) {
602+ setnilvalue(gval(n)); /* remove value ... */
603+ removeentry(n); /* and remove entry from table */
604+ }
605+ }
606+ }
607+}
608+
609+
610+/*
611+** clear entries with unmarked values from all weaktables in list 'l' up
612+** to element 'f'
566613 */
567−static void cleartable (GCObject *l) {
568− for (; l != NULL; l = gco2t(l)->gclist) {
614+static void clearvalues (GCObject *l, GCObject *f) {
615+ for (; l != f; l = gco2t(l)->gclist) {
569616 Table *h = gco2t(l);
570617 Node *n, *limit = gnode(h, sizenode(h));
571618 int i;
572619 for (i = 0; i < h->sizearray; i++) {
573620 TValue *o = &h->array[i];
574− if (iscleared(o, 0)) /* value was collected? */
621+ if (iscleared(o)) /* value was collected? */
575622 setnilvalue(o); /* remove value */
576623 }
577624 for (n = gnode(h, 0); n < limit; n++) {
578− if (!ttisnil(gval(n)) && /* non-empty entry? */
579− (iscleared(gkey(n), 1) || iscleared(gval(n), 0))) {
625+ if (!ttisnil(gval(n)) && iscleared(gval(n))) {
580626 setnilvalue(gval(n)); /* remove value ... */
581627 removeentry(n); /* and remove entry from table */
582628 }
@@ -743,10 +789,10 @@ static void GCTM (lua_State *L, int propagateerrors) { · 160 unmodified lines
743789
744790
745791 /*
746−** move all unreachable objects that need finalization from list 'finobj'
747−** to list 'tobefnz'
792+** move all unreachable objects (or 'all' objects) that need
793+** finalization from list 'finobj' to list 'tobefnz' (to be finalized)
748794 */
749−void luaC_separateudata (lua_State *L, int all) {
795+static void separatetobefnz (lua_State *L, int all) {
750796 global_State *g = G(L);
751797 GCObject **p = &g->finobj;
752798 GCObject *curr;
@@ -842,14 +888,13 @@ static void callallpendingfinalizers (lua_State *L, int propagateerrors) { · 89 unmodified lines
842888 void luaC_freeallobjects (lua_State *L) {
843889 global_State *g = G(L);
844890 int i;
891+ separatetobefnz(L, 1); /* separate all objects with finalizers */
892+ lua_assert(g->finobj == NULL);
845893 callallpendingfinalizers(L, 0);
846− /* following "white" makes all objects look dead */
847− g->currentwhite = WHITEBITS;
894+ g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */
848895 g->gckind = KGC_NORMAL;
849− sweepwholelist(L, &g->finobj);
850− lua_assert(g->finobj == NULL);
896+ sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */
851897 sweepwholelist(L, &g->allgc);
852− lua_assert(g->allgc == NULL);
853898 for (i = 0; i < g->strt.size; i++) /* free all string lists */
854899 sweepwholelist(L, &g->strt.hash[i]);
855900 lua_assert(g->strt.nuse == 0);
@@ -858,6 +903,7 @@ void luaC_freeallobjects (lua_State *L) { · 2 unmodified lines
858903
859904 static void atomic (lua_State *L) {
860905 global_State *g = G(L);
906+ GCObject *origweak, *origall;
861907 lua_assert(!iswhite(obj2gco(g->mainthread)));
862908 markobject(g, L); /* mark running thread */
863909 /* registry and global metatables may be changed by API */
@@ -866,20 +912,24 @@ static void atomic (lua_State *L) { · 2 unmodified lines
866912 /* remark occasional upvalues of (maybe) dead threads */
867913 remarkupvals(g);
868914 /* traverse objects caught by write barrier and by 'remarkupvals' */
869− propagateall(g);
870− traverselistofgrays(g, &g->weak); /* remark weak tables */
871− traverselistofgrays(g, &g->ephemeron); /* remark ephemeron tables */
872− traverselistofgrays(g, &g->grayagain); /* remark gray again */
915+ retraversegrays(g);
873916 convergeephemerons(g);
874917 /* at this point, all strongly accessible objects are marked. */
875− luaC_separateudata(L, 0); /* separate userdata to be finalized */
918+ /* clear values from weak tables, before checking finalizers */
919+ clearvalues(g->weak, NULL);
920+ clearvalues(g->allweak, NULL);
921+ origweak = g->weak; origall = g->allweak;
922+ separatetobefnz(L, 0); /* separate objects to be finalized */
876923 markbeingfnz(g); /* mark userdata that will be finalized */
877924 propagateall(g); /* remark, to propagate `preserveness' */
878925 convergeephemerons(g);
879− /* remove collected objects from weak tables */
880− cleartable(g->weak);
881− cleartable(g->ephemeron);
882− cleartable(g->allweak);
926+ /* at this point, all resurrected objects are marked. */
927+ /* remove dead objects from weak tables */
928+ clearkeys(g->ephemeron, NULL); /* clear keys from all ephemeron tables */
929+ clearkeys(g->allweak, NULL); /* clear keys from all allweak tables */
930+ /* clear values from resurrected weak tables */
931+ clearvalues(g->weak, origweak);
932+ clearvalues(g->allweak, origall);
883933 g->sweepstrgc = 0; /* prepare to sweep strings */
884934 g->gcstate = GCSsweepstring;
885935 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
src/lgc.h+1−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.h,v 2.50 2011/01/26 16:30:02 roberto Exp $
2+** $Id: lgc.h,v 2.52 2011/10/03 17:54:25 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -63,9 +63,6 @@ · 57 unmodified lines
6363 #define l_setbit(x,b) setbits(x, bitmask(b))
6464 #define resetbit(x,b) resetbits(x, bitmask(b))
6565 #define testbit(x,b) testbits(x, bitmask(b))
66−#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
67−#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
68−
6966
7067
7168 /* Layout for bit use in `marked' field: */
@@ -125,7 +122,6 @@ · 53 unmodified lines
125122 #define luaC_barrierproto(L,p,c) \
126123 { if (isblack(obj2gco(p))) luaC_barrierproto_(L,p,c); }
127124
128−LUAI_FUNC void luaC_separateudata (lua_State *L, int all);
129125 LUAI_FUNC void luaC_freeallobjects (lua_State *L);
130126 LUAI_FUNC void luaC_step (lua_State *L);
131127 LUAI_FUNC void luaC_forcestep (lua_State *L);
src/liolib.c+74−30
@@ -1,10 +1,20 @@
11 /*
2−** $Id: liolib.c,v 2.101 2011/06/27 19:42:31 roberto Exp $
2+** $Id: liolib.c,v 2.107 2011/11/14 16:55:35 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
66
77
8+/*
9+** POSIX idiosyncrasy!
10+** This definition must come before the inclusion of 'stdio.h'; it
11+** should not affect non-POSIX systems
12+*/
13+#if !defined(_FILE_OFFSET_BITS)
14+#define _FILE_OFFSET_BITS 64
15+#endif
16+
17+
818 #include <errno.h>
919 #include <stdio.h>
1020 #include <stdlib.h>
@@ -21,9 +31,12 @@ · 10 unmodified lines
2131
2232
2333 /*
24−** lua_popen spawns a new process connected to the current one through
25−** the file streams.
34+** {======================================================
35+** lua_popen spawns a new process connected to the current
36+** one through the file streams.
37+** =======================================================
2638 */
39+
2740 #if !defined(lua_popen) /* { */
2841
2942 #if defined(LUA_USE_POPEN) /* { */
@@ -48,22 +61,48 @@ · 18 unmodified lines
4861
4962 #endif /* } */
5063
64+/* }====================================================== */
65+
66+
67+/*
68+** {======================================================
69+** lua_fseek/lua_ftell: configuration for longer offsets
70+** =======================================================
71+*/
72+
73+#if !defined(lua_fseek) /* { */
74+
75+#if defined(LUA_USE_POSIX)
76+
77+#define l_fseek(f,o,w) fseeko(f,o,w)
78+#define l_ftell(f) ftello(f)
79+#define l_seeknum off_t
80+
81+#elif defined(LUA_WIN)
82+
83+#define l_fseek(f,o,w) _fseeki64(f,o,w)
84+#define l_ftell(f) _ftelli64(f)
85+#define l_seeknum __int64
86+
87+#else
88+
89+#define l_fseek(f,o,w) fseek(f,o,w)
90+#define l_ftell(f) ftell(f)
91+#define l_seeknum long
92+
93+#endif
94+
95+#endif /* } */
96+
97+/* }====================================================== */
98+
5199
52100 #define IO_PREFIX "_IO_"
53101 #define IO_INPUT (IO_PREFIX "input")
54102 #define IO_OUTPUT (IO_PREFIX "output")
55103
56104
57−typedef struct LStream {
58− FILE *f; /* stream */
59− lua_CFunction closef; /* to close stream (NULL for closed streams) */
60−} LStream;
61−
62−
63−static void fileerror (lua_State *L, int arg, const char *filename) {
64− lua_pushfstring(L, "%s: %s", filename, strerror(errno));
65− luaL_argerror(L, arg, lua_tostring(L, -1));
66−}
105+typedef luaL_Stream LStream;
67106
68107
69108 #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
@@ -159,6 +198,14 @@ static LStream *newfile (lua_State *L) { · 89 unmodified lines
159198 }
160199
161200
201+static void opencheck (lua_State *L, const char *fname, const char *mode) {
202+ LStream *p = newfile(L);
203+ p->f = fopen(fname, mode);
204+ if (p->f == NULL)
205+ luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
206+}
207+
208+
162209 static int io_open (lua_State *L) {
163210 const char *filename = luaL_checkstring(L, 1);
164211 const char *mode = luaL_optstring(L, 2, "r");
@@ -169,7 +216,7 @@ static int io_open (lua_State *L) { · 4 unmodified lines
169216 (mode[i] != '+' || ++i) && /* skip if char is '+' */
170217 (mode[i] != 'b' || ++i) && /* skip if char is 'b' */
171218 (mode[i] == '\0')))
172− return luaL_error(L, "invalid mode " LUA_QL("%s")
219+ return luaL_error(L, "invalid mode " LUA_QS
173220 " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
174221 p->f = fopen(filename, mode);
175222 return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
@@ -215,12 +262,8 @@ static FILE *getiofile (lua_State *L, const char *findex) { · 39 unmodified lines
215262 static int g_iofile (lua_State *L, const char *f, const char *mode) {
216263 if (!lua_isnoneornil(L, 1)) {
217264 const char *filename = lua_tostring(L, 1);
218− if (filename) {
219− LStream *p = newfile(L);
220− p->f = fopen(filename, mode);
221− if (p->f == NULL)
222− fileerror(L, 1, filename);
223− }
265+ if (filename)
266+ opencheck(L, filename, mode);
224267 else {
225268 tofile(L); /* check that it's a valid file handle */
226269 lua_pushvalue(L, 1);
@@ -277,10 +320,7 @@ static int io_lines (lua_State *L) { · 50 unmodified lines
277320 }
278321 else { /* open a new file */
279322 const char *filename = luaL_checkstring(L, 1);
280− LStream *p = newfile(L);
281− p->f = fopen(filename, "r");
282− if (p->f == NULL)
283− fileerror(L, 1, filename);
323+ opencheck(L, filename, "r");
284324 lua_replace(L, 1); /* put file at index 1 */
285325 toclose = 1; /* close it after iteration */
286326 }
@@ -444,9 +484,10 @@ static int io_readline (lua_State *L) { · 157 unmodified lines
444484 if (!lua_isnil(L, -n)) /* read at least one value? */
445485 return n; /* return them */
446486 else { /* first result is nil: EOF or error */
447− if (!lua_isnil(L, -1)) /* is there error information? */
448− return luaL_error(L, "%s", lua_tostring(L, -1)); /* error */
449− /* else EOF */
487+ if (n > 1) { /* is there error information? */
488+ /* 2nd result is error message */
489+ return luaL_error(L, "%s", lua_tostring(L, -n + 1));
490+ }
450491 if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
451492 lua_settop(L, 0);
452493 lua_pushvalue(L, lua_upvalueindex(1));
@@ -496,12 +537,15 @@ static int f_seek (lua_State *L) { · 43 unmodified lines
496537 static const char *const modenames[] = {"set", "cur", "end", NULL};
497538 FILE *f = tofile(L);
498539 int op = luaL_checkoption(L, 2, "cur", modenames);
499− long offset = luaL_optlong(L, 3, 0);
500− op = fseek(f, offset, mode[op]);
540+ lua_Number p3 = luaL_optnumber(L, 3, 0);
541+ l_seeknum offset = (l_seeknum)p3;
542+ luaL_argcheck(L, (lua_Number)offset == p3, 3,
543+ "not an integer in proper range");
544+ op = l_fseek(f, offset, mode[op]);
501545 if (op)
502546 return luaL_fileresult(L, 0, NULL); /* error */
503547 else {
504− lua_pushinteger(L, ftell(f));
548+ lua_pushnumber(L, (lua_Number)l_ftell(f));
505549 return 1;
506550 }
507551 }
src/llex.c+40−47
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.53 2011/07/08 20:01:38 roberto Exp $
2+** $Id: llex.c,v 2.58 2011/08/15 19:41:58 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -126,8 +126,10 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { · 120 unmodified lines
126126 TValue *o; /* entry for `str' */
127127 TString *ts = luaS_newlstr(L, str, l); /* create new string */
128128 setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */
129− o = luaH_setstr(L, ls->fs->h, ts);
130− if (ttisnil(o)) {
129+ o = luaH_set(L, ls->fs->h, L->top - 1);
130+ if (ttisnil(o)) { /* not in use yet? (see 'addK') */
131+ /* boolean value does not need GC barrier;
132+ table has no metatable, so it does not need to invalidate cache */
131133 setbvalue(o, 1); /* t[string] = true */
132134 luaC_checkGC(L);
133135 }
@@ -297,39 +299,29 @@ static void escerror (LexState *ls, int *c, int n, const char *msg) { · 163 unmodified lines
297299
298300
299301 static int readhexaesc (LexState *ls) {
300− int c[3]; /* keep input for error message */
301− int i = 2; /* at least 'x?' will go to error message */
302− c[0] = 'x';
303− c[1] = next(ls); /* first hexa digit */
304− if (lisxdigit(c[1])) {
305− c[i++] = next(ls); /* second hexa digit */
306− if (lisxdigit(c[2]))
307− return (luaO_hexavalue(c[1]) << 4) + luaO_hexavalue(c[2]);
308− /* else go through to error */
302+ int c[3], i; /* keep input for error message */
303+ int r = 0; /* result accumulator */
304+ c[0] = 'x'; /* for error message */
305+ for (i = 1; i < 3; i++) { /* read two hexa digits */
306+ c[i] = next(ls);
307+ if (!lisxdigit(c[i]))
308+ escerror(ls, c, i + 1, "hexadecimal digit expected");
309+ r = (r << 4) + luaO_hexavalue(c[i]);
309310 }
310− escerror(ls, c, i, "hexadecimal digit expected");
311− return 0; /* to avoid warnings */
311+ return r;
312312 }
313313
314314
315315 static int readdecesc (LexState *ls) {
316− int c[3], r;
317− int i = 2; /* at least two chars will be read */
318− c[0] = ls->current; /* first char must be a digit */
319− c[1] = next(ls); /* read second char */
320− r = c[0] - '0'; /* partial result */
321− if (lisdigit(c[1])) {
322− c[i++] = next(ls); /* read third char */
323− r = 10*r + c[1] - '0'; /* update result */
324− if (lisdigit(c[2])) {
325− r = 10*r + c[2] - '0'; /* update result */
326− if (r > UCHAR_MAX)
327− escerror(ls, c, i, "decimal escape too large");
328− return r;
329− }
316+ int c[3], i;
317+ int r = 0; /* result accumulator */
318+ for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */
319+ c[i] = ls->current;
320+ r = 10*r + c[i] - '0';
321+ next(ls);
330322 }
331− /* else, has read one character that was not a digit */
332− zungetc(ls->z); /* return it to input stream */
323+ if (r > UCHAR_MAX)
324+ escerror(ls, c, i, "decimal escape too large");
333325 return r;
334326 }
335327
@@ -349,37 +341,38 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 13 unmodified lines
349341 int c; /* final character to be saved */
350342 next(ls); /* do not save the `\' */
351343 switch (ls->current) {
352− case 'a': c = '\a'; break;
353− case 'b': c = '\b'; break;
354− case 'f': c = '\f'; break;
355− case 'n': c = '\n'; break;
356− case 'r': c = '\r'; break;
357− case 't': c = '\t'; break;
358− case 'v': c = '\v'; break;
359− case 'x': c = readhexaesc(ls); break;
360− case '\n':
361− case '\r': save(ls, '\n'); inclinenumber(ls); continue;
362− case '\\': case '\"': case '\'': c = ls->current; break;
363− case EOZ: continue; /* will raise an error next loop */
344+ case 'a': c = '\a'; goto read_save;
345+ case 'b': c = '\b'; goto read_save;
346+ case 'f': c = '\f'; goto read_save;
347+ case 'n': c = '\n'; goto read_save;
348+ case 'r': c = '\r'; goto read_save;
349+ case 't': c = '\t'; goto read_save;
350+ case 'v': c = '\v'; goto read_save;
351+ case 'x': c = readhexaesc(ls); goto read_save;
352+ case '\n': case '\r':
353+ inclinenumber(ls); c = '\n'; goto only_save;
354+ case '\\': case '\"': case '\'':
355+ c = ls->current; goto read_save;
356+ case EOZ: goto no_save; /* will raise an error next loop */
364357 case 'z': { /* zap following span of spaces */
365358 next(ls); /* skip the 'z' */
366359 while (lisspace(ls->current)) {
367360 if (currIsNewline(ls)) inclinenumber(ls);
368361 else next(ls);
369362 }
370− continue; /* do not save 'c' */
363+ goto no_save;
371364 }
372365 default: {
373366 if (!lisdigit(ls->current))
374367 escerror(ls, &ls->current, 1, "invalid escape sequence");
375368 /* digital escape \ddd */
376369 c = readdecesc(ls);
377− break;
370+ goto only_save;
378371 }
379372 }
380− next(ls);
381− save(ls, c);
382− break;
373+ read_save: next(ls); /* read next character */
374+ only_save: save(ls, c); /* save 'c' */
375+ no_save: break;
383376 }
384377 default:
385378 save_and_next(ls);
src/llimits.h+16−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.90 2011/07/02 15:57:25 roberto Exp $
2+** $Id: llimits.h,v 1.93 2011/10/07 20:45:19 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -30,7 +30,6 @@ typedef unsigned char lu_byte; · 24 unmodified lines
3030 #define MAX_SIZET ((size_t)(~(size_t)0)-2)
3131
3232 #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
33−#define MIN_LMEM ((l_mem)~((~(lu_mem)0)>>1))
3433
3534
3635 #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
@@ -62,9 +61,9 @@ typedef LUAI_UACNUMBER l_uacNumber; · 25 unmodified lines
6261 /* to avoid problems with conditions too long */
6362 #define lua_longassert(c) { if (!(c)) lua_assert(0); }
6463 #else
65−#define lua_assert(c) /* empty */
64+#define lua_assert(c) ((void)0)
6665 #define check_exp(c,e) (e)
67−#define lua_longassert(c) /* empty */
66+#define lua_longassert(c) ((void)0)
6867 #endif
6968
7069 /*
@@ -97,6 +96,19 @@ typedef LUAI_UACNUMBER l_uacNumber; · 26 unmodified lines
9796 #define cast_uchar(i) cast(unsigned char, (i))
9897
9998
99+/*
100+** non-return type
101+*/
102+#if defined(__GNUC__)
103+#define l_noret void __attribute__((noreturn))
104+#elif defined(_MSC_VER)
105+#define l_noret void __declspec(noreturn)
106+#else
107+#define l_noret void
108+#endif
109+
110+
111+
100112 /*
101113 ** maximum depth for nested C calls and syntactical nested non-terminals
102114 ** in a program. (Value must fit in an unsigned short int.)
src/lmem.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmem.c,v 1.81 2010/12/20 19:40:07 roberto Exp $
2+** $Id: lmem.c,v 1.82 2011/09/20 19:25:23 roberto Exp $
33 ** Interface to Memory Manager
44 ** See Copyright Notice in lua.h
55 */
@@ -106,7 +106,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 100 unmodified lines
106106 if ((total % 200) == 0) {
107107 if (f == NULL) f = fopen(TRACEMEM, "w");
108108 fprintf(f, "%lu %u %d %d\n", total,
109− g->totalbytes, g->GCdebt, g->gcstate * 1000);
109+ gettotalbytes(g), g->GCdebt, g->gcstate * 10000);
110110 }
111111 }
112112 #endif
src/loadlib.c+71−33
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.100 2011/07/05 12:49:35 roberto Exp $
2+** $Id: loadlib.c,v 1.104 2011/11/10 11:42:58 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -9,6 +9,14 @@ · 3 unmodified lines
99 */
1010
1111
12+/*
13+** if needed, includes windows header before everything else
14+*/
15+#if defined(LUA_DL_DLL)
16+#include <windows.h>
17+#endif
18+
19+
1220 #include <stdlib.h>
1321 #include <string.h>
1422
@@ -62,6 +70,20 @@ · 47 unmodified lines
6270 #endif
6371
6472
73+/*
74+** LUA_CSUBSEP is the character that replaces dots in submodule names
75+** when searching for a C loader.
76+** LUA_LSUBSEP is the character that replaces dots in submodule names
77+** when searching for a Lua loader.
78+*/
79+#if !defined(LUA_CSUBSEP)
80+#define LUA_CSUBSEP LUA_DIRSEP
81+#endif
82+
83+#if !defined(LUA_LSUBSEP)
84+#define LUA_LSUBSEP LUA_DIRSEP
85+#endif
86+
6587
6688 /* prefix for open functions in C libraries */
6789 #define LUA_POF "luaopen_"
@@ -133,8 +155,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 65 unmodified lines
133155 ** =======================================================================
134156 */
135157
136−#include <windows.h>
137−
138158 #undef setprogdir
139159
140160 /*
@@ -322,10 +342,12 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { · 181 unmodified lines
322342
323343 static const char *searchpath (lua_State *L, const char *name,
324344 const char *path,
325− const char *sep) {
345+ const char *sep,
346+ const char *dirsep) {
347+ luaL_Buffer msg; /* to build error message */
348+ luaL_buffinit(L, &msg);
326349 if (*sep != '\0') /* non-empty separator? */
327− name = luaL_gsub(L, name, sep, LUA_DIRSEP); /* replace it by proper one */
328− lua_pushliteral(L, ""); /* error accumulator */
350+ name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
329351 while ((path = pushnexttemplate(L, path)) != NULL) {
330352 const char *filename = luaL_gsub(L, lua_tostring(L, -1),
331353 LUA_PATH_MARK, name);
@@ -334,8 +356,9 @@ static const char *searchpath (lua_State *L, const char *name, · 2 unmodified lines
334356 return filename; /* return that file name */
335357 lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
336358 lua_remove(L, -2); /* remove file name */
337− lua_concat(L, 2); /* add entry to possible error message */
359+ luaL_addvalue(&msg); /* concatenate error msg. entry */
338360 }
361+ luaL_pushresult(&msg); /* create error message */
339362 return NULL; /* not found */
340363 }
341364
@@ -343,7 +366,8 @@ static const char *searchpath (lua_State *L, const char *name, · 1 unmodified line
343366 static int ll_searchpath (lua_State *L) {
344367 const char *f = searchpath(L, luaL_checkstring(L, 1),
345368 luaL_checkstring(L, 2),
346− luaL_optstring(L, 3, "."));
369+ luaL_optstring(L, 3, "."),
370+ luaL_optstring(L, 4, LUA_DIRSEP));
347371 if (f != NULL) return 1;
348372 else { /* error message is on top of the stack */
349373 lua_pushnil(L);
@@ -354,13 +378,14 @@ static int ll_searchpath (lua_State *L) { · 4 unmodified lines
354378
355379
356380 static const char *findfile (lua_State *L, const char *name,
357− const char *pname) {
381+ const char *pname,
382+ const char *dirsep) {
358383 const char *path;
359384 lua_getfield(L, lua_upvalueindex(1), pname);
360385 path = lua_tostring(L, -1);
361386 if (path == NULL)
362387 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
363− return searchpath(L, name, path, ".");
388+ return searchpath(L, name, path, ".", dirsep);
364389 }
365390
366391
@@ -379,7 +404,7 @@ static int checkload (lua_State *L, int stat, const char *filename) { · 12 unmodified lines
379404 static int searcher_Lua (lua_State *L) {
380405 const char *filename;
381406 const char *name = luaL_checkstring(L, 1);
382− filename = findfile(L, name, "path");
407+ filename = findfile(L, name, "path", LUA_LSUBSEP);
383408 if (filename == NULL) return 1; /* module not found in this path */
384409 return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);
385410 }
@@ -405,7 +430,7 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) { · 19 unmodified lines
405430
406431 static int searcher_C (lua_State *L) {
407432 const char *name = luaL_checkstring(L, 1);
408− const char *filename = findfile(L, name, "cpath");
433+ const char *filename = findfile(L, name, "cpath", LUA_CSUBSEP);
409434 if (filename == NULL) return 1; /* module not found in this path */
410435 return checkload(L, (loadfunc(L, filename, name) == 0), filename);
411436 }
@@ -418,7 +443,7 @@ static int searcher_Croot (lua_State *L) { · 6 unmodified lines
418443 int stat;
419444 if (p == NULL) return 0; /* is root */
420445 lua_pushlstring(L, name, p - name);
421− filename = findfile(L, lua_tostring(L, -1), "cpath");
446+ filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP);
422447 if (filename == NULL) return 1; /* root not found */
423448 if ((stat = loadfunc(L, filename, name)) != 0) {
424449 if (stat != ERRFUNC)
@@ -444,35 +469,46 @@ static int searcher_preload (lua_State *L) { · 19 unmodified lines
444469 }
445470
446471
447−static int ll_require (lua_State *L) {
448− const char *name = luaL_checkstring(L, 1);
472+static void findloader (lua_State *L, const char *name) {
449473 int i;
450− lua_settop(L, 1); /* _LOADED table will be at index 2 */
451− lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
452− lua_getfield(L, 2, name);
453− if (lua_toboolean(L, -1)) /* is it there? */
454− return 1; /* package is already loaded */
455− /* else must load it; iterate over available seachers to find a loader */
456− lua_getfield(L, lua_upvalueindex(1), "searchers");
457− if (!lua_istable(L, -1))
474+ luaL_Buffer msg; /* to build error message */
475+ luaL_buffinit(L, &msg);
476+ lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */
477+ if (!lua_istable(L, 3))
458478 luaL_error(L, LUA_QL("package.searchers") " must be a table");
459− lua_pushliteral(L, ""); /* error message accumulator */
460− for (i=1; ; i++) {
461− lua_rawgeti(L, -2, i); /* get a seacher */
462− if (lua_isnil(L, -1)) /* no more searchers? */
479+ /* iterate over available seachers to find a loader */
480+ for (i = 1; ; i++) {
481+ lua_rawgeti(L, 3, i); /* get a seacher */
482+ if (lua_isnil(L, -1)) { /* no more searchers? */
483+ lua_pop(L, 1); /* remove nil */
484+ luaL_pushresult(&msg); /* create error message */
463485 luaL_error(L, "module " LUA_QS " not found:%s",
464− name, lua_tostring(L, -2));
486+ name, lua_tostring(L, -1));
487+ }
465488 lua_pushstring(L, name);
466489 lua_call(L, 1, 2); /* call it */
467490 if (lua_isfunction(L, -2)) /* did it find a loader? */
468− break; /* module loader found */
491+ return; /* module loader found */
469492 else if (lua_isstring(L, -2)) { /* searcher returned error message? */
470493 lua_pop(L, 1); /* remove extra return */
471− lua_concat(L, 2); /* accumulate error message */
494+ luaL_addvalue(&msg); /* concatenate error message */
472495 }
473496 else
474497 lua_pop(L, 2); /* remove both returns */
475498 }
499+}
500+
501+
502+static int ll_require (lua_State *L) {
503+ const char *name = luaL_checkstring(L, 1);
504+ lua_settop(L, 1); /* _LOADED table will be at index 2 */
505+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
506+ lua_getfield(L, 2, name); /* _LOADED[name] */
507+ if (lua_toboolean(L, -1)) /* is it there? */
508+ return 1; /* package is already loaded */
509+ /* else must load package */
510+ lua_pop(L, 1); /* remove 'getfield' result */
511+ findloader(L, name);
476512 lua_pushstring(L, name); /* pass name as argument to module loader */
477513 lua_insert(L, -2); /* name is 1st argument (before search data) */
478514 lua_call(L, 2, 1); /* run loader to load module */
@@ -516,9 +552,11 @@ static void set_env (lua_State *L) { · 37 unmodified lines
516552 static void dooptions (lua_State *L, int n) {
517553 int i;
518554 for (i = 2; i <= n; i++) {
519− lua_pushvalue(L, i); /* get option (a function) */
520− lua_pushvalue(L, -2); /* module */
521− lua_call(L, 1, 0);
555+ if (lua_isfunction(L, i)) { /* avoid 'calling' extra info. */
556+ lua_pushvalue(L, i); /* get option (a function) */
557+ lua_pushvalue(L, -2); /* module */
558+ lua_call(L, 1, 0);
559+ }
522560 }
523561 }
524562
src/lobject.c+6−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.52 2011/06/24 12:25:02 roberto Exp $
2+** $Id: lobject.c,v 2.53 2011/07/27 12:13:08 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -103,8 +103,8 @@ static int isneg (const char **s) { · 97 unmodified lines
103103
104104
105105 static lua_Number readhexa (const char **s, lua_Number r, int *count) {
106− while (lisxdigit(cast_uchar(**s))) { /* read integer part */
107− r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++)));
106+ for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */
107+ r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(**s)));
108108 (*count)++;
109109 }
110110 return r;
@@ -157,7 +157,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 46 unmodified lines
157157
158158 int luaO_str2d (const char *s, size_t len, lua_Number *result) {
159159 char *endptr;
160− if (strpbrk(s, "xX")) /* hexa? */
160+ if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */
161+ return 0;
162+ else if (strpbrk(s, "xX")) /* hexa? */
161163 *result = lua_strx2number(s, &endptr);
162164 else
163165 *result = lua_str2number(s, &endptr);
src/lobject.h+46−22
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp $
2+** $Id: lobject.h,v 2.64 2011/10/31 17:48:22 roberto Exp $
33 ** Type definitions for Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -132,7 +132,7 @@ typedef struct lua_TValue TValue; · 126 unmodified lines
132132 #define ttislcf(o) checktag((o), LUA_TLCF)
133133 #define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA))
134134 #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
135−#define ttisdeadkey(o) checktag((o), ctb(LUA_TDEADKEY))
135+#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
136136
137137 #define ttisequal(o1,o2) (rttype(o1) == rttype(o2))
138138
@@ -151,6 +151,8 @@ typedef struct lua_TValue TValue; · 12 unmodified lines
151151 #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
152152 #define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
153153 #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th)
154+/* a dead value may get the 'gc' field, but cannot access its contents */
155+#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
154156
155157 #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
156158
@@ -224,7 +226,7 @@ typedef struct lua_TValue TValue; · 67 unmodified lines
224226 val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \
225227 checkliveness(G(L),io); }
226228
227−#define setdeadvalue(obj) settt_(obj, ctb(LUA_TDEADKEY))
229+#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
228230
229231
230232
@@ -262,51 +264,73 @@ typedef struct lua_TValue TValue; · 31 unmodified lines
262264 ** =======================================================
263265 */
264266
265−#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE)
267+#if defined(LUA_NANTRICK) \
268+ || defined(LUA_NANTRICK_LE) \
269+ || defined(LUA_NANTRICK_BE)
266270
267271 /*
268272 ** numbers are represented in the 'd_' field. All other values have the
269−** value (NNMARK | tag) in 'tt_'. A number with such pattern would be
273+** value (NNMARK | tag) in 'tt__'. A number with such pattern would be
270274 ** a "signaled NaN", which is never generated by regular operations by
271275 ** the CPU (nor by 'strtod')
272276 */
273277 #if !defined(NNMARK)
274278 #define NNMARK 0x7FF7A500
279+#define NNMASK 0x7FFFFF00
275280 #endif
276281
277282 #undef TValuefields
278283 #undef NILCONSTANT
279−#if defined(LUA_NANTRICKLE)
284+
285+#if defined(LUA_NANTRICK_LE)
286+
280287 /* little endian */
281288 #define TValuefields \
282− union { struct { Value v_; int tt_; } i; double d_; } u
289+ union { struct { Value v__; int tt__; } i; double d__; } u
283290 #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
284−#else
291+/* field-access macros */
292+#define v_(o) ((o)->u.i.v__)
293+#define d_(o) ((o)->u.d__)
294+#define tt_(o) ((o)->u.i.tt__)
295+
296+#elif defined(LUA_NANTRICK_BE)
297+
285298 /* big endian */
286299 #define TValuefields \
287− union { struct { int tt_; Value v_; } i; double d_; } u
300+ union { struct { int tt__; Value v__; } i; double d__; } u
288301 #define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
302+/* field-access macros */
303+#define v_(o) ((o)->u.i.v__)
304+#define d_(o) ((o)->u.d__)
305+#define tt_(o) ((o)->u.i.tt__)
306+
307+#elif !defined(TValuefields)
308+#error option 'LUA_NANTRICK' needs declaration for 'TValuefields'
309+
289310 #endif
290311
312+
313+/* correspondence with standard representation */
314+#undef val_
315+#define val_(o) v_(o)
316+#undef num_
317+#define num_(o) d_(o)
318+
319+
291320 #undef numfield
292321 #define numfield /* no such field; numbers are the entire struct */
293322
294323 /* basic check to distinguish numbers from non-numbers */
295324 #undef ttisnumber
296−#define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK)
325+#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
297326
298327 #define tag2tt(t) (NNMARK | (t))
299328
300−#undef val_
301−#define val_(o) ((o)->u.i.v_)
302−#undef num_
303−#define num_(o) ((o)->u.d_)
304−
305329 #undef rttype
306−#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : (o)->u.i.tt_ & 0xff)
330+#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
307331
308332 #undef settt_
309−#define settt_(o,t) ((o)->u.i.tt_=tag2tt(t))
333+#define settt_(o,t) (tt_(o) = tag2tt(t))
310334
311335 #undef setnvalue
312336 #define setnvalue(obj,x) \
@@ -324,11 +348,11 @@ typedef struct lua_TValue TValue; · 11 unmodified lines
324348 */
325349
326350 #undef checktag
327−#define checktag(o,t) ((o)->u.i.tt_ == tag2tt(t))
351+#define checktag(o,t) (tt_(o) == tag2tt(t))
328352
329353 #undef ttisequal
330354 #define ttisequal(o1,o2) \
331− (ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_))
355+ (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))
332356
333357
334358
@@ -435,11 +459,11 @@ typedef struct Proto { · 100 unmodified lines
435459 TValue *k; /* constants used by the function */
436460 Instruction *code;
437461 struct Proto **p; /* functions defined inside the function */
438− int *lineinfo; /* map from opcodes to source lines */
439− LocVar *locvars; /* information about local variables */
462+ int *lineinfo; /* map from opcodes to source lines (debug information) */
463+ LocVar *locvars; /* information about local variables (debug information) */
440464 Upvaldesc *upvalues; /* upvalue information */
441465 union Closure *cache; /* last created closure with this prototype */
442− TString *source;
466+ TString *source; /* used for debug information */
443467 int sizeupvalues; /* size of 'upvalues' */
444468 int sizek; /* size of `k' */
445469 int sizecode;
src/lopcodes.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.141 2011/04/19 16:22:13 roberto Exp $
2+** $Id: lopcodes.h,v 1.142 2011/07/15 12:50:29 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -196,7 +196,7 @@ OP_LEN,/* A B R(A) := length of R(B) */ · 190 unmodified lines
196196
197197 OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
198198
199−OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
199+OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
200200 OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
201201 OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
202202 OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
src/lparser.c+90−70
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.113 2011/07/02 15:58:14 roberto Exp $
2+** $Id: lparser.c,v 2.122 2011/10/31 17:46:04 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -41,8 +41,8 @@ · 35 unmodified lines
4141 */
4242 typedef struct BlockCnt {
4343 struct BlockCnt *previous; /* chain */
44− int firstlabel; /* index of first label in this block */
45− int firstgoto; /* index of first pending goto in this block */
44+ short firstlabel; /* index of first label in this block */
45+ short firstgoto; /* index of first pending goto in this block */
4646 lu_byte nactvar; /* # active locals outside the block */
4747 lu_byte upval; /* true if some variable in the block is an upvalue */
4848 lu_byte isloop; /* true if `block' is a loop */
@@ -81,13 +81,14 @@ static void error_expected (LexState *ls, int token) { · 32 unmodified lines
8181
8282
8383 static void errorlimit (FuncState *fs, int limit, const char *what) {
84+ lua_State *L = fs->ls->L;
8485 const char *msg;
8586 int line = fs->f->linedefined;
8687 const char *where = (line == 0)
8788 ? "main function"
88− : luaO_pushfstring(fs->L, "function at line %d", line);
89− msg = luaO_pushfstring(fs->L, "too many %s (limit is %d) in %s",
90− what, limit, where);
89+ : luaO_pushfstring(L, "function at line %d", line);
90+ msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
91+ what, limit, where);
9192 luaX_syntaxerror(fs->ls, msg);
9293 }
9394
@@ -182,7 +183,7 @@ static void new_localvar (LexState *ls, TString *name) { · 88 unmodified lines
182183 MAXVARS, "local variables");
183184 luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
184185 dyd->actvar.size, Vardesc, MAX_INT, "local variables");
185− dyd->actvar.arr[dyd->actvar.n++].idx = cast(unsigned short, reg);
186+ dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
186187 }
187188
188189
@@ -231,13 +232,13 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) { · 42 unmodified lines
231232 Proto *f = fs->f;
232233 int oldsize = f->sizeupvalues;
233234 checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
234− luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues,
235+ luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
235236 Upvaldesc, MAXUPVAL, "upvalues");
236237 while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
237238 f->upvalues[fs->nups].instack = (v->k == VLOCAL);
238239 f->upvalues[fs->nups].idx = cast_byte(v->u.info);
239240 f->upvalues[fs->nups].name = name;
240− luaC_objbarrier(fs->L, f, name);
241+ luaC_objbarrier(fs->ls->L, f, name);
241242 return fs->nups++;
242243 }
243244
@@ -327,13 +328,13 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { · 83 unmodified lines
327328
328329
329330 static void enterlevel (LexState *ls) {
330− global_State *g = G(ls->L);
331− ++g->nCcalls;
332− checklimit(ls->fs, g->nCcalls, LUAI_MAXCCALLS, "syntax levels");
331+ lua_State *L = ls->L;
332+ ++L->nCcalls;
333+ checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "syntax levels");
333334 }
334335
335336
336−#define leavelevel(ls) (G((ls)->L)->nCcalls--)
337+#define leavelevel(ls) ((ls)->L->nCcalls--)
337338
338339
339340 static void closegoto (LexState *ls, int g, Labeldesc *label) {
@@ -343,9 +344,10 @@ static void closegoto (LexState *ls, int g, Labeldesc *label) { · 3 unmodified lines
343344 Labeldesc *gt = &gl->arr[g];
344345 lua_assert(eqstr(gt->name, label->name));
345346 if (gt->nactvar < label->nactvar) {
347+ TString *vname = getlocvar(fs, gt->nactvar)->varname;
346348 const char *msg = luaO_pushfstring(ls->L,
347349 "<goto %s> at line %d jumps into the scope of local " LUA_QS,
348− getstr(gt->name), gt->line, getstr(getlocvar(fs, gt->nactvar)->varname));
350+ getstr(gt->name), gt->line, getstr(vname));
349351 semerror(ls, msg);
350352 }
351353 luaK_patchlist(fs, gt->pc, label->pc);
@@ -382,7 +384,8 @@ static int findlabel (LexState *ls, int g) { · 30 unmodified lines
382384 static int newlabelentry (LexState *ls, Labellist *l, TString *name,
383385 int line, int pc) {
384386 int n = l->n;
385− luaM_growvector(ls->L, l->arr, n, l->size, Labeldesc, MAX_INT, "labels");
387+ luaM_growvector(ls->L, l->arr, n, l->size,
388+ Labeldesc, SHRT_MAX, "labels/gotos");
386389 l->arr[n].name = name;
387390 l->arr[n].line = line;
388391 l->arr[n].nactvar = ls->fs->nactvar;
@@ -418,7 +421,7 @@ static void movegotosout (FuncState *fs, BlockCnt *bl) { · 29 unmodified lines
418421 int i = bl->firstgoto;
419422 Labellist *gl = &fs->ls->dyd->gt;
420423 /* correct pending gotos to current block and try to close it
421− with visible labels */
424+ with visible labels */
422425 while (i < gl->n) {
423426 Labeldesc *gt = &gl->arr[i];
424427 if (gt->nactvar > bl->nactvar) {
@@ -514,7 +517,6 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { · 89 unmodified lines
514517 Proto *f;
515518 fs->prev = ls->fs; /* linked list of funcstates */
516519 fs->ls = ls;
517− fs->L = L;
518520 ls->fs = fs;
519521 fs->pc = 0;
520522 fs->lasttarget = 0;
@@ -1039,7 +1041,7 @@ static const struct { · 518 unmodified lines
10391041 ** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
10401042 ** where `binop' is any binary operator with a priority higher than `limit'
10411043 */
1042−static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
1044+static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
10431045 BinOpr op;
10441046 UnOpr uop;
10451047 enterlevel(ls);
@@ -1105,31 +1107,34 @@ struct LHS_assign { · 59 unmodified lines
11051107
11061108
11071109 /*
1108−** check whether, in an assignment to a local variable, the local variable
1109−** is needed in a previous assignment (to a table). If so, save original
1110−** local value in a safe place and use this safe copy in the previous
1111−** assignment.
1110+** check whether, in an assignment to an upvalue/local variable, the
1111+** upvalue/local variable is begin used in a previous assignment to a
1112+** table. If so, save original upvalue/local value in a safe place and
1113+** use this safe copy in the previous assignment.
11121114 */
11131115 static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
11141116 FuncState *fs = ls->fs;
11151117 int extra = fs->freereg; /* eventual position to save local variable */
11161118 int conflict = 0;
1117− for (; lh; lh = lh->prev) {
1118− /* conflict in table 't'? */
1119− if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
1120− conflict = 1;
1121− lh->v.u.ind.vt = VLOCAL;
1122− lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
1123− }
1124− /* conflict in index 'idx'? */
1125− if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
1126− conflict = 1;
1127− lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1119+ for (; lh; lh = lh->prev) { /* check all previous assignments */
1120+ if (lh->v.k == VINDEXED) { /* assigning to a table? */
1121+ /* table is the upvalue/local being assigned now? */
1122+ if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
1123+ conflict = 1;
1124+ lh->v.u.ind.vt = VLOCAL;
1125+ lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
1126+ }
1127+ /* index is the local being assigned? (index cannot be upvalue) */
1128+ if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
1129+ conflict = 1;
1130+ lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1131+ }
11281132 }
11291133 }
11301134 if (conflict) {
1135+ /* copy upvalue/local value to a temporary (in position 'extra') */
11311136 OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
1132− luaK_codeABC(fs, op, fs->freereg, v->u.info, 0); /* make copy */
1137+ luaK_codeABC(fs, op, extra, v->u.info, 0);
11331138 luaK_reserveregs(fs, 1);
11341139 }
11351140 }
@@ -1144,7 +1149,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { · 8 unmodified lines
11441149 primaryexp(ls, &nv.v);
11451150 if (nv.v.k != VINDEXED)
11461151 check_conflict(ls, lh, &nv.v);
1147− checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls,
1152+ checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
11481153 "variable names");
11491154 assignment(ls, &nv, nvars+1);
11501155 }
@@ -1178,10 +1183,18 @@ static int cond (LexState *ls) { · 27 unmodified lines
11781183 }
11791184
11801185
1181−static void gotostat (LexState *ls, TString *label, int line) {
1182− /* create new entry for this goto */
1183− int g = newlabelentry(ls, &ls->dyd->gt, label, line, luaK_jump(ls->fs));
1184− findlabel(ls, g);
1186+static void gotostat (LexState *ls, int pc) {
1187+ int line = ls->linenumber;
1188+ TString *label;
1189+ int g;
1190+ if (testnext(ls, TK_GOTO))
1191+ label = str_checkname(ls);
1192+ else {
1193+ luaX_next(ls); /* skip break */
1194+ label = luaS_new(ls->L, "break");
1195+ }
1196+ g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);
1197+ findlabel(ls, g); /* close it if label already defined */
11851198 }
11861199
11871200
@@ -1190,7 +1203,7 @@ static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) { · 2 unmodified lines
11901203 int i;
11911204 for (i = fs->bl->firstlabel; i < ll->n; i++) {
11921205 if (eqstr(label, ll->arr[i].name)) {
1193− const char *msg = luaO_pushfstring(fs->ls->L,
1206+ const char *msg = luaO_pushfstring(fs->ls->L,
11941207 "label " LUA_QS " already defined on line %d",
11951208 getstr(label), ll->arr[i].line);
11961209 semerror(fs->ls, msg);
@@ -1360,38 +1373,51 @@ static void forstat (LexState *ls, int line) { · 163 unmodified lines
13601373 }
13611374
13621375
1363−static int test_then_block (LexState *ls) {
1376+static void test_then_block (LexState *ls, int *escapelist) {
13641377 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1365− int condexit;
1378+ BlockCnt bl;
1379+ FuncState *fs = ls->fs;
1380+ expdesc v;
1381+ int jf; /* instruction to skip 'then' code (if condition is false) */
13661382 luaX_next(ls); /* skip IF or ELSEIF */
1367− condexit = cond(ls);
1383+ expr(ls, &v); /* read condition */
13681384 checknext(ls, TK_THEN);
1369− block(ls); /* `then' part */
1370− return condexit;
1385+ if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
1386+ luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
1387+ enterblock(fs, &bl, 0); /* must enter block before 'goto' */
1388+ gotostat(ls, v.t); /* handle goto/break */
1389+ if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
1390+ leaveblock(fs);
1391+ return; /* and that is it */
1392+ }
1393+ else /* must skip over 'then' part if condition is false */
1394+ jf = luaK_jump(fs);
1395+ }
1396+ else { /* regular case (not goto/break) */
1397+ luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
1398+ enterblock(fs, &bl, 0);
1399+ jf = v.f;
1400+ }
1401+ statlist(ls); /* `then' part */
1402+ leaveblock(fs);
1403+ if (ls->t.token == TK_ELSE ||
1404+ ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
1405+ luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
1406+ luaK_patchtohere(fs, jf);
13711407 }
13721408
13731409
13741410 static void ifstat (LexState *ls, int line) {
13751411 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
13761412 FuncState *fs = ls->fs;
1377− int flist;
1378− int escapelist = NO_JUMP;
1379− flist = test_then_block(ls); /* IF cond THEN block */
1380− while (ls->t.token == TK_ELSEIF) {
1381− luaK_concat(fs, &escapelist, luaK_jump(fs));
1382− luaK_patchtohere(fs, flist);
1383− flist = test_then_block(ls); /* ELSEIF cond THEN block */
1384− }
1385− if (ls->t.token == TK_ELSE) {
1386− luaK_concat(fs, &escapelist, luaK_jump(fs));
1387− luaK_patchtohere(fs, flist);
1388− luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
1413+ int escapelist = NO_JUMP; /* exit list for finished parts */
1414+ test_then_block(ls, &escapelist); /* IF cond THEN block */
1415+ while (ls->t.token == TK_ELSEIF)
1416+ test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
1417+ if (testnext(ls, TK_ELSE))
13891418 block(ls); /* `else' part */
1390− }
1391− else
1392− luaK_concat(fs, &escapelist, flist);
1393− luaK_patchtohere(fs, escapelist);
13941419 check_match(ls, TK_END, TK_IF, line);
1420+ luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
13951421 }
13961422
13971423
@@ -1551,15 +1577,9 @@ static void statement (LexState *ls) { · 153 unmodified lines
15511577 retstat(ls);
15521578 break;
15531579 }
1554− case TK_BREAK: { /* stat -> breakstat */
1555− luaX_next(ls); /* skip BREAK */
1556− /* code it as "goto 'break'" */
1557− gotostat(ls, luaS_new(ls->L, "break"), line);
1558− break;
1559− }
1580+ case TK_BREAK: /* stat -> breakstat */
15601581 case TK_GOTO: { /* stat -> 'goto' NAME */
1561− luaX_next(ls); /* skip GOTO */
1562− gotostat(ls, str_checkname(ls), line);
1582+ gotostat(ls, luaK_jump(ls->fs));
15631583 break;
15641584 }
15651585 default: { /* stat -> func | assignment */
@@ -1595,8 +1615,8 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, · 29 unmodified lines
15951615 close_func(&lexstate);
15961616 L->top--; /* pop name */
15971617 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
1598− return funcstate.f;
15991618 /* all scopes should be correctly finished */
16001619 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
1620+ return funcstate.f;
16011621 }
16021622
src/lparser.h+6−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp $
2+** $Id: lparser.h,v 1.69 2011/07/27 18:09:01 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -55,7 +55,7 @@ typedef struct expdesc { · 49 unmodified lines
5555
5656 /* description of active local variable */
5757 typedef struct Vardesc {
58− unsigned short idx; /* variable index in stack */
58+ short idx; /* variable index in stack */
5959 } Vardesc;
6060
6161
@@ -98,18 +98,17 @@ typedef struct FuncState { · 36 unmodified lines
9898 Table *h; /* table to find (and reuse) elements in `k' */
9999 struct FuncState *prev; /* enclosing function */
100100 struct LexState *ls; /* lexical state */
101− struct lua_State *L; /* copy of the Lua state */
102101 struct BlockCnt *bl; /* chain of current blocks */
103102 int pc; /* next position to code (equivalent to `ncode') */
104− int lasttarget; /* `pc' of last `jump target' */
103+ int lasttarget; /* 'label' of last 'jump label' */
105104 int jpc; /* list of pending jumps to `pc' */
106− int freereg; /* first free register */
107105 int nk; /* number of elements in `k' */
108106 int np; /* number of elements in `p' */
109− int firstlocal; /* index of first local var of this function */
110− short nlocvars; /* number of elements in `locvars' */
107+ int firstlocal; /* index of first local var (in Dyndata array) */
108+ short nlocvars; /* number of elements in 'f->locvars' */
111109 lu_byte nactvar; /* number of active local variables */
112110 lu_byte nups; /* number of upvalues */
111+ lu_byte freereg; /* first free register */
113112 } FuncState;
114113
115114
src/lstate.c+5−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.c,v 2.89 2010/12/20 19:40:07 roberto Exp $
2+** $Id: lstate.c,v 2.92 2011/10/03 17:54:25 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -136,10 +136,10 @@ static void init_registry (lua_State *L, global_State *g) { · 130 unmodified lines
136136 luaH_resize(L, registry, LUA_RIDX_LAST, 0);
137137 /* registry[LUA_RIDX_MAINTHREAD] = L */
138138 setthvalue(L, &mt, L);
139− setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt);
139+ luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt);
140140 /* registry[LUA_RIDX_GLOBALS] = table of globals */
141141 sethvalue(L, &mt, luaH_new(L));
142− setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt);
142+ luaH_setint(L, registry, LUA_RIDX_GLOBALS, &mt);
143143 }
144144
145145
@@ -171,6 +171,7 @@ static void preinit_state (lua_State *L, global_State *g) { · 25 unmodified lines
171171 L->ci = NULL;
172172 L->stacksize = 0;
173173 L->errorJmp = NULL;
174+ L->nCcalls = 0;
174175 L->hook = NULL;
175176 L->hookmask = 0;
176177 L->basehookcount = 0;
@@ -191,7 +192,7 @@ static void close_state (lua_State *L) { · 14 unmodified lines
191192 luaZ_freebuffer(L, &g->buff);
192193 freestack(L);
193194 lua_assert(gettotalbytes(g) == sizeof(LG));
194− (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0);
195+ (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
195196 }
196197
197198
@@ -237,7 +238,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 39 unmodified lines
237238 g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
238239 L->marked = luaC_white(g);
239240 g->gckind = KGC_NORMAL;
240− g->nCcalls = 0;
241241 preinit_state(L, g);
242242 g->frealloc = f;
243243 g->ud = ud;
@@ -279,9 +279,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 35 unmodified lines
279279 LUA_API void lua_close (lua_State *L) {
280280 L = G(L)->mainthread; /* only the main thread can be closed */
281281 lua_lock(L);
282− luaF_close(L, L->stack); /* close all upvalues for this thread */
283− luaC_separateudata(L, 1); /* separate all udata with GC metamethods */
284− lua_assert(L->next == NULL);
285282 luai_userstateclose(L);
286283 close_state(L);
287284 }
src/lstate.h+2−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.h,v 2.72 2011/06/02 19:31:40 roberto Exp $
2+** $Id: lstate.h,v 2.74 2011/09/30 12:45:07 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -47,8 +47,6 @@ struct lua_longjmp; /* defined in ldo.c */ · 41 unmodified lines
4747 #define EXTRA_STACK 5
4848
4949
50−#define BASIC_CI_SIZE 8
51−
5250 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
5351
5452
@@ -118,7 +116,6 @@ typedef struct global_State { · 63 unmodified lines
118116 lu_mem lastmajormem; /* memory in use after last major collection */
119117 stringtable strt; /* hash table for strings */
120118 TValue l_registry;
121− unsigned short nCcalls; /* number of nested C calls */
122119 lu_byte currentwhite;
123120 lu_byte gcstate; /* state of garbage collector */
124121 lu_byte gckind; /* kind of GC running */
@@ -161,6 +158,7 @@ struct lua_State { · 36 unmodified lines
161158 StkId stack; /* stack base */
162159 int stacksize;
163160 unsigned short nny; /* number of non-yieldable calls in stack */
161+ unsigned short nCcalls; /* number of nested C calls */
164162 lu_byte hookmask;
165163 lu_byte allowhook;
166164 int basehookcount;
src/lstrlib.c+15−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.170 2011/06/28 17:13:52 roberto Exp $
2+** $Id: lstrlib.c,v 1.172 2011/10/25 12:01:20 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -138,7 +138,7 @@ static int str_byte (lua_State *L) { · 132 unmodified lines
138138 if (pose > l) pose = l;
139139 if (posi > pose) return 0; /* empty interval; return no values */
140140 n = (int)(pose - posi + 1);
141− if (posi + n <= pose) /* overflow? */
141+ if (posi + n <= pose) /* (size_t -> int) overflow? */
142142 return luaL_error(L, "string slice too long");
143143 luaL_checkstack(L, n, "string slice too long");
144144 for (i=0; i<n; i++)
@@ -154,7 +154,7 @@ static int str_char (lua_State *L) { · 9 unmodified lines
154154 char *p = luaL_buffinitsize(L, &b, n);
155155 for (i=1; i<=n; i++) {
156156 int c = luaL_checkint(L, i);
157− luaL_argcheck(L, uchar(c) == c, i, "invalid value");
157+ luaL_argcheck(L, uchar(c) == c, i, "value out of range");
158158 p[i - 1] = uchar(c);
159159 }
160160 luaL_pushresultsize(&b, n);
@@ -865,11 +865,20 @@ static int str_format (lua_State *L) { · 704 unmodified lines
865865 nb = sprintf(buff, form, luaL_checkint(L, arg));
866866 break;
867867 }
868− case 'd': case 'i':
868+ case 'd': case 'i': {
869+ lua_Number n = luaL_checknumber(L, arg);
870+ LUA_INTFRM_T r = (LUA_INTFRM_T)n;
871+ luaL_argcheck(L, (lua_Number)r == n, arg,
872+ "not an integer in proper range");
873+ addlenmod(form, LUA_INTFRMLEN);
874+ nb = sprintf(buff, form, r);
875+ break;
876+ }
869877 case 'o': case 'u': case 'x': case 'X': {
870878 lua_Number n = luaL_checknumber(L, arg);
871− LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n :
872− (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n;
879+ unsigned LUA_INTFRM_T r = (unsigned LUA_INTFRM_T)n;
880+ luaL_argcheck(L, (lua_Number)r == n, arg,
881+ "not a non-negative integer in proper range");
873882 addlenmod(form, LUA_INTFRMLEN);
874883 nb = sprintf(buff, form, r);
875884 break;
src/ltable.c+25−36
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.60 2011/06/16 14:14:31 roberto Exp $
2+** $Id: ltable.c,v 2.65 2011/09/30 12:45:27 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -64,13 +64,6 @@ · 58 unmodified lines
6464 #define hashpointer(t,p) hashmod(t, IntPoint(p))
6565
6666
67−/*
68−** number of ints inside a lua_Number
69−*/
70−#define numints cast_int(sizeof(lua_Number)/sizeof(int))
71−
72−
73−
7467 #define dummynode (&dummynode_)
7568
7669 #define isdummy(n) ((n) == dummynode)
@@ -152,7 +145,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 75 unmodified lines
152145 /* key may be dead already, but it is ok to use it in `next' */
153146 if (luaV_rawequalobj(gkey(n), key) ||
154147 (ttisdeadkey(gkey(n)) && iscollectable(key) &&
155− gcvalue(gkey(n)) == gcvalue(key))) {
148+ deadvalue(gkey(n)) == gcvalue(key))) {
156149 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
157150 /* hash elements are numbered after array ones */
158151 return i + t->sizearray;
@@ -314,7 +307,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 155 unmodified lines
314307 /* re-insert elements from vanishing slice */
315308 for (i=nasize; i<oldasize; i++) {
316309 if (!ttisnil(&t->array[i]))
317− setobjt2t(L, luaH_setint(L, t, i+1), &t->array[i]);
310+ luaH_setint(L, t, i + 1, &t->array[i]);
318311 }
319312 /* shrink array */
320313 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
@@ -322,8 +315,11 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 1 unmodified line
322315 /* re-insert elements from hash part */
323316 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
324317 Node *old = nold+i;
325− if (!ttisnil(gval(old)))
318+ if (!ttisnil(gval(old))) {
319+ /* doesn't need barrier/invalidate cache, as entry was
320+ already present in the table */
326321 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
322+ }
327323 }
328324 if (!isdummy(nold))
329325 luaM_freearray(L, nold, twoto(oldhsize)); /* free old array */
@@ -398,14 +394,19 @@ static Node *getfreepos (Table *t) { · 68 unmodified lines
398394 ** put new key in its main position; otherwise (colliding node is in its main
399395 ** position), new key goes to an empty position.
400396 */
401−static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
402− Node *mp = mainposition(t, key);
397+TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
398+ Node *mp;
399+ if (ttisnil(key)) luaG_runerror(L, "table index is nil");
400+ else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
401+ luaG_runerror(L, "table index is NaN");
402+ mp = mainposition(t, key);
403403 if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
404404 Node *othern;
405405 Node *n = getfreepos(t); /* get a free place */
406406 if (n == NULL) { /* cannot find a free place? */
407407 rehash(L, t, key); /* grow table */
408− return luaH_set(L, t, key); /* re-insert key into grown table */
408+ /* whatever called 'newkey' take care of TM cache and GC barrier */
409+ return luaH_set(L, t, key); /* insert key into grown table */
409410 }
410411 lua_assert(!isdummy(n));
411412 othern = mainposition(t, gkey(mp));
@@ -493,41 +494,29 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 81 unmodified lines
493494 }
494495
495496
497+/*
498+** beware: when using this function you probably need to check a GC
499+** barrier and invalidate the TM cache.
500+*/
496501 TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
497502 const TValue *p = luaH_get(t, key);
498− t->flags = 0;
499503 if (p != luaO_nilobject)
500504 return cast(TValue *, p);
501− else {
502− if (ttisnil(key)) luaG_runerror(L, "table index is nil");
503− else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
504− luaG_runerror(L, "table index is NaN");
505− return newkey(L, t, key);
506− }
505+ else return luaH_newkey(L, t, key);
507506 }
508507
509508
510−TValue *luaH_setint (lua_State *L, Table *t, int key) {
509+void luaH_setint (lua_State *L, Table *t, int key, TValue *value) {
511510 const TValue *p = luaH_getint(t, key);
511+ TValue *cell;
512512 if (p != luaO_nilobject)
513− return cast(TValue *, p);
513+ cell = cast(TValue *, p);
514514 else {
515515 TValue k;
516516 setnvalue(&k, cast_num(key));
517− return newkey(L, t, &k);
518− }
519−}
520−
521−
522−TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
523− const TValue *p = luaH_getstr(t, key);
524− if (p != luaO_nilobject)
525− return cast(TValue *, p);
526− else {
527− TValue k;
528− setsvalue(L, &k, key);
529− return newkey(L, t, &k);
517+ cell = luaH_newkey(L, t, &k);
530518 }
519+ setobj2t(L, cell, value);
531520 }
532521
533522
src/ltable.h+5−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.h,v 2.14 2010/06/25 12:18:10 roberto Exp $
2+** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -15,12 +15,14 @@ · 9 unmodified lines
1515 #define gval(n) (&(n)->i_val)
1616 #define gnext(n) ((n)->i_key.nk.next)
1717
18+#define invalidateTMcache(t) ((t)->flags = 0)
19+
1820
1921 LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
20−LUAI_FUNC TValue *luaH_setint (lua_State *L, Table *t, int key);
22+LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
2123 LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
22−LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
2324 LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
25+LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
2426 LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
2527 LUAI_FUNC Table *luaH_new (lua_State *L);
2628 LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize);
src/ltablib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltablib.c,v 1.61 2011/07/05 12:49:35 roberto Exp $
2+** $Id: ltablib.c,v 1.62 2011/09/30 12:45:45 roberto Exp $
33 ** Library for Table Manipulation
44 ** See Copyright Notice in lua.h
55 */
@@ -86,7 +86,7 @@ static void addfield (lua_State *L, luaL_Buffer *b, int i) { · 80 unmodified lines
8686 if (!lua_isstring(L, -1))
8787 luaL_error(L, "invalid value (%s) at index %d in table for "
8888 LUA_QL("concat"), luaL_typename(L, -1), i);
89− luaL_addvalue(b);
89+ luaL_addvalue(b);
9090 }
9191
9292
src/lua.c+39−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.200 2011/06/16 14:30:58 roberto Exp $
2+** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -118,6 +118,7 @@ static void print_usage (const char *badoption) { · 112 unmodified lines
118118 " -i enter interactive mode after executing " LUA_QL("script") "\n"
119119 " -l name require library " LUA_QL("name") "\n"
120120 " -v show version information\n"
121+ " -E ignore environment variables\n"
121122 " -- stop handling options\n"
122123 " - stop handling options and execute stdin\n"
123124 ,
@@ -348,7 +349,16 @@ static int handle_script (lua_State *L, char **argv, int n) { · 224 unmodified lines
348349 #define noextrachars(x) {if ((x)[2] != '\0') return -1;}
349350
350351
351−static int collectargs (char **argv, int *pi, int *pv, int *pe) {
352+/* indices of various argument indicators in array args */
353+#define has_i 0 /* -i */
354+#define has_v 1 /* -v */
355+#define has_e 2 /* -e */
356+#define has_E 3 /* -E */
357+
358+#define num_has 4 /* number of 'has_*' */
359+
360+
361+static int collectargs (char **argv, int *args) {
352362 int i;
353363 for (i = 1; argv[i] != NULL; i++) {
354364 if (argv[i][0] != '-') /* not an option? */
@@ -359,15 +369,18 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 4 unmodified lines
359369 return (argv[i+1] != NULL ? i+1 : 0);
360370 case '\0':
361371 return i;
372+ case 'E':
373+ args[has_E] = 1;
374+ break;
362375 case 'i':
363376 noextrachars(argv[i]);
364− *pi = 1; /* go through */
377+ args[has_i] = 1; /* go through */
365378 case 'v':
366379 noextrachars(argv[i]);
367− *pv = 1;
380+ args[has_v] = 1;
368381 break;
369382 case 'e':
370− *pe = 1; /* go through */
383+ args[has_e] = 1; /* go through */
371384 case 'l': /* both options need an argument */
372385 if (argv[i][2] == '\0') { /* no concatenated argument? */
373386 i++; /* try next 'argv' */
@@ -426,32 +439,46 @@ static int handle_luainit (lua_State *L) { · 52 unmodified lines
426439 }
427440
428441
442+static void resetpaths (lua_State *L) {
443+ lua_getglobal(L, "package");
444+ if (!lua_istable(L, -1)) /* no module 'package'? */
445+ return; /* nothing to be done */
446+ lua_pushliteral(L, LUA_PATH_DEFAULT);
447+ lua_setfield(L, -2, "path"); /* package.path = default */
448+ lua_pushliteral(L, LUA_CPATH_DEFAULT);
449+ lua_setfield(L, -2, "cpath"); /* package.cpath = default */
450+ lua_pop(L, 1); /* remove 'package' */
451+}
452+
453+
429454 static int pmain (lua_State *L) {
430455 int argc = (int)lua_tointeger(L, 1);
431456 char **argv = (char **)lua_touserdata(L, 2);
432457 int script;
433− int has_i = 0, has_v = 0, has_e = 0;
458+ int args[num_has];
459+ args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
434460 if (argv[0] && argv[0][0]) progname = argv[0];
435− script = collectargs(argv, &has_i, &has_v, &has_e);
461+ script = collectargs(argv, args);
436462 if (script < 0) { /* invalid arg? */
437463 print_usage(argv[-script]);
438464 return 0;
439465 }
440− if (has_v) print_version();
466+ if (args[has_v]) print_version();
441467 /* open standard libraries */
442468 luaL_checkversion(L);
443469 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
444470 luaL_openlibs(L); /* open libraries */
445471 lua_gc(L, LUA_GCRESTART, 0);
446− /* run LUA_INIT */
447− if (handle_luainit(L) != LUA_OK) return 0;
472+ if (args[has_E]) /* avoid LUA_INIT? */
473+ resetpaths(L);
474+ else if (handle_luainit(L) != LUA_OK) return 0;
448475 /* execute arguments -e and -l */
449476 if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
450477 /* execute main script (if there is one) */
451478 if (script && handle_script(L, argv, script) != LUA_OK) return 0;
452− if (has_i) /* -i option? */
479+ if (args[has_i]) /* -i option? */
453480 dotty(L);
454− else if (script == 0 && !has_e && !has_v) { /* no arguments? */
481+ else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */
455482 if (lua_stdin_is_tty()) {
456483 print_version();
457484 dotty(L);
src/lua.h+7−10
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.278 2011/07/02 16:00:15 roberto Exp $
2+** $Id: lua.h,v 1.281 2011/10/24 16:53:05 roberto Exp $
33 ** Lua - A Scripting Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -19,7 +19,7 @@ · 13 unmodified lines
1919 #define LUA_VERSION_MAJOR "5"
2020 #define LUA_VERSION_MINOR "2"
2121 #define LUA_VERSION_NUM 502
22−#define LUA_VERSION_RELEASE "0" " (beta)"
22+#define LUA_VERSION_RELEASE "0"
2323
2424 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
2525 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
@@ -215,10 +215,12 @@ LUA_API int (lua_pushthread) (lua_State *L); · 189 unmodified lines
215215 /*
216216 ** get functions (Lua -> stack)
217217 */
218+LUA_API void (lua_getglobal) (lua_State *L, const char *var);
218219 LUA_API void (lua_gettable) (lua_State *L, int idx);
219220 LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
220221 LUA_API void (lua_rawget) (lua_State *L, int idx);
221222 LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
223+LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p);
222224 LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
223225 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
224226 LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
@@ -228,10 +230,12 @@ LUA_API void (lua_getuservalue) (lua_State *L, int idx); · 3 unmodified lines
228230 /*
229231 ** set functions (stack -> Lua)
230232 */
233+LUA_API void (lua_setglobal) (lua_State *L, const char *var);
231234 LUA_API void (lua_settable) (lua_State *L, int idx);
232235 LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
233236 LUA_API void (lua_rawset) (lua_State *L, int idx);
234237 LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
238+LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
235239 LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
236240 LUA_API void (lua_setuservalue) (lua_State *L, int idx);
237241
@@ -261,7 +265,7 @@ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); · 23 unmodified lines
261265 LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
262266 lua_CFunction k);
263267 #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
264−LUA_API int (lua_resume) (lua_State *L, int narg);
268+LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
265269 LUA_API int (lua_status) (lua_State *L);
266270
267271 /*
@@ -314,13 +318,6 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); · 46 unmodified lines
314318
315319 #define lua_newtable(L) lua_createtable(L, 0, 0)
316320
317−#define lua_setglobal(L,s) \
318− (lua_pushglobaltable(L), lua_pushvalue(L, -2), \
319− lua_setfield(L, -2, (s)), lua_pop(L, 2))
320−
321−#define lua_getglobal(L,s) \
322− (lua_pushglobaltable(L), lua_getfield(L, -1, (s)), lua_remove(L, -2))
323−
324321 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
325322
326323 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
src/luac.c+3−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luac.c,v 1.67 2011/06/21 12:29:00 lhf Exp $
2+** $Id: luac.c,v 1.68 2011/11/23 17:48:18 lhf Exp $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -53,7 +53,7 @@ static void usage(const char* message) · 47 unmodified lines
5353 fprintf(stderr,
5454 "usage: %s [options] [filenames]\n"
5555 "Available options are:\n"
56− " -l list\n"
56+ " -l list (use -l -l for full listing)\n"
5757 " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
5858 " -p parse only\n"
5959 " -s strip debug information\n"
@@ -203,7 +203,7 @@ int main(int argc, char* argv[]) · 143 unmodified lines
203203 }
204204
205205 /*
206−** $Id: print.c,v 1.67 2011/05/06 13:37:15 lhf Exp $
206+** $Id: print.c,v 1.68 2011/09/30 10:21:20 lhf Exp $
207207 ** print bytecodes
208208 ** See Copyright Notice in lua.h
209209 */
@@ -218,7 +218,6 @@ int main(int argc, char* argv[]) · 8 unmodified lines
218218 #include "lobject.h"
219219 #include "lopcodes.h"
220220
221−#define Sizeof(x) ((int)sizeof(x))
222221 #define VOID(p) ((const void*)(p))
223222
224223 static void PrintString(const TString* ts)
src/luaconf.h+16−11
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.161 2011/07/08 20:07:11 roberto Exp $
2+** $Id: luaconf.h,v 1.166 2011/11/09 14:47:14 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -29,8 +29,8 @@ · 23 unmodified lines
2929 #endif
3030
3131
32−#if !defined(LUA_ANSI) && defined(_WIN32)
33−#define LUA_WIN
32+#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
33+#define LUA_WIN /* enable goodies for regular Windows platforms */
3434 #endif
3535
3636 #if defined(LUA_WIN)
@@ -210,10 +210,14 @@ · 173 unmodified lines
210210
211211 /*
212212 @@ luai_writestring/luai_writeline define how 'print' prints its results.
213+** They are only used in libraries and the stand-alone program. (The #if
214+** avoids including 'stdio.h' everywhere.)
213215 */
216+#if defined(LUA_LIB) || defined(lua_c) || defined(luaall_c)
214217 #include <stdio.h>
215218 #define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
216219 #define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
220+#endif
217221
218222 /*
219223 @@ luai_writestringerror defines how to print error messages.
@@ -459,7 +463,7 @@ · 239 unmodified lines
459463
460464 /* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
461465 with a DirectX idiosyncrasy */
462−#if defined(_MSC_VER) && defined(M_IX86) /* { */
466+#if defined(LUA_WIN) && defined(_M_IX86) /* { */
463467
464468 #define MS_ASMTRICK
465469
@@ -492,12 +496,13 @@ · 26 unmodified lines
492496
493497
494498 /*
495−@@ LUA_NANTRICKLE/LUA_NANTRICKBE controls the use of a trick to pack all
496−** types into a single double value, using NaN values to represent
497−** non-number values. The trick only works on 32-bit machines (ints and
498−** pointers are 32-bit values) with numbers represented as IEEE 754-2008
499−** doubles with conventional endianess (12345678 or 87654321), in CPUs
500−** that do not produce signaling NaN values (all NaNs are quiet).
499+@@ LUA_NANTRICK_LE/LUA_NANTRICK_BE controls the use of a trick to
500+** pack all types into a single double value, using NaN values to
501+** represent non-number values. The trick only works on 32-bit machines
502+** (ints and pointers are 32-bit values) with numbers represented as
503+** IEEE 754-2008 doubles with conventional endianess (12345678 or
504+** 87654321), in CPUs that do not produce signaling NaN values (all NaNs
505+** are quiet).
501506 */
502507 #if defined(LUA_CORE) && \
503508 defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
@@ -506,7 +511,7 @@ · 2 unmodified lines
506511 #if defined(__i386__) || defined(__i386) || defined(__X86__) || \
507512 defined(_M_IX86)
508513
509−#define LUA_NANTRICKLE
514+#define LUA_NANTRICK_LE
510515
511516 #endif
512517
src/lvm.c+29−20
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 2.141 2011/06/09 18:24:22 roberto Exp $
2+** $Id: lvm.c,v 2.144 2011/10/07 20:45:19 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -127,29 +127,38 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { · 121 unmodified lines
127127
128128 void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
129129 int loop;
130− TValue temp;
131130 for (loop = 0; loop < MAXTAGLOOP; loop++) {
132131 const TValue *tm;
133132 if (ttistable(t)) { /* `t' is a table? */
134133 Table *h = hvalue(t);
135− TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
136− if (!ttisnil(oldval) || /* result is not nil? */
137− (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
138− setobj2t(L, oldval, val);
134+ TValue *oldval = cast(TValue *, luaH_get(h, key));
135+ /* if previous value is not nil, there must be a previous entry
136+ in the table; moreover, a metamethod has no relevance */
137+ if (!ttisnil(oldval) ||
138+ /* previous value is nil; must check the metamethod */
139+ ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
140+ /* no metamethod; is there a previous entry in the table? */
141+ (oldval != luaO_nilobject ||
142+ /* no previous entry; must create one. (The next test is
143+ always true; we only need the assignment.) */
144+ (oldval = luaH_newkey(L, h, key), 1)))) {
145+ /* no metamethod and (now) there is an entry with given key */
146+ setobj2t(L, oldval, val); /* assign new value to that entry */
147+ invalidateTMcache(h);
139148 luaC_barrierback(L, obj2gco(h), val);
140149 return;
141150 }
142− /* else will try the tag method */
151+ /* else will try the metamethod */
143152 }
144− else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
145− luaG_typeerror(L, t, "index");
153+ else /* not a table; check metamethod */
154+ if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
155+ luaG_typeerror(L, t, "index");
156+ /* there is a metamethod */
146157 if (ttisfunction(tm)) {
147158 callTM(L, tm, t, key, val, 0);
148159 return;
149160 }
150− /* else repeat with 'tm' */
151− setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */
152− t = &temp;
161+ t = tm; /* else repeat with 'tm' */
153162 }
154163 luaG_runerror(L, "loop in settable");
155164 }
@@ -217,9 +226,9 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 61 unmodified lines
217226 return luai_numlt(L, nvalue(l), nvalue(r));
218227 else if (ttisstring(l) && ttisstring(r))
219228 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
220− else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
221− return res;
222− return luaG_ordererror(L, l, r);
229+ else if ((res = call_orderTM(L, l, r, TM_LT)) < 0)
230+ luaG_ordererror(L, l, r);
231+ return res;
223232 }
224233
225234
@@ -229,11 +238,11 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { · 3 unmodified lines
229238 return luai_numle(L, nvalue(l), nvalue(r));
230239 else if (ttisstring(l) && ttisstring(r))
231240 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
232− else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
241+ else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */
233242 return res;
234− else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
235− return !res;
236− return luaG_ordererror(L, l, r);
243+ else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */
244+ luaG_ordererror(L, l, r);
245+ return !res;
237246 }
238247
239248
@@ -808,7 +817,7 @@ void luaV_execute (lua_State *L) { · 568 unmodified lines
808817 luaH_resizearray(L, h, last); /* pre-allocate it at once */
809818 for (; n > 0; n--) {
810819 TValue *val = ra+n;
811− setobj2t(L, luaH_setint(L, h, last--), val);
820+ luaH_setint(L, h, last--, val);
812821 luaC_barrierback(L, obj2gco(h), val);
813822 }
814823 L->top = ci->top; /* correct top (in case of previous open call) */
src/lzio.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lzio.c,v 1.33 2011/02/23 13:13:10 roberto Exp $
2+** $Id: lzio.c,v 1.34 2011/07/15 12:35:32 roberto Exp $
33 ** a generic input stream interface
44 ** See Copyright Notice in lua.h
55 */
@@ -29,7 +29,7 @@ int luaZ_fill (ZIO *z) { · 23 unmodified lines
2929 return EOZ;
3030 z->n = size - 1; /* discount char being returned */
3131 z->p = buff;
32− return char2int(*(z->p++));
32+ return cast_uchar(*(z->p++));
3333 }
3434
3535
src/lzio.h+2−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lzio.h,v 1.24 2011/02/23 13:13:10 roberto Exp $
2+** $Id: lzio.h,v 1.26 2011/07/15 12:48:03 roberto Exp $
33 ** Buffered streams
44 ** See Copyright Notice in lua.h
55 */
@@ -17,11 +17,7 @@ · 11 unmodified lines
1717
1818 typedef struct Zio ZIO;
1919
20−#define char2int(c) cast(int, cast(unsigned char, (c)))
21−
22−#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
23−
24−#define zungetc(z) ((z)->n++, (z)->p--)
20+#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
2521
2622
2723 typedef struct Mbuffer {