[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Finding out the number of requested return values for a Lua-Perl bridge
- From: Duncan Cross <duncan.cross@...>
- Date: Thu, 29 Apr 2010 18:37:00 +0100
On Wed, Apr 28, 2010 at 5:21 PM, Rob Hoelz <rob@hoelzro.net> wrote:
> If I were to call foo in Perl, I could do it several ways:
>
> my $a = foo; # $a is 3
> my @values = foo; # $values[0] is 1, $values[1] is 2
> my ( $a, $b ) = foo; # $a is 1, $b is two
> my ( $a ) = foo; # $a is 1, the second return value is discarded
>
> The equivalent statements in Lua:
>
> local a = foo()
> local values = { foo() }
> local a, b = foo()
> local a = ({ foo() })[0] -- not sure how else to do this, really...
Hi Rob,
I don't know anything about Perl, but I think I can still usefully
comment on this last equivalent statement, that you're not sure how
else to do. All you need to do is:
local a = foo()
...and the second value will be silently discarded. You don't need to
create a temporary table to do this. (Also, don't forget Lua tables
index from 1 rather than 0, unless you have patched your version of
Lua, so ({ foo() })[0] will always evaluate to nil anyway.)
-Duncan