[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ah, those uninitiated people...
- From: Wesley Smith <wesley.hoke@...>
- Date: Thu, 14 Jan 2010 16:30:06 +0100
I've mostly built pretty simple state machines with coros for things
like handling asynchronous events from mouse and keyboard. Typically
they look like this (coded in the mail so pardon any mistakes):
while(true) do
local event = co.yield()
if(event == "down") then
-- do something
local res1 = calc1()
event = co.yield()
while(event == "drag") do
-- do something else
local res2 = calc2()
if(res1 == res2) then
generate_event()
end
end
end
end
This is really basic, but shows the principle. The thing I like about
coroutines is that I can setup calculations at local scope for use at
further states along the way as illustrated with res1 and res2 and I
don't have to construct on object or closures to do so.
wes
- References:
- Ah, those uninitiated people..., Alexander Gladysh
- Re: Ah, those uninitiated people..., Roberto Ierusalimschy
- Re: Ah, those uninitiated people..., Andrew Wilson
- Re: Ah, those uninitiated people..., Mark Hamburg
- Re: Ah, those uninitiated people..., steve donovan
- Re: Ah, those uninitiated people..., David Given
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., Wesley Smith
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Jorge