Migrating To Five One |
|
function catchall( ... ) for i=1,arg.n do print( "Argument #", i, "is", arg[ i ] ) end -- Pass all arguments to another function show3( unpack( arg ) ) end function show3( a, b, c ) print( a, b, c ) end catchall( nil, 'two', nil ) --> Argument # 1 is nil --> Argument # 2 is two --> Argument # 3 is nil --> nil two nil
function catchall( ... ) -- Make a new table of values local theArguments = { ... } for i=1,select( '#', ... ) do print( "Argument #", i, "is", theArguments[ i ] ) end -- Pass all arguments to another function show3( ... ) end function show3( a, b, c ) print( a, b, c ) end catchall( nil, 'two', nil ) --> Argument # 1 is nil --> Argument # 2 is two --> Argument # 3 is nil --> nil two nil
ipairs() will stop at the first embedded nil value;
# (the length operator) [may] stop at the first embedded nil value;
table.maxn() will skip embedded nil values; but
select( '#', ... ) will allow you to see that the user passed in trailing nil values.
if (index < 0 && -index <= top)
index = top+index+1;
my* = luaL_check*(L, index, ...);
package.loadlib for 5.0 uses of loadlib