[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ffi helper

From: Matt Wette
Subject: Re: ffi helper
Date: Mon, 17 Apr 2017 19:26:57 -0700

> On Mar 21, 2017, at 3:40 PM, Matt Wette <address@hidden> wrote:
>> On Mar 19, 2017, at 10:23 AM, Matt Wette <address@hidden> wrote:
>>> On Mar 13, 2017, at 5:53 PM, Matt Wette <address@hidden> wrote:
>>>> On Mar 8, 2017, at 6:06 PM, Matt Wette <address@hidden> wrote:
>>>> I’m now working on a FFI helper based on the nyacc C99 parser.   

Still working on it.  I ran into some issues with the C preprocessor again so 
had to fix that.  

I have a lot to do still, but now I have a source file that looks like this:

(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)))

and generates a 4800 line files that includes stuff like this:

(define-module (path-list)           <= should read (cairo cairo)
  #:(use-module (ffi-help)
  #:(use-module (system foreign)
  #:(use-module ((bytestructures guile) #:renamer bs-renamer)

(define lib-link (dynamic-link "libcairo"))
(define (lib-func name) (dynamic-func name lib-link))

;; "cairo_version"
(define cairo_version
  (let ((f (pointer->procedure
             (lib-func "cairo_version")
    (lambda () (let () (wrap-int (f))))))
(export cairo_version)

;; "cairo_version_string"
(define cairo_version_string
  (let ((f (pointer->procedure
             (lib-func "cairo_version_string")
    (lambda () (let () (wrap-char* (f))))))
(export cairo_version_string)

;; "cairo_t"
(define-std-pointer-wrapper cairo_t*)
(export cairo_t*)

;; "cairo_surface_t"
(define-std-pointer-wrapper cairo_surface_t*)
(export cairo_surface_t*)

;; "cairo_device_t"
(define-std-pointer-wrapper cairo_device_t*)
(export cairo_device_t*)

;; "cairo_matrix_t"
(define cairo_matrix_t
    `((xx ,double)
      (yx ,double)
      (xy ,double)
      (yy ,double)
      (x0 ,double)
      (y0 ,double))))
(export cairo_matrix_t)

;; "cairo_get_user_data"
(define cairo_get_user_data
  (let ((f (pointer->procedure
             (lib-func "cairo_get_user_data")
             (list '* '*))))
    (lambda (cr key)
      (let ((~cr (unwrap-cairo_t* cr))
            (~key (unwrap-cairo_user_data_key_t* key)))
        (wrap-void* (f ~cr ~key))))))
(export cairo_get_user_data)

;; "cairo_push_group_with_content"
(define cairo_push_group_with_content
  (let ((f (pointer->procedure
             (lib-func "cairo_push_group_with_content")
             (list '* tbd:cairo_content_t))))
    (lambda (cr content)
      (let ((~cr (unwrap-cairo_t* cr)) (~content content))
        (f ~cr ~content)))))
(export cairo_push_group_with_content)

;; "cairo_set_source_rgba"
(define cairo_set_source_rgba
  (let ((f (pointer->procedure
             (lib-func "cairo_set_source_rgba")
             (list '* double double double double))))
    (lambda (cr red green blue alpha)
      (let ((~cr (unwrap-cairo_t* cr))
            (~red red)
            (~green green)
            (~blue blue)
            (~alpha alpha))
        (f ~cr ~red ~green ~blue ~alpha)))))
(export cairo_set_source_rgba)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]