If those are int consts from the C header files of the lib, then import them as is fromt here (define CAIRO_FORMAT_ARGB32 ((c-lambda () int "___result = CAIRO_FORMAT_ARGB32;")) etc. , and any arguments that need them declare as int too.

If they're C enums, maybe you want another datatype declaration of them than int - though I suppose int ought to be generally viable for that too.

The exception in your example below is not so strange, as the second arg is an int while the procedure is declared as cairo-format-t. For it to work, I suppose define CAIRO_FORMAT_RGB24 to ((c-lambda () cairo-format-t "___result = CAIRO_FORMAT_RGB24;")) . Works?

2012/2/5 Álvaro Castro-Castilla <alvaro.castro.castilla@gmail.com>
Hi,

I'm using my ffi cairo bindings, that worked fine in the past. However now that I'm using Gambit compiled with C++ support it stopped working.




I got this error:

*** ERROR IN main-sdl#main, "main-sdl.scm"@19.24 -- (Argument 2) Can't convert to C type
(cairo#cairo-image-surface-create-for-data '#<|unsigned char*| #16 0x7f33ba191000> 1 500 500 2000)

On the ffi side, things are declared like this:

(c-define-type cairo-format-t "cairo_format_t")
(define CAIRO_FORMAT_ARGB32 0)
(define CAIRO_FORMAT_RGB24 1)
(define CAIRO_FORMAT_A8 2)
(define CAIRO_FORMAT_A1 3)
(define CAIRO_FORMAT_RGB16_565 4)
(define cairo-image-surface-create-for-data (c-lambda (unsigned-char* cairo-format-t int int int) cairo-surface-t* "cairo_image_surface_create_for_data"))

And used like this:

(cairo-image-surface-create-for-data
                         (SDL::surface-pixels sdl-surface)
                         CAIRO_FORMAT_RGB24
                         maxx
                         maxy
                         (SDL::screen-pitch sdl-surface))

I've tried with this idea:

(define cairo-format
  (c-lambda (int) cairo-format-t
            "
            switch (___arg1) {
              case 0: ___result = CAIRO_FORMAT_ARGB32; break;
              case 1: ___result = CAIRO_FORMAT_RGB24; break; // and so on...
            }
            "))

And then calling on the Scheme side "(cairo-format CAIRO_FORMAT_RGB24)" instead of just using the int directly, but it segfaults.


How should I really handle enums properly?



Best regards,


_______________________________________________
Gambit-list mailing list
Gambit-list@iro.umontreal.ca
https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list