lua-users home
lua-l archive

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


Hello Rob,

take a look at what we have inside the Splay runtime, as it sounds very close to that:

http://www.splay-project.org/manual#events

best,
valerio

On Wed, May 9, 2012 at 1:22 PM, Rob Hoelz <rob@hoelz.ro> wrote:
Hello list,

I've been meaning to write a new event library for a while, but I
thought I'd throw the idea at the list first to see if it has merit.

Basically, I want to create an event library for Lua that sits on top
of another event library (luaevent for now, but I would probably make
the system flexible enough for a different library should that be
desired).  It would provide a simpler interface for events, so you could
do something like this:

   local w = ev:timer {
     interval = 1,
     callback = function()
       print 'One second has passed!'
     end
   }

However, that part is just the gravy.  The point of doing a whole new
library would be to make the entire thing coroutine-based.  Think of it
like Copas, but applied to generic events instead of just TCP/IP
sockets.  So let's say I wanted to print 'hello' a second after a user
clicked a button in a GUI.  I could do something like this:

 -- this assumes that the GUI plays nicely with the event loop
 button:onclick(function()
   ev:sleep(1)
   print 'hi'
 end)

and other events would continue to fire while the button handler is
sleeping.  Also, you could write a timer-based event like this:

ev:go(function()
 while true do
   ev:sleep(1)
   print 'waking up!'
 end
end)

The library would also provide other operations for waiting for an event
to happen.

So, what do you all think?  Does this idea sound cool to you too, or
does it sound useless/dumb/too magical/etc?

-Rob