In the FFI you can take an enum such as the following from the SDL library:
typedef enum { SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_ALPHA_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_DOUBLEBUFFER, SDL_GL_DEPTH_SIZE, SDL_GL_STENCIL_SIZE, SDL_GL_ACCUM_RED_SIZE, SDL_GL_ACCUM_GREEN_SIZE, SDL_GL_ACCUM_BLUE_SIZE, SDL_GL_ACCUM_ALPHA_SIZE, SDL_GL_STEREO, SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLESAMPLES } SDL_GLattr;
What is the best way to define this as a foreign type?
If you do the following: (c-define-type SDL_GLattr "SDL_GLattr") Then to get at the values you have to assign a pointer to the enum value (c-lambda () SDL_GLattr "___result_voidstar = &SDL_GL_SWAP_CONTROL;")
Seems like passing the actual value would be preferable. Am I missing something obvious?
Afficher les réponses par date
Well, considering that enumerated values are just names mapped to integers, I would personally have:
(define SDL_GL_RED_SIZE 0) (define SDL_GL_GREEN_SIZE 1) (define SDL_GL_BLUE_SIZE 2) ...
By doing this, you lose the type information, but provided you scheme wrapper is sound, that should generate no compilation nor runtime issues, should it? If needed, you should be able to cast from integer to SDL_GLattr in your calls (and hopefully, this should only be a compile time check, and have no incidence on actual execution).
I know it's not exactly what you wanted, but this should do the job until someone points out the right thing to do.
P!
2008/8/15 Frederick LeMaster fred.lemaster@gmail.com
In the FFI you can take an enum such as the following from the SDL library:
typedef enum { SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_ALPHA_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_DOUBLEBUFFER, SDL_GL_DEPTH_SIZE, SDL_GL_STENCIL_SIZE, SDL_GL_ACCUM_RED_SIZE, SDL_GL_ACCUM_GREEN_SIZE, SDL_GL_ACCUM_BLUE_SIZE, SDL_GL_ACCUM_ALPHA_SIZE, SDL_GL_STEREO, SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLESAMPLES } SDL_GLattr;
What is the best way to define this as a foreign type?
If you do the following: (c-define-type SDL_GLattr "SDL_GLattr") Then to get at the values you have to assign a pointer to the enum value (c-lambda () SDL_GLattr "___result_voidstar = &SDL_GL_SWAP_CONTROL;")
Seems like passing the actual value would be preferable. Am I missing something obvious? _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list