[cffi-devel] Re: Type translators

Luis Oliveira luismbo at gmail.com
Fri Aug 5 03:27:34 UTC 2005


On 4/ago/2005, at 04:57, James Bielman wrote:
>   ;; IMO the cleanest, but also verbose, using a function
>   ;; that returns the form using backquote:
>   :in (lambda (var value body)
>         `(let ((,var (foreign-string-alloc ,value)))
>            (unwind-protect
>                (progn , at body)
>              (foreign-string-free ,var))))

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

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

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www2.iro.umontreal.ca/~pinard/po/registry.cgi?team=pt




More information about the cffi-devel mailing list