I've extended with-foreign-slots to return slot pointers in this fashion (basically I took this macro with minor modifications but named it with-foreign-slots).<br><br>Liam<br><br><div class="gmail_quote">On Thu, Apr 25, 2013 at 10:23 PM, Liam Healy <span dir="ltr"><<a href="mailto:lnp@healy.washington.dc.us" target="_blank">lnp@healy.washington.dc.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div><div class="h5">On Thu, Apr 25, 2013 at 4:33 AM, Chris Bagley <span dir="ltr"><<a href="mailto:chris.bagley@gmail.com" target="_blank">chris.bagley@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 dir="ltr">I ran into similar issues to Willem and have taken to using the following macro:<br><br><div class="gmail_extra">(defmacro with-foreign-slots* ((vars ptr type) &body body)<br> "Create local symbol macros for each var in VARS to reference<br>
foreign slots in PTR of TYPE. Similar to WITH-SLOTS.<br>Each var can be of the form: slot-name - in which case slot-name will<br>be bound to the value of the slot or: (:pointer slot-name) - in which <br>case slot-name will be bound to the pointer to that slot."<br>
(let ((ptr-var (gensym "PTR")))<br> `(let ((,ptr-var ,ptr))<br> (symbol-macrolet<br> ,(loop :for var :in vars :collect<br> (if (listp var)<br> (if (eq (first var) :pointer)<br>
`(,(second var) (foreign-slot-pointer<br> ,ptr-var ',type ',(second var)))<br> (error "Malformed var names must be:~%name~% -or- ~%(:pointer name)"))<br>
`(,var (foreign-slot-value<br> ,ptr-var ',type ',var))))<br> ,@body))))<br><br>This, for me, balances the needs quite nicely and feels in line with the style of cffi. Thoughts or modifications?<br>
</div></div></blockquote></div></div><div><br>I had thought about doing something like this when looking into Willem's problems. I like it, but I think the "*" in the name is unnecessary. It is upwardly compatible with the current with-foreign-slots, isn't it? That is, if it were to replace with-foreign-slots, it would expand correctly for current usage (to values). I think we should replace that macro with this.<span class="HOEnZb"><font color="#888888"><br>
<br>Liam<br></font></span></div></div><br>
</blockquote></div><br>