Luís Oliveira wrote:
I suppose defcenum shouldn't force the user to use keywords though?
Certainly not! Where would you get their value from if they are interned into the keyword package.
BTW, I think a SWITCH macro would be a useful companion to ENUM. It's CASE where you can put such things into the selector clauses. Instead of (case event-type (#.SDL-keyboard-event[-enum] (do-this)) ... ... or (cond ((if (eql event-type SDL-keyboard-event[-enum]) ... ((if ... or (cond ((if (enum-eq? event-type SDL-keyboard-event) ...) ...
BTW, I hate enums in Lisp and the explosion of constants etc. that they cause.
I'm not convinced DEFCONSTANT is appropriate. Maybe all is needed is a mapping from name to values (and vice-versa, the CLISP FFI has it), and nice useable forms like the above SWITCH to hide ugliness.
BTW, DEFCONSTANT won't help with types like (:array :character MAX_PATH) which once again, shows that it's not a good translation of C. It's just widespread. (:array :character #.MAX_PATH) is also ugly, but I've never thought about finding something better.
FWIW, remember to wrap such uses of defconstant into EVAL-when also compile.
Regards, Jörg Höhle
"Hoehle, Joerg-Cyril" Joerg-Cyril.Hoehle@t-systems.com writes:
I suppose defcenum shouldn't force the user to use keywords though?
Certainly not! Where would you get their value from if they are interned into the keyword package.
With FOREIGN-ENUM-VALUE, see http://common-lisp.net/project/cffi/manual/html_node/foreign_002denum_002dva...
BTW, I think a SWITCH macro would be a useful companion to ENUM. It's CASE where you can put such things into the selector clauses. Instead of (case event-type (#.SDL-keyboard-event[-enum] (do-this)) ... ... or (cond ((if (eql event-type SDL-keyboard-event[-enum]) ... ((if ... or (cond ((if (enum-eq? event-type SDL-keyboard-event) ...) ...
(case (sdl:get-event-type ...) ; or whatever (:keyboard ...) (:mouse ...))
I don't see the point of a SWITCH macro nor what it's supposed to do?
I'm not convinced DEFCONSTANT is appropriate. Maybe all is needed is a mapping from name to values (and vice-versa, the CLISP FFI has it),
Right, that's what CFFI has, see http://common-lisp.net/project/cffi/manual/html_node/defcenum.html
I'm not convinced DEFCONSTANT is appropriate. Maybe all is needed is a mapping from name to values (and vice-versa, the CLISP FFI has it),
Right, that's what CFFI has, see http://common-lisp.net/project/cffi/manual/html_node/defcenum.html
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.
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 wrote:
(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)
ok, this is a good translation, if you do it by hand. My problem is that I want to automate it with SWIG or Verrazano, without the need to do manual editing of the generated bindings, and this frameworks can't invent the named enum "event", because it is an anonymous enum in the header source.
On 2006-jan-24, at 05:09, Frank Buss wrote:
ok, this is a good translation, if you do it by hand. My problem is that I want to automate it with SWIG or Verrazano, without the need to do manual editing of the generated bindings, and this frameworks can't invent the named enum "event", because it is an anonymous enum in the header source.
I suppose in this case it should expand into a couple of defconstants like you suggest. :-) I'm curious, can SWIG or Verrazano actually handle the enum that's defining those masks?
Also, I'd have thought Verrazano could already handle this kind of enums. What does it do with those?