lua-users home
lua-l archive

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


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)