@@ -1371,7 +1371,9 @@ <h2>3.1 – <a name="3.1">Lexical Conventions</a></h2>
1371
1371
which start with < code > 0x</ code > or < code > 0X</ code > .
1372
1372
Hexadecimal constants also accept an optional fractional part
1373
1373
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 > .)
1375
1377
1376
1378
1377
1379
< p >
@@ -1613,21 +1615,13 @@ <h3>3.3.3 – <a name="3.3.3">Assignment</a></h3>
1613
1615
< p >
1614
1616
Before the assignment,
1615
1617
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 "> §3.4</ a > ).
1618
+ the list of variables (see < a href ="#3.4.12 "> §3.4.12</ a > ).
1625
1619
1626
1620
1627
1621
< p >
1628
1622
If a variable is both assigned and read
1629
1623
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
1631
1625
before the assignment.
1632
1626
Thus the code
1633
1627
@@ -2051,7 +2045,7 @@ <h2>3.4 – <a name="3.4">Expressions</a></h2>
2051
2045
table constructors are explained in < a href ="#3.4.9 "> §3.4.9</ a > .
2052
2046
Vararg expressions,
2053
2047
denoted by three dots ('< code > ...</ code > '), can only be used when
2054
- directly inside a vararg function;
2048
+ directly inside a variadic function;
2055
2049
they are explained in < a href ="#3.4.11 "> §3.4.11</ a > .
2056
2050
2057
2051
@@ -2066,52 +2060,6 @@ <h2>3.4 – <a name="3.4">Expressions</a></h2>
2066
2060
and the unary < em > length operator</ em > (see < a href ="#3.4.7 "> §3.4.7</ a > ).
2067
2061
2068
2062
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 "> §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
-
2115
2063
2116
2064
2117
2065
@@ -2244,8 +2192,9 @@ <h3>3.4.3 – <a name="3.4.3">Coercions and Conversions</a></h3><p>
2244
2192
2245
2193
2246
2194
< 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;
2249
2198
in particular, < code > "1"==1</ code > is false and < code > "1"<1</ code > raises an error
2250
2199
(see < a href ="#3.4.4 "> §3.4.4</ a > ).
2251
2200
These coercions exist mainly for compatibility and may be removed
@@ -2550,9 +2499,9 @@ <h3>3.4.9 – <a name="3.4.9">Table Constructors</a></h3><p>
2550
2499
2551
2500
< p >
2552
2501
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,
2554
2503
then all values returned by this expression enter the list consecutively
2555
- (see < a href ="#3.4.10 "> §3.4.10 </ a > ).
2504
+ (see < a href ="#3.4.12 "> §3.4.12 </ a > ).
2556
2505
2557
2506
2558
2507
< p >
@@ -2616,7 +2565,7 @@ <h3>3.4.10 – <a name="3.4.10">Function Calls</a></h3><p>
2616
2565
scope of a to-be-closed variable is called a < em > tail call</ em > .
2617
2566
Lua implements < em > proper tail calls</ em >
2618
2567
(or < em > proper tail recursion</ em > ):
2619
- in a tail call,
2568
+ In a tail call,
2620
2569
the called function reuses the stack entry of the calling function.
2621
2570
Therefore, there is no limit on the number of nested tail calls that
2622
2571
a program can execute.
@@ -2719,22 +2668,16 @@ <h3>3.4.11 – <a name="3.4.11">Function Definitions</a></h3>
2719
2668
</ pre > < p >
2720
2669
When a Lua function is called,
2721
2670
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 " > §3.4.12 </ a > ) ,
2672
+ unless the function is a < em > variadic function</ em > ,
2724
2673
which is indicated by three dots ('< code > ...</ code > ')
2725
2674
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;
2727
2676
instead, it collects all extra arguments and supplies them
2728
2677
to the function through a < em > vararg expression</ em > ,
2729
2678
which is also written as three dots.
2730
2679
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 "> §3.4.12</ a > ).
2738
2681
2739
2682
2740
2683
< p >
@@ -2795,6 +2738,122 @@ <h3>3.4.11 – <a name="3.4.11">Function Definitions</a></h3>
2795
2738
2796
2739
2797
2740
2741
+ < h3 > 3.4.12 – < 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 "> §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 "> §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 "> §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 "> §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 "> §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 "> §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 "> §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
+
2798
2857
2799
2858
2800
2859
< h2 > 3.5 – < a name ="3.5 "> Visibility Rules</ a > </ h2 >
@@ -6027,7 +6086,7 @@ <h2>4.7 – <a name="4.7">The Debug Interface</a></h2>
6027
6086
</ li >
6028
6087
6029
6088
< li > < b > < code > isvararg</ code > : </ b >
6030
- true if the function is a vararg function
6089
+ true if the function is a variadic function
6031
6090
(always true for C functions).
6032
6091
</ li >
6033
6092
@@ -7679,9 +7738,7 @@ <h2>5.1 – <a name="5.1">Functions and Types</a></h2>
7679
7738
7680
7739
< hr > < h3 > < a name ="luaL_typeerror "> < code > luaL_typeerror</ code > </ a > </ h3 > < p >
7681
7740
< 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 >
7685
7742
7686
7743
< p >
7687
7744
Raises a type error for the argument < code > arg</ code >
@@ -8702,6 +8759,8 @@ <h2>6.3 – <a name="6.3">Modules</a></h2>
8702
8759
This variable is only a reference to the real table;
8703
8760
assignments to this variable do not change the
8704
8761
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 "> §4.3</ a > ),
8763
+ indexed by the key < a name ="pdf-LUA_LOADED_TABLE "> < code > LUA_LOADED_TABLE</ code > </ a > , a string.
8705
8764
8706
8765
8707
8766
@@ -8793,6 +8852,8 @@ <h2>6.3 – <a name="6.3">Modules</a></h2>
8793
8852
This variable is only a reference to the real table;
8794
8853
assignments to this variable do not change the
8795
8854
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 "> §4.3</ a > ),
8856
+ indexed by the key < a name ="pdf-LUA_PRELOAD_TABLE "> < code > LUA_PRELOAD_TABLE</ code > </ a > , a string.
8796
8857
8797
8858
8798
8859
@@ -10085,9 +10146,9 @@ <h2>6.7 – <a name="6.7">Mathematical Functions</a></h2>
10085
10146
10086
10147
10087
10148
< p >
10088
-
10149
+
10089
10150
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
10091
10152
quadrant of the result.
10092
10153
It also handles correctly the case of < code > x</ code > being zero.
10093
10154
@@ -11576,7 +11637,7 @@ <h1>7 – <a name="7">Lua Standalone</a></h1>
11576
11637
the script is called with arguments
11577
11638
< code > arg[1]</ code > , ···, < code > arg[#arg]</ code > .
11578
11639
Like all chunks in Lua,
11579
- the script is compiled as a vararg function.
11640
+ the script is compiled as a variadic function.
11580
11641
11581
11642
11582
11643
< p >
0 commit comments