[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.2.0 (rc2) now available
- From: Patrick Rapin <toupie300@...>
- Date: Sat, 26 Nov 2011 13:16:54 +0100
After looking a little bit more, this is not a bug but a pitfall.
Function table.pack returns two values: a table and its length.
When passing it directly to table.unpack, the second result is taken
as the starting index.
An extra parenthesis solves the problem.
1 2 3
Still, is there a way to avoid that pitfall ?
I will probably not be the last to try that apparently logical syntax...
My proposal  was that table.pack should set __len metamethod
instead of returning the value or setting "n" field.
Wouldn't it be less risky ?