** Fix an expression to return the number of results 'nresults'. ** 'e' must be a multi-ret expression (function call or vararg). */
| 756 | ** 'e' must be a multi-ret expression (function call or vararg). |
| 757 | */ |
| 758 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { |
| 759 | Instruction *pc = &getinstruction(fs, e); |
| 760 | luaY_checklimit(fs, nresults + 1, MAXARG_C, "multiple results"); |
| 761 | if (e->k == VCALL) /* expression is an open function call? */ |
| 762 | SETARG_C(*pc, nresults + 1); |
| 763 | else if (e->k == VSAFECALL) { |
| 764 | SETARG_C(*pc, nresults + 1); |
| 765 | if (nresults != LUA_MULTRET) { |
| 766 | lua_assert(GET_OPCODE(pc[2]) == OP_LOADNIL); |
| 767 | SETARG_B(pc[2], nresults - 1); |
| 768 | /* handle double-safecall as well (optinst?:optmethod?) */ |
| 769 | if (e->u.pc + 4 < fs->pc && GET_OPCODE(pc[3]) == OP_JMP && GET_OPCODE(pc[4]) == OP_LOADNIL) { |
| 770 | SETARG_B(pc[4], nresults - 1); |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | else { |
| 775 | lua_assert(e->k == VVARARG); |
| 776 | SETARG_C(*pc, nresults + 1); |
| 777 | SETARG_A(*pc, fs->freereg); |
| 778 | luaK_reserveregs(fs, 1); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | |
| 783 | /* |
no test coverage detected