[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: AW: Lua 5.1 (alpha) - no more table.foreach(i) ?
- From: PA <petite.abeille@...>
- Date: Fri, 2 Sep 2005 23:05:10 +0200
On Sep 02, 2005, at 22:34, steffenj wrote:
i don't see them in the docs in the table section, have they been
removed in
favor or (i)pairs ?
Talking of which, what is the present consensus on how to enumerate
over vararg?
Considering:
local function test( ... )
print( "print", #{ ... }, ... )
for anIndex, aValue in ipairs( { ... } ) do
print( "test", anIndex, aValue )
end
table.foreachi( { ... }, print )
end
test( "a", "b", nil, "c" )
print 4 a b nil c
test 1 a
test 2 b
1 a
2 b
3 nil
4 c
The print() function recognizes the nil parameter. The length operator
returns 4. foreachi() enumerates all the values. ipairs() stops at the
first nil.
What gives?
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/