[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: unpack() behaviour not as documented
- From: Bulat Ziganshin <bulat.ziganshin@...>
- Date: Wed, 24 Jun 2009 02:02:56 +0400
Hello Duncan,
Thursday, June 11, 2009, 1:02:57 AM, you wrote:
> if you want to iterate over the varargs of a function, when some of them
> may be nil, you have to use:
> for i = 1,select('#', ...) do
> local k = select(i, ...)
> -- (stuff)
> end
> instead of:
> for i,k in ipairs{...} do
> -- (stuff)
> end
> ...as ipairs will stop on the first nil.
afai now realized, it's neither guaranteed with #:
> The length of a table t is defined to be any integer index n such that
> t[n] is not nil and t[n+1] is nil; moreover, if t[1] is nil, n can be
> zero. For a regular array, with non-nil values from 1 to a given n,
> its length is exactly that n, the index of its last value. If the
> array has "holes" (that is, nil values between other non-nil values),
> then #t can be any of the indices that directly precedes a nil value
> (that is, it may consider any such nil value as the end of the array).
although your code works with 5.1.4 in my program, it may break. so i
still looking for the proper way to iterate in order over all array
elements. it looks like i should make list of table indexes and then sort
them - fortunately, my array is very short
--
Best regards,
Bulat mailto:Bulat.Ziganshin@gmail.com