From 942c10a5e33811a08a290ec15031c950a6d17c99 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 8 Jul 2025 13:33:57 -0300 Subject: Optional initialization for global declarations --- manual/manual.of | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'manual/manual.of') diff --git a/manual/manual.of b/manual/manual.of index bcc8173b..8f90f942 100644 --- a/manual/manual.of +++ b/manual/manual.of @@ -229,7 +229,7 @@ as the following example illustrates: @verbatim{ X = 1 -- Ok, global by default do - global Y -- voids implicit initial declaration + global Y -- voids the implicit initial declaration Y = 1 -- Ok, Y declared as global X = 1 -- ERROR, X not declared end @@ -269,7 +269,7 @@ print(x) --> 10 (the global one) Notice that, in a declaration like @T{local x = x}, the new @id{x} being declared is not in scope yet, -and so the @id{x} in the left-hand side refers to the outside variable. +and so the @id{x} in the right-hand side refers to the outside variable. Because of the @x{lexical scoping} rules, local variables can be freely accessed by functions @@ -1651,11 +1651,12 @@ Function calls are explained in @See{functioncall}. @sect3{localvar| @title{Variable Declarations} Local and global variables can be declared anywhere inside a block. -The declaration for locals can include an initialization: +The declaration can include an initialization: @Produc{ @producname{stat}@producbody{@Rw{local} attnamelist @bnfopt{@bnfter{=} explist}} -@producname{stat}@producbody{@Rw{global} attnamelist} +@producname{stat}@producbody{@Rw{global} + attnamelist @bnfopt{@bnfter{=} explist}} } If present, an initial assignment has the same semantics of a multiple assignment @see{assignment}. @@ -1712,7 +1713,8 @@ and a program that starts with any other global declaration (e.g., @T{global none}) can only refer to declared variables. Note that, for global variables, -the effect of any declaration is only syntactical: +the effect of any declaration is only syntactical +(except for the optional assignment): @verbatim{ global X , _G X = 1 -- ERROR @@ -3924,8 +3926,8 @@ This macro may evaluate its arguments more than once. } -@APIEntry{unsigned (lua_numbertocstring) (lua_State *L, int idx, - char *buff);| +@APIEntry{unsigned lua_numbertocstring (lua_State *L, int idx, + char *buff);| @apii{0,0,-} Converts the number at acceptable index @id{idx} to a string @@ -4050,7 +4052,7 @@ This function is equivalent to @Lid{lua_pushcclosure} with no upvalues. } -@APIEntry{const char *(lua_pushexternalstring) (lua_State *L, +@APIEntry{const char *lua_pushexternalstring (lua_State *L, const char *s, size_t len, lua_Alloc falloc, void *ud);| @apii{0,1,m} -- cgit v1.2.3-55-g6feb