+[JH-LUA-SETINIT]: Set constructor powerpatch (see §3.4.9, +§9). +
+
Table constructors are expressions that create tables. Every time a constructor is evaluated, a new table is created. A constructor can be used to create an empty table or to create a table and initialize some of its fields. The general syntax for constructors is
tableconstructor ::= ‘{’ [fieldlist] ‘}’ fieldlist ::= field {fieldsep field} [fieldsep] - field ::= ‘[’ exp ‘]’ ‘=’ exp | Name ‘=’ exp | exp + field ::= ‘[’ exp ‘]’ ‘=’ exp | ‘.’ Name ‘=’ exp | ‘[’ exp ‘]’ | ‘.’ Name | + Name ‘=’ exp | exp fieldsep ::= ‘,’ | ‘;’
+[JH-LUA-SETINIT]: The two .Name
and the [exp]
field syntax options are added by the powerpatch.
+
+
Each field of the form [exp1] = exp2
adds to the new table an entry
-with key exp1
and value exp2
.
-A field of the form name = exp
is equivalent to
-["name"] = exp
.
-Finally, fields of the form exp
are equivalent to
-[i] = exp
, where i
are consecutive integers
-starting with 1.
-Fields in the other formats do not affect this counting.
-For example,
+with key exp1
and value exp2
. A field of the form
+name = exp
or .name = exp
is equivalent to
+["name"] = exp
. Fields of the form exp
are equivalent to
+[i] = exp
, where i
are consecutive integers starting
+with 1. Fields in the other formats do not affect this counting. For example,
a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
is equivalent to
@@ -2221,12 +2252,15 @@
t[3] = f(x) -- 3rd exp
t[30] = 23
t[4] = 45 -- 4th exp
a = t
end
+
+A field of the form [exp]
is equivalent to [exp] = true
+and a field of the form .name
is equivalent to ["name"] = true
.
The order of the assignments in a constructor is undefined. (This order would be relevant only when there are repeated keys.) @@ -10711,15 +10759,16 @@ {A} means 0 or more As, and [A] means an optional A. (For operator precedences, see §3.4.8; for a description of the terminals Name, Numeral, and LiteralString, see §3.1.) - +
-
+[JH-LUA-SETINIT]: The syntax of field
is extended by the powerpatch (see §3.4.9).
+
chunk ::= block block ::= {stat} [retstat] @@ -10770,13 +10819,14 @@ parlist ::= namelist [‘,’ ‘...’] | ‘...’ tableconstructor ::= ‘{’ [fieldlist] ‘}’ fieldlist ::= field {fieldsep field} [fieldsep] - field ::= ‘[’ exp ‘]’ ‘=’ exp | Name ‘=’ exp | exp + field ::= ‘[’ exp ‘]’ ‘=’ exp | ‘.’ Name ‘=’ exp | ‘[’ exp ‘]’ | ‘.’ Name | + Name ‘=’ exp | exp fieldsep ::= ‘,’ | ‘;’ binop ::= ‘+’ | ‘-’ | ‘*’ | ‘/’ | ‘//’ | ‘^’ | ‘%’ | ‘&’ | ‘~’ | ‘|’ | ‘>>’ | ‘<<’ | ‘..’ | ‘<’ | ‘<=’ | ‘>’ | ‘>=’ | ‘==’ | ‘~=’ |