lua-users home
lua-l archive

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


I propose that the select code read like

    int i = luaL_checkint(L, 1);
    if (i < 0) i = n+i;
    else if (i == 0) i = 1;
    else if (i >= n) i = n;
    return n - i;

This gives

> =select(1,5,6,7)
5       6       7
> =select(2,5,6,7)
6       7
> =select(-2,5,6,7)
6       7
> =select(-1,5,6,7)
7
> =select(-3,5,6,7)
5       6       7
> =select(0,5,6,7)
5       6       7

This means that the "#" for the last parameter is replaced by -1.
n means return parameters starting with parameter n
-n means return the last n parameters
0 means return all

DB