[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: General purpose notification mechanism for Lua
- From: Tiago Katcipis <tiagokatcipis@...>
- Date: Mon, 4 Jan 2010 11:01:14 -0200
On Fri, Jan 1, 2010 at 6:44 PM, Jerome Vuarand <firstname.lastname@example.org>
2009/12/31 Tiago Katcipis <email@example.com>:
>> If you do implement it, especiallyI wrote a very simple event system on top of a Win32 API binding. You
>> with your experience in with so many other event systems, I'd be very
>> interested in seeing what it
>> looks like.
> Well I'm experienced with this other systems but i do not master them :-), i
> don't know if i will have a good idea of how to implement it on Lua, that's
> exactly why I'm trying to get some help from you guys.
can find the source online:
It's pretty specific to my underlying event system (the Windows one),
but the outer API may be a good example of what to provide. Basically
the module has four functions :
Associate the 'handler' function with the 'object'. When it's
notified the 'handler' function is called.
Removes the association of a handler with 'object', if any.
Enters a loop that read from the system events sent to all
registered objects, and call the associated handlers. The function
returns after a timeout, which is set by writing the 'timeout'
variable in the module (a handle can set it to zero to exit the 'run'
Process all pendings events on registered objects, calling
handlers, and return.
There is no easy way to interrupt running Lua code, and process an
event, because the Lua interpreter is single-threaded. However with a
coroutine scheduler on top of the event module described above you can
get a pretty flexible system.
Another example is Copas, which is kindof specialized for network
servers, but the principle could be extended.
Finally I attached another eventloop.lua file (which is different from
the one linked and described above), which is such a generalization of
the Copas architecture for mixed client/server application.
Thanks Jerome, i think your API is a little more than what we need but it helps on how to design our lib.
We will start to build our lib today, i think it will not be something very useful to almost of you, but ill post it here.
I thank you all for the help, it helped me a lot.