I figured it was time I hacked the event system into Bonsai, if only because at some point I need to process keyboard input and the events are kinda important for that [grin]
I decided to model it on the PyGame method; you ask for events and then you can process them as you want. When you ask for the events you run the event pump as well to get the events moving.
At the moment the event system is very tied to my OpenGL Window Framework's way of working; at some point I'll do some voodoo on this so that other systems can be compiled/plugged in instead, such as *shudder* SDL or some other windowing library to let games work on other platforms (well, GTL is cross platform and so is Lua so it'd be a shame to have the windowing code screw things up).
However, regardless of what happens in the backend I intend to keep the main loop looking like this;
quit = false
while(quit == false)
events = bonsai.getEvents()
for i = 1, #events
if events.message == bonsai.Event.types.quit
quit = true
"getEvents" returns a table with a number of event tables in it; each event table has 'message', 'param1' and 'param2' entries in them so that you can extract the event information. The params aren't always valid for all messages.
Right now it supports all the messages OGLWFW does, which is kinda 'the big 6';
At some point I'll add support for mouse move, click and scroll events as well as keyboard input, with the final one being top of my list right now as I need it for the game.
Returning to the 'plugable' idea, I'll probably just have a system where I'll get Lua to load a windowing DLL for me, which would nicely isolate the main Bonsai code from the windowing system; end of the day it doesn't need to know HOW you handle events or make a window, just that it's done in a sane way; from there any windowing system implimenting the correct interface could be used.
I'll puzzle out the refactoring for that tomorrow I think, for now I'm feeling happy with the code and I'm going to bed.