[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua-5.1-alpha: length operator on tables (arrays) and nil values
- From: PA <petite.abeille@...>
- Date: Wed, 14 Sep 2005 07:06:49 +0200
On Sep 14, 2005, at 02:12, Luiz Henrique de Figueiredo wrote:
The use of "arg" inside vargars function is only supported for
compatibility.
If you need a table with all args, use {...}. No need for pack.
Hmmm... but... as mentioned by Michael.. would that handle arguments
with nil values as well?
function test1( ... )
for anIndex, aValue in ipairs( { ... } ) do
print( "test1", anIndex, aValue )
end
end
test1( "first", "second", nil, "third" )
> test1 1 first
> test1 2 second
function test2( ... )
for anIndex = 1, select( "#", ... ) do
local aValue = select( anIndex, ... )
print( "test2", anIndex, aValue )
end
end
> test2 1 first
> test2 2 second
> test2 3 nil
> test2 4 third
function test3( ... )
local someArguments = { ... }
local aSize = select( "#", ... )
for anIndex = 1, aSize do
local aValue = someArguments[ anIndex ]
print( "test3", anIndex, aValue )
end
end
> test3 1 first
> test3 2 second
> test3 3 nil
> test3 4 third
What's the proper way to enumerate vararg then?
Thanks.
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/