aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-08 17:21:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-08 17:21:02 -0300
commit71bc69c2afaf49ab5f54f3443af9ae70dd1fed06 (patch)
treec10d56af3b96105748fa4afa0dbcb489341f039b
parentcd56f222b735a6b2c5392c74904b6c744af2e549 (diff)
downloadlua-71bc69c2afaf49ab5f54f3443af9ae70dd1fed06.tar.gz
lua-71bc69c2afaf49ab5f54f3443af9ae70dd1fed06.tar.bz2
lua-71bc69c2afaf49ab5f54f3443af9ae70dd1fed06.zip
Note in the manual about using '...' as an expression
-rw-r--r--manual/manual.of21
1 files changed, 16 insertions, 5 deletions
diff --git a/manual/manual.of b/manual/manual.of
index ca7f9933..ade47b20 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -1144,7 +1144,9 @@ Lua also accepts @x{hexadecimal constants},
1144which start with @T{0x} or @T{0X}. 1144which start with @T{0x} or @T{0X}.
1145Hexadecimal constants also accept an optional fractional part 1145Hexadecimal constants also accept an optional fractional part
1146plus an optional binary exponent, 1146plus an optional binary exponent,
1147marked by a letter @Char{p} or @Char{P}. 1147marked by a letter @Char{p} or @Char{P} and written in decimal.
1148(For instance, @T{0x1.fp10} denotes 1984,
1149which is @M{0x1f / 16} multiplied by @M{2@sp{10}}.)
1148 1150
1149A numeric constant with a radix point or an exponent 1151A numeric constant with a radix point or an exponent
1150denotes a float; 1152denotes a float;
@@ -2291,7 +2293,7 @@ the number of parameters in a call to a non-variadic function
2291@see{func-def}, 2293@see{func-def},
2292the number of variables in a multiple assignment or 2294the number of variables in a multiple assignment or
2293a local declaration, 2295a local declaration,
2294and exactly four for a generic @rw{for} loop. 2296and exactly four values for a generic @rw{for} loop.
2295The @def{adjustment} follows these rules: 2297The @def{adjustment} follows these rules:
2296If there are more values than needed, 2298If there are more values than needed,
2297the extra values are thrown away; 2299the extra values are thrown away;
@@ -2310,7 +2312,16 @@ the syntax expects a single expression inside a parenthesized expression;
2310therefore, adding parentheses around a multires expression 2312therefore, adding parentheses around a multires expression
2311forces it to produce exactly one result. 2313forces it to produce exactly one result.
2312 2314
2313Here are some examples. 2315We seldom need to use a vararg expression in a place
2316where the syntax expects a single expression.
2317(Usually it is simpler to add a regular parameter before
2318the variadic part and use that parameter.)
2319When there is such a need,
2320we recommend assigning the vararg expression
2321to a single variable and using that variable
2322in its place.
2323
2324Here are some examples of uses of mutlres expressions.
2314In all cases, when the construction needs 2325In all cases, when the construction needs
2315@Q{the n-th result} and there is no such result, 2326@Q{the n-th result} and there is no such result,
2316it uses a @nil. 2327it uses a @nil.
@@ -2319,6 +2330,7 @@ print(x, f()) -- prints x and all results from f().
2319print(x, (f())) -- prints x and the first result from f(). 2330print(x, (f())) -- prints x and the first result from f().
2320print(f(), x) -- prints the first result from f() and x. 2331print(f(), x) -- prints the first result from f() and x.
2321print(1 + f()) -- prints 1 added to the first result from f(). 2332print(1 + f()) -- prints 1 added to the first result from f().
2333local x = ... -- x gets the first vararg argument.
2322x,y = ... -- x gets the first vararg argument, 2334x,y = ... -- x gets the first vararg argument,
2323 -- y gets the second vararg argument. 2335 -- y gets the second vararg argument.
2324x,y,z = w, f() -- x gets w, y gets the first result from f(), 2336x,y,z = w, f() -- x gets w, y gets the first result from f(),
@@ -2331,8 +2343,7 @@ x,y,z = f(), g() -- x gets the first result from f(),
2331 -- z gets the second result from g(). 2343 -- z gets the second result from g().
2332x,y,z = (f()) -- x gets the first result from f(), y and z get nil. 2344x,y,z = (f()) -- x gets the first result from f(), y and z get nil.
2333return f() -- returns all results from f(). 2345return f() -- returns all results from f().
2334return ... -- returns all received vararg arguments. 2346return x, ... -- returns x and all received vararg arguments.
2335return (...) -- returns the first received vararg argument.
2336return x,y,f() -- returns x, y, and all results from f(). 2347return x,y,f() -- returns x, y, and all results from f().
2337{f()} -- creates a list with all results from f(). 2348{f()} -- creates a list with all results from f().
2338{...} -- creates a list with all vararg arguments. 2349{...} -- creates a list with all vararg arguments.