> On Apr 17, 2017, at 7:26 PM, Matt Wette <matt.we...@gmail.com> wrote: > > >> On Mar 21, 2017, at 3:40 PM, Matt Wette <matt.we...@gmail.com> wrote: >>> On Mar 19, 2017, at 10:23 AM, Matt Wette <matt.we...@gmail.com> wrote: >>>> On Mar 13, 2017, at 5:53 PM, Matt Wette <matt.we...@gmail.com> wrote: >>>>> On Mar 8, 2017, at 6:06 PM, Matt Wette <matt.we...@gmail.com> wrote: >>>>> I’m now working on a FFI helper based on the nyacc C99 parser.
Still grinding away. I can generate wrappers for function pointers passed to C routines: see cairo_destroy_func_t below. I don’t know if the converter should be called “wrap” or something else as, wrt the pointer wrappers, we are adding a “C” wrapper instead of a “scheme” wrapper. I am deciding how to handle enums. I will likely have wrapper to map symbols to integers and vice versa, but I will have to handle anonymous enums as well (e.g." enum { ABC = 1 };”). Matt (use-modules (ffi-help)) (define-ffi-helper (cairo cairo) #:pkg-config "cairo" #:include "cairo-svg.h" #:library "libcairo" #:filter (lambda (path) (string=? "cairo" (substring path 0 5))) ) ==[GENERATES]==>[filter samples]==> ;; ;; auto-generated by ffi-help.scm ;; (define-module (cairo cairo) #:use-module (ffi-help) #:use-module ((system foreign) #:prefix ffi:) #:use-module ((bytestructures guile) #:prefix bs:) ) (define bs:struct bs:bs:struct) (define lib-link (dynamic-link "libcairo")) (define (lib-func name) (dynamic-func name lib-link)) ;; typedef struct _cairo_surface cairo_surface_t; (define-std-pointer-wrapper cairo_surface_t*) ;; cairo_matrix_t (define cairo_matrix_t (bs:struct (list `(xx ,bs:double) `(yx ,bs:double) `(xy ,bs:double) `(yy ,bs:double) `(x0 ,bs:double) `(y0 ,bs:double)))) (export cairo_matrix_t) ;; typedef void (*cairo_destroy_func_t)(void *data); (define (wrap-cairo_destroy_func_t proc) ;; => pointer (ffi:procedure->pointer ffi:void proc (list '*)) ) (export wrap-cairo_destroy_func_t) ;; cairo_t *cairo_create(cairo_surface_t *target); (define cairo_create (let ((f (ffi:pointer->procedure '* (lib-func "cairo_create") (list '*)))) (lambda (target) (let ((~target ((unwrap-cairo_surface_t* target)))) (identity (f ~target)))))) (export cairo_create) ;; typedef struct _cairo_region cairo_region_t; (define-std-pointer-wrapper cairo_region_t*) ;; cairo_bool_t cairo_region_contains_point(const cairo_region_t *region, int ;; x, int y); (define cairo_region_contains_point (let ((f (ffi:pointer->procedure ffi:int (lib-func "cairo_region_contains_point") (list '* ffi:int ffi:int)))) (lambda (region x y) (let ((~region ((unwrap-cairo_region_t* region)))) (f ~region x y))))) (export cairo_region_contains_point) ;; --- last line ---