lua-users home
lua-l archive

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


Hi All,

I am currently reading "Programing Lua" first edition (I couldn't buy second edition from INDIA :( ).

In the first edition, it is mentioned that select() gives a specific return value of a function. So if the first argument of select() is 1, it returns the first return value.

print(string.find("hello hello", " hel")) > 6 9
print(select(1, string.find("hello hello", " hel"))) > 6
print(select(2, string.find("hello hello", " hel"))) > 9

But when I tried a sample, select was actually giving all the return values starting from the index specified.

function test(a, b)
    return a, b
end
print(select(1, test(10,20)))

---------- Run ----------
10    20
Output completed (0 sec consumed) - Normal Termination

I cross checked in 5.1 reference.

select (index, ···)
If index is a number, returns all arguments after argument number index. Otherwise,
index must be the string "#", and select returns the total number of extra arguments it
received.

Is this a new change in 5.1 ? If so, where can I get list of core language changes in 5.1 (since 5.0)? And may I ask the reason behind the change in select() function behavior in 5.1?

FYI,
I am from Java/J2EE => Ruby/Rails background. I initially thought Java was complex and moved to Ruby. Because of Lua, I feel Ruby is complex ;). I believe in doing more with less. Lua rocks.

Cheers,
GG