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