lua-users home
lua-l archive

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


Have a look at CopasTimer, https://github.com/Tieske/CopasTimer  it does
this to some extent.

CopasTimer extents Copas to add timer functionality, and includes an eventer
module that allows standard tables to be decorated with event
properties/methods, and events fired will execute as a coroutine on the
Copas loop.

I still intent to update it with better synchronization primitives (the
current waitfor() and finish() methods, I like the Koneki approach to that),
but haven't had a real requirement nor time for it.

The test directory contains eventer_test.lua, which is an example.
 


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
> On Behalf Of Rob Hoelz
> Sent: woensdag 9 mei 2012 13:22
> To: Lua mailing list
> Subject: Idea for an event loop library
> 
> 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