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