[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ffi-helper: status
From: |
Matt Wette |
Subject: |
Re: ffi-helper: status |
Date: |
Mon, 10 Jul 2017 19:49:12 -0700 |
> On Jul 7, 2017, at 5:31 PM, Matt Wette <address@hidden> wrote:
>
>
>> On Jul 7, 2017, at 5:18 PM, Matt Wette <address@hidden> wrote:
>> However, the above generates 397 FFI declarations into a cairo.scm file
>> which is about 6000 lines long. I’m not
>> sure if I want to start testing this code or start converting suggestions
>> and have guile-users do some testing.
>
> That is, for this example, I no longer run into declarations which my code
> says “failed,” indicating that it didn’t know what to do with the declaration.
>
> I already notice that the function types converters should be called “unwrap”
> and that they should be called by the procedure interface. I am going to
> start playing with cairo_set_user_data to see if passed procedures work.
Another working demo:
mwette$ guile exam.d/cairo02.scm
d1 called with ((abc . 123) (def . 456))
mwette$ cat exam.d/cairo02.scm
;; exam.d/cairo02.scm
(use-modules (cairo cairo)) ; auto-generated from cairo.h etc
(use-modules (ffi-help-rt)) ; pointer-to
(use-modules (system foreign)) ; string->pointer, pointer<->scm
(define srf (cairo_svg_surface_create (string->pointer "abc.svg") 200.0 200.0))
(define cr (cairo_create srf))
;; typedef struct _cairo_user_data_key {
;; int unused;
;; } cairo_user_data_key_t;
;;
;; typedef void (*cairo_destroy_func_t)(void *data);
;;
;; cairo_status_t cairo_set_user_data(cairo_t *cr, const cairo_user_data_key_t
;; *key, void *user_data, cairo_destroy_func_t destroy);
(define k1 (make-cairo_user_data_key_t)) ; make a key
(define v1 '((abc . 123) (def . 456))) ; make some data
(define (d1 data) ; callback
(simple-format #t "d1 called with ~S\n" (pointer->scm data)))
(cairo_set_user_data cr (pointer-to k1) (scm->pointer v1) d1)
(cairo_destroy cr)
(cairo_surface_destroy srf)
;; --- last line ---