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