lua-users home
lua-l archive

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


I could not find what the syntax is for short lambdas with no parameters (I
didn't look very hard), but I found the "Concise Anonymous Functions" patch.
It does exactly what I want and it looks beautiful:
wait([GetPlayerHealth(index)<50])

Thanks for your help
Ivo

-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
Behalf Of steve donovan
Sent: Monday, January 07, 2013 11:34 PM
To: Lua mailing list
Subject: Re: Passing expression as a parameter

On Tue, Jan 8, 2013 at 9:21 AM, Ivo Beltchev <ivo@ibeltchev.com> wrote:
> #3 gives me direct control when and how often to evaluate the 
> function, but I'm not sure how efficient it is, especially if local 
> variables are used

I'd wager that it's not slower than #2 (and a lot faster than #1) if the
payload is non-trivial.

Anonymous functions in Lua are very cool, pity about the need to use three
keywords.  If it's for an in-house project, maybe use the short lambda
patch? That is, |x| x^2 is fully equivalent to function(x) return x^2 end.

Alternatively, macro preprocessing. E.g. in Luamacro you can implement
wait(GetPlayerHealth(index)<50) easily, and the short lambda syntax is
\x(x^2)

(Yes, I would like this for Christmas, any Christmas, but people get
surprisingly excited about this)