Skip to content

Commit 803630c

Browse files
committed
update lua54
1 parent 4148865 commit 803630c

File tree

2 files changed

+142
-81
lines changed

2 files changed

+142
-81
lines changed

doc/en-us/54/manual.html

Lines changed: 141 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,9 @@ <h2>3.1 &ndash; <a name="3.1">Lexical Conventions</a></h2>
13711371
which start with <code>0x</code> or <code>0X</code>.
13721372
Hexadecimal constants also accept an optional fractional part
13731373
plus an optional binary exponent,
1374-
marked by a letter '<code>p</code>' or '<code>P</code>'.
1374+
marked by a letter '<code>p</code>' or '<code>P</code>' and written in decimal.
1375+
(For instance, <code>0x1.fp10</code> denotes 1984,
1376+
which is <em>0x1f / 16</em> multiplied by <em>2<sup>10</sup></em>.)
13751377

13761378

13771379
<p>
@@ -1613,21 +1615,13 @@ <h3>3.3.3 &ndash; <a name="3.3.3">Assignment</a></h3>
16131615
<p>
16141616
Before the assignment,
16151617
the list of values is <em>adjusted</em> to the length of
1616-
the list of variables.
1617-
If there are more values than needed,
1618-
the excess values are thrown away.
1619-
If there are fewer values than needed,
1620-
the list is extended with <b>nil</b>'s.
1621-
If the list of expressions ends with a function call,
1622-
then all values returned by that call enter the list of values,
1623-
before the adjustment
1624-
(except when the call is enclosed in parentheses; see <a href="#3.4">&sect;3.4</a>).
1618+
the list of variables (see <a href="#3.4.12">&sect;3.4.12</a>).
16251619

16261620

16271621
<p>
16281622
If a variable is both assigned and read
16291623
inside a multiple assignment,
1630-
Lua ensures all reads get the value of the variable
1624+
Lua ensures that all reads get the value of the variable
16311625
before the assignment.
16321626
Thus the code
16331627

@@ -2051,7 +2045,7 @@ <h2>3.4 &ndash; <a name="3.4">Expressions</a></h2>
20512045
table constructors are explained in <a href="#3.4.9">&sect;3.4.9</a>.
20522046
Vararg expressions,
20532047
denoted by three dots ('<code>...</code>'), can only be used when
2054-
directly inside a vararg function;
2048+
directly inside a variadic function;
20552049
they are explained in <a href="#3.4.11">&sect;3.4.11</a>.
20562050

20572051

@@ -2066,52 +2060,6 @@ <h2>3.4 &ndash; <a name="3.4">Expressions</a></h2>
20662060
and the unary <em>length operator</em> (see <a href="#3.4.7">&sect;3.4.7</a>).
20672061

20682062

2069-
<p>
2070-
Both function calls and vararg expressions can result in multiple values.
2071-
If a function call is used as a statement (see <a href="#3.3.6">&sect;3.3.6</a>),
2072-
then its return list is adjusted to zero elements,
2073-
thus discarding all returned values.
2074-
If an expression is used as the last (or the only) element
2075-
of a list of expressions,
2076-
then no adjustment is made
2077-
(unless the expression is enclosed in parentheses).
2078-
In all other contexts,
2079-
Lua adjusts the result list to one element,
2080-
either discarding all values except the first one
2081-
or adding a single <b>nil</b> if there are no values.
2082-
2083-
2084-
<p>
2085-
Here are some examples:
2086-
2087-
<pre>
2088-
f() -- adjusted to 0 results
2089-
g(f(), x) -- f() is adjusted to 1 result
2090-
g(x, f()) -- g gets x plus all results from f()
2091-
a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil)
2092-
a,b = ... -- a gets the first vararg argument, b gets
2093-
-- the second (both a and b can get nil if there
2094-
-- is no corresponding vararg argument)
2095-
2096-
a,b,c = x, f() -- f() is adjusted to 2 results
2097-
a,b,c = f() -- f() is adjusted to 3 results
2098-
return f() -- returns all results from f()
2099-
return ... -- returns all received vararg arguments
2100-
return x,y,f() -- returns x, y, and all results from f()
2101-
{f()} -- creates a list with all results from f()
2102-
{...} -- creates a list with all vararg arguments
2103-
{f(), nil} -- f() is adjusted to 1 result
2104-
</pre>
2105-
2106-
<p>
2107-
Any expression enclosed in parentheses always results in only one value.
2108-
Thus,
2109-
<code>(f(x,y,z))</code> is always a single value,
2110-
even if <code>f</code> returns several values.
2111-
(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>
2112-
or <b>nil</b> if <code>f</code> does not return any values.)
2113-
2114-
21152063

21162064

21172065

@@ -2244,8 +2192,9 @@ <h3>3.4.3 &ndash; <a name="3.4.3">Coercions and Conversions</a></h3><p>
22442192

22452193

22462194
<p>
2247-
Nonetheless, it is always a good practice not to rely on these
2248-
implicit coercions, as they are not always applied;
2195+
It is always a good practice not to rely on the
2196+
implicit coercions from strings to numbers,
2197+
as they are not always applied;
22492198
in particular, <code>"1"==1</code> is false and <code>"1"&lt;1</code> raises an error
22502199
(see <a href="#3.4.4">&sect;3.4.4</a>).
22512200
These coercions exist mainly for compatibility and may be removed
@@ -2550,9 +2499,9 @@ <h3>3.4.9 &ndash; <a name="3.4.9">Table Constructors</a></h3><p>
25502499

25512500
<p>
25522501
If the last field in the list has the form <code>exp</code>
2553-
and the expression is a function call or a vararg expression,
2502+
and the expression is a multires expression,
25542503
then all values returned by this expression enter the list consecutively
2555-
(see <a href="#3.4.10">&sect;3.4.10</a>).
2504+
(see <a href="#3.4.12">&sect;3.4.12</a>).
25562505

25572506

25582507
<p>
@@ -2616,7 +2565,7 @@ <h3>3.4.10 &ndash; <a name="3.4.10">Function Calls</a></h3><p>
26162565
scope of a to-be-closed variable is called a <em>tail call</em>.
26172566
Lua implements <em>proper tail calls</em>
26182567
(or <em>proper tail recursion</em>):
2619-
in a tail call,
2568+
In a tail call,
26202569
the called function reuses the stack entry of the calling function.
26212570
Therefore, there is no limit on the number of nested tail calls that
26222571
a program can execute.
@@ -2719,22 +2668,16 @@ <h3>3.4.11 &ndash; <a name="3.4.11">Function Definitions</a></h3>
27192668
</pre><p>
27202669
When a Lua function is called,
27212670
it adjusts its list of arguments to
2722-
the length of its list of parameters,
2723-
unless the function is a <em>vararg function</em>,
2671+
the length of its list of parameters (see <a href="#3.4.12">&sect;3.4.12</a>),
2672+
unless the function is a <em>variadic function</em>,
27242673
which is indicated by three dots ('<code>...</code>')
27252674
at the end of its parameter list.
2726-
A vararg function does not adjust its argument list;
2675+
A variadic function does not adjust its argument list;
27272676
instead, it collects all extra arguments and supplies them
27282677
to the function through a <em>vararg expression</em>,
27292678
which is also written as three dots.
27302679
The value of this expression is a list of all actual extra arguments,
2731-
similar to a function with multiple results.
2732-
If a vararg expression is used inside another expression
2733-
or in the middle of a list of expressions,
2734-
then its return list is adjusted to one element.
2735-
If the expression is used as the last element of a list of expressions,
2736-
then no adjustment is made
2737-
(unless that last expression is enclosed in parentheses).
2680+
similar to a function with multiple results (see <a href="#3.4.12">&sect;3.4.12</a>).
27382681

27392682

27402683
<p>
@@ -2795,6 +2738,122 @@ <h3>3.4.11 &ndash; <a name="3.4.11">Function Definitions</a></h3>
27952738

27962739

27972740

2741+
<h3>3.4.12 &ndash; <a name="3.4.12">Lists of expressions, multiple results,
2742+
and adjustment</a></h3>
2743+
2744+
<p>
2745+
Both function calls and vararg expressions can result in multiple values.
2746+
These expressions are called <em>multires expressions</em>.
2747+
2748+
2749+
<p>
2750+
When a multires expression is used as the last element
2751+
of a list of expressions,
2752+
all results from the expression are added to the
2753+
list of values produced by the list of expressions.
2754+
Note that a single expression
2755+
in a place that expects a list of expressions
2756+
is the last expression in that (singleton) list.
2757+
2758+
2759+
<p>
2760+
These are the places where Lua expects a list of expressions:
2761+
2762+
<ul>
2763+
2764+
<li>A <b>return</b> statement,
2765+
for instance <code>return e1, e2, e3</code> (see <a href="#3.3.4">&sect;3.3.4</a>).</li>
2766+
2767+
<li>A table constructor,
2768+
for instance <code>{e1, e2, e3}</code> (see <a href="#3.4.9">&sect;3.4.9</a>).</li>
2769+
2770+
<li>The arguments of a function call,
2771+
for instance <code>foo(e1, e2, e3)</code> (see <a href="#3.4.10">&sect;3.4.10</a>).</li>
2772+
2773+
<li>A multiple assignment,
2774+
for instance <code>a , b, c = e1, e2, e3</code> (see <a href="#3.3.3">&sect;3.3.3</a>).</li>
2775+
2776+
<li>A local declaration,
2777+
for instance <code>local a , b, c = e1, e2, e3</code> (see <a href="#3.3.7">&sect;3.3.7</a>).</li>
2778+
2779+
<li>The initial values in a generic <b>for</b> loop,
2780+
for instance <code>for k in e1, e2, e3 do ... end</code> (see <a href="#3.3.5">&sect;3.3.5</a>).</li>
2781+
2782+
</ul><p>
2783+
In the last four cases,
2784+
the list of values from the list of expressions
2785+
must be <em>adjusted</em> to a specific length:
2786+
the number of parameters in a call to a non-variadic function
2787+
(see <a href="#3.4.11">&sect;3.4.11</a>),
2788+
the number of variables in a multiple assignment or
2789+
a local declaration,
2790+
and exactly four values for a generic <b>for</b> loop.
2791+
The <em>adjustment</em> follows these rules:
2792+
If there are more values than needed,
2793+
the extra values are thrown away;
2794+
if there are fewer values than needed,
2795+
the list is extended with <b>nil</b>'s.
2796+
When the list of expressions ends with a multires expression,
2797+
all results from that expression enter the list of values
2798+
before the adjustment.
2799+
2800+
2801+
<p>
2802+
When a multires expression is used
2803+
in a list of expressions without being the last element,
2804+
or in a place where the syntax expects a single expression,
2805+
Lua adjusts the result list of that expression to one element.
2806+
As a particular case,
2807+
the syntax expects a single expression inside a parenthesized expression;
2808+
therefore, adding parentheses around a multires expression
2809+
forces it to produce exactly one result.
2810+
2811+
2812+
<p>
2813+
We seldom need to use a vararg expression in a place
2814+
where the syntax expects a single expression.
2815+
(Usually it is simpler to add a regular parameter before
2816+
the variadic part and use that parameter.)
2817+
When there is such a need,
2818+
we recommend assigning the vararg expression
2819+
to a single variable and using that variable
2820+
in its place.
2821+
2822+
2823+
<p>
2824+
Here are some examples of uses of mutlres expressions.
2825+
In all cases, when the construction needs
2826+
"the n-th result" and there is no such result,
2827+
it uses a <b>nil</b>.
2828+
2829+
<pre>
2830+
print(x, f()) -- prints x and all results from f().
2831+
print(x, (f())) -- prints x and the first result from f().
2832+
print(f(), x) -- prints the first result from f() and x.
2833+
print(1 + f()) -- prints 1 added to the first result from f().
2834+
local x = ... -- x gets the first vararg argument.
2835+
x,y = ... -- x gets the first vararg argument,
2836+
-- y gets the second vararg argument.
2837+
x,y,z = w, f() -- x gets w, y gets the first result from f(),
2838+
-- z gets the second result from f().
2839+
x,y,z = f() -- x gets the first result from f(),
2840+
-- y gets the second result from f(),
2841+
-- z gets the third result from f().
2842+
x,y,z = f(), g() -- x gets the first result from f(),
2843+
-- y gets the first result from g(),
2844+
-- z gets the second result from g().
2845+
x,y,z = (f()) -- x gets the first result from f(), y and z get nil.
2846+
return f() -- returns all results from f().
2847+
return x, ... -- returns x and all received vararg arguments.
2848+
return x,y,f() -- returns x, y, and all results from f().
2849+
{f()} -- creates a list with all results from f().
2850+
{...} -- creates a list with all vararg arguments.
2851+
{f(), 5} -- creates a list with the first result from f() and 5.
2852+
</pre>
2853+
2854+
2855+
2856+
27982857

27992858

28002859
<h2>3.5 &ndash; <a name="3.5">Visibility Rules</a></h2>
@@ -6027,7 +6086,7 @@ <h2>4.7 &ndash; <a name="4.7">The Debug Interface</a></h2>
60276086
</li>
60286087

60296088
<li><b><code>isvararg</code>: </b>
6030-
true if the function is a vararg function
6089+
true if the function is a variadic function
60316090
(always true for C&nbsp;functions).
60326091
</li>
60336092

@@ -7679,9 +7738,7 @@ <h2>5.1 &ndash; <a name="5.1">Functions and Types</a></h2>
76797738

76807739
<hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
76817740
<span class="apii">[-0, +0, <em>v</em>]</span>
7682-
<pre>const char *luaL_typeerror (lua_State *L,
7683-
int arg,
7684-
const char *tname);</pre>
7741+
<pre>int luaL_typeerror (lua_State *L, int arg, const char *tname);</pre>
76857742

76867743
<p>
76877744
Raises a type error for the argument <code>arg</code>
@@ -8702,6 +8759,8 @@ <h2>6.3 &ndash; <a name="6.3">Modules</a></h2>
87028759
This variable is only a reference to the real table;
87038760
assignments to this variable do not change the
87048761
table used by <a href="#pdf-require"><code>require</code></a>.
8762+
The real table is stored in the C registry (see <a href="#4.3">&sect;4.3</a>),
8763+
indexed by the key <a name="pdf-LUA_LOADED_TABLE"><code>LUA_LOADED_TABLE</code></a>, a string.
87058764

87068765

87078766

@@ -8793,6 +8852,8 @@ <h2>6.3 &ndash; <a name="6.3">Modules</a></h2>
87938852
This variable is only a reference to the real table;
87948853
assignments to this variable do not change the
87958854
table used by <a href="#pdf-require"><code>require</code></a>.
8855+
The real table is stored in the C registry (see <a href="#4.3">&sect;4.3</a>),
8856+
indexed by the key <a name="pdf-LUA_PRELOAD_TABLE"><code>LUA_PRELOAD_TABLE</code></a>, a string.
87968857

87978858

87988859

@@ -10085,9 +10146,9 @@ <h2>6.7 &ndash; <a name="6.7">Mathematical Functions</a></h2>
1008510146

1008610147

1008710148
<p>
10088-
10149+
1008910150
Returns the arc tangent of <code>y/x</code> (in radians),
10090-
but uses the signs of both arguments to find the
10151+
using the signs of both arguments to find the
1009110152
quadrant of the result.
1009210153
It also handles correctly the case of <code>x</code> being zero.
1009310154

@@ -11576,7 +11637,7 @@ <h1>7 &ndash; <a name="7">Lua Standalone</a></h1>
1157611637
the script is called with arguments
1157711638
<code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.
1157811639
Like all chunks in Lua,
11579-
the script is compiled as a vararg function.
11640+
the script is compiled as a variadic function.
1158011641

1158111642

1158211643
<p>

0 commit comments

Comments
 (0)