| 607 | |
| 608 | |
| 609 | static void funcargs (LexState *ls, expdesc *f) { |
| 610 | FuncState *fs = ls->fs; |
| 611 | expdesc args; |
| 612 | int base, nparams; |
| 613 | int line = ls->linenumber; |
| 614 | switch (ls->t.token) { |
| 615 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ |
| 616 | if (line != ls->lastline) |
| 617 | luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); |
| 618 | luaX_next(ls); |
| 619 | if (ls->t.token == ')') /* arg list is empty? */ |
| 620 | args.k = VVOID; |
| 621 | else { |
| 622 | explist1(ls, &args); |
| 623 | luaK_setmultret(fs, &args); |
| 624 | } |
| 625 | check_match(ls, ')', '(', line); |
| 626 | break; |
| 627 | } |
| 628 | case '{': { /* funcargs -> constructor */ |
| 629 | constructor(ls, &args); |
| 630 | break; |
| 631 | } |
| 632 | case TK_STRING: { /* funcargs -> STRING */ |
| 633 | codestring(ls, &args, ls->t.seminfo.ts); |
| 634 | luaX_next(ls); /* must use `seminfo' before `next' */ |
| 635 | break; |
| 636 | } |
| 637 | default: { |
| 638 | luaX_syntaxerror(ls, "function arguments expected"); |
| 639 | return; |
| 640 | } |
| 641 | } |
| 642 | lua_assert(f->k == VNONRELOC); |
| 643 | base = f->u.s.info; /* base register for call */ |
| 644 | if (hasmultret(args.k)) |
| 645 | nparams = LUA_MULTRET; /* open call */ |
| 646 | else { |
| 647 | if (args.k != VVOID) |
| 648 | luaK_exp2nextreg(fs, &args); /* close last argument */ |
| 649 | nparams = fs->freereg - (base+1); |
| 650 | } |
| 651 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); |
| 652 | luaK_fixline(fs, line); |
| 653 | fs->freereg = base+1; /* call remove function and arguments and leaves |
| 654 | (unless changed) one result */ |
| 655 | } |
| 656 | |
| 657 | |
| 658 |
no test coverage detected