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.