July 12, 2008

macrodef event-loop

I spent most of today writing up the new event-loop macro, and I got it to work. Here is a shot of it in action, together with a very basic event loop definition which is driving the graphics in the top right.

If you have taken a look at cl-sdl you'll find that my event loop looks very similar. The most obvious difference is that I treat capture of event values differently. I use keywords to ask for the right value, whereas cl-sdl somehow seemed to figure this out based on the variable names you used. This last was somewhat mystifying to me at the start; I think that the new way is somewhat clearer, if more verbose.

Behind the scenes the macro expansion happens in a very different way. In cl-sdl you'll find a lot of accessor definitions which are then used by the macro somehow. In my setup I basically defined a meta-data structure which is queried by the macro to do the expansion. This means that the details of the mappings and slot accesses are all in one place, and adding new stuff should be pretty straightforward.

Caveats of the current code: there are very few sanity checks, which means you can give it some bad input and it won't even complain. So don't give it any bad input!

Everything is also in need of the right packaging. And I need to find a way to get rid of some hardcoded paths. But barring that I'm pretty close to the end of cffi-sdl hacking.

No comments: