unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Re: ffi helper
       [not found]       ` <093A1AB8-D7BD-4DAF-B5EC-DC0228D6A29C@gmail.com>
@ 2017-05-13 16:19         ` Matt Wette
  0 siblings, 0 replies; only message in thread
From: Matt Wette @ 2017-05-13 16:19 UTC (permalink / raw)
  To: guile-user, guile-devel


> On Apr 17, 2017, at 7:26 PM, Matt Wette <matt.wette@gmail.com> wrote:
> 
> 
>> On Mar 21, 2017, at 3:40 PM, Matt Wette <matt.wette@gmail.com> wrote:
>>> On Mar 19, 2017, at 10:23 AM, Matt Wette <matt.wette@gmail.com> wrote:
>>>> On Mar 13, 2017, at 5:53 PM, Matt Wette <matt.wette@gmail.com> wrote:
>>>>> On Mar 8, 2017, at 6:06 PM, Matt Wette <matt.wette@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 ---




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-13 16:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <96434CF4-E3F9-4410-82B6-9EB8DEE130B9@gmail.com>
     [not found] ` <95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com>
     [not found]   ` <201FF019-FA10-4B35-A96D-BC0AD078F5DB@gmail.com>
     [not found]     ` <CFDEFCDA-A72C-4FF2-B602-EE787530E705@gmail.com>
     [not found]       ` <093A1AB8-D7BD-4DAF-B5EC-DC0228D6A29C@gmail.com>
2017-05-13 16:19         ` ffi helper Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).