| 1026 | |
| 1027 | |
| 1028 | static void constructor (LexState *ls, expdesc *t) { |
| 1029 | /* constructor -> '{' [ field { sep field } [sep] ] '}' |
| 1030 | sep -> ',' | ';' */ |
| 1031 | FuncState *fs = ls->fs; |
| 1032 | int line = ls->linenumber; |
| 1033 | int pc = luaK_codevABCk(fs, OP_NEWTABLE, 0, 0, 0, 0); |
| 1034 | ConsControl cc; |
| 1035 | luaK_code(fs, 0); /* space for extra arg. */ |
| 1036 | cc.na = cc.nh = cc.tostore = 0; |
| 1037 | cc.t = t; |
| 1038 | init_exp(t, VNONRELOC, fs->freereg); /* table will be at stack top */ |
| 1039 | luaK_reserveregs(fs, 1); |
| 1040 | init_exp(&cc.v, VVOID, 0); /* no value (yet) */ |
| 1041 | checknext(ls, '{' /*}*/); |
| 1042 | cc.maxtostore = maxtostore(fs); |
| 1043 | do { |
| 1044 | if (ls->t.token == /*{*/ '}') break; |
| 1045 | if (cc.v.k != VVOID) /* is there a previous list item? */ |
| 1046 | closelistfield(fs, &cc); /* close it */ |
| 1047 | field(ls, &cc); |
| 1048 | luaY_checklimit(fs, cc.tostore + cc.na + cc.nh, MAX_CNST, |
| 1049 | "items in a constructor"); |
| 1050 | } while (testnext(ls, ',') || testnext(ls, ';')); |
| 1051 | check_match(ls, /*{*/ '}', '{' /*}*/, line); |
| 1052 | lastlistfield(fs, &cc); |
| 1053 | luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh); |
| 1054 | } |
| 1055 | |
| 1056 | /* }====================================================================== */ |
| 1057 |
no test coverage detected