History

Lua 5.1.2-rc1

Lua Team committed 19 years ago

Commit ce51ee41 parent 954596315 files · +362 −206Browse files

Unified · Split

15 files
  1. doc/amazon.gif +0 −0
  2. doc/contents.html +39 −12
  3. doc/cover.png +0 −0
  4. doc/lua.css +21 −2
  5. doc/manual.css +7 −0
  6. doc/manual.html +218 −153
  7. doc/readme.html +11 −3
  8. src/lbaselib.c +5 −5
  9. src/lcode.c +30 −14
  10. src/ldebug.c +6 −4
  11. src/loslib.c +17 −6
  12. src/lparser.c +2 −2
  13. src/lstrlib.c +2 −2
  14. src/lua.h +4 −4
  15. src/print.c +2 −1
doc/amazon.gif+0−0

Binary file not shown.

doc/contents.html+39−12
@@ -2,31 +2,59 @@ · 1 unmodified line
22 <HEAD>
33 <TITLE>Lua 5.1 reference manual - contents</TITLE>
44 <LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
5−<style type="text/css">
5+<STYLE TYPE="text/css">
66 ul {
77 list-style-type: none ;
88 list-style-position: outside ;
99 }
10−</style>
10+</STYLE>
1111 </HEAD>
1212
1313 <BODY>
1414
1515 <HR>
1616 <H1>
17−<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
18−Reference manual for Lua 5.1
17+<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A>
18+Lua 5.1 Reference Manual
1919 </H1>
2020
21+This is an online version of
22+<BLOCKQUOTE>
23+<A HREF="http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20">
24+<IMG SRC="cover.png" ALT="" TITLE="buy from Amazon" BORDER=1 ALIGN="left" HSPACE=12>
25+</A>
26+<B>Lua 5.1 Reference Manual</B>
27+<BR>by R. Ierusalimschy, L. H. de Figueiredo, W. Celes
28+<BR>Lua.org, August 2006
29+<BR>ISBN 85-903798-3-3
30+<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20">
31+<IMG SRC="amazon.gif" ALT="[Buy from Amazon]" BORDER=0></A>
32+<BR CLEAR="all">
33+</BLOCKQUOTE>
34+<P>
35+
36+Buy a paper copy and
37+<A HREF="http://www.lua.org/donations.html">help to support</A>
38+the Lua project.
39+<P>
40+
41+<A HREF="manual.html">start</A>
42+&middot;
2143 <A HREF="#contents">contents</A>
2244 &middot;
2345 <A HREF="#index">index</A>
46+&middot;
47+<A HREF="http://www.lua.org/manual/5.1/errata.html">errata</A>
2448 <HR>
49+<SMALL>
50+Copyright &copy; 2006-2007 Lua.org, PUC-Rio.
51+Freely available under the terms of the
52+<a href="http://www.lua.org/license.html#5">Lua license</a>.
53+</SMALL>
2554 <P>
2655
2756 <H2><A NAME="contents">Contents</A></H2>
2857 <UL style="padding: 0">
29−<LI><A HREF="manual.html">Top</A>
3058 <LI><A HREF="manual.html#1">1 - Introduction</A>
3159 <LI><A HREF="manual.html#2">2 - The Language</A>
3260 <UL>
@@ -107,13 +135,12 @@ Reference manual for Lua 5.1 · 74 unmodified lines
107135 <LI><A HREF="manual.html#7.3">7.3 - Changes in the API</A>
108136 </UL>
109137 <LI><A HREF="manual.html#8">8 - The Complete Syntax of Lua</A>
110−
111138 </UL>
112139
113140 <H2><A NAME="index">Index</A></H2>
114−<TABLE>
141+<TABLE WIDTH="100%">
115142 <TR VALIGN="top">
116−<TD WIDTH="20%">
143+<TD>
117144 <H3><A NAME="functions">Lua functions</A></H3>
118145 <A HREF="manual.html#pdf-_G">_G</A><BR>
119146 <A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
@@ -146,7 +173,7 @@ Reference manual for Lua 5.1 · 26 unmodified lines
146173 <A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
147174
148175 </TD>
149−<TD WIDTH="30%">
176+<TD>
150177 <H3>&nbsp;</H3>
151178 <A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
152179 <A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>
@@ -254,7 +281,7 @@ Reference manual for Lua 5.1 · 101 unmodified lines
254281 <A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
255282
256283 </TD>
257−<TD WIDTH="25%">
284+<TD>
258285 <H3>C API</H3>
259286 <A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
260287 <A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
@@ -419,10 +446,10 @@ Reference manual for Lua 5.1 · 158 unmodified lines
419446 <HR>
420447 <SMALL>
421448 Last update:
422−Tue Jun 6 14:55:31 BRT 2006
449+Fri Mar 23 08:33:19 BRT 2007
423450 </SMALL>
424451 <!--
425−Last change: reformatted index
452+Last change: minor edit
426453 -->
427454
428455 </BODY>
doc/cover.png+0−0

Binary file not shown.

doc/lua.css+21−2
@@ -2,16 +2,24 @@ body { · 1 unmodified line
22 color: #000000 ;
33 background-color: #FFFFFF ;
44 font-family: sans-serif ;
5+ text-align: justify ;
6+ margin-right: 20px ;
7+ margin-left: 20px ;
8+}
9+
10+h1, h2, h3, h4 {
11+ font-weight: normal ;
12+ font-style: italic ;
513 }
614
715 a:link {
816 color: #000080 ;
9− background-color: #FFFFFF ;
17+ background-color: inherit ;
1018 text-decoration: none ;
1119 }
1220
1321 a:visited {
14− background-color: #FFFFFF ;
22+ background-color: inherit ;
1523 text-decoration: none ;
1624 }
1725
@@ -20,3 +28,14 @@ a:link:hover, a:visited:hover { · 2 unmodified lines
2028 background-color: #E0E0FF ;
2129 }
2230
31+a:link:active, a:visited:active {
32+ color: #FF0000 ;
33+}
34+
35+hr {
36+ border: 0 ;
37+ height: 1px ;
38+ color: #a0a0a0 ;
39+ background-color: #a0a0a0 ;
40+}
41+
doc/manual.css+7−0
@@ -0,0 +1,7 @@
1+h3 code {
2+ font-family: inherit ;
3+}
4+
5+pre {
6+ font-size: 105% ;
7+}
doc/manual.html+218−153
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 <head>
55 <title>Lua 5.1 Reference Manual</title>
66 <link rel="stylesheet" href="lua.css">
7+<link rel="stylesheet" href="manual.css">
78 </head>
89
910 <body>
@@ -17,10 +18,16 @@ Lua 5.1 Reference Manual · 7 unmodified lines
1718 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
1819 <p>
1920 <small>
20−<a href="http://www.lua.org/copyright.html">Copyright</a>
21−&copy; 2006 Lua.org, PUC-Rio. All rights reserved.
21+Copyright &copy; 2006-2007 Lua.org, PUC-Rio.
22+Freely available under the terms of the
23+<a href="http://www.lua.org/license.html#5">Lua license</a>.
2224 </small>
2325 <hr>
26+<p>
27+
28+<a href="contents.html#contents">contents</A>
29+&middot;
30+<a href="contents.html#index">index</A>
2431
2532 <!-- ====================================================================== -->
2633 <p>
@@ -71,7 +78,7 @@ this document is dry in places. · 44 unmodified lines
7178 For a discussion of the decisions behind the design of Lua,
7279 see the technical papers available at Lua's web site.
7380 For a detailed introduction to programming in Lua,
74−see Roberto's book, <em>Programming in Lua</em>.
81+see Roberto's book, <em>Programming in Lua (Second Edition)</em>.
7582
7683
7784
@@ -390,8 +397,8 @@ Name denotes identifiers, as defined in <a href="#2.1">&sect;2.1</a>. · 312 unmodified lines
390397
391398
392399 <p>
393−Variables are assumed to be global unless explicitly declared local
394−(see <a href="#2.4.7">&sect;2.4.7</a>).
400+Any variable is assumed to be global unless explicitly declared
401+as a local (see <a href="#2.4.7">&sect;2.4.7</a>).
395402 Local variables are <em>lexically scoped</em>:
396403 local variables can be freely accessed by functions
397404 defined inside their scope (see <a href="#2.6">&sect;2.6</a>).
@@ -708,18 +715,18 @@ third <em>exp</em>. · 310 unmodified lines
708715 More precisely, a <b>for</b> statement like
709716
710717 <pre>
711− for var = e1, e2, e3 do block end
718+ for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end
712719 </pre><p>
713720 is equivalent to the code:
714721
715722 <pre>
716723 do
717− local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
718− if not (_var and _limit and _step) then error() end
719− while (_step&gt;0 and _var&lt;=_limit) or (_step&lt;=0 and _var&gt;=_limit) do
720− local var = _var
724+ local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)
725+ if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end
726+ while (<em>step</em> &gt; 0 and <em>var</em> &lt;= <em>limit</em>) or (<em>step</em> &lt;= 0 and <em>var</em> &gt;= <em>limit</em>) do
727+ local v = <em>var</em>
721728 <em>block</em>
722− _var = _var + _step
729+ <em>var</em> = <em>var</em> + <em>step</em>
723730 end
724731 end
725732 </pre><p>
@@ -734,7 +741,7 @@ They must all result in numbers. · 8 unmodified lines
734741 </li>
735742
736743 <li>
737−<code>_var</code>, <code>_limit</code>, and <code>_step</code> are invisible variables.
744+<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.
738745 The names are here for explanatory purposes only.
739746 </li>
740747
@@ -748,10 +755,10 @@ You can use <b>break</b> to exit a <b>for</b> loop. · 7 unmodified lines
748755 </li>
749756
750757 <li>
751−The loop variable <code>var</code> is local to the loop;
758+The loop variable <code>v</code> is local to the loop;
752759 you cannot use its value after the <b>for</b> ends or is broken.
753−If you need the value of the loop variable <code>var</code>,
754−then assign it to another variable before breaking or exiting the loop.
760+If you need this value,
761+assign it to another variable before breaking or exiting the loop.
755762 </li>
756763
757764 </ul>
@@ -770,18 +777,18 @@ The generic <b>for</b> loop has the following syntax: · 12 unmodified lines
770777 A <b>for</b> statement like
771778
772779 <pre>
773− for var_1, &middot;&middot;&middot;, var_n in explist do block end
780+ for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end
774781 </pre><p>
775782 is equivalent to the code:
776783
777784 <pre>
778785 do
779− local _f, _s, _var = explist
786+ local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>
780787 while true do
781− local var_1, &middot;&middot;&middot;, var_n = _f(_s, _var)
782− _var = var_1
783− if _var == nil then break end
784− block
788+ local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)
789+ <em>var</em> = <em>var_1</em>
790+ if <em>var</em> == nil then break end
791+ <em>block</em>
785792 end
786793 end
787794 </pre><p>
@@ -790,13 +797,14 @@ Note the following: · 2 unmodified lines
790797 <ul>
791798
792799 <li>
793−<code>explist</code> is evaluated only once.
800+<code><em>explist</em></code> is evaluated only once.
794801 Its results are an <em>iterator</em> function,
795−a <em>state</em>, and an initial value for the first <em>iterator variable</em>.
802+a <em>state</em>,
803+and an initial value for the first <em>iterator variable</em>.
796804 </li>
797805
798806 <li>
799−<code>_f</code>, <code>_s</code>, and <code>_var</code> are invisible variables.
807+<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.
800808 The names are here for explanatory purposes only.
801809 </li>
802810
@@ -805,7 +813,7 @@ You can use <b>break</b> to exit a <b>for</b> loop. · 2 unmodified lines
805813 </li>
806814
807815 <li>
808−The loop variables <code>var_i</code> are local to the loop;
816+The loop variables <code><em>var_i</em></code> are local to the loop;
809817 you cannot use their values after the <b>for</b> ends.
810818 If you need these values,
811819 then assign them to other variables before breaking or exiting the loop.
@@ -902,13 +910,13 @@ If the expression is used as a statement (see <a href="#2.4.6">&sect;2.4.6</a>) · 90 unmodified lines
902910 (only possible for function calls),
903911 then its return list is adjusted to zero elements,
904912 thus discarding all returned values.
905−If the expression is used inside another expression
906−or in the middle of a list of expressions,
907−then its result list is adjusted to one element,
908−thus discarding all values except the first one.
909−If the expression is used as the last element of a list of expressions,
910−then no adjustment is made,
911−unless the call is enclosed in parentheses.
913+If the expression is used as the last (or the only) element
914+of a list of expressions,
915+then no adjustment is made
916+(unless the call is enclosed in parentheses).
917+In all other contexts,
918+Lua adjusts the result list to one element,
919+discarding all values except the first one.
912920
913921
914922 <p>
@@ -917,17 +925,18 @@ Here are some examples: · 2 unmodified lines
917925 <pre>
918926 f() -- adjusted to 0 results
919927 g(f(), x) -- f() is adjusted to 1 result
920− g(x, f()) -- g gets x plus all values returned by f()
928+ g(x, f()) -- g gets x plus all results from f()
921929 a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil)
922930 a,b = ... -- a gets the first vararg parameter, b gets
923− -- the second (both a and b may get nil if there is
924− -- no corresponding vararg parameter)
931+ -- the second (both a and b may get nil if there
932+ -- is no corresponding vararg parameter)
933+
925934 a,b,c = x, f() -- f() is adjusted to 2 results
926935 a,b,c = f() -- f() is adjusted to 3 results
927− return f() -- returns all values returned by f()
936+ return f() -- returns all results from f()
928937 return ... -- returns all received vararg parameters
929− return x,y,f() -- returns x, y, and all values returned by f()
930− {f()} -- creates a list with all values returned by f()
938+ return x,y,f() -- returns x, y, and all results from f()
939+ {f()} -- creates a list with all results from f()
931940 {...} -- creates a list with all vararg parameters
932941 {f(), nil} -- f() is adjusted to 1 result
933942 </pre>
@@ -1543,8 +1552,7 @@ you must use the C&nbsp;API for that. · 609 unmodified lines
15431552
15441553 <p>
15451554 Tables and userdata have individual metatables
1546−(although multiple tables and userdata can share
1547−a same table as their metatable);
1555+(although multiple tables and userdata can share their metatables);
15481556 values of all other types share one single metatable per type.
15491557 So, there is one single metatable for all numbers,
15501558 and for all strings, etc.
@@ -1592,6 +1600,7 @@ This should be read as · 41 unmodified lines
15921600 <pre>
15931601 rawget(getmetatable(obj) or {}, event)
15941602 </pre><p>
1603+
15951604 That is, the access to a metamethod does not invoke other metamethods,
15961605 and the access to objects with no metatables does not fail
15971606 (it simply results in <b>nil</b>).
@@ -2077,7 +2086,7 @@ A table with both weak keys and weak values allows the collection of · 479 unmodified lines
20772086 both keys and values.
20782087 In any case, if either the key or the value is collected,
20792088 the whole pair is removed from the table.
2080−The weakness of a table is controlled by the value of the
2089+The weakness of a table is controlled by the
20812090 <code>__mode</code> field of its metatable.
20822091 If the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',
20832092 the keys in the table are weak.
@@ -2156,8 +2165,8 @@ arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code · 72 unmodified lines
21562165
21572166
21582167 <p>
2159−The <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function creates a coroutine,
2160−just like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
2168+Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
2169+the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine,
21612170 but instead of returning the coroutine itself,
21622171 it returns a function that, when called, resumes the coroutine.
21632172 Any arguments passed to this function
@@ -2198,6 +2207,7 @@ When you run it, it produces the following output: · 34 unmodified lines
21982207 <pre>
21992208 co-body 1 10
22002209 foo 2
2210+
22012211 main true 4
22022212 co-body r
22032213 main true 11 -9
@@ -2268,7 +2278,7 @@ then index&nbsp;1 represents the first element · 64 unmodified lines
22682278 and
22692279 index&nbsp;<em>n</em> represents the last element;
22702280 index&nbsp;-1 also represents the last element
2271−(that is, the element at the top)
2281+(that is, the element at the&nbsp;top)
22722282 and index <em>-n</em> represents the first element.
22732283 We say that an index is <em>valid</em>
22742284 if it lies between&nbsp;1 and the stack top
@@ -2473,21 +2483,25 @@ Lua assumes that the allocator never fails when · 198 unmodified lines
24732483
24742484 <p>
24752485 Here is a simple implementation for the allocator function.
2476−It is used in the auxiliary library by <a href="#lua_newstate"><code>lua_newstate</code></a>.
2486+It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
24772487
24782488 <pre>
2479− static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
2480− (void)ud; /* not used */
2481− (void)osize; /* not used */
2489+ static void *l_alloc (void *ud, void *ptr, size_t osize,
2490+ size_t nsize) {
2491+ (void)ud; (void)osize; /* not used */
24822492 if (nsize == 0) {
2483− free(ptr); /* ANSI requires that free(NULL) has no effect */
2493+ free(ptr);
24842494 return NULL;
24852495 }
24862496 else
2487− /* ANSI requires that realloc(NULL, size) == malloc(size) */
24882497 return realloc(ptr, nsize);
24892498 }
2490−</pre>
2499+</pre><p>
2500+This code assumes
2501+that <code>free(NULL)</code> has no effect and that
2502+<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
2503+ANSI&nbsp;C ensures both behaviors.
2504+
24912505
24922506
24932507
@@ -2557,14 +2571,14 @@ equivalent to this Lua code: · 63 unmodified lines
25572571 Here it is in&nbsp;C:
25582572
25592573 <pre>
2560− lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
2561− lua_pushstring(L, "how"); /* 1st argument */
2562− lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
2563− lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
2564− lua_remove(L, -2); /* remove 't' from the stack */
2565− lua_pushinteger(L, 14); /* 3rd argument */
2566− lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */
2567− lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable 'a' */
2574+ lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
2575+ lua_pushstring(L, "how"); /* 1st argument */
2576+ lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
2577+ lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
2578+ lua_remove(L, -2); /* remove 't' from the stack */
2579+ lua_pushinteger(L, 14); /* 3rd argument */
2580+ lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */
2581+ lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global 'a' */
25682582 </pre><p>
25692583 Note that the code above is "balanced":
25702584 at its end, the stack is back to its original configuration.
@@ -2611,7 +2625,7 @@ of numerical arguments and returns their average and sum: · 40 unmodified lines
26112625 int i;
26122626 for (i = 1; i &lt;= n; i++) {
26132627 if (!lua_isnumber(L, i)) {
2614− lua_pushstring(L, "incorrect argument to function 'average'");
2628+ lua_pushstring(L, "incorrect argument");
26152629 lua_error(L);
26162630 }
26172631 sum += lua_tonumber(L, i);
@@ -2723,7 +2737,7 @@ to write them. · 105 unmodified lines
27232737 <p>
27242738 The value returned is the error code returned by the last
27252739 call to the writer;
2726−0 means no errors.
2740+0&nbsp;means no errors.
27272741
27282742
27292743 <p>
@@ -2814,7 +2828,7 @@ The function returns the previous value of the pause. · 84 unmodified lines
28142828 </li>
28152829
28162830 <li><b><code>LUA_GCSETSTEPMUL</code>:</b>
2817−sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of
2831+sets <code>data</code>/100 as the new value for the <em>step multiplier</em> of
28182832 the collector (see <a href="#2.10">&sect;2.10</a>).
28192833 The function returns the previous value of the step multiplier.
28202834 </li>
@@ -2942,7 +2956,7 @@ The type used by the Lua API to represent integral values. · 121 unmodified lines
29422956
29432957 <p>
29442958 By default it is a <code>ptrdiff_t</code>,
2945−which is usually the largest integral type the machine handles
2959+which is usually the largest signed integral type the machine handles
29462960 "comfortably".
29472961
29482962
@@ -2954,7 +2968,7 @@ which is usually the largest integral type the machine handles · 5 unmodified lines
29542968
29552969 <p>
29562970 Returns 1 if the value at the given acceptable index has type boolean,
2957−and 0 otherwise.
2971+and 0&nbsp;otherwise.
29582972
29592973
29602974
@@ -2965,7 +2979,7 @@ and 0 otherwise. · 4 unmodified lines
29652979
29662980 <p>
29672981 Returns 1 if the value at the given acceptable index is a C&nbsp;function,
2968−and 0 otherwise.
2982+and 0&nbsp;otherwise.
29692983
29702984
29712985
@@ -2976,7 +2990,7 @@ and 0 otherwise. · 4 unmodified lines
29762990
29772991 <p>
29782992 Returns 1 if the value at the given acceptable index is a function
2979−(either C or Lua), and 0 otherwise.
2993+(either C or Lua), and 0&nbsp;otherwise.
29802994
29812995
29822996
@@ -2987,7 +3001,7 @@ Returns 1 if the value at the given acceptable index is a function · 4 unmodified lines
29873001
29883002 <p>
29893003 Returns 1 if the value at the given acceptable index is a light userdata,
2990−and 0 otherwise.
3004+and 0&nbsp;otherwise.
29913005
29923006
29933007
@@ -2998,7 +3012,32 @@ and 0 otherwise. · 4 unmodified lines
29983012
29993013 <p>
30003014 Returns 1 if the value at the given acceptable index is <b>nil</b>,
3001−and 0 otherwise.
3015+and 0&nbsp;otherwise.
3016+
3017+
3018+
3019+
3020+
3021+<hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3>
3022+<pre>int lua_isnone (lua_State *L, int index);</pre>
3023+
3024+<p>
3025+Returns 1 if the the given acceptable index is not valid
3026+(that is, it refers to an element outside the current stack),
3027+and 0&nbsp;otherwise.
3028+
3029+
3030+
3031+
3032+
3033+<hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3>
3034+<pre>int lua_isnoneornil (lua_State *L, int index);</pre>
3035+
3036+<p>
3037+Returns 1 if the the given acceptable index is not valid
3038+(that is, it refers to an element outside the current stack)
3039+or if the value at this index is <b>nil</b>,
3040+and 0&nbsp;otherwise.
30023041
30033042
30043043
@@ -3010,7 +3049,7 @@ and 0 otherwise. · 5 unmodified lines
30103049 <p>
30113050 Returns 1 if the value at the given acceptable index is a number
30123051 or a string convertible to a number,
3013−and 0 otherwise.
3052+and 0&nbsp;otherwise.
30143053
30153054
30163055
@@ -3022,7 +3061,7 @@ and 0 otherwise. · 5 unmodified lines
30223061 <p>
30233062 Returns 1 if the value at the given acceptable index is a string
30243063 or a number (which is always convertible to a string),
3025−and 0 otherwise.
3064+and 0&nbsp;otherwise.
30263065
30273066
30283067
@@ -3033,7 +3072,7 @@ and 0 otherwise. · 4 unmodified lines
30333072
30343073 <p>
30353074 Returns 1 if the value at the given acceptable index is a table,
3036−and 0 otherwise.
3075+and 0&nbsp;otherwise.
30373076
30383077
30393078
@@ -3044,7 +3083,7 @@ and 0 otherwise. · 4 unmodified lines
30443083
30453084 <p>
30463085 Returns 1 if the value at the given acceptable index is a thread,
3047−and 0 otherwise.
3086+and 0&nbsp;otherwise.
30483087
30493088
30503089
@@ -3055,7 +3094,7 @@ and 0 otherwise. · 4 unmodified lines
30553094
30563095 <p>
30573096 Returns 1 if the value at the given acceptable index is a userdata
3058−(either full or light), and 0 otherwise.
3097+(either full or light), and 0&nbsp;otherwise.
30593098
30603099
30613100
@@ -3113,8 +3152,8 @@ and loads it accordingly (see program <code>luac</code>). · 51 unmodified lines
31133152
31143153
31153154 <p>
3116−<a href="#lua_load"><code>lua_load</code></a> uses a user-supplied <code>reader</code> function to read the chunk
3117−(see <a href="#lua_Reader"><code>lua_Reader</code></a>).
3155+The <a href="#lua_load"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function
3156+to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
31183157 The <code>data</code> argument is an opaque value passed to the reader function.
31193158
31203159
@@ -3219,10 +3258,12 @@ A typical traversal looks like this: · 98 unmodified lines
32193258 /* table is in the stack at index 't' */
32203259 lua_pushnil(L); /* first key */
32213260 while (lua_next(L, t) != 0) {
3222− /* 'key' is at index -2 and 'value' at index -1 */
3261+ /* uses 'key' (at index -2) and 'value' (at index -1) */
32233262 printf("%s - %s\n",
3224− lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)));
3225− lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */
3263+ lua_typename(L, lua_type(L, -2)),
3264+ lua_typename(L, lua_type(L, -1)));
3265+ /* removes 'value'; keeps 'key' for next iteration */
3266+ lua_pop(L, 1);
32263267 }
32273268 </pre>
32283269
@@ -3270,7 +3311,7 @@ for other values, it is&nbsp;0. · 41 unmodified lines
32703311
32713312
32723313 <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3>
3273−<pre>lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre>
3314+<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre>
32743315
32753316 <p>
32763317 Calls a function in protected mode.
@@ -3396,9 +3437,11 @@ and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code>< · 119 unmodified lines
33963437
33973438
33983439 <p>
3399−The call <code>lua_pushcfunction(L, f)</code> is equivalent to
3400−<code>lua_pushcclosure(L, f, 0)</code>.
3440+<code>lua_pushcfunction</code> is defined as a macro:
34013441
3442+<pre>
3443+ #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
3444+</pre>
34023445
34033446
34043447
@@ -3642,14 +3685,17 @@ The reader function may return pieces of any size greater than zero. · 237 unmodified lines
36423685
36433686
36443687 <hr><h3><a name="lua_register"><code>lua_register</code></a></h3>
3645−<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>
3688+<pre>void lua_register (lua_State *L,
3689+ const char *name,
3690+ lua_CFunction f);</pre>
36463691
36473692 <p>
36483693 Sets the C function <code>f</code> as the new value of global <code>name</code>.
36493694 It is defined as a macro:
36503695
36513696 <pre>
3652− #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
3697+ #define lua_register(L,n,f) \
3698+ (lua_pushcfunction(L, f), lua_setglobal(L, n))
36533699 </pre>
36543700
36553701
@@ -3905,8 +3951,7 @@ it is truncated in some non-specified way. · 249 unmodified lines
39053951 <pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>
39063952
39073953 <p>
3908−Converts the Lua value at the given acceptable index to a string
3909−(<code>const char*</code>).
3954+Converts the Lua value at the given acceptable index to a C&nbsp;string.
39103955 If <code>len</code> is not <code>NULL</code>,
39113956 it also sets <code>*len</code> with the string length.
39123957 The Lua value must be a string or a number;
@@ -3937,7 +3982,7 @@ will be valid after the corresponding value is removed from the stack. · 24 unmodified lines
39373982
39383983 <p>
39393984 Converts the Lua value at the given acceptable index
3940−to a number (see <a href="#lua_Number"><code>lua_Number</code></a>).
3985+to the C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>).
39413986 The Lua value must be a number or a string convertible to a number
39423987 (see <a href="#2.2.1">&sect;2.2.1</a>);
39433988 otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns&nbsp;0.
@@ -4054,7 +4099,7 @@ and the <code>data</code> parameter supplied to <a href="#lua_dump"><code>lua_du · 110 unmodified lines
40544099
40554100 <p>
40564101 The writer returns an error code:
4057−0 means no errors;
4102+0&nbsp;means no errors;
40584103 any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
40594104 calling the writer again.
40604105
@@ -4279,8 +4324,8 @@ a value to be pushed on the stack: · 218 unmodified lines
42794324 </li>
42804325
42814326 <li><b>'<code>S</code>':</b>
4282−fills in the fields <code>source</code>, <code>linedefined</code>,
4283−<code>lastlinedefined</code>, <code>what</code>, and <code>short_src</code>;
4327+fills in the fields <code>source</code>, <code>short_src</code>,
4328+<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
42844329 </li>
42854330
42864331 <li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>;
@@ -4313,7 +4358,7 @@ This function returns 0 on error · 26 unmodified lines
43134358
43144359
43154360 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3>
4316−<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre>
4361+<pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>
43174362
43184363 <p>
43194364 Gets information about a local variable of a given activation record.
@@ -4424,14 +4469,14 @@ this execution occurs without any calls to hooks. · 104 unmodified lines
44244469
44254470
44264471 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3>
4427−<pre>int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);</pre>
4472+<pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>
44284473
44294474 <p>
44304475 Sets the debugging hook function.
44314476
44324477
44334478 <p>
4434−<code>func</code> is the hook function.
4479+Argument <code>f</code> is the hook function.
44354480 <code>mask</code> specifies on which events the hook will be called:
44364481 it is formed by a bitwise or of the constants
44374482 <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,
@@ -4475,7 +4520,7 @@ A hook is disabled by setting <code>mask</code> to zero. · 37 unmodified lines
44754520
44764521
44774522 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3>
4478−<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre>
4523+<pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre>
44794524
44804525 <p>
44814526 Sets the value of a local variable of a given activation record.
@@ -4500,11 +4545,11 @@ the number of active local variables. · 18 unmodified lines
45004545
45014546 <p>
45024547 Sets the value of a closure's upvalue.
4503−Parameters <code>funcindex</code> and <code>n</code> are as in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
4504−(see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>).
45054548 It assigns the value at the top of the stack
45064549 to the upvalue and returns its name.
45074550 It also pops the value from the stack.
4551+Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
4552+(see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>).
45084553
45094554
45104555 <p>
@@ -4588,9 +4633,9 @@ The string may contain embedded zeros. · 77 unmodified lines
45884633 <pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>
45894634
45904635 <p>
4591−Adds a string of length <code>n</code> previously copied to the
4592−buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to the buffer <code>B</code>
4593−(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
4636+Adds to the buffer <code>B</code> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>)
4637+a string of length <code>n</code> previously copied to the
4638+buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
45944639
45954640
45964641
@@ -4631,7 +4676,7 @@ which is the value to be added to the buffer. · 34 unmodified lines
46314676 <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3>
46324677 <pre>void luaL_argcheck (lua_State *L,
46334678 int cond,
4634− int numarg,
4679+ int narg,
46354680 const char *extramsg);</pre>
46364681
46374682 <p>
@@ -4640,21 +4685,21 @@ If not, raises an error with the following message, · 2 unmodified lines
46404685 where <code>func</code> is retrieved from the call stack:
46414686
46424687 <pre>
4643− bad argument #&lt;numarg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
4688+ bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
46444689 </pre>
46454690
46464691
46474692
46484693
46494694 <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3>
4650−<pre>int luaL_argerror (lua_State *L, int numarg, const char *extramsg);</pre>
4695+<pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre>
46514696
46524697 <p>
46534698 Raises an error with the following message,
46544699 where <code>func</code> is retrieved from the call stack:
46554700
46564701 <pre>
4657− bad argument #&lt;numarg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
4702+ bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)
46584703 </pre>
46594704
46604705 <p>
@@ -5079,9 +5124,10 @@ with <code>tname</code> in the registry. · 418 unmodified lines
50795124 <pre>lua_State *luaL_newstate (void);</pre>
50805125
50815126 <p>
5082−Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an
5083−allocation function based on the standard&nbsp;C <code>realloc</code> function
5084−and setting a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
5127+Creates a new Lua state.
5128+It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
5129+allocator based on the standard&nbsp;C <code>realloc</code> function
5130+and then sets a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
50855131 an error message to the standard error output in case of fatal
50865132 errors.
50875133
@@ -5119,7 +5165,9 @@ Otherwise, raises an error. · 31 unmodified lines
51195165
51205166
51215167 <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3>
5122−<pre>lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer d);</pre>
5168+<pre>lua_Integer luaL_optinteger (lua_State *L,
5169+ int narg,
5170+ lua_Integer d);</pre>
51235171
51245172 <p>
51255173 If the function argument <code>narg</code> is a number,
@@ -5183,7 +5231,9 @@ Otherwise, raises an error. · 57 unmodified lines
51835231
51845232
51855233 <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3>
5186−<pre>const char *luaL_optstring (lua_State *L, int narg, const char *d);</pre>
5234+<pre>const char *luaL_optstring (lua_State *L,
5235+ int narg,
5236+ const char *d);</pre>
51875237
51885238 <p>
51895239 If the function argument <code>narg</code> is a string,
@@ -5285,7 +5335,7 @@ it simply registers all functions in the list <code>l</code> · 95 unmodified lines
52855335
52865336 <p>
52875337 When called with a non-null <code>libname</code>,
5288−creates a new table <code>t</code>,
5338+<code>luaL_register</code> creates a new table <code>t</code>,
52895339 sets it as the value of the global variable <code>libname</code>,
52905340 sets it as the value of <code>package.loaded[libname]</code>,
52915341 and registers on it all functions in the list <code>l</code>.
@@ -5316,14 +5366,14 @@ Returns the name of the type of the value at index <code>idx</code>. · 24 unmodified lines
53165366 <pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre>
53175367
53185368 <p>
5319−Generates an error with a message like
5369+Generates an error with a message like the following:
53205370
53215371 <pre>
5322− &lt;location&gt;: bad argument &lt;narg&gt; to &lt;function&gt; (&lt;tname&gt; expected, got &lt;realt&gt;)
5372+ <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>)
53235373 </pre><p>
5324−where <code>&lt;location&gt;</code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
5325−<code>&lt;function&gt;</code> is the name of the current function,
5326−and <code>&lt;realt&gt;</code> is the type name of the actual argument.
5374+where <code><em>location</em></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
5375+<code><em>func</em></code> is the name of the current function,
5376+and <code><em>rt</em></code> is the type name of the actual argument.
53275377
53285378
53295379
@@ -5354,7 +5404,11 @@ If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a · 24 unmodified lines
53545404 <p>
53555405 Pushes onto the stack a string identifying the current position
53565406 of the control at level <code>lvl</code> in the call stack.
5357−Typically this string has the format <code>&lt;chunkname&gt;:&lt;currentline&gt;:</code>.
5407+Typically this string has the following format:
5408+
5409+<pre>
5410+ <em>chunkname</em>:<em>currentline</em>:
5411+</pre><p>
53585412 Level&nbsp;0 is the running function,
53595413 level&nbsp;1 is the function that called the running function,
53605414 etc.
@@ -5413,9 +5467,8 @@ or as methods of its objects. · 52 unmodified lines
54135467
54145468 <p>
54155469 To have access to these libraries,
5416−the C&nbsp;host program must call
5417−<a href="#luaL_openlibs"><code>luaL_openlibs</code></a>,
5418−which open all standard libraries.
5470+the C&nbsp;host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> function,
5471+which opens all standard libraries.
54195472 Alternatively,
54205473 it can open them individually by calling
54215474 <a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
@@ -5547,7 +5600,7 @@ nor vice-versa. · 125 unmodified lines
55475600
55485601
55495602 <p>
5550−<hr><h3><a name="pdf-getfenv"><code>getfenv (f)</code></a></h3>
5603+<hr><h3><a name="pdf-getfenv"><code>getfenv ([f])</code></a></h3>
55515604 Returns the current environment in use by the function.
55525605 <code>f</code> can be a Lua function or a number
55535606 that specifies the function at that stack level:
@@ -5589,10 +5642,6 @@ will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middo · 35 unmodified lines
55895642 up to the first integer key absent from the table.
55905643
55915644
5592−<p>
5593−See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
5594−
5595−
55965645
55975646
55985647 <p>
@@ -5704,7 +5753,8 @@ will iterate over all key&ndash;value pairs of table <code>t</code>. · 105 unmodified lines
57045753
57055754
57065755 <p>
5707−See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
5756+See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
5757+the table during its traversal.
57085758
57095759
57105760
@@ -5911,7 +5961,7 @@ The current contents of this variable is "<code>Lua 5.1</code>". · 200 unmodified lines
59115961
59125962
59135963 <p>
5914−This function is similar to <code>pcall</code>,
5964+This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
59155965 except that you can set a new error handler.
59165966
59175967
@@ -6101,7 +6151,7 @@ where each option is a function to be applied over the module. · 183 unmodified lines
61016151
61026152 <p>
61036153 Loads the given module.
6104−The function starts by looking into the table <a href="#pdf-package.loaded"><code>package.loaded</code></a>
6154+The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></a> table
61056155 to determine whether <code>modname</code> is already loaded.
61066156 If it is, then <code>require</code> returns the value stored
61076157 at <code>package.loaded[modname]</code>.
@@ -6156,7 +6206,7 @@ with each submodule keeping its original open function. · 48 unmodified lines
61566206 Once a loader is found,
61576207 <code>require</code> calls the loader with a single argument, <code>modname</code>.
61586208 If the loader returns any value,
6159−<code>require</code> assigns it to <code>package.loaded[modname]</code>.
6209+<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
61606210 If the loader returns no value and
61616211 has not assigned any value to <code>package.loaded[modname]</code>,
61626212 then <code>require</code> assigns <b>true</b> to this entry.
@@ -6190,6 +6240,7 @@ using the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a · 27 unmodified lines
61906240
61916241
61926242 <p>
6243+
61936244 <hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>
61946245
61956246
@@ -6426,7 +6477,8 @@ whereas <code>q</code> and <code>s</code> expect a string. · 230 unmodified lines
64266477
64276478 <p>
64286479 This function does not accept string values
6429−containing embedded zeros.
6480+containing embedded zeros,
6481+except as arguments to the <code>q</code> option.
64306482
64316483
64326484
@@ -6436,9 +6488,6 @@ containing embedded zeros. · 3 unmodified lines
64366488 Returns an iterator function that,
64376489 each time it is called,
64386490 returns the next captures from <code>pattern</code> over string <code>s</code>.
6439−
6440−
6441−<p>
64426491 If <code>pattern</code> specifies no captures,
64436492 then the whole match is produced in each call.
64446493
@@ -6465,6 +6514,11 @@ given string into a table: · 20 unmodified lines
64656514 end
64666515 </pre>
64676516
6517+<p>
6518+For this function, a '<code>^</code>' at the start of a pattern does not
6519+work as an anchor, as this would prevent the iteration.
6520+
6521+
64686522
64696523
64706524 <p>
@@ -6540,7 +6594,7 @@ Here are some examples: · 69 unmodified lines
65406594 --&gt; x="4+5 = 9"
65416595
65426596 local t = {name="lua", version="5.1"}
6543− x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t)
6597+ x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
65446598 --&gt; x="lua-5.1.tar.gz"
65456599 </pre>
65466600
@@ -6824,7 +6878,8 @@ we mean the result of the length operator. · 277 unmodified lines
68246878
68256879 <p>
68266880 <hr><h3><a name="pdf-table.concat"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3>
6827−Returns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.
6881+Given an array where all elements are strings or numbers,
6882+returns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.
68286883 The default value for <code>sep</code> is the empty string,
68296884 the default for <code>i</code> is 1,
68306885 and the default for <code>j</code> is the length of the table.
@@ -7122,7 +7177,7 @@ the integral part of <code>x</code> and the fractional part of <code>x</code>. · 291 unmodified lines
71227177
71237178
71247179 <p>
7125−The value PI.
7180+The value of <em>pi</em>.
71267181
71277182
71287183
@@ -7266,7 +7321,8 @@ three predefined file descriptors with their usual meanings from C: · 137 unmodified lines
72667321 <p>
72677322 Unless otherwise stated,
72687323 all I/O functions return <b>nil</b> on failure
7269−(plus an error message as a second result)
7324+(plus an error message as a second result and
7325+a system-dependent error code as a third result)
72707326 and some value different from <b>nil</b> on success.
72717327
72727328
@@ -7331,7 +7387,7 @@ it returns <b>nil</b> (to finish the loop) and automatically closes the file. · 58 unmodified lines
73317387
73327388
73337389 <p>
7334−The call <code>io.lines()</code> (without a file name) is equivalent
7390+The call <code>io.lines()</code> (with no file name) is equivalent
73357391 to <code>io.input():lines()</code>;
73367392 that is, it iterates over the lines of the default input file.
73377393 In this case it does not close the file when the loop ends.
@@ -7381,7 +7437,7 @@ Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over · 43 unmodified lines
73817437
73827438
73837439 <p>
7384−<hr><h3><a name="pdf-io.popen"><code>io.popen ([prog [, mode]])</code></a></h3>
7440+<hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3>
73857441
73867442
73877443 <p>
@@ -7596,7 +7652,7 @@ or there is any input from some special files · 208 unmodified lines
75967652 </li>
75977653
75987654 </ul><p>
7599−For the last two cases, <code>sizes</code>
7655+For the last two cases, <code>size</code>
76007656 specifies the size of the buffer, in bytes.
76017657 The default is an appropriate size.
76027658
@@ -7657,7 +7713,7 @@ Otherwise, <code>date</code> formats the current time. · 54 unmodified lines
76577713 If <code>format</code> starts with '<code>!</code>',
76587714 then the date is formatted in Coordinated Universal Time.
76597715 After this optional character,
7660−if <code>format</code> is <code>*t</code>,
7716+if <code>format</code> is the string "<code>*t</code>",
76617717 then <code>date</code> returns a table with the following fields:
76627718 <code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),
76637719 <code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),
@@ -7667,7 +7723,7 @@ and <code>isdst</code> (daylight saving flag, a boolean). · 3 unmodified lines
76677723
76687724
76697725 <p>
7670−If <code>format</code> is not <code>*t</code>,
7726+If <code>format</code> is not "<code>*t</code>",
76717727 then <code>date</code> returns the date as a string,
76727728 formatted according to the same rules as the C&nbsp;function <code>strftime</code>.
76737729
@@ -7771,6 +7827,13 @@ The function returns the name of the new locale, · 97 unmodified lines
77717827 or <b>nil</b> if the request cannot be honored.
77727828
77737829
7830+<p>
7831+If <code>locale</code> is the empty string,
7832+the current locate is set to an implementation-defined native locale.
7833+If <code>locate</code> is the string "<code>C</code>",
7834+the current locate is set to the standard C locale.
7835+
7836+
77747837 <p>
77757838 When called with <b>nil</b> as the first argument,
77767839 this function only returns the name of the current locale
@@ -7921,7 +7984,8 @@ valid lines. · 144 unmodified lines
79217984 <p>
79227985 For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
79237986 a name of the current function, if a reasonable name can be found,
7924−and <code>debug.getinfo(print)</code> returns a table with all available information
7987+and the expression <code>debug.getinfo(print)</code>
7988+returns a table with all available information
79257989 about the <a href="#pdf-print"><code>print</code></a> function.
79267990
79277991
@@ -8080,15 +8144,16 @@ Otherwise, it returns the name of the upvalue. · 152 unmodified lines
80808144
80818145
80828146 <p>
8083−<hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message])</code></a></h3>
8147+<hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message] [, level])</code></a></h3>
80848148
80858149
80868150 <p>
80878151 Returns a string with a traceback of the call stack.
80888152 An optional <code>message</code> string is appended
8089−at the beginning of the traceback.
8090−This function is typically used with <a href="#pdf-xpcall"><code>xpcall</code></a> to produce
8091−better error messages.
8153+at the beginning of the traceback.
8154+An optional <code>level</code> number tells at which level
8155+to start the traceback
8156+(default is 1, the function calling <code>traceback</code>).
80928157
80938158
80948159
@@ -8232,7 +8297,7 @@ is a more portable solution.) · 137 unmodified lines
82328297 <h1>7 - <a name="7">Incompatibilities with the Previous Version</a></h1>
82338298
82348299 <p>
8235−Here we list the incompatibilities that may be found when moving a program
8300+Here we list the incompatibilities that you may found when moving a program
82368301 from Lua&nbsp;5.0 to Lua&nbsp;5.1.
82378302 You can avoid most of the incompatibilities compiling Lua with
82388303 appropriate options (see file <code>luaconf.h</code>).
@@ -8247,7 +8312,7 @@ all these compatibility options will be removed in the next version of Lua. · 8 unmodified lines
82478312 <li>
82488313 The vararg system changed from the pseudo-argument <code>arg</code> with a
82498314 table with the extra arguments to the vararg expression.
8250−(Option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)
8315+(See compile-time option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)
82518316 </li>
82528317
82538318 <li>
@@ -8259,7 +8324,7 @@ variables of the <b>for</b> statement and for the <b>repeat</b> statement. · 5 unmodified lines
82598324 The long string/long comment syntax (<code>[[<em>string</em>]]</code>)
82608325 does not allow nesting.
82618326 You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases.
8262−(Option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)
8327+(See compile-time option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)
82638328 </li>
82648329
82658330 </ul>
@@ -8272,7 +8337,7 @@ You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases. · 6 unmodified lines
82728337
82738338 <li>
82748339 Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.
8275−(Option <code>LUA_COMPAT_GFIND</code>)
8340+(See compile-time option <code>LUA_COMPAT_GFIND</code> in <code>luaconf.h</code>.)
82768341 </li>
82778342
82788343 <li>
@@ -8288,17 +8353,17 @@ Function <code>table.setn</code> was deprecated. · 9 unmodified lines
82888353 Function <code>table.getn</code> corresponds
82898354 to the new length operator (<code>#</code>);
82908355 use the operator instead of the function.
8291−(Option <code>LUA_COMPAT_GETN</code>)
8356+(See compile-time option <code>LUA_COMPAT_GETN</code> in <code>luaconf.h</code>.)
82928357 </li>
82938358
82948359 <li>
82958360 Function <code>loadlib</code> was renamed <a href="#pdf-package.loadlib"><code>package.loadlib</code></a>.
8296−(Option <code>LUA_COMPAT_LOADLIB</code>)
8361+(See compile-time option <code>LUA_COMPAT_LOADLIB</code> in <code>luaconf.h</code>.)
82978362 </li>
82988363
82998364 <li>
83008365 Function <code>math.mod</code> was renamed <a href="#pdf-math.fmod"><code>math.fmod</code></a>.
8301−(Option <code>LUA_COMPAT_MOD</code>)
8366+(See compile-time option <code>LUA_COMPAT_MOD</code> in <code>luaconf.h</code>.)
83028367 </li>
83038368
83048369 <li>
@@ -8446,10 +8511,10 @@ Here is the complete syntax of Lua in extended BNF. · 141 unmodified lines
84468511 <HR>
84478512 <SMALL>
84488513 Last update:
8449−Mon Jun 5 17:05:27 BRT 2006
8514+Fri Mar 23 14:37:09 BRT 2007
84508515 </SMALL>
84518516 <!--
8452−Last change: ready for Lua 5.1.1
8517+Last change: ready for Lua 5.1.2
84538518 -->
84548519
84558520 </body></html>
doc/readme.html+11−3
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 <LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
55 </HEAD>
66
7−<BODY BGCOLOR="#FFFFFF">
7+<BODY>
88
99 <HR>
1010 <H1>
@@ -12,8 +12,9 @@ · 1 unmodified line
1212 Documentation
1313 </H1>
1414
15+This is the documentation included in the source distribution of Lua 5.1.2.
16+
1517 <UL>
16−<LI><A HREF="http://www.lua.org/">Official web site</A>
1718 <LI><A HREF="contents.html">Reference manual</A>
1819 <LI><A HREF="lua.html">lua man page</A>
1920 <LI><A HREF="luac.html">luac man page</A>
@@ -22,10 +23,17 @@ Documentation · 2 unmodified lines
2223 <LI><A HREF="../test/README">lua/test/README</A>
2324 </UL>
2425
26+Lua's
27+<A HREF="http://www.lua.org/">official web site</A>
28+contains updated documentation,
29+especially the
30+<A HREF="http://www.lua.org/manual/5.1/">reference manual</A>.
31+<P>
32+
2533 <HR>
2634 <SMALL>
2735 Last update:
28−Wed Sep 7 12:57:50 BRST 2005
36+Fri Mar 23 14:19:36 BRT 2007
2937 </SMALL>
3038
3139 </BODY>
src/lbaselib.c+5−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) { · 108 unmodified lines
114114 }
115115
116116
117−static void getfunc (lua_State *L) {
117+static void getfunc (lua_State *L, int opt) {
118118 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
119119 else {
120120 lua_Debug ar;
121− int level = luaL_optint(L, 1, 1);
121+ int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
122122 luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
123123 if (lua_getstack(L, level, &ar) == 0)
124124 luaL_argerror(L, 1, "invalid level");
@@ -131,7 +131,7 @@ static void getfunc (lua_State *L) { · 6 unmodified lines
131131
132132
133133 static int luaB_getfenv (lua_State *L) {
134− getfunc(L);
134+ getfunc(L, 1);
135135 if (lua_iscfunction(L, -1)) /* is a C function? */
136136 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
137137 else
@@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) { · 4 unmodified lines
142142
143143 static int luaB_setfenv (lua_State *L) {
144144 luaL_checktype(L, 2, LUA_TTABLE);
145− getfunc(L);
145+ getfunc(L, 0);
146146 lua_pushvalue(L, 2);
147147 if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
148148 /* change environment of current thread */
src/lcode.c+30−14
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $
2+** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines
3535 void luaK_nil (FuncState *fs, int from, int n) {
3636 Instruction *previous;
3737 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38− if (fs->pc == 0) /* function start? */
39− return; /* positions are already clean */
40− if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
41− int pfrom = GETARG_A(*previous);
42− int pto = GETARG_B(*previous);
43− if (pfrom <= from && from <= pto+1) { /* can connect both? */
44− if (from+n-1 > pto)
45− SETARG_B(*previous, from+n-1);
46− return;
38+ if (fs->pc == 0) { /* function start? */
39+ if (from >= fs->nactvar)
40+ return; /* positions are already clean */
41+ }
42+ else {
43+ previous = &fs->f->code[fs->pc-1];
44+ if (GET_OPCODE(*previous) == OP_LOADNIL) {
45+ int pfrom = GETARG_A(*previous);
46+ int pto = GETARG_B(*previous);
47+ if (pfrom <= from && from <= pto+1) { /* can connect both? */
48+ if (from+n-1 > pto)
49+ SETARG_B(*previous, from+n-1);
50+ return;
51+ }
4752 }
4853 }
4954 }
@@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 607 unmodified lines
657662 if (constfolding(op, e1, e2))
658663 return;
659664 else {
660− int o1 = luaK_exp2RK(fs, e1);
661665 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
662− freeexp(fs, e2);
663− freeexp(fs, e1);
666+ int o1 = luaK_exp2RK(fs, e1);
667+ if (o1 > o2) {
668+ freeexp(fs, e1);
669+ freeexp(fs, e2);
670+ }
671+ else {
672+ freeexp(fs, e2);
673+ freeexp(fs, e1);
674+ }
664675 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665676 e1->k = VRELOCABLE;
666677 }
@@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines
718729 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
719730 break;
720731 }
721− default: {
732+ case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
733+ case OPR_MOD: case OPR_POW: {
722734 if (!isnumeral(v)) luaK_exp2RK(fs, v);
723735 break;
724736 }
737+ default: {
738+ luaK_exp2RK(fs, v);
739+ break;
740+ }
725741 }
726742 }
727743
src/ldebug.c+6−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $
2+** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 426 unmodified lines
432432 break;
433433 }
434434 case OP_CLOSURE: {
435− int nup;
435+ int nup, j;
436436 check(b < pt->sizep);
437437 nup = pt->p[b]->nups;
438438 check(pc + nup < pt->sizecode);
439− for (; nup>0; nup--) {
440− OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
439+ for (j = 1; j <= nup; j++) {
440+ OpCode op1 = GET_OPCODE(pt->code[pc + j]);
441441 check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
442442 }
443+ if (reg != NO_REG) /* tracing? */
444+ pc += nup; /* do not 'execute' these pseudo-instructions */
443445 break;
444446 }
445447 case OP_VARARG: {
src/loslib.c+17−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $
2+** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -146,11 +146,22 @@ static int os_date (lua_State *L) { · 140 unmodified lines
146146 setboolfield(L, "isdst", stm->tm_isdst);
147147 }
148148 else {
149− char b[256];
150− if (strftime(b, sizeof(b), s, stm))
151− lua_pushstring(L, b);
152− else
153− return luaL_error(L, LUA_QL("date") " format too long");
149+ char cc[3];
150+ luaL_Buffer b;
151+ cc[0] = '%'; cc[2] = '\0';
152+ luaL_buffinit(L, &b);
153+ for (; *s; s++) {
154+ if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
155+ luaL_addchar(&b, *s);
156+ else {
157+ size_t reslen;
158+ char buff[200]; /* should be big enough for any conversion result */
159+ cc[1] = *(++s);
160+ reslen = strftime(buff, sizeof(buff), cc, stm);
161+ luaL_addlstring(&b, buff, reslen);
162+ }
163+ }
164+ luaL_pushresult(&b);
154165 }
155166 return 1;
156167 }
src/lparser.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp $
2+** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -489,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 483 unmodified lines
489489
490490 static void listfield (LexState *ls, struct ConsControl *cc) {
491491 expr(ls, &cc->v);
492− luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor");
492+ luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
493493 cc->na++;
494494 cc->tostore++;
495495 }
src/lstrlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $
2+** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 717 unmodified lines
723723
724724 static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
725725 const char *p = strfrmt;
726− while (strchr(FLAGS, *p)) p++; /* skip flags */
726+ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
727727 if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
728728 luaL_error(L, "invalid format (repeated flags)");
729729 if (isdigit(uchar(*p))) p++; /* skip width */
src/lua.h+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.218 2006/06/02 15:34:00 roberto Exp $
2+** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $
33 ** Lua - An Extensible Extension Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -17,9 +17,9 @@ · 11 unmodified lines
1717
1818
1919 #define LUA_VERSION "Lua 5.1"
20−#define LUA_RELEASE "Lua 5.1.1"
20+#define LUA_RELEASE "Lua 5.1.2"
2121 #define LUA_VERSION_NUM 501
22−#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
22+#define LUA_COPYRIGHT "Copyright (C) 1994-2007 Lua.org, PUC-Rio"
2323 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
2424
2525
@@ -359,7 +359,7 @@ struct lua_Debug { · 333 unmodified lines
359359
360360
361361 /******************************************************************************
362−* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.
362+* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved.
363363 *
364364 * Permission is hereby granted, free of charge, to any person obtaining
365365 * a copy of this software and associated documentation files (the
src/print.c+2−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $
2+** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
33 ** print bytecodes
44 ** See Copyright Notice in lua.h
55 */
@@ -32,6 +32,7 @@ static void PrintString(const TString* ts) · 26 unmodified lines
3232 switch (c)
3333 {
3434 case '"': printf("\\\""); break;
35+ case '\\': printf("\\\\"); break;
3536 case '\a': printf("\\a"); break;
3637 case '\b': printf("\\b"); break;
3738 case '\f': printf("\\f"); break;