--- lua-5.3.1/src/lparser.c 2014年12月27日 21:31:42.000000000 +0100 +++ lua-5.3.1jh/src/lparser.c 2015年09月25日 14:45:58.000000000 +0100 @@ -640,22 +640,45 @@ static void recfield (LexState *ls, struct ConsControl *cc) { /* recfield -> (NAME | '['exp1']') = exp1 */ FuncState *fs = ls->fs; int reg = ls->fs->freereg; expdesc key, val; int rkkey; if (ls->t.token == TK_NAME) { checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); checkname(ls, &key); } +#if defined(JH_LUA_SETINIT) + else if (ls->t.token == '.') + { + luaX_next(ls); + checkname(ls, &key); + } +#endif else /* ls->t.token == '[' */ yindex(ls, &key); cc->nh++; +#if defined(JH_LUA_SETINIT) + if (ls->t.token == '=') + { + luaX_next(ls); + rkkey = luaK_exp2RK(fs, &key); + expr(ls, &val); + } + else + { + rkkey = luaK_exp2RK(fs, &key); + init_exp(&val, VTRUE, 0); + } +#else checknext(ls, '='); rkkey = luaK_exp2RK(fs, &key); expr(ls, &val); +#endif luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val)); fs->freereg = reg; /* free registers */ } static void closelistfield (FuncState *fs, struct ConsControl *cc) { @@ -700,12 +723,15 @@ if (luaX_lookahead(ls) != '=') /* expression? */ listfield(ls, cc); else recfield(ls, cc); break; } +#if defined(JH_LUA_SETINIT) + case '.': +#endif case '[': { recfield(ls, cc); break; } default: { listfield(ls, cc); --- lua-5.3.1/doc/manual.html 2015年06月10日 22:31:16.000000000 +0100 +++ lua-5.3.1jh/doc/manual.html 2015年09月25日 11:10:07.000000000 +0100 @@ -21,12 +21,20 @@ Copyright © 2015 Lua.org, PUC-Rio. Freely available under the terms of the Lua license. +
+[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 ::= ‘+’ | ‘-’ | ‘*’ | ‘/’ | ‘//’ | ‘^’ | ‘%’ |
‘&’ | ‘~’ | ‘|’ | ‘>>’ | ‘<<’ | ‘..’ |
‘<’ | ‘<=’ | ‘>’ | ‘>=’ | ‘==’ | ‘~=’ |