| 1004 | |
| 1005 | |
| 1006 | static void funcargs (LexState *ls, expdesc *f, int line) { |
| 1007 | FuncState *fs = ls->fs; |
| 1008 | expdesc args; |
| 1009 | int base, nparams; |
| 1010 | switch (ls->t.token) { |
| 1011 | case '(': { /* funcargs -> '(' [ explist ] ')' */ |
| 1012 | luaX_next(ls); |
| 1013 | if (ls->t.token == ')') /* arg list is empty? */ |
| 1014 | args.k = VVOID; |
| 1015 | else { |
| 1016 | explist(ls, &args); |
| 1017 | if (hasmultret(args.k)) |
| 1018 | luaK_setmultret(fs, &args); |
| 1019 | } |
| 1020 | check_match(ls, ')', '(', line); |
| 1021 | break; |
| 1022 | } |
| 1023 | case '{': { /* funcargs -> constructor */ |
| 1024 | constructor(ls, &args); |
| 1025 | break; |
| 1026 | } |
| 1027 | case TK_STRING: { /* funcargs -> STRING */ |
| 1028 | codestring(&args, ls->t.seminfo.ts); |
| 1029 | luaX_next(ls); /* must use 'seminfo' before 'next' */ |
| 1030 | break; |
| 1031 | } |
| 1032 | default: { |
| 1033 | luaX_syntaxerror(ls, "function arguments expected"); |
| 1034 | } |
| 1035 | } |
| 1036 | lua_assert(f->k == VNONRELOC); |
| 1037 | base = f->u.info; /* base register for call */ |
| 1038 | if (hasmultret(args.k)) |
| 1039 | nparams = LUA_MULTRET; /* open call */ |
| 1040 | else { |
| 1041 | if (args.k != VVOID) |
| 1042 | luaK_exp2nextreg(fs, &args); /* close last argument */ |
| 1043 | nparams = fs->freereg - (base+1); |
| 1044 | } |
| 1045 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); |
| 1046 | luaK_fixline(fs, line); |
| 1047 | fs->freereg = base+1; /* call remove function and arguments and leaves |
| 1048 | (unless changed) one result */ |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 |
no test coverage detected