[Openmcl-devel] Calling a callback & closures

Gary Byers gb at clozure.com
Mon May 2 22:43:17 PDT 2005



On Mon, 2 May 2005, David Steuber wrote:

>
> The idea is to make a callback that uses a closure to associate the function 
> pointer with a CLOS object that can then be used by the callback function. 
> This would get rid of an ugly hack in some Carbon event handler code I have 
> and also allow me to abstract the notion of Carbon callbacks as other APIs 
> want different callbacks with different function signatures (in the C sense 
> of the word).
>

If you want to associate a CLOS object with a particular (foreign) function
pointer, that seems fairly straightforward:

(defun make-callback-with-object (thing)
   (let ((fn))
     (declare (special fn))
     (defcallback fn (:int arg :int) ; for instance
       (some-random-method thing arg)
       (slot-value thing 'whatever))
     fn))




More information about the Openmcl-devel mailing list