<div class="gmail_quote">On Sat, Aug 27, 2011 at 4:10 PM, Luís Oliveira <span dir="ltr"><<a href="mailto:luismbo@gmail.com">luismbo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Sat, Aug 27, 2011 at 7:39 PM, Liam Healy <<a href="mailto:lhealy@common-lisp.net">lhealy@common-lisp.net</a>> wrote:<br>
>> What kind of translation do you need these methods to do on<br>
>> FOREIGN-STRUCT-TYPE?<br>
>><br>
> They should take the lisp object, allocate the foreign structure, then<br>
> define the slots correctly (recursively if necessary), and return the<br>
> pointer.  For the return pointer, they should read the contents and generate<br>
> the lisp equivalent.  I suppose the calls to libffi functions should invoke<br>
> translate-*-foreign just like it now invokes the functions on the properties<br>
> fsbv::foreign-object-components and fsbv::setf-foreign-object-components.<br>
<br>
</div>That seems to fit the translation-*-foreign pretty well. Moreover, it<br>
seems like there should be no default conversion, i.e., you could pass<br>
structures by value using the same code you currently use for passing<br>
structures by reference:<br>
<br>
  (with-foreign-object (foo 'some-struct-type)<br>
    (bar foo))<br>
<br>
The only difference is that BAR's first argument would be defined to<br>
be a structure argument passed by value. It's a bit subtle. Not sure<br>
how sensible it would be. An alternative would be represent structure<br>
values (as opposed to structure pointers) using some kind of wrapper<br>
object. Any thoughts?<font color="#888888"><br></font></blockquote><div><br>So you're suggesting retaining the :constructor and :deconstructor arguments to defcstruct?    It seems like a custom translate-*-foreign may be more compatible with existing CFFI, though I guess a compatibility expansion might be convenient.<br>

<br>For a default conversion assuming a structure on the lisp side, I'm not sure how to iterate over the structure.  Maybe MOP has something?  I do have iterate-foreign-structure.   If I assume a list or vector on the lisp side, then I could iterate through it.  <br>

<br>If I define a specializer for a particular cstruct, what should the class be?  This looks like a type name, not the actual object that's passed as the second argument 'type, so I presume it should be an eql specializer on the name, but I admit I'm getting confused by this.  In any case I think the :class option to defcstruct won't always work because it does a defclass, I need something like :existing-class that would just do a find-class.<br>

<br>Does any of this make sense?<br><br>Liam<br><br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><font color="#888888">
--<br>
</font><div><div></div><div class="h5">Luís Oliveira<br>
<a href="http://r42.eu/%7Eluis/" target="_blank">http://r42.eu/~luis/</a><br>
</div></div></blockquote></div><br>