[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lightweight function syntax (again) Re: [ANN] Lua 5.2.0 (alpha-rc2) now available
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 23 Nov 2010 18:22:20 +0200
2010/11/23 Pierre-Yves Gérardy <pygy79@gmail.com>:
> In my case, it is about tying callbacks to keypresses and events in games.
String lambdas to the rescue!
state "menu" :keyconfig
"%arrows" :held 'k,dt => hero:move(k,dt)'
" " :pressed '|=> hero:shoot()'
:held '_,dt => hero:accumulateEnergy(dt)'
:released '=> hero:releaseBigBlow()'
"escape" :pressed(function()
makesound()
state.goto "pause"
end)
()
Very doable in existing Lua, efficient (especially if you keep a
string-function cache), and straightforward. Your handlers just have
to check if they're passed a string and compile that string for later
calling.
The irritating thing is that 'hero' would have to be a global or at
least a field in the environment you use to compile the lambdas; they
cannot be _closures_.
steve d.