[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: help with lua style and syntax
- From: "David Collier" <myshkin@...>
- Date: Tue, 23 Oct 2012 11:00 +0100 (BST)
My colleague has pointed out that for a simple situation where I am
returning an error status and a single value, I can use nil in place of
the value to indicate an error.
But obviously that doesn't work for more return values.
I don't quite understand why the syntax of "if" can't be extended to say
that if it is given a list of values it tests the first one. But maybe
something else would graunch to a halt then.
David
> *From:* "David Collier" <myshkin@cix.co.uk>
> *To:* <lua-l@lists.lua.org>
> *Date:* Thu, 18 Oct 2012 13:18 +0100 (BST)
>
> in C I can write:
>
> if ( passed = myFunction( x , y , &z ) )
> && ( passed = mySecondFunction( z, &q ) )
>
> which is preferable to
>
> passed = function(x, y, &z)
> if ( passed )
> {
> passed = mySecondFunction( z, &q ) )
>
> ---------------------------
> Now Lua allows me to return more than one value, so I can write
>
> passed, z = myFunction(x, y)
>
> but is there any way in Lua I can write
>
> if passed, z = myFunction(x, y)
>
> and set both passed and z, but then test 'passed' ??
>
> It would allow me to do:
>
> if ( passed, z = myFunction(x, y) )
> and ( passed, q = mySecondFunction(z) )
> and ( passed, result = myThirdFunction(q) )
>
> which is a lot more comapct than what I'm writing at present.
>
>
>