<div dir="ltr"><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">Hi <span style="background-color:yellow">Juanjo</span>,<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">Sorry for being unclear.</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">I am writing a <span style="background-color:yellow">plugin</span> for Rhino3D, a <span style="background-color:yellow">NURBS</span>-based 3-D modeling software.  The <span style="background-color:yellow">plugin</span> makes it possible to script Rhino<span style="background-color:yellow">NURBS</span> models with lisp.</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">When the <span style="background-color:yellow">plugin</span> is used, the following function is called by Rhino:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  <span style="background-color:yellow">CRhinoCommand</span>::result <span style="background-color:yellow">CCommandRhinoLisp</span>::<span style="background-color:yellow">RunCommand</span>(<span style="background-color:yellow">const</span> <span style="background-color:yellow">CRhinoCommandContext</span>& context) {</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">    ...</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  }</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
The parameter 'context' (for which I unsuccessfully substituted 'global_int' in my last email to make things "easier to understand"...) is essential for many of the Rhino functions.  The following, for example, adds a cone object (which has to be initialized before) to a Rhino scene:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  context.m_doc.<span style="background-color:yellow">AddObject</span>(cone_object);</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
I therefore need a way to access 'context' from lisp and thought about implementing this via a global variable which is set in the <span style="background-color:yellow">RunCommand</span>() function.  But for some reason I was not able to overwrite the value of the global variable...</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">Currently I therefore solve the problem as follows:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">In the file where the lisp wrappers are defined I have the following:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">--- rhino-lisp-api.lisp ---</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">(<span style="background-color:yellow">ffi</span>:<span style="background-color:yellow">clines</span> "static <span style="background-color:yellow">CRhinoCommandContext</span> *global_<span style="background-color:yellow">rhinoCommandContext</span> = (<span style="background-color:yellow">CRhinoCommandContext</span> *) NULL;")</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">(<span style="background-color:yellow">defun</span> set-rhino-command-context (context)</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  (<span style="background-color:yellow">ffi</span>:c-<span style="background-color:yellow">inline</span></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
   (context) (:pointer-void) :void</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   "global_<span style="background-color:yellow">rhinoCommandContext</span> = (<span style="background-color:yellow">CRhinoCommandContext</span> *) #0"</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   :one-liner t</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   :side-effects t))</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">(<span style="background-color:yellow">defun</span> get-rhino-command-context ()</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  (<span style="background-color:yellow">ffi</span>:c-<span style="background-color:yellow">inline</span></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
   () () :pointer-void</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   "(void *) global_<span style="background-color:yellow">rhinoCommandContext</span>"</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   :one-liner t</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   :side-effects t))</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">From <span style="background-color:yellow">RunCommand</span>() I call the function <span style="background-color:yellow">setRhinoCommandContext</span>(context) and define the constant '+context+' to refer to the Rhino command context:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><span style="background-color:yellow">CRhinoCommand</span>::result <span style="background-color:yellow">CCommandRhinoLisp</span>::<span style="background-color:yellow">RunCommand</span>(<span style="background-color:yellow">const</span> <span style="background-color:yellow">CRhinoCommandContext</span>& context) {</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  ...</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  <span style="background-color:yellow">setRhinoCommandContext</span>(context);</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  cl_<span style="background-color:yellow">eval</span>(<span style="background-color:yellow">READCL</span>((<span style="background-color:yellow">defconstant</span> +context+ (get-rhino-command-context)</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><span style="white-space:pre-wrap">              </span>  "The Rhino Command Context")));</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
  ...</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">}</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><span style="background-color:yellow">setRhinoCommandContext</span>() is defined as follows:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">static void <span style="background-color:yellow">setRhinoCommandContext</span>(<span style="background-color:yellow">const</span> <span style="background-color:yellow">CRhinoCommandContext</span>& context) {</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  union cl_<span style="background-color:yellow">lispunion</span> cl_context_object;</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  cl_context_object.foreign.t    = t_foreign;</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
  cl_context_object.foreign.tag  = <span style="background-color:yellow">ECL</span>_<span style="background-color:yellow">SYM</span>(":POINTER-VOID",1377);</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
  cl_context_object.foreign.size = 0;</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  cl_context_object.foreign.data = (char*) &context;</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
  cl_object cl_context = &cl_context_object;</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
  cl_<span style="background-color:yellow">funcall</span>(2, c_string_to_object("set-rhino-command-context"), cl_context);</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
}</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">It works, but I wonder if there is a better way to solve this problem?</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">Rather than wrapping the pointer into a cl_object it would be nice to directly define the setter function in the file where the lisp wrappers are defined:</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">--- rhino-lisp-api.lisp ---</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">(<span style="background-color:yellow">ffi</span>:<span style="background-color:yellow">clines</span> "</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">static <span style="background-color:yellow">CRhinoCommandContext</span> *global_<span style="background-color:yellow">rhinoCommandContext</span> = (<span style="background-color:yellow">CRhinoCommandContext</span> *) NULL;</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">static void <span style="background-color:yellow">setRhinoCommandContext</span>(<span style="background-color:yellow">const</span> <span style="background-color:yellow">CRhinoCommandContext </span>&context) {</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  global_<span style="background-color:yellow">rhinoCommandContext</span> = (<span style="background-color:yellow">CRhinoCommandContext</span> *) &context;</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">}</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
")</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">(<span style="background-color:yellow">defun</span> get-rhino-command-context ()</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  (<span style="background-color:yellow">ffi</span>:c-<span style="background-color:yellow">inline</span></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
   () () :pointer-void</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   "(void *) global_<span style="background-color:yellow">rhinoCommandContext</span>"</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   :one-liner t</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">   :side-effects t))</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">At least I would like to avoid <span style="background-color:yellow">hardcoding</span> the integer 1377 corresponding to ":POINTER-VOID" - for example by using some (imagined) function 'pointer_to_cl_object()': </div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">static void <span style="background-color:yellow">setRhinoCommandContext</span>(<span style="background-color:yellow">const</span> <span style="background-color:yellow">CRhinoCommandContext</span>& context) {</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">  cl_<span style="background-color:yellow">funcall</span>(2,</div>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">             c_string_to_object("set-rhino-command-context"),</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
             pointer_to_cl_object((char*) &context));</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">}</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">---</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
But I was not able to find anything similar...</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
Is my explanation more understandable this time?</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.800000190734863px">
Thanks, Dietrich</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jul 14, 2013 at 3:21 AM, Juan Jose Garcia-Ripoll <span dir="ltr"><<a href="mailto:juanjose.garciaripoll@gmail.com" target="_blank">juanjose.garciaripoll@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"><div class="gmail_extra"><div class="im"><br><div class="gmail_quote">On Sat, Jul 13, 2013 at 5:31 PM, Dietrich Bollmann <span dir="ltr"><<a href="mailto:dietrich@formgames.org" target="_blank">dietrich@formgames.org</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">But when evaluating (test) before and after the value is changed, in both cases the original value is printed</blockquote>


</div><br></div>You cooked up a very nice and complex example and leave out the most relevant part which is where you use the lisp code. How does this code look like?<span class="HOEnZb"><font color="#888888"><br><br clear="all">
<div><br></div>-- <br>Instituto de Física Fundamental, CSIC<br>

c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://juanjose.garciaripoll.googlepages.com" target="_blank">http://juanjose.garciaripoll.googlepages.com</a>
</font></span></div></div>
</blockquote></div><br></div>