lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


VirusCamp wrote:
I'm working on luadec, but got confused about OP_VARARG in lua-5.1.4.
I think the comment is wrong, that should be R(A), R(A+1), ...,
R(A+B-2) = vararg

lopcodes.h line 210
OP_VARARG/*	A B	R(A), R(A+1), ..., R(A+B-1) = vararg		*/


lvm.c line 751
      case OP_VARARG: {
        int b = GETARG_B(i) - 1;
..........
        for (j = 0; j < b; j++) {

Nothing wrong there. You can plug in some numbers in order to 'see' the indices and ranges better.

GETARG_B(i)'s zero value is taken by multiple return mode, since b is -1 when GETARG_B(i) == 0 and -1 is LUA_MULTRET in the test.

When GETARG_B(i) is 1, b = 0 and the loop iterates once only, for one value. So, A+B-1 = A+1-1 = A.

I think perhaps you have confused b with B in the comments. B is GETARG_B(i).

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia