aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-11-08 11:43:42 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-11-08 11:43:42 -0300
commite44f3a2ffc7ced5e75cca7657aaa60ef27da89aa (patch)
tree090174ab9a66fbec195e9dd539710ab19370ec2f /manual
parentf791bb69061c15f73395c5a95958ac18af5ef764 (diff)
downloadlua-e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa.tar.gz
lua-e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa.tar.bz2
lua-e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa.zip
Global initialization checks name conflict
Initialization "global a = 10" raises an error if global 'a' is already defined, that is, it has a non-nil value.
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of14
1 files changed, 11 insertions, 3 deletions
diff --git a/manual/manual.of b/manual/manual.of
index 0127df02..eaf0ce78 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -1660,9 +1660,15 @@ The declaration can include an initialization:
1660@producname{stat}@producbody{@Rw{global} 1660@producname{stat}@producbody{@Rw{global}
1661 attnamelist @bnfopt{@bnfter{=} explist}} 1661 attnamelist @bnfopt{@bnfter{=} explist}}
1662} 1662}
1663If present, an initial assignment has the same semantics 1663If there is no initialization,
1664local variables are initialized with @nil;
1665global variables are left unchanged.
1666Otherwise, the initialization gets the same adjustment
1664of a multiple assignment @see{assignment}. 1667of a multiple assignment @see{assignment}.
1665Otherwise, all local variables are initialized with @nil. 1668Moreover, for global variables,
1669the initialization will raise a runtime error
1670if the variable is already defined,
1671that is, it has a non-nil value.
1666 1672
1667The list of names may be prefixed by an attribute 1673The list of names may be prefixed by an attribute
1668(a name between angle brackets) 1674(a name between angle brackets)
@@ -2312,8 +2318,10 @@ global function f () @rep{body} end
2312} 2318}
2313translates to 2319translates to
2314@verbatim{ 2320@verbatim{
2315global f; f = function () @rep{body} end 2321global f; global f = function () @rep{body} end
2316} 2322}
2323The second @Rw{global} makes the assignment an initialization,
2324which will raise an error if that global is already defined.
2317 2325
2318The @emphx{colon} syntax 2326The @emphx{colon} syntax
2319is used to emulate @def{methods}, 2327is used to emulate @def{methods},