Re: Calling back from FLI to Lisp
I do exactly what you describe in my interface to OpenRM; the pointer
is an integer used to associate objects on the Lisp side.
In my case I used CFFI. This method worked just fine using Lispworks.
However SBCL would core after a while. The probability of coreing in
SBCL increased considerably if I printed debug information within the
callback, or if objects are removed from a hash table within the
callback.
-Luke
On Feb 22, 2013, at 22:21, Camille Troillard <camille@osculator.net> wrote:
>
> Thank you Ron, I appreciate your help!
> FLI:DEFINE-FOREIGN-CALLABLE is already what I use to define a callback that I pass to a C function as a parameter.
>
> I realize my question was not clearly formulated:
>
> I have found no way to associate a callback (or rather, a "foreign-callable") with specific data from my code, other than using the "user info" pointer that most of those callbacks provide.
>
> The problem with this pointer is that you can obviously not pass it any lisp object, you have to choose an integer number that you associate with your Lisp object and pass it as the "user info". Then when foreign code calls back in, reconnect it to a Lisp object by looking up the integer value you receive in the callback.
>
> Foreign-callable functions are defined as top-level forms, you cannot define them on the fly. If foreign-callables were able to capture local state of my program (like a closure), the solution would be trivial.
>
> I would like to know how LispWorks users deal with this situation when they need to associate more than one context with a single foreign callback.
>
>
> Best,
> Cam
>
>
> On 22 févr. 2013, at 23:12, Ron Lund <rlund@secureoutcomes.net> wrote:
>
>> While researching a problem of my own I came across a reference to a LispWorks
>> FLI function which may be what you're looking for with the issue in this email of yours.
>>
>> It's in the FLI reference, "define-foreign-callable"
>
>
>
>> On 2/21/2013 11:03 AM, Camille Troillard wrote:
>>> Hi,
>>>
>>> Here is a problem with the foreign language interface I haven't got to solve properly and was hoping that someone has a solution.
>>>
>>> I need to dispatch a foreign callback into my Lisp code. The only information I have is a "user info" pointer I can set when creating the underlying data structure, more specifically [1]:
>>>
>>> CVReturn MyDisplayLinkCallback (
>>> CVDisplayLinkRef displayLink,
>>> const CVTimeStamp *inNow,
>>> const CVTimeStamp *inOutputTime,
>>> CVOptionFlags flagsIn,
>>> CVOptionFlags *flagsOut,
>>> void *displayLinkContext
>>> );
>>>
>>>
>>> displayLinkContext is the pointer to the data I provided when creating a display link.
>>>
>>> I would like to be able to create several display links with different callbacks, so I need to be able to make the difference between two callbacks. The only solution I see is to maintain a hash-table of identifiers paired with my lisp objects, and pass that identifier to the display link creation function.
>>>
>>> It seems like I could use FLI wrappers, but I don't totally understand how they work and how they would make it easier for me.
>>>
>>> How would do to efficiently get back a lisp object from a callback like this?
>>>
>>>
>>> Best,
>>> Cam
>>>
>>>
>>> [1] http://developer.apple.com/library/mac/#documentation/QuartzCore/Reference/CVDisplayLinkRef/Reference/reference.html
>
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> http://www.lispworks.com/support/lisp-hug.html
>
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html