diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-10-11 13:49:13 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-10-11 13:49:13 -0300 |
commit | 87a9573b2eb3f1da8e438f92ade994160d930b09 (patch) | |
tree | a935872e61f23c81b430dd867c98329b8782a907 /manual | |
parent | deac067ed39a44c001599c0d15de09872496b2aa (diff) | |
download | lua-87a9573b2eb3f1da8e438f92ade994160d930b09.tar.gz lua-87a9573b2eb3f1da8e438f92ade994160d930b09.tar.bz2 lua-87a9573b2eb3f1da8e438f92ade994160d930b09.zip |
Documentation
Better explanation about the guaranties of multiple assignment in
the manual.
Diffstat (limited to '')
-rw-r--r-- | manual/manual.of | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/manual/manual.of b/manual/manual.of index ea9a0302..9e0b8835 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -1346,8 +1346,10 @@ then all values returned by that call enter the list of values, | |||
1346 | before the adjustment | 1346 | before the adjustment |
1347 | (except when the call is enclosed in parentheses; see @See{expressions}). | 1347 | (except when the call is enclosed in parentheses; see @See{expressions}). |
1348 | 1348 | ||
1349 | The assignment statement first evaluates all its expressions | 1349 | If a variable is both assigned and read |
1350 | and only then the assignments are performed. | 1350 | inside a multiple assignment, |
1351 | Lua ensures all reads get the value of the variable | ||
1352 | before the assignment. | ||
1351 | Thus the code | 1353 | Thus the code |
1352 | @verbatim{ | 1354 | @verbatim{ |
1353 | i = 3 | 1355 | i = 3 |
@@ -1367,6 +1369,12 @@ x, y, z = y, z, x | |||
1367 | } | 1369 | } |
1368 | cyclically permutes the values of @id{x}, @id{y}, and @id{z}. | 1370 | cyclically permutes the values of @id{x}, @id{y}, and @id{z}. |
1369 | 1371 | ||
1372 | Note that this guarantee covers only accesses | ||
1373 | syntactically inside the assignment statement. | ||
1374 | If a function or a metamethod called during the assignment | ||
1375 | changes the value of a variable, | ||
1376 | Lua gives no guarantees about the order of that access. | ||
1377 | |||
1370 | An assignment to a global name @T{x = val} | 1378 | An assignment to a global name @T{x = val} |
1371 | is equivalent to the assignment | 1379 | is equivalent to the assignment |
1372 | @T{_ENV.x = val} @see{globalenv}. | 1380 | @T{_ENV.x = val} @see{globalenv}. |