[cffi-devel] Re: Type translators

James Bielman jamesjb at jamesjb.com
Fri Aug 5 03:31:08 UTC 2005


Luis Oliveira <luismbo at gmail.com> writes:

> After trying to implement this and realizing some of my assumptions
> were incorrect (eg. (symbol-)macrolet for &$var won't work, I'd need
> to search for it in the form) I got to these two syntaxes:
>
>    (define-type-translation string :pointer
>      "Translation between C and Lisp strings."
>      :to-c-arg
>      (lambda (var value body)
>        `(with-foreign-string (,var ,value)
>           , at body))
>      :to-c
>      (lambda (value)
>        `(foreign-string-alloc ,value))
>      :from-c
>      (lambda (value)
>        `(foreign-string-to-lisp ,value)))

Honestly, I like the explicit lambdas here.  It's not that much
more verbose and it makes things pretty clear IMO.

>
>    (define-type-translation string :pointer
>      "Translation between C and Lisp strings."
>      (:to-c-arg (var value body)
>                 `(with-foreign-string (,var ,value)
>                    , at body))
>      (:to-c (value)
>             `(foreign-string-alloc ,value))
>      (:from-c (value)
>               `(foreign-string-to-lisp ,value)))
>
> Preferences and/or comments anyone?

James



More information about the cffi-devel mailing list