lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

On Feb 22, 2006, at 22:12, Wim Couwenberg wrote:

Try modifying your code as follows:

 function try( ... )
   local someArguments = { ... }
+  local n = select("#", ...)
   local aFunction = function()
<    tryToDoIt( unpack( someArguments ) )
>   tryToDoIt( unpack( someArguments, 1, n ) )

Thanks for the hint :)

Works great:

function pack( ... )
        local someArguments = { ... }
        local aLength = select( "#", ... )

        return unpack( someArguments, 1, aLength )
end

print( pack( 1, nil, 2, nil ) )

> 1       nil     2       nil

Is there a way to achieve the same effect with multiple return values which may or may not include nil?

For example:

function test()
        return 1, nil, 2
end

local someResults = { test() }

print( unpack( someResults ) )

> 1

Is there a way to get all the return values, including the ones after a nil?

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/