| 8183 | |
| 8184 | |
| 8185 | static void funcargs (LexState *ls, expdesc *f) { |
| 8186 | FuncState *fs = ls->fs; |
| 8187 | expdesc args; |
| 8188 | int base, nparams; |
| 8189 | int line = ls->linenumber; |
| 8190 | switch (ls->t.token) { |
| 8191 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ |
| 8192 | if (line != ls->lastline) |
| 8193 | luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); |
| 8194 | luaX_next(ls); |
| 8195 | if (ls->t.token == ')') /* arg list is empty? */ |
| 8196 | args.k = VVOID; |
| 8197 | else { |
| 8198 | explist1(ls, &args); |
| 8199 | luaK_setmultret(fs, &args); |
| 8200 | } |
| 8201 | check_match(ls, ')', '(', line); |
| 8202 | break; |
| 8203 | } |
| 8204 | case '{': { /* funcargs -> constructor */ |
| 8205 | constructor(ls, &args); |
| 8206 | break; |
| 8207 | } |
| 8208 | case TK_STRING: { /* funcargs -> STRING */ |
| 8209 | codestring(ls, &args, ls->t.seminfo.ts); |
| 8210 | luaX_next(ls); /* must use `seminfo' before `next' */ |
| 8211 | break; |
| 8212 | } |
| 8213 | default: { |
| 8214 | luaX_syntaxerror(ls, "function arguments expected"); |
| 8215 | return; |
| 8216 | } |
| 8217 | } |
| 8218 | lua_assert(f->k == VNONRELOC); |
| 8219 | base = f->u.s.info; /* base register for call */ |
| 8220 | if (hasmultret(args.k)) |
| 8221 | nparams = LUA_MULTRET; /* open call */ |
| 8222 | else { |
| 8223 | if (args.k != VVOID) |
| 8224 | luaK_exp2nextreg(fs, &args); /* close last argument */ |
| 8225 | nparams = fs->freereg - (base+1); |
| 8226 | } |
| 8227 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); |
| 8228 | luaK_fixline(fs, line); |
| 8229 | fs->freereg = base+1; /* call remove function and arguments and leaves |
| 8230 | (unless changed) one result */ |
| 8231 | } |
| 8232 | |
| 8233 | |
| 8234 |
no test coverage detected