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