[cffi-devel] trying to understand foreign types and translations
rif
rif at MIT.EDU
Thu Jul 6 00:47:20 UTC 2006
> The two arguments to TRANSLATE-TO-FOREIGN are the Lisp object to be
> converted, and the name of the foreign type to convert to. First,
> declare a foreign typedef for :POINTER (since you will ultimately be
> returning a pointer from the type translator) that you use to hang
> your type translator on:
>
> (defctype fnv-double :pointer)
>
> Then you can specialize TRANSLATE-TO-FOREIGN on both the Lisp value
> and the foreign type (using an EQL specializer):
>
> (defmethod translate-to-foreign ((value fnv-double) (name (eql 'fnv-double)))
> (fnv-foreign-pointer value))
>
> It might be confusing to call both the Lisp and foreign types
> FNV-DOUBLE, but it is legal because foreign type names are a separate
> namespace from Lisp types (viva Lisp-N!). It is important to remember
> the distinction between the two though.
>
> > and then declaring something like
> >
> > (defcfun ("foo" :%foo) :double
> > (x fnv-double))
>
> should just work!
>
> (This is untested and I haven't really been doing any CFFI hacking
> lately, so I apologize if I missed something obvious here.)
>
> James
I don't quite understand. fnv-double is NOT a pointer. It's a CL
struct that holds two arguments, one of which is the foreign pointer. I
see I was misusing translate-to-foreign, so maybe I don't need a
defctype at all, just an appropriate translate-to-foreign?
rif
More information about the cffi-devel
mailing list