lua-users home
lua-l archive

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


Hello Ezequiel,
That is exactly what I did in Telemídia's Ginga implementation.
Most DFB events unblock the call to WaitForEventsWithTimeout, so no need for busy waits.
For polling events (or events not integrated to DFB) I had to set a small timeout to check from time to time.
A pure Lua implementation for Ginga is an old dream, I hope you succeed.

2012/1/10 Ezequiel García <elezegarcia@gmail.com>
Hi,

I am working on a simple 'event' module implementation, based on NCLua
event module:

http://www.lua.inf.puc-rio.br/~francisco/nclua/referencia/event.html

This module defines, among others:
 * event.register() to register event handler
 * event.timer() to register a user timer

It is supposed to handle keyboard events, timer events, and other
events and it is typically implemented in C or C++.
I am trying a pure Lua implementation, with keyboard and stuff handled
by DirectFB.

The challenging part is: How to implement it without busy waits?

The user may well request timers with zero expiration time, for
example to display an animation. Lucky for me,
DirectFB has a WaitForEventsWithTimeout function, so my solution is
based on this. I calculate the expiration
time of the next timer in table (if I have one), and then Wait...()
with that timeout value. I use socket.gettime()
to calculate the *actual* time spent waiting, because an actual event
may have been triggered.

Of course, this is assuming the most significant time will be spent in
DirectFB WaitForEventsWithTimeout(),
wich is *not* true.

So, I wanted to share with the ML to know your opinion.

Thanks,
Ezequiel.