[cffi-devel] Re: defenum proposal

Luís Oliveira luismbo at gmail.com
Tue Jan 24 04:50:23 UTC 2006


On 2006-jan-24, at 03:59, Frank Buss wrote:
> How does this work with anonymous enums? E.g. like this (C code) :
>
> enum { SDL_NOEVENT = 0,
>        SDL_ACTIVEEVENT,
>        SDL_KEYDOWN,
>        SDL_KEYUP,
> };
> #define SDL_EVENTMASK(X)	(1<<(X))
> enum {
> 	SDL_ACTIVEEVENTMASK	= SDL_EVENTMASK(SDL_ACTIVEEVENT),
> 	SDL_KEYDOWNMASK		= SDL_EVENTMASK(SDL_KEYDOWN),
> 	SDL_KEYUPMASK		= SDL_EVENTMASK(SDL_KEYUP),
> };
>
> setEventMask(SDL_ACTIVEEVENTMASK | SDL_KEYUPMASK);
>
> How would you translate this to Lisp with CFFI? With my def-anon- 
> emum macro,
> which translates just to defconstant, it would be easy, but perhaps  
> there
> are better ways to do it.

(defcenum event
   :no-event
   :active-event
   :key-down
   :key-up)

(defmacro define-event-mask (name keyword)
   `(defconstant ,name (ash 1 (foreign-enum-value 'event ',keyword))))

(define-event-mask +active-event-mask+ :active-event)
(define-event-mask +key-down-mask+     :key-down)
(define-event-mask +key-up-mask+       :key-up)


I understand what you mean now anyway. I suppose some helpers for  
dealing with constants and masks might be nice. :-)

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt




More information about the cffi-devel mailing list