From: Rici Lake <lua@ricilake.net>
Reply-To: Lua list <lua@bazar2.conectiva.com.br>
To: Lua list <lua@bazar2.conectiva.com.br>
Subject: Behaviour of unpack in 5.1alpha
Date: Tue, 18 Oct 2005 10:59:41 -0500
The 5.1alpha version of unpack allows you to specify start and end indices,
which is useful.
There is an undocumented feature where:
unpack(tab, start, -1)
is the same as
unpack(tab, start, #tab)
Any other negative index is treated as a negative index. Unfortunately,
this creates an inconsistency; if the table actually has negative indices
(say, the arg table in the standalone interpreter), then:
unpack(arg, -3, -2) -- works as expected
unpack(arg, -3, -1) -- does not work as expected
(As always, depending on one's expectations)
In any event, unpack(tab, start, -fin) is not equivalent to unpack(tab,
start, #tab+1-fin), as one might expect by analogy with string.sub, unless
-fin is exactly -1.
I think its behaviour ought to be consistent. Either negative indices are
always valid and treated literally as negative indices, or both negative
start and negative fin are treated as relative to #tab (which would make it
useless for arrays which actually had negative indices).
R.