lispgames / cl-sdl2

Common Lisp bindings for SDL2 using C2FFI.
MIT License
304 stars 82 forks source link

autowrap is renaming SDL_TRUE and SDL_FALSE to :TRU and :FALS #25

Closed Zulu-Inuoe closed 10 years ago

Zulu-Inuoe commented 10 years ago

If you look at the macroexpansion of src/autowrap.lisp you'll find this:

(COMMON-LISP:PROGN
     (COMMON-LISP:EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
       (SB-C::%DEFCONSTANT '+SDL-FALSE+ 0 'COMMON-LISP:NIL
                           (SB-C:SOURCE-LOCATION)))
     (COMMON-LISP:EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
       (SB-C::%DEFCONSTANT '+SDL-TRUE+ 1 'COMMON-LISP:NIL
                           (SB-C:SOURCE-LOCATION)))
     (AUTOWRAP:DEFINE-FOREIGN-ENUM '#:ANON-TYPE-1518 28
                                   '((:FALS . 0) (:TRU . 1))))

Notice the :FALS and :TRU symbols defined there.

I tracked this down to an autowrap feature which detects 'suffixes' on enumerations and removes them (just as it detects prefixes), done by the function autowrap::parse-enum-fields in parse.lisp. It sees the common 'E' at the end of both SDL_TRUE and SDL_FALSE, so considers this a suffix.

This causes sdl2::sdl-true-p to call (autowrap:enum-value 'sdl2-ffi:sdl-bool :true) and receive NIL back (since autowrap only knows about :tru), causing a type error when calling = on it.

This causes the example code to fail if any controllers are plugged in, but you can easily replicate it by calling sdl2::sdl-true-p directly.

No clue what the right thing to do here. Could make sdl2 expect this and look for :TRU instead of :TRUE, or somehow find a way to make autowrap not treat these as suffixes which it strips.

rpav commented 10 years ago

Haha, nice catch. Looking into it.

rpav commented 10 years ago

All right, I have pushed a fix for cl-autowrap and cl-sdl2 which should fix this.