Hello, Sorry for the long winded questions... I was wondering if someone could point me to any example example on how to set/get arrays in C from lisp ? I am using CFFI and Swig. currently I have only primitive interface functions that pass pointers and floats. I am thinking of three array cases. I'm a bit of a beginner here, so please bear with me - the existing documentation is not completely clear (to me, as a lisp beginner :-)..<div>
<br><div><div><div><br></div><div>1) the C function allocates an array (as a side effect) and passes back a pointer to array to lisp . I would later have to free memory for this array explicitly.</div><div><br></div><div>
2) the lisp function allocates an array and passes a pointer to the "C" function, The C function modifies the array. In this case lisp would be allocating the array. Side question: Do I need to use CFFI in lisp to allocate the array ? - or can this be done transparently by the lisp dynamic typing when the array variable is bound ?</div>
</div><div><br></div><div>3) I have several simple C functions that return smaller arrays (like [ x, y, z], where x,y,z = float or integer.). Would be nice to be able to pass by value as a return value on the stack, but I am not sure how to handle this from C to lisp. Example: </div>
<div><br></div><div>C function:</div><div><br></div><div>Color getColorValue ( Image *image, x, y), Where color is a array triplet [r, g, b],, could be floats or ints depending...</div><div><br></div><div>Desired lisp function:</div>
<div><br></div><div>(let ((color (get-color-value image x y))</div><div> ; then do something with list "color</div><div><br></div><div>4) unrelated question...maybe this should be posted to swig list (but i am not sure if there are any active CFFI users in that group).</div>
<div>Is there an easy way to automatically create lisp-style function names ?</div><div><br></div><div>For example:</div><div><br></div><div>swig generates:</div><div><br></div><div><div>(cffi:defcfun ("frameHeight" frameHeight) :int</div>
<div> (frame :pointer))</div></div><div><br></div><div>I would like to generate translate the C function name to "frame-height" (to make it more of a lisp style).</div><div><br></div><div>I tried using</div><div>
<br></div><div>%rename frameHeight frame-height </div><div><br></div><div>in the swig. ".i" file template, but that doesn't seem to work. The notes in the documentation on "lispify" I am not at the stage where I understand it.</div>
<div><br></div><div>I thought that some google searches would turn up some canonical examples or tutorials on this, but there are not many (except the curl example - and it makes me wonder how many people are actually using it :-)</div>
<div><br></div><div>thanks again,</div><div><br></div><div>K</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div>