diff -burN lua-5.2.0/src/lparser.c lua-5.2.0-mod/src/lparser.c --- lua-5.2.0/src/lparser.c 2011年12月02日 08:23:56 -0500 +++ lua-5.2.0-mod/src/lparser.c 2012年01月06日 21:54:51 -0500 @@ -676,6 +676,26 @@ } +/* bn 01/2012: added class-like function/method constructors */ +static void body (LexState *ls, expdesc *e, int ismethod, int line); +static void funcfield (LexState *ls, struct ConsControl *cc) { + /* funcfield -> function NAME funcargs */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + int rkkey; + checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + luaX_next(ls); + checkname(ls, &key); + cc->nh++; + rkkey = luaK_exp2RK(fs, &key); + body(ls, &val, 1, ls->linenumber); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} +/* end changes */ + + static void closelistfield (FuncState *fs, struct ConsControl *cc) { if (cc->v.k == VVOID) return; /* there is no list item */ luaK_exp2nextreg(fs, &cc->v); @@ -721,6 +741,17 @@ recfield(ls, cc); break; } + + /* bn 01/2012: added class-like function/method constructors */ + case TK_FUNCTION: { /* funcfield */ + if (luaX_lookahead(ls) == '(') /* anonymous? */ + listfield(ls, cc); + else + funcfield(ls, cc); + break; + } + /* end changes */ + case '[': { recfield(ls, cc); break;

AltStyle によって変換されたページ (->オリジナル) /