diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-17 11:11:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-17 11:11:44 -0300 |
commit | d9f40e3f6fb61650240c47d548bee69b24b07859 (patch) | |
tree | ab01022b3e3bc6bdb800423c97095a9423e0a798 /manual | |
parent | 347d6961ac14213264c7176e3d125c9ba8475b01 (diff) | |
download | lua-d9f40e3f6fb61650240c47d548bee69b24b07859.tar.gz lua-d9f40e3f6fb61650240c47d548bee69b24b07859.tar.bz2 lua-d9f40e3f6fb61650240c47d548bee69b24b07859.zip |
First implementation for 'const' variables
A variable can be declared const, which means it cannot be assigned to,
with the syntax 'local <const> name = exp'.
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/manual/manual.of b/manual/manual.of index 54a07879..6cac8c6c 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -1488,13 +1488,24 @@ Function calls are explained in @See{functioncall}. | |||
1488 | 1488 | ||
1489 | @sect3{localvar| @title{Local Declarations} | 1489 | @sect3{localvar| @title{Local Declarations} |
1490 | @x{Local variables} can be declared anywhere inside a block. | 1490 | @x{Local variables} can be declared anywhere inside a block. |
1491 | The declaration can include an initial assignment: | 1491 | The declaration can include an initialization: |
1492 | @Produc{ | 1492 | @Produc{ |
1493 | @producname{stat}@producbody{@Rw{local} namelist @bnfopt{@bnfter{=} explist}} | 1493 | @producname{stat}@producbody{@Rw{local} namelist @bnfopt{@bnfter{=} explist}} |
1494 | } | 1494 | @producname{stat}@producbody{ |
1495 | @Rw{local} @bnfter{<} Name @bnfter{>} Name @bnfter{=} exp | ||
1496 | }} | ||
1495 | If present, an initial assignment has the same semantics | 1497 | If present, an initial assignment has the same semantics |
1496 | of a multiple assignment @see{assignment}. | 1498 | of a multiple assignment @see{assignment}. |
1497 | Otherwise, all variables are initialized with @nil. | 1499 | Otherwise, all variables are initialized with @nil. |
1500 | The second syntax declares a local with a given attribute, | ||
1501 | which is the name between the angle brackets. | ||
1502 | In this case, there must be an initialization. | ||
1503 | There are two possible attributes: | ||
1504 | @id{const}, which declares a @x{constant variable}, | ||
1505 | that is, a variable that cannot be assigned to | ||
1506 | after its initialization; | ||
1507 | and @id{toclose}, wich declares a to-be-closed variable @see{to-be-closed}. | ||
1508 | |||
1498 | 1509 | ||
1499 | A chunk is also a block @see{chunks}, | 1510 | A chunk is also a block @see{chunks}, |
1500 | and so local variables can be declared in a chunk outside any explicit block. | 1511 | and so local variables can be declared in a chunk outside any explicit block. |
@@ -1506,12 +1517,12 @@ The visibility rules for local variables are explained in @See{visibility}. | |||
1506 | @sect3{to-be-closed| @title{To-be-closed Variables} | 1517 | @sect3{to-be-closed| @title{To-be-closed Variables} |
1507 | 1518 | ||
1508 | A local variable can be declared as a @def{to-be-closed} variable, | 1519 | A local variable can be declared as a @def{to-be-closed} variable, |
1509 | with the following syntax: | 1520 | using the identifier @id{toclose} as its attribute: |
1510 | @Produc{ | 1521 | @Produc{ |
1511 | @producname{stat}@producbody{ | 1522 | @producname{stat}@producbody{ |
1512 | @Rw{local} @bnfter{<} @bnfter{toclose} @bnfter{>} Name @bnfter{=} exp | 1523 | @Rw{local} @bnfter{<} @id{toclose} @bnfter{>} Name @bnfter{=} exp |
1513 | }} | 1524 | }} |
1514 | A to-be-closed variable behaves like a normal local variable, | 1525 | A to-be-closed variable behaves like a constant local variable, |
1515 | except that its value is @emph{closed} whenever the variable | 1526 | except that its value is @emph{closed} whenever the variable |
1516 | goes out of scope, including normal block termination, | 1527 | goes out of scope, including normal block termination, |
1517 | exiting its block by @Rw{break}/@Rw{goto}/@Rw{return}, | 1528 | exiting its block by @Rw{break}/@Rw{goto}/@Rw{return}, |
@@ -7603,7 +7614,7 @@ or a float otherwise. | |||
7603 | 7614 | ||
7604 | @LibEntry{math.abs (x)| | 7615 | @LibEntry{math.abs (x)| |
7605 | 7616 | ||
7606 | Returns the absolute value of @id{x}. (integer/float) | 7617 | Returns the maximum value between @id{x} and @id{-x}. (integer/float) |
7607 | 7618 | ||
7608 | } | 7619 | } |
7609 | 7620 | ||
@@ -8042,7 +8053,8 @@ following the lexical conventions of Lua. | |||
8042 | This format always reads the longest input sequence that | 8053 | This format always reads the longest input sequence that |
8043 | is a valid prefix for a numeral; | 8054 | is a valid prefix for a numeral; |
8044 | if that prefix does not form a valid numeral | 8055 | if that prefix does not form a valid numeral |
8045 | (e.g., an empty string, @St{0x}, or @St{3.4e-}), | 8056 | (e.g., an empty string, @St{0x}, or @St{3.4e-}) |
8057 | or it is too long (more than 200 characters), | ||
8046 | it is discarded and the format returns @nil. | 8058 | it is discarded and the format returns @nil. |
8047 | } | 8059 | } |
8048 | 8060 | ||
@@ -8949,7 +8961,7 @@ and @bnfNter{LiteralString}, see @See{lexical}.) | |||
8949 | @OrNL @Rw{function} funcname funcbody | 8961 | @OrNL @Rw{function} funcname funcbody |
8950 | @OrNL @Rw{local} @Rw{function} @bnfNter{Name} funcbody | 8962 | @OrNL @Rw{local} @Rw{function} @bnfNter{Name} funcbody |
8951 | @OrNL @Rw{local} namelist @bnfopt{@bnfter{=} explist} | 8963 | @OrNL @Rw{local} namelist @bnfopt{@bnfter{=} explist} |
8952 | @OrNL @Rw{local} @bnfter{<} @bnfter{toclose} @bnfter{>} Name @bnfter{=} exp | 8964 | @OrNL @Rw{local} @bnfter{<} Name @bnfter{>} Name @bnfter{=} exp |
8953 | } | 8965 | } |
8954 | 8966 | ||
8955 | @producname{retstat}@producbody{@Rw{return} | 8967 | @producname{retstat}@producbody{@Rw{return} |