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
2<HEAD>2<HEAD>
3<TITLE>Lua 5.1 reference manual - contents</TITLE>3<TITLE>Lua 5.1 reference manual - contents</TITLE>
4<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">4<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
5<style type="text/css">5<STYLE TYPE="text/css">
6ul {6ul {
7 list-style-type: none ;7 list-style-type: none ;
8 list-style-position: outside ;8 list-style-position: outside ;
9}9}
10</style>10</STYLE>
11</HEAD>11</HEAD>
12 12
13<BODY>13<BODY>
14 14
15<HR>15<HR>
16<H1>16<H1>
17<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>17<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A>
18Reference manual for Lua 5.118Lua 5.1 Reference Manual
19</H1>19</H1>
20 20
21This 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
36Buy a paper copy and
37<A HREF="http://www.lua.org/donations.html">help to support</A>
38the Lua project.
39<P>
40
41<A HREF="manual.html">start</A>
42&middot;
21<A HREF="#contents">contents</A>43<A HREF="#contents">contents</A>
22&middot;44&middot;
23<A HREF="#index">index</A>45<A HREF="#index">index</A>
46&middot;
47<A HREF="http://www.lua.org/manual/5.1/errata.html">errata</A>
24<HR>48<HR>
49<SMALL>
50Copyright &copy; 2006-2007 Lua.org, PUC-Rio.
51Freely available under the terms of the
52<a href="http://www.lua.org/license.html#5">Lua license</a>.
53</SMALL>
25<P>54<P>
26 55
27<H2><A NAME="contents">Contents</A></H2>56<H2><A NAME="contents">Contents</A></H2>
28<UL style="padding: 0">57<UL style="padding: 0">
29<LI><A HREF="manual.html">Top</A>
30<LI><A HREF="manual.html#1">1 - Introduction</A>58<LI><A HREF="manual.html#1">1 - Introduction</A>
31<LI><A HREF="manual.html#2">2 - The Language</A>59<LI><A HREF="manual.html#2">2 - The Language</A>
32<UL>60<UL>
@@ -107,13 +135,12 @@ Reference manual for Lua 5.1 · 74 unmodified lines
107<LI><A HREF="manual.html#7.3">7.3 - Changes in the API</A>135<LI><A HREF="manual.html#7.3">7.3 - Changes in the API</A>
108</UL>136</UL>
109<LI><A HREF="manual.html#8">8 - The Complete Syntax of Lua</A>137<LI><A HREF="manual.html#8">8 - The Complete Syntax of Lua</A>
110
111</UL>138</UL>
112 139
113<H2><A NAME="index">Index</A></H2>140<H2><A NAME="index">Index</A></H2>
114<TABLE>141<TABLE WIDTH="100%">
115<TR VALIGN="top">142<TR VALIGN="top">
116<TD WIDTH="20%">143<TD>
117<H3><A NAME="functions">Lua functions</A></H3>144<H3><A NAME="functions">Lua functions</A></H3>
118<A HREF="manual.html#pdf-_G">_G</A><BR>145<A HREF="manual.html#pdf-_G">_G</A><BR>
119<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>146<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
@@ -146,7 +173,7 @@ Reference manual for Lua 5.1 · 26 unmodified lines
146<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>173<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
147 174
148</TD>175</TD>
149<TD WIDTH="30%">176<TD>
150<H3>&nbsp;</H3>177<H3>&nbsp;</H3>
151<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>178<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
152<A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>179<A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>
@@ -254,7 +281,7 @@ Reference manual for Lua 5.1 · 101 unmodified lines
254<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>281<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
255 282
256</TD>283</TD>
257<TD WIDTH="25%">284<TD>
258<H3>C API</H3>285<H3>C API</H3>
259<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>286<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
260<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>287<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
@@ -419,10 +446,10 @@ Reference manual for Lua 5.1 · 158 unmodified lines
419<HR>446<HR>
420<SMALL>447<SMALL>
421Last update:448Last update:
422Tue Jun 6 14:55:31 BRT 2006449Fri Mar 23 08:33:19 BRT 2007
423</SMALL>450</SMALL>
424<!--451<!--
425Last change: reformatted index452Last change: minor edit
426-->453-->
427 454
428</BODY>455</BODY>
doc/cover.png+0−0

Binary file not shown.

doc/lua.css+21−2
@@ -2,16 +2,24 @@ body { · 1 unmodified line
2 color: #000000 ;2 color: #000000 ;
3 background-color: #FFFFFF ;3 background-color: #FFFFFF ;
4 font-family: sans-serif ;4 font-family: sans-serif ;
5 text-align: justify ;
6 margin-right: 20px ;
7 margin-left: 20px ;
8}
9
10h1, h2, h3, h4 {
11 font-weight: normal ;
12 font-style: italic ;
5}13}
6 14
7a:link {15a:link {
8 color: #000080 ;16 color: #000080 ;
9 background-color: #FFFFFF ;17 background-color: inherit ;
10 text-decoration: none ;18 text-decoration: none ;
11}19}
12 20
13a:visited {21a:visited {
14 background-color: #FFFFFF ;22 background-color: inherit ;
15 text-decoration: none ;23 text-decoration: none ;
16}24}
17 25
@@ -20,3 +28,14 @@ a:link:hover, a:visited:hover { · 2 unmodified lines
20 background-color: #E0E0FF ;28 background-color: #E0E0FF ;
21}29}
22 30
31a:link:active, a:visited:active {
32 color: #FF0000 ;
33}
34
35hr {
36 border: 0 ;
37 height: 1px ;
38 color: #a0a0a0 ;
39 background-color: #a0a0a0 ;
40}
41
doc/manual.css+7−0
@@ -0,0 +1,7 @@
1h3 code {
2 font-family: inherit ;
3}
4
5pre {
6 font-size: 105% ;
7}
doc/manual.html+218−153
@@ -4,6 +4,7 @@ · 3 unmodified lines
4<head>4<head>
5<title>Lua 5.1 Reference Manual</title>5<title>Lua 5.1 Reference Manual</title>
6<link rel="stylesheet" href="lua.css">6<link rel="stylesheet" href="lua.css">
7<link rel="stylesheet" href="manual.css">
7</head>8</head>
8 9
9<body>10<body>
@@ -17,10 +18,16 @@ Lua 5.1 Reference Manual · 7 unmodified lines
17by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes18by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
18<p>19<p>
19<small>20<small>
20<a href="http://www.lua.org/copyright.html">Copyright</a>21Copyright &copy; 2006-2007 Lua.org, PUC-Rio.
21&copy; 2006 Lua.org, PUC-Rio. All rights reserved.22Freely available under the terms of the
23<a href="http://www.lua.org/license.html#5">Lua license</a>.
22</small>24</small>
23<hr>25<hr>
26<p>
27
28<a href="contents.html#contents">contents</A>
29&middot;
30<a href="contents.html#index">index</A>
24 31
25<!-- ====================================================================== -->32<!-- ====================================================================== -->
26<p>33<p>
@@ -71,7 +78,7 @@ this document is dry in places. · 44 unmodified lines
71For a discussion of the decisions behind the design of Lua,78For a discussion of the decisions behind the design of Lua,
72see the technical papers available at Lua's web site.79see the technical papers available at Lua's web site.
73For a detailed introduction to programming in Lua,80For a detailed introduction to programming in Lua,
74see Roberto's book, <em>Programming in Lua</em>.81see Roberto's book, <em>Programming in Lua (Second Edition)</em>.
75 82
76 83
77 84
@@ -390,8 +397,8 @@ Name denotes identifiers, as defined in <a href="#2.1">&sect;2.1</a>. · 312 unmodified lines
390 397
391 398
392<p>399<p>
393Variables are assumed to be global unless explicitly declared local400Any variable is assumed to be global unless explicitly declared
394(see <a href="#2.4.7">&sect;2.4.7</a>).401as a local (see <a href="#2.4.7">&sect;2.4.7</a>).
395Local variables are <em>lexically scoped</em>:402Local variables are <em>lexically scoped</em>:
396local variables can be freely accessed by functions403local variables can be freely accessed by functions
397defined inside their scope (see <a href="#2.6">&sect;2.6</a>).404defined inside their scope (see <a href="#2.6">&sect;2.6</a>).
@@ -708,18 +715,18 @@ third <em>exp</em>. · 310 unmodified lines
708More precisely, a <b>for</b> statement like715More precisely, a <b>for</b> statement like
709 716
710<pre>717<pre>
711 for var = e1, e2, e3 do block end718 for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end
712</pre><p>719</pre><p>
713is equivalent to the code:720is equivalent to the code:
714 721
715<pre>722<pre>
716 do723 do
717 local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)724 local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)
718 if not (_var and _limit and _step) then error() end725 if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end
719 while (_step&gt;0 and _var&lt;=_limit) or (_step&lt;=0 and _var&gt;=_limit) do726 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
720 local var = _var727 local v = <em>var</em>
721 <em>block</em>728 <em>block</em>
722 _var = _var + _step729 <em>var</em> = <em>var</em> + <em>step</em>
723 end730 end
724 end731 end
725</pre><p>732</pre><p>
@@ -734,7 +741,7 @@ They must all result in numbers. · 8 unmodified lines
734</li>741</li>
735 742
736<li>743<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.
738The names are here for explanatory purposes only.745The names are here for explanatory purposes only.
739</li>746</li>
740 747
@@ -748,10 +755,10 @@ You can use <b>break</b> to exit a <b>for</b> loop. · 7 unmodified lines
748</li>755</li>
749 756
750<li>757<li>
751The loop variable <code>var</code> is local to the loop;758The loop variable <code>v</code> is local to the loop;
752you cannot use its value after the <b>for</b> ends or is broken.759you cannot use its value after the <b>for</b> ends or is broken.
753If you need the value of the loop variable <code>var</code>,760If you need this value,
754then assign it to another variable before breaking or exiting the loop.761assign it to another variable before breaking or exiting the loop.
755</li>762</li>
756 763
757</ul>764</ul>
@@ -770,18 +777,18 @@ The generic <b>for</b> loop has the following syntax: · 12 unmodified lines
770A <b>for</b> statement like777A <b>for</b> statement like
771 778
772<pre>779<pre>
773 for var_1, &middot;&middot;&middot;, var_n in explist do block end780 for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end
774</pre><p>781</pre><p>
775is equivalent to the code:782is equivalent to the code:
776 783
777<pre>784<pre>
778 do785 do
779 local _f, _s, _var = explist786 local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>
780 while true do787 while true do
781 local var_1, &middot;&middot;&middot;, var_n = _f(_s, _var)788 local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)
782 _var = var_1789 <em>var</em> = <em>var_1</em>
783 if _var == nil then break end790 if <em>var</em> == nil then break end
784 block791 <em>block</em>
785 end792 end
786 end793 end
787</pre><p>794</pre><p>
@@ -790,13 +797,14 @@ Note the following: · 2 unmodified lines
790<ul>797<ul>
791 798
792<li>799<li>
793<code>explist</code> is evaluated only once.800<code><em>explist</em></code> is evaluated only once.
794Its results are an <em>iterator</em> function,801Its results are an <em>iterator</em> function,
795a <em>state</em>, and an initial value for the first <em>iterator variable</em>.802a <em>state</em>,
803and an initial value for the first <em>iterator variable</em>.
796</li>804</li>
797 805
798<li>806<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.
800The names are here for explanatory purposes only.808The names are here for explanatory purposes only.
801</li>809</li>
802 810
@@ -805,7 +813,7 @@ You can use <b>break</b> to exit a <b>for</b> loop. · 2 unmodified lines
805</li>813</li>
806 814
807<li>815<li>
808The loop variables <code>var_i</code> are local to the loop;816The loop variables <code><em>var_i</em></code> are local to the loop;
809you cannot use their values after the <b>for</b> ends.817you cannot use their values after the <b>for</b> ends.
810If you need these values,818If you need these values,
811then assign them to other variables before breaking or exiting the loop.819then 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
902(only possible for function calls),910(only possible for function calls),
903then its return list is adjusted to zero elements,911then its return list is adjusted to zero elements,
904thus discarding all returned values.912thus discarding all returned values.
905If the expression is used inside another expression913If the expression is used as the last (or the only) element
906or in the middle of a list of expressions,914of a list of expressions,
907then its result list is adjusted to one element,915then no adjustment is made
908thus discarding all values except the first one.916(unless the call is enclosed in parentheses).
909If the expression is used as the last element of a list of expressions,917In all other contexts,
910then no adjustment is made,918Lua adjusts the result list to one element,
911unless the call is enclosed in parentheses.919discarding all values except the first one.
912 920
913 921
914<p>922<p>
@@ -917,17 +925,18 @@ Here are some examples: · 2 unmodified lines
917<pre>925<pre>
918 f() -- adjusted to 0 results926 f() -- adjusted to 0 results
919 g(f(), x) -- f() is adjusted to 1 result927 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()
921 a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil)929 a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil)
922 a,b = ... -- a gets the first vararg parameter, b gets930 a,b = ... -- a gets the first vararg parameter, b gets
923 -- the second (both a and b may get nil if there is931 -- the second (both a and b may get nil if there
924 -- no corresponding vararg parameter)932 -- is no corresponding vararg parameter)
933
925 a,b,c = x, f() -- f() is adjusted to 2 results934 a,b,c = x, f() -- f() is adjusted to 2 results
926 a,b,c = f() -- f() is adjusted to 3 results935 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()
928 return ... -- returns all received vararg parameters937 return ... -- returns all received vararg parameters
929 return x,y,f() -- returns x, y, and all values returned by f()938 return x,y,f() -- returns x, y, and all results from f()
930 {f()} -- creates a list with all values returned by f()939 {f()} -- creates a list with all results from f()
931 {...} -- creates a list with all vararg parameters940 {...} -- creates a list with all vararg parameters
932 {f(), nil} -- f() is adjusted to 1 result941 {f(), nil} -- f() is adjusted to 1 result
933</pre>942</pre>
@@ -1543,8 +1552,7 @@ you must use the C&nbsp;API for that. · 609 unmodified lines
1543 1552
1544<p>1553<p>
1545Tables and userdata have individual metatables1554Tables and userdata have individual metatables
1546(although multiple tables and userdata can share1555(although multiple tables and userdata can share their metatables);
1547a same table as their metatable);
1548values of all other types share one single metatable per type.1556values of all other types share one single metatable per type.
1549So, there is one single metatable for all numbers,1557So, there is one single metatable for all numbers,
1550and for all strings, etc.1558and for all strings, etc.
@@ -1592,6 +1600,7 @@ This should be read as · 41 unmodified lines
1592<pre>1600<pre>
1593 rawget(getmetatable(obj) or {}, event)1601 rawget(getmetatable(obj) or {}, event)
1594</pre><p>1602</pre><p>
1603
1595That is, the access to a metamethod does not invoke other metamethods,1604That is, the access to a metamethod does not invoke other metamethods,
1596and the access to objects with no metatables does not fail1605and the access to objects with no metatables does not fail
1597(it simply results in <b>nil</b>).1606(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
2077both keys and values.2086both keys and values.
2078In any case, if either the key or the value is collected,2087In any case, if either the key or the value is collected,
2079the whole pair is removed from the table.2088the whole pair is removed from the table.
2080The weakness of a table is controlled by the value of the2089The weakness of a table is controlled by the
2081<code>__mode</code> field of its metatable.2090<code>__mode</code> field of its metatable.
2082If the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',2091If the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',
2083the keys in the table are weak.2092the 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
2156 2165
2157 2166
2158<p>2167<p>
2159The <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function creates a coroutine,2168Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
2160just like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,2169the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine,
2161but instead of returning the coroutine itself,2170but instead of returning the coroutine itself,
2162it returns a function that, when called, resumes the coroutine.2171it returns a function that, when called, resumes the coroutine.
2163Any arguments passed to this function2172Any arguments passed to this function
@@ -2198,6 +2207,7 @@ When you run it, it produces the following output: · 34 unmodified lines
2198<pre>2207<pre>
2199 co-body 1 102208 co-body 1 10
2200 foo 22209 foo 2
2210
2201 main true 42211 main true 4
2202 co-body r2212 co-body r
2203 main true 11 -92213 main true 11 -9
@@ -2268,7 +2278,7 @@ then index&nbsp;1 represents the first element · 64 unmodified lines
2268and2278and
2269index&nbsp;<em>n</em> represents the last element;2279index&nbsp;<em>n</em> represents the last element;
2270index&nbsp;-1 also represents the last element2280index&nbsp;-1 also represents the last element
2271(that is, the element at the top)2281(that is, the element at the&nbsp;top)
2272and index <em>-n</em> represents the first element.2282and index <em>-n</em> represents the first element.
2273We say that an index is <em>valid</em>2283We say that an index is <em>valid</em>
2274if it lies between&nbsp;1 and the stack top2284if it lies between&nbsp;1 and the stack top
@@ -2473,21 +2483,25 @@ Lua assumes that the allocator never fails when · 198 unmodified lines
2473 2483
2474<p>2484<p>
2475Here is a simple implementation for the allocator function.2485Here is a simple implementation for the allocator function.
2476It is used in the auxiliary library by <a href="#lua_newstate"><code>lua_newstate</code></a>.2486It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
2477 2487
2478<pre>2488<pre>
2479 static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {2489 static void *l_alloc (void *ud, void *ptr, size_t osize,
2480 (void)ud; /* not used */2490 size_t nsize) {
2481 (void)osize; /* not used */2491 (void)ud; (void)osize; /* not used */
2482 if (nsize == 0) {2492 if (nsize == 0) {
2483 free(ptr); /* ANSI requires that free(NULL) has no effect */2493 free(ptr);
2484 return NULL;2494 return NULL;
2485 }2495 }
2486 else2496 else
2487 /* ANSI requires that realloc(NULL, size) == malloc(size) */
2488 return realloc(ptr, nsize);2497 return realloc(ptr, nsize);
2489 }2498 }
2490</pre>2499</pre><p>
2500This code assumes
2501that <code>free(NULL)</code> has no effect and that
2502<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
2503ANSI&nbsp;C ensures both behaviors.
2504
2491 2505
2492 2506
2493 2507
@@ -2557,14 +2571,14 @@ equivalent to this Lua code: · 63 unmodified lines
2557Here it is in&nbsp;C:2571Here it is in&nbsp;C:
2558 2572
2559<pre>2573<pre>
2560 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */2574 lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
2561 lua_pushstring(L, "how"); /* 1st argument */2575 lua_pushstring(L, "how"); /* 1st argument */
2562 lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */2576 lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
2563 lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */2577 lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
2564 lua_remove(L, -2); /* remove 't' from the stack */2578 lua_remove(L, -2); /* remove 't' from the stack */
2565 lua_pushinteger(L, 14); /* 3rd argument */2579 lua_pushinteger(L, 14); /* 3rd argument */
2566 lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */2580 lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */
2567 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable 'a' */2581 lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global 'a' */
2568</pre><p>2582</pre><p>
2569Note that the code above is "balanced":2583Note that the code above is "balanced":
2570at its end, the stack is back to its original configuration.2584at 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
2611 int i;2625 int i;
2612 for (i = 1; i &lt;= n; i++) {2626 for (i = 1; i &lt;= n; i++) {
2613 if (!lua_isnumber(L, i)) {2627 if (!lua_isnumber(L, i)) {
2614 lua_pushstring(L, "incorrect argument to function 'average'");2628 lua_pushstring(L, "incorrect argument");
2615 lua_error(L);2629 lua_error(L);
2616 }2630 }
2617 sum += lua_tonumber(L, i);2631 sum += lua_tonumber(L, i);
@@ -2723,7 +2737,7 @@ to write them. · 105 unmodified lines
2723<p>2737<p>
2724The value returned is the error code returned by the last2738The value returned is the error code returned by the last
2725call to the writer;2739call to the writer;
27260 means no errors.27400&nbsp;means no errors.
2727 2741
2728 2742
2729<p>2743<p>
@@ -2814,7 +2828,7 @@ The function returns the previous value of the pause. · 84 unmodified lines
2814</li>2828</li>
2815 2829
2816<li><b><code>LUA_GCSETSTEPMUL</code>:</b>2830<li><b><code>LUA_GCSETSTEPMUL</code>:</b>
2817sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of2831sets <code>data</code>/100 as the new value for the <em>step multiplier</em> of
2818the collector (see <a href="#2.10">&sect;2.10</a>).2832the collector (see <a href="#2.10">&sect;2.10</a>).
2819The function returns the previous value of the step multiplier.2833The function returns the previous value of the step multiplier.
2820</li>2834</li>
@@ -2942,7 +2956,7 @@ The type used by the Lua API to represent integral values. · 121 unmodified lines
2942 2956
2943<p>2957<p>
2944By default it is a <code>ptrdiff_t</code>,2958By default it is a <code>ptrdiff_t</code>,
2945which is usually the largest integral type the machine handles2959which is usually the largest signed integral type the machine handles
2946"comfortably".2960"comfortably".
2947 2961
2948 2962
@@ -2954,7 +2968,7 @@ which is usually the largest integral type the machine handles · 5 unmodified lines
2954 2968
2955<p>2969<p>
2956Returns 1 if the value at the given acceptable index has type boolean,2970Returns 1 if the value at the given acceptable index has type boolean,
2957and 0 otherwise.2971and 0&nbsp;otherwise.
2958 2972
2959 2973
2960 2974
@@ -2965,7 +2979,7 @@ and 0 otherwise. · 4 unmodified lines
2965 2979
2966<p>2980<p>
2967Returns 1 if the value at the given acceptable index is a C&nbsp;function,2981Returns 1 if the value at the given acceptable index is a C&nbsp;function,
2968and 0 otherwise.2982and 0&nbsp;otherwise.
2969 2983
2970 2984
2971 2985
@@ -2976,7 +2990,7 @@ and 0 otherwise. · 4 unmodified lines
2976 2990
2977<p>2991<p>
2978Returns 1 if the value at the given acceptable index is a function2992Returns 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.
2980 2994
2981 2995
2982 2996
@@ -2987,7 +3001,7 @@ Returns 1 if the value at the given acceptable index is a function · 4 unmodified lines
2987 3001
2988<p>3002<p>
2989Returns 1 if the value at the given acceptable index is a light userdata,3003Returns 1 if the value at the given acceptable index is a light userdata,
2990and 0 otherwise.3004and 0&nbsp;otherwise.
2991 3005
2992 3006
2993 3007
@@ -2998,7 +3012,32 @@ and 0 otherwise. · 4 unmodified lines
2998 3012
2999<p>3013<p>
3000Returns 1 if the value at the given acceptable index is <b>nil</b>,3014Returns 1 if the value at the given acceptable index is <b>nil</b>,
3001and 0 otherwise.3015and 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>
3025Returns 1 if the the given acceptable index is not valid
3026(that is, it refers to an element outside the current stack),
3027and 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>
3037Returns 1 if the the given acceptable index is not valid
3038(that is, it refers to an element outside the current stack)
3039or if the value at this index is <b>nil</b>,
3040and 0&nbsp;otherwise.
3002 3041
3003 3042
3004 3043
@@ -3010,7 +3049,7 @@ and 0 otherwise. · 5 unmodified lines
3010<p>3049<p>
3011Returns 1 if the value at the given acceptable index is a number3050Returns 1 if the value at the given acceptable index is a number
3012or a string convertible to a number,3051or a string convertible to a number,
3013and 0 otherwise.3052and 0&nbsp;otherwise.
3014 3053
3015 3054
3016 3055
@@ -3022,7 +3061,7 @@ and 0 otherwise. · 5 unmodified lines
3022<p>3061<p>
3023Returns 1 if the value at the given acceptable index is a string3062Returns 1 if the value at the given acceptable index is a string
3024or a number (which is always convertible to a string),3063or a number (which is always convertible to a string),
3025and 0 otherwise.3064and 0&nbsp;otherwise.
3026 3065
3027 3066
3028 3067
@@ -3033,7 +3072,7 @@ and 0 otherwise. · 4 unmodified lines
3033 3072
3034<p>3073<p>
3035Returns 1 if the value at the given acceptable index is a table,3074Returns 1 if the value at the given acceptable index is a table,
3036and 0 otherwise.3075and 0&nbsp;otherwise.
3037 3076
3038 3077
3039 3078
@@ -3044,7 +3083,7 @@ and 0 otherwise. · 4 unmodified lines
3044 3083
3045<p>3084<p>
3046Returns 1 if the value at the given acceptable index is a thread,3085Returns 1 if the value at the given acceptable index is a thread,
3047and 0 otherwise.3086and 0&nbsp;otherwise.
3048 3087
3049 3088
3050 3089
@@ -3055,7 +3094,7 @@ and 0 otherwise. · 4 unmodified lines
3055 3094
3056<p>3095<p>
3057Returns 1 if the value at the given acceptable index is a userdata3096Returns 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.
3059 3098
3060 3099
3061 3100
@@ -3113,8 +3152,8 @@ and loads it accordingly (see program <code>luac</code>). · 51 unmodified lines
3113 3152
3114 3153
3115<p>3154<p>
3116<a href="#lua_load"><code>lua_load</code></a> uses a user-supplied <code>reader</code> function to read the chunk3155The <a href="#lua_load"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function
3117(see <a href="#lua_Reader"><code>lua_Reader</code></a>).3156to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
3118The <code>data</code> argument is an opaque value passed to the reader function.3157The <code>data</code> argument is an opaque value passed to the reader function.
3119 3158
3120 3159
@@ -3219,10 +3258,12 @@ A typical traversal looks like this: · 98 unmodified lines
3219 /* table is in the stack at index 't' */3258 /* table is in the stack at index 't' */
3220 lua_pushnil(L); /* first key */3259 lua_pushnil(L); /* first key */
3221 while (lua_next(L, t) != 0) {3260 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) */
3223 printf("%s - %s\n",3262 printf("%s - %s\n",
3224 lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1)));3263 lua_typename(L, lua_type(L, -2)),
3225 lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */3264 lua_typename(L, lua_type(L, -1)));
3265 /* removes 'value'; keeps 'key' for next iteration */
3266 lua_pop(L, 1);
3226 }3267 }
3227</pre>3268</pre>
3228 3269
@@ -3270,7 +3311,7 @@ for other values, it is&nbsp;0. · 41 unmodified lines
3270 3311
3271 3312
3272<hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3>3313<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>
3274 3315
3275<p>3316<p>
3276Calls a function in protected mode.3317Calls 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
3396 3437
3397 3438
3398<p>3439<p>
3399The call <code>lua_pushcfunction(L, f)</code> is equivalent to3440<code>lua_pushcfunction</code> is defined as a macro:
3400<code>lua_pushcclosure(L, f, 0)</code>.
3401 3441
3442<pre>
3443 #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
3444</pre>
3402 3445
3403 3446
3404 3447
@@ -3642,14 +3685,17 @@ The reader function may return pieces of any size greater than zero. · 237 unmodified lines
3642 3685
3643 3686
3644<hr><h3><a name="lua_register"><code>lua_register</code></a></h3>3687<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>
3646 3691
3647<p>3692<p>
3648Sets the C function <code>f</code> as the new value of global <code>name</code>.3693Sets the C function <code>f</code> as the new value of global <code>name</code>.
3649It is defined as a macro:3694It is defined as a macro:
3650 3695
3651<pre>3696<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))
3653</pre>3699</pre>
3654 3700
3655 3701
@@ -3905,8 +3951,7 @@ it is truncated in some non-specified way. · 249 unmodified lines
3905<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>3951<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>
3906 3952
3907<p>3953<p>
3908Converts the Lua value at the given acceptable index to a string3954Converts the Lua value at the given acceptable index to a C&nbsp;string.
3909(<code>const char*</code>).
3910If <code>len</code> is not <code>NULL</code>,3955If <code>len</code> is not <code>NULL</code>,
3911it also sets <code>*len</code> with the string length.3956it also sets <code>*len</code> with the string length.
3912The Lua value must be a string or a number;3957The 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
3937 3982
3938<p>3983<p>
3939Converts the Lua value at the given acceptable index3984Converts the Lua value at the given acceptable index
3940to a number (see <a href="#lua_Number"><code>lua_Number</code></a>).3985to the C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>).
3941The Lua value must be a number or a string convertible to a number3986The Lua value must be a number or a string convertible to a number
3942(see <a href="#2.2.1">&sect;2.2.1</a>);3987(see <a href="#2.2.1">&sect;2.2.1</a>);
3943otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns&nbsp;0.3988otherwise, <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
4054 4099
4055<p>4100<p>
4056The writer returns an error code:4101The writer returns an error code:
40570 means no errors;41020&nbsp;means no errors;
4058any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from4103any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
4059calling the writer again.4104calling the writer again.
4060 4105
@@ -4279,8 +4324,8 @@ a value to be pushed on the stack: · 218 unmodified lines
4279</li>4324</li>
4280 4325
4281<li><b>'<code>S</code>':</b>4326<li><b>'<code>S</code>':</b>
4282fills in the fields <code>source</code>, <code>linedefined</code>,4327fills in the fields <code>source</code>, <code>short_src</code>,
4283<code>lastlinedefined</code>, <code>what</code>, and <code>short_src</code>;4328<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
4284</li>4329</li>
4285 4330
4286<li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>;4331<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
4313 4358
4314 4359
4315<hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3>4360<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>
4317 4362
4318<p>4363<p>
4319Gets information about a local variable of a given activation record.4364Gets 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
4424 4469
4425 4470
4426<hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3>4471<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>
4428 4473
4429<p>4474<p>
4430Sets the debugging hook function.4475Sets the debugging hook function.
4431 4476
4432 4477
4433<p>4478<p>
4434<code>func</code> is the hook function.4479Argument <code>f</code> is the hook function.
4435<code>mask</code> specifies on which events the hook will be called:4480<code>mask</code> specifies on which events the hook will be called:
4436it is formed by a bitwise or of the constants4481it is formed by a bitwise or of the constants
4437<a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,4482<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
4475 4520
4476 4521
4477<hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3>4522<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>
4479 4524
4480<p>4525<p>
4481Sets the value of a local variable of a given activation record.4526Sets the value of a local variable of a given activation record.
@@ -4500,11 +4545,11 @@ the number of active local variables. · 18 unmodified lines
4500 4545
4501<p>4546<p>
4502Sets the value of a closure's upvalue.4547Sets the value of a closure's upvalue.
4503Parameters <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>).
4505It assigns the value at the top of the stack4548It assigns the value at the top of the stack
4506to the upvalue and returns its name.4549to the upvalue and returns its name.
4507It also pops the value from the stack.4550It also pops the value from the stack.
4551Parameters <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>).
4508 4553
4509 4554
4510<p>4555<p>
@@ -4588,9 +4633,9 @@ The string may contain embedded zeros. · 77 unmodified lines
4588<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>4633<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>
4589 4634
4590<p>4635<p>
4591Adds a string of length <code>n</code> previously copied to the4636Adds to the buffer <code>B</code> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>)
4592buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to the buffer <code>B</code>4637a string of length <code>n</code> previously copied to the
4593(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).4638buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
4594 4639
4595 4640
4596 4641
@@ -4631,7 +4676,7 @@ which is the value to be added to the buffer. · 34 unmodified lines
4631<hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3>4676<hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3>
4632<pre>void luaL_argcheck (lua_State *L,4677<pre>void luaL_argcheck (lua_State *L,
4633 int cond,4678 int cond,
4634 int numarg,4679 int narg,
4635 const char *extramsg);</pre>4680 const char *extramsg);</pre>
4636 4681
4637<p>4682<p>
@@ -4640,21 +4685,21 @@ If not, raises an error with the following message, · 2 unmodified lines
4640where <code>func</code> is retrieved from the call stack:4685where <code>func</code> is retrieved from the call stack:
4641 4686
4642<pre>4687<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;)
4644</pre>4689</pre>
4645 4690
4646 4691
4647 4692
4648 4693
4649<hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3>4694<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>
4651 4696
4652<p>4697<p>
4653Raises an error with the following message,4698Raises an error with the following message,
4654where <code>func</code> is retrieved from the call stack:4699where <code>func</code> is retrieved from the call stack:
4655 4700
4656<pre>4701<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;)
4658</pre>4703</pre>
4659 4704
4660<p>4705<p>
@@ -5079,9 +5124,10 @@ with <code>tname</code> in the registry. · 418 unmodified lines
5079<pre>lua_State *luaL_newstate (void);</pre>5124<pre>lua_State *luaL_newstate (void);</pre>
5080 5125
5081<p>5126<p>
5082Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an5127Creates a new Lua state.
5083allocation function based on the standard&nbsp;C <code>realloc</code> function5128It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
5084and setting a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints5129allocator based on the standard&nbsp;C <code>realloc</code> function
5130and then sets a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints
5085an error message to the standard error output in case of fatal5131an error message to the standard error output in case of fatal
5086errors.5132errors.
5087 5133
@@ -5119,7 +5165,9 @@ Otherwise, raises an error. · 31 unmodified lines
5119 5165
5120 5166
5121<hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3>5167<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>
5123 5171
5124<p>5172<p>
5125If the function argument <code>narg</code> is a number,5173If the function argument <code>narg</code> is a number,
@@ -5183,7 +5231,9 @@ Otherwise, raises an error. · 57 unmodified lines
5183 5231
5184 5232
5185<hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3>5233<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>
5187 5237
5188<p>5238<p>
5189If the function argument <code>narg</code> is a string,5239If 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
5285 5335
5286<p>5336<p>
5287When called with a non-null <code>libname</code>,5337When called with a non-null <code>libname</code>,
5288creates a new table <code>t</code>,5338<code>luaL_register</code> creates a new table <code>t</code>,
5289sets it as the value of the global variable <code>libname</code>,5339sets it as the value of the global variable <code>libname</code>,
5290sets it as the value of <code>package.loaded[libname]</code>,5340sets it as the value of <code>package.loaded[libname]</code>,
5291and registers on it all functions in the list <code>l</code>.5341and 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
5316<pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre>5366<pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre>
5317 5367
5318<p>5368<p>
5319Generates an error with a message like5369Generates an error with a message like the following:
5320 5370
5321<pre>5371<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>)
5323</pre><p>5373</pre><p>
5324where <code>&lt;location&gt;</code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,5374where <code><em>location</em></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,5375<code><em>func</em></code> is the name of the current function,
5326and <code>&lt;realt&gt;</code> is the type name of the actual argument.5376and <code><em>rt</em></code> is the type name of the actual argument.
5327 5377
5328 5378
5329 5379
@@ -5354,7 +5404,11 @@ If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a · 24 unmodified lines
5354<p>5404<p>
5355Pushes onto the stack a string identifying the current position5405Pushes onto the stack a string identifying the current position
5356of the control at level <code>lvl</code> in the call stack.5406of the control at level <code>lvl</code> in the call stack.
5357Typically this string has the format <code>&lt;chunkname&gt;:&lt;currentline&gt;:</code>.5407Typically this string has the following format:
5408
5409<pre>
5410 <em>chunkname</em>:<em>currentline</em>:
5411</pre><p>
5358Level&nbsp;0 is the running function,5412Level&nbsp;0 is the running function,
5359level&nbsp;1 is the function that called the running function,5413level&nbsp;1 is the function that called the running function,
5360etc.5414etc.
@@ -5413,9 +5467,8 @@ or as methods of its objects. · 52 unmodified lines
5413 5467
5414<p>5468<p>
5415To have access to these libraries,5469To have access to these libraries,
5416the C&nbsp;host program must call5470the C&nbsp;host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> function,
5417<a href="#luaL_openlibs"><code>luaL_openlibs</code></a>,5471which opens all standard libraries.
5418which open all standard libraries.
5419Alternatively,5472Alternatively,
5420it can open them individually by calling5473it can open them individually by calling
5421<a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),5474<a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
@@ -5547,7 +5600,7 @@ nor vice-versa. · 125 unmodified lines
5547 5600
5548 5601
5549<p>5602<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>
5551Returns the current environment in use by the function.5604Returns the current environment in use by the function.
5552<code>f</code> can be a Lua function or a number5605<code>f</code> can be a Lua function or a number
5553that specifies the function at that stack level:5606that 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
5589up to the first integer key absent from the table.5642up to the first integer key absent from the table.
5590 5643
5591 5644
5592<p>
5593See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.
5594
5595
5596 5645
5597 5646
5598<p>5647<p>
@@ -5704,7 +5753,8 @@ will iterate over all key&ndash;value pairs of table <code>t</code>. · 105 unmodified lines
5704 5753
5705 5754
5706<p>5755<p>
5707See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal.5756See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
5757the table during its traversal.
5708 5758
5709 5759
5710 5760
@@ -5911,7 +5961,7 @@ The current contents of this variable is "<code>Lua 5.1</code>". · 200 unmodified lines
5911 5961
5912 5962
5913<p>5963<p>
5914This function is similar to <code>pcall</code>,5964This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
5915except that you can set a new error handler.5965except that you can set a new error handler.
5916 5966
5917 5967
@@ -6101,7 +6151,7 @@ where each option is a function to be applied over the module. · 183 unmodified lines
6101 6151
6102<p>6152<p>
6103Loads the given module.6153Loads the given module.
6104The function starts by looking into the table <a href="#pdf-package.loaded"><code>package.loaded</code></a>6154The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></a> table
6105to determine whether <code>modname</code> is already loaded.6155to determine whether <code>modname</code> is already loaded.
6106If it is, then <code>require</code> returns the value stored6156If it is, then <code>require</code> returns the value stored
6107at <code>package.loaded[modname]</code>.6157at <code>package.loaded[modname]</code>.
@@ -6156,7 +6206,7 @@ with each submodule keeping its original open function. · 48 unmodified lines
6156Once a loader is found,6206Once a loader is found,
6157<code>require</code> calls the loader with a single argument, <code>modname</code>.6207<code>require</code> calls the loader with a single argument, <code>modname</code>.
6158If the loader returns any value,6208If 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>.
6160If the loader returns no value and6210If the loader returns no value and
6161has not assigned any value to <code>package.loaded[modname]</code>,6211has not assigned any value to <code>package.loaded[modname]</code>,
6162then <code>require</code> assigns <b>true</b> to this entry.6212then <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
6190 6240
6191 6241
6192<p>6242<p>
6243
6193<hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>6244<hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>
6194 6245
6195 6246
@@ -6426,7 +6477,8 @@ whereas <code>q</code> and <code>s</code> expect a string. · 230 unmodified lines
6426 6477
6427<p>6478<p>
6428This function does not accept string values6479This function does not accept string values
6429containing embedded zeros.6480containing embedded zeros,
6481except as arguments to the <code>q</code> option.
6430 6482
6431 6483
6432 6484
@@ -6436,9 +6488,6 @@ containing embedded zeros. · 3 unmodified lines
6436Returns an iterator function that,6488Returns an iterator function that,
6437each time it is called,6489each time it is called,
6438returns the next captures from <code>pattern</code> over string <code>s</code>.6490returns the next captures from <code>pattern</code> over string <code>s</code>.
6439
6440
6441<p>
6442If <code>pattern</code> specifies no captures,6491If <code>pattern</code> specifies no captures,
6443then the whole match is produced in each call.6492then the whole match is produced in each call.
6444 6493
@@ -6465,6 +6514,11 @@ given string into a table: · 20 unmodified lines
6465 end6514 end
6466</pre>6515</pre>
6467 6516
6517<p>
6518For this function, a '<code>^</code>' at the start of a pattern does not
6519work as an anchor, as this would prevent the iteration.
6520
6521
6468 6522
6469 6523
6470<p>6524<p>
@@ -6540,7 +6594,7 @@ Here are some examples: · 69 unmodified lines
6540 --&gt; x="4+5 = 9"6594 --&gt; x="4+5 = 9"
6541 6595
6542 local t = {name="lua", version="5.1"}6596 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)
6544 --&gt; x="lua-5.1.tar.gz"6598 --&gt; x="lua-5.1.tar.gz"
6545</pre>6599</pre>
6546 6600
@@ -6824,7 +6878,8 @@ we mean the result of the length operator. · 277 unmodified lines
6824 6878
6825<p>6879<p>
6826<hr><h3><a name="pdf-table.concat"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3>6880<hr><h3><a name="pdf-table.concat"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3>
6827Returns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.6881Given an array where all elements are strings or numbers,
6882returns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.
6828The default value for <code>sep</code> is the empty string,6883The default value for <code>sep</code> is the empty string,
6829the default for <code>i</code> is 1,6884the default for <code>i</code> is 1,
6830and the default for <code>j</code> is the length of the table.6885and 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
7122 7177
7123 7178
7124<p>7179<p>
7125The value PI.7180The value of <em>pi</em>.
7126 7181
7127 7182
7128 7183
@@ -7266,7 +7321,8 @@ three predefined file descriptors with their usual meanings from C: · 137 unmodified lines
7266<p>7321<p>
7267Unless otherwise stated,7322Unless otherwise stated,
7268all I/O functions return <b>nil</b> on failure7323all 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
7325a system-dependent error code as a third result)
7270and some value different from <b>nil</b> on success.7326and some value different from <b>nil</b> on success.
7271 7327
7272 7328
@@ -7331,7 +7387,7 @@ it returns <b>nil</b> (to finish the loop) and automatically closes the file. · 58 unmodified lines
7331 7387
7332 7388
7333<p>7389<p>
7334The call <code>io.lines()</code> (without a file name) is equivalent7390The call <code>io.lines()</code> (with no file name) is equivalent
7335to <code>io.input():lines()</code>;7391to <code>io.input():lines()</code>;
7336that is, it iterates over the lines of the default input file.7392that is, it iterates over the lines of the default input file.
7337In this case it does not close the file when the loop ends.7393In 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
7381 7437
7382 7438
7383<p>7439<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>
7385 7441
7386 7442
7387<p>7443<p>
@@ -7596,7 +7652,7 @@ or there is any input from some special files · 208 unmodified lines
7596</li>7652</li>
7597 7653
7598</ul><p>7654</ul><p>
7599For the last two cases, <code>sizes</code>7655For the last two cases, <code>size</code>
7600specifies the size of the buffer, in bytes.7656specifies the size of the buffer, in bytes.
7601The default is an appropriate size.7657The default is an appropriate size.
7602 7658
@@ -7657,7 +7713,7 @@ Otherwise, <code>date</code> formats the current time. · 54 unmodified lines
7657If <code>format</code> starts with '<code>!</code>',7713If <code>format</code> starts with '<code>!</code>',
7658then the date is formatted in Coordinated Universal Time.7714then the date is formatted in Coordinated Universal Time.
7659After this optional character,7715After this optional character,
7660if <code>format</code> is <code>*t</code>,7716if <code>format</code> is the string "<code>*t</code>",
7661then <code>date</code> returns a table with the following fields:7717then <code>date</code> returns a table with the following fields:
7662<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),7718<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),
7663<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),7719<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
7667 7723
7668 7724
7669<p>7725<p>
7670If <code>format</code> is not <code>*t</code>,7726If <code>format</code> is not "<code>*t</code>",
7671then <code>date</code> returns the date as a string,7727then <code>date</code> returns the date as a string,
7672formatted according to the same rules as the C&nbsp;function <code>strftime</code>.7728formatted according to the same rules as the C&nbsp;function <code>strftime</code>.
7673 7729
@@ -7771,6 +7827,13 @@ The function returns the name of the new locale, · 97 unmodified lines
7771or <b>nil</b> if the request cannot be honored.7827or <b>nil</b> if the request cannot be honored.
7772 7828
7773 7829
7830<p>
7831If <code>locale</code> is the empty string,
7832the current locate is set to an implementation-defined native locale.
7833If <code>locate</code> is the string "<code>C</code>",
7834the current locate is set to the standard C locale.
7835
7836
7774<p>7837<p>
7775When called with <b>nil</b> as the first argument,7838When called with <b>nil</b> as the first argument,
7776this function only returns the name of the current locale7839this function only returns the name of the current locale
@@ -7921,7 +7984,8 @@ valid lines. · 144 unmodified lines
7921<p>7984<p>
7922For instance, the expression <code>debug.getinfo(1,"n").name</code> returns7985For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
7923a name of the current function, if a reasonable name can be found,7986a name of the current function, if a reasonable name can be found,
7924and <code>debug.getinfo(print)</code> returns a table with all available information7987and the expression <code>debug.getinfo(print)</code>
7988returns a table with all available information
7925about the <a href="#pdf-print"><code>print</code></a> function.7989about the <a href="#pdf-print"><code>print</code></a> function.
7926 7990
7927 7991
@@ -8080,15 +8144,16 @@ Otherwise, it returns the name of the upvalue. · 152 unmodified lines
8080 8144
8081 8145
8082<p>8146<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>
8084 8148
8085 8149
8086<p>8150<p>
8087Returns a string with a traceback of the call stack.8151Returns a string with a traceback of the call stack.
8088An optional <code>message</code> string is appended8152An optional <code>message</code> string is appended
8089at the beginning of the traceback. 8153at the beginning of the traceback.
8090This function is typically used with <a href="#pdf-xpcall"><code>xpcall</code></a> to produce8154An optional <code>level</code> number tells at which level
8091better error messages.8155to start the traceback
8156(default is 1, the function calling <code>traceback</code>).
8092 8157
8093 8158
8094 8159
@@ -8232,7 +8297,7 @@ is a more portable solution.) · 137 unmodified lines
8232<h1>7 - <a name="7">Incompatibilities with the Previous Version</a></h1>8297<h1>7 - <a name="7">Incompatibilities with the Previous Version</a></h1>
8233 8298
8234<p>8299<p>
8235Here we list the incompatibilities that may be found when moving a program8300Here we list the incompatibilities that you may found when moving a program
8236from Lua&nbsp;5.0 to Lua&nbsp;5.1.8301from Lua&nbsp;5.0 to Lua&nbsp;5.1.
8237You can avoid most of the incompatibilities compiling Lua with8302You can avoid most of the incompatibilities compiling Lua with
8238appropriate options (see file <code>luaconf.h</code>).8303appropriate 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
8247<li>8312<li>
8248The vararg system changed from the pseudo-argument <code>arg</code> with a8313The vararg system changed from the pseudo-argument <code>arg</code> with a
8249table with the extra arguments to the vararg expression.8314table 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>.)
8251</li>8316</li>
8252 8317
8253<li>8318<li>
@@ -8259,7 +8324,7 @@ variables of the <b>for</b> statement and for the <b>repeat</b> statement. · 5 unmodified lines
8259The long string/long comment syntax (<code>[[<em>string</em>]]</code>)8324The long string/long comment syntax (<code>[[<em>string</em>]]</code>)
8260does not allow nesting.8325does not allow nesting.
8261You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases.8326You 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>.)
8263</li>8328</li>
8264 8329
8265</ul>8330</ul>
@@ -8272,7 +8337,7 @@ You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases. · 6 unmodified lines
8272 8337
8273<li>8338<li>
8274Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>.8339Function <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>.)
8276</li>8341</li>
8277 8342
8278<li>8343<li>
@@ -8288,17 +8353,17 @@ Function <code>table.setn</code> was deprecated. · 9 unmodified lines
8288Function <code>table.getn</code> corresponds8353Function <code>table.getn</code> corresponds
8289to the new length operator (<code>#</code>);8354to the new length operator (<code>#</code>);
8290use the operator instead of the function.8355use 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>.)
8292</li>8357</li>
8293 8358
8294<li>8359<li>
8295Function <code>loadlib</code> was renamed <a href="#pdf-package.loadlib"><code>package.loadlib</code></a>.8360Function <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>.)
8297</li>8362</li>
8298 8363
8299<li>8364<li>
8300Function <code>math.mod</code> was renamed <a href="#pdf-math.fmod"><code>math.fmod</code></a>.8365Function <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>.)
8302</li>8367</li>
8303 8368
8304<li>8369<li>
@@ -8446,10 +8511,10 @@ Here is the complete syntax of Lua in extended BNF. · 141 unmodified lines
8446<HR>8511<HR>
8447<SMALL>8512<SMALL>
8448Last update:8513Last update:
8449Mon Jun 5 17:05:27 BRT 20068514Fri Mar 23 14:37:09 BRT 2007
8450</SMALL>8515</SMALL>
8451<!--8516<!--
8452Last change: ready for Lua 5.1.18517Last change: ready for Lua 5.1.2
8453-->8518-->
8454 8519
8455</body></html>8520</body></html>
doc/readme.html+11−3
@@ -4,7 +4,7 @@ · 3 unmodified lines
4<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">4<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
5</HEAD>5</HEAD>
6 6
7<BODY BGCOLOR="#FFFFFF">7<BODY>
8 8
9<HR>9<HR>
10<H1>10<H1>
@@ -12,8 +12,9 @@ · 1 unmodified line
12Documentation12Documentation
13</H1>13</H1>
14 14
15This is the documentation included in the source distribution of Lua 5.1.2.
16
15<UL>17<UL>
16<LI><A HREF="http://www.lua.org/">Official web site</A>
17<LI><A HREF="contents.html">Reference manual</A>18<LI><A HREF="contents.html">Reference manual</A>
18<LI><A HREF="lua.html">lua man page</A>19<LI><A HREF="lua.html">lua man page</A>
19<LI><A HREF="luac.html">luac man page</A>20<LI><A HREF="luac.html">luac man page</A>
@@ -22,10 +23,17 @@ Documentation · 2 unmodified lines
22<LI><A HREF="../test/README">lua/test/README</A>23<LI><A HREF="../test/README">lua/test/README</A>
23</UL>24</UL>
24 25
26Lua's
27<A HREF="http://www.lua.org/">official web site</A>
28contains updated documentation,
29especially the
30<A HREF="http://www.lua.org/manual/5.1/">reference manual</A>.
31<P>
32
25<HR>33<HR>
26<SMALL>34<SMALL>
27Last update:35Last update:
28Wed Sep 7 12:57:50 BRST 200536Fri Mar 23 14:19:36 BRT 2007
29</SMALL>37</SMALL>
30 38
31</BODY>39</BODY>
src/lbaselib.c+5−5
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) { · 108 unmodified lines
114}114}
115 115
116 116
117static void getfunc (lua_State *L) {117static void getfunc (lua_State *L, int opt) {
118 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);118 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
119 else {119 else {
120 lua_Debug ar;120 lua_Debug ar;
121 int level = luaL_optint(L, 1, 1);121 int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
122 luaL_argcheck(L, level >= 0, 1, "level must be non-negative");122 luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
123 if (lua_getstack(L, level, &ar) == 0)123 if (lua_getstack(L, level, &ar) == 0)
124 luaL_argerror(L, 1, "invalid level");124 luaL_argerror(L, 1, "invalid level");
@@ -131,7 +131,7 @@ static void getfunc (lua_State *L) { · 6 unmodified lines
131 131
132 132
133static int luaB_getfenv (lua_State *L) {133static int luaB_getfenv (lua_State *L) {
134 getfunc(L);134 getfunc(L, 1);
135 if (lua_iscfunction(L, -1)) /* is a C function? */135 if (lua_iscfunction(L, -1)) /* is a C function? */
136 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */136 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
137 else137 else
@@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) { · 4 unmodified lines
142 142
143static int luaB_setfenv (lua_State *L) {143static int luaB_setfenv (lua_State *L) {
144 luaL_checktype(L, 2, LUA_TTABLE);144 luaL_checktype(L, 2, LUA_TTABLE);
145 getfunc(L);145 getfunc(L, 0);
146 lua_pushvalue(L, 2);146 lua_pushvalue(L, 2);
147 if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {147 if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
148 /* change environment of current thread */148 /* change environment of current thread */
src/lcode.c+30−14
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines
35void luaK_nil (FuncState *fs, int from, int n) {35void luaK_nil (FuncState *fs, int from, int n) {
36 Instruction *previous;36 Instruction *previous;
37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38 if (fs->pc == 0) /* function start? */38 if (fs->pc == 0) { /* function start? */
39 return; /* positions are already clean */39 if (from >= fs->nactvar)
40 if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {40 return; /* positions are already clean */
41 int pfrom = GETARG_A(*previous);41 }
42 int pto = GETARG_B(*previous);42 else {
43 if (pfrom <= from && from <= pto+1) { /* can connect both? */43 previous = &fs->f->code[fs->pc-1];
44 if (from+n-1 > pto)44 if (GET_OPCODE(*previous) == OP_LOADNIL) {
45 SETARG_B(*previous, from+n-1);45 int pfrom = GETARG_A(*previous);
46 return;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 }
47 }52 }
48 }53 }
49 }54 }
@@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 607 unmodified lines
657 if (constfolding(op, e1, e2))662 if (constfolding(op, e1, e2))
658 return;663 return;
659 else {664 else {
660 int o1 = luaK_exp2RK(fs, e1);
661 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;665 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
662 freeexp(fs, e2);666 int o1 = luaK_exp2RK(fs, e1);
663 freeexp(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 }
664 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);675 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665 e1->k = VRELOCABLE;676 e1->k = VRELOCABLE;
666 }677 }
@@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines
718 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */729 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
719 break;730 break;
720 }731 }
721 default: {732 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
733 case OPR_MOD: case OPR_POW: {
722 if (!isnumeral(v)) luaK_exp2RK(fs, v);734 if (!isnumeral(v)) luaK_exp2RK(fs, v);
723 break;735 break;
724 }736 }
737 default: {
738 luaK_exp2RK(fs, v);
739 break;
740 }
725 }741 }
726}742}
727 743
src/ldebug.c+6−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Debug Interface3** Debug Interface
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -432,14 +432,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) { · 426 unmodified lines
432 break;432 break;
433 }433 }
434 case OP_CLOSURE: {434 case OP_CLOSURE: {
435 int nup;435 int nup, j;
436 check(b < pt->sizep);436 check(b < pt->sizep);
437 nup = pt->p[b]->nups;437 nup = pt->p[b]->nups;
438 check(pc + nup < pt->sizecode);438 check(pc + nup < pt->sizecode);
439 for (; nup>0; nup--) {439 for (j = 1; j <= nup; j++) {
440 OpCode op1 = GET_OPCODE(pt->code[pc+nup]);440 OpCode op1 = GET_OPCODE(pt->code[pc + j]);
441 check(op1 == OP_GETUPVAL || op1 == OP_MOVE);441 check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
442 }442 }
443 if (reg != NO_REG) /* tracing? */
444 pc += nup; /* do not 'execute' these pseudo-instructions */
443 break;445 break;
444 }446 }
445 case OP_VARARG: {447 case OP_VARARG: {
src/loslib.c+17−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard Operating System library3** Standard Operating System library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -146,11 +146,22 @@ static int os_date (lua_State *L) { · 140 unmodified lines
146 setboolfield(L, "isdst", stm->tm_isdst);146 setboolfield(L, "isdst", stm->tm_isdst);
147 }147 }
148 else {148 else {
149 char b[256];149 char cc[3];
150 if (strftime(b, sizeof(b), s, stm))150 luaL_Buffer b;
151 lua_pushstring(L, b);151 cc[0] = '%'; cc[2] = '\0';
152 else152 luaL_buffinit(L, &b);
153 return luaL_error(L, LUA_QL("date") " format too long");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);
154 }165 }
155 return 1;166 return 1;
156}167}
src/lparser.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -489,7 +489,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { · 483 unmodified lines
489 489
490static void listfield (LexState *ls, struct ConsControl *cc) {490static void listfield (LexState *ls, struct ConsControl *cc) {
491 expr(ls, &cc->v);491 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");
493 cc->na++;493 cc->na++;
494 cc->tostore++;494 cc->tostore++;
495}495}
src/lstrlib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard library for string operations and pattern-matching3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 717 unmodified lines
723 723
724static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {724static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
725 const char *p = strfrmt;725 const char *p = strfrmt;
726 while (strchr(FLAGS, *p)) p++; /* skip flags */726 while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
727 if ((size_t)(p - strfrmt) >= sizeof(FLAGS))727 if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
728 luaL_error(L, "invalid format (repeated flags)");728 luaL_error(L, "invalid format (repeated flags)");
729 if (isdigit(uchar(*p))) p++; /* skip width */729 if (isdigit(uchar(*p))) p++; /* skip width */
src/lua.h+4−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua - An Extensible Extension Language3** Lua - An Extensible Extension Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file5** See Copyright Notice at the end of this file
@@ -17,9 +17,9 @@ · 11 unmodified lines
17 17
18 18
19#define LUA_VERSION "Lua 5.1"19#define LUA_VERSION "Lua 5.1"
20#define LUA_RELEASE "Lua 5.1.1"20#define LUA_RELEASE "Lua 5.1.2"
21#define LUA_VERSION_NUM 50121#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"
23#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"23#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
24 24
25 25
@@ -359,7 +359,7 @@ struct lua_Debug { · 333 unmodified lines
359 359
360 360
361/******************************************************************************361/******************************************************************************
362* Copyright (C) 1994-2006 Lua.org, PUC-Rio. All rights reserved.362* Copyright (C) 1994-2007 Lua.org, PUC-Rio. All rights reserved.
363*363*
364* Permission is hereby granted, free of charge, to any person obtaining364* Permission is hereby granted, free of charge, to any person obtaining
365* a copy of this software and associated documentation files (the365* a copy of this software and associated documentation files (the
src/print.c+2−1
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** print bytecodes3** print bytecodes
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -32,6 +32,7 @@ static void PrintString(const TString* ts) · 26 unmodified lines
32 switch (c)32 switch (c)
33 {33 {
34 case '"': printf("\\\""); break;34 case '"': printf("\\\""); break;
35 case '\\': printf("\\\\"); break;
35 case '\a': printf("\\a"); break;36 case '\a': printf("\\a"); break;
36 case '\b': printf("\\b"); break;37 case '\b': printf("\\b"); break;
37 case '\f': printf("\\f"); break;38 case '\f': printf("\\f"); break;