summaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-17 11:11:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-17 11:11:44 -0300
commitd9f40e3f6fb61650240c47d548bee69b24b07859 (patch)
treeab01022b3e3bc6bdb800423c97095a9423e0a798 /manual
parent347d6961ac14213264c7176e3d125c9ba8475b01 (diff)
downloadlua-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.of28
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.
1491The declaration can include an initial assignment: 1491The 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}}
1495If present, an initial assignment has the same semantics 1497If present, an initial assignment has the same semantics
1496of a multiple assignment @see{assignment}. 1498of a multiple assignment @see{assignment}.
1497Otherwise, all variables are initialized with @nil. 1499Otherwise, all variables are initialized with @nil.
1500The second syntax declares a local with a given attribute,
1501which is the name between the angle brackets.
1502In this case, there must be an initialization.
1503There are two possible attributes:
1504@id{const}, which declares a @x{constant variable},
1505that is, a variable that cannot be assigned to
1506after its initialization;
1507and @id{toclose}, wich declares a to-be-closed variable @see{to-be-closed}.
1508
1498 1509
1499A chunk is also a block @see{chunks}, 1510A chunk is also a block @see{chunks},
1500and so local variables can be declared in a chunk outside any explicit block. 1511and 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
1508A local variable can be declared as a @def{to-be-closed} variable, 1519A local variable can be declared as a @def{to-be-closed} variable,
1509with the following syntax: 1520using 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}}
1514A to-be-closed variable behaves like a normal local variable, 1525A to-be-closed variable behaves like a constant local variable,
1515except that its value is @emph{closed} whenever the variable 1526except that its value is @emph{closed} whenever the variable
1516goes out of scope, including normal block termination, 1527goes out of scope, including normal block termination,
1517exiting its block by @Rw{break}/@Rw{goto}/@Rw{return}, 1528exiting 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
7606Returns the absolute value of @id{x}. (integer/float) 7617Returns 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.
8042This format always reads the longest input sequence that 8053This format always reads the longest input sequence that
8043is a valid prefix for a numeral; 8054is a valid prefix for a numeral;
8044if that prefix does not form a valid numeral 8055if 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-})
8057or it is too long (more than 200 characters),
8046it is discarded and the format returns @nil. 8058it 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}