[cffi-devel] Calling Lisp Function from C: How to declare this function in C land ?

Stelian Ionescu sionescu at cddr.org
Sat Sep 22 21:18:46 UTC 2012


On Sat, 2012-09-22 at 21:27 +0200, Frank Goenninger wrote:
> (also posted to comp.lang.lisp)
> 
> Hi all:
> 
> I have a lisp image that contains the following functions:
> 
> (defun frgo (a)
>   (format *debug-io* "~%~A~&" a)
>   (values))
> 
> (cffi:defcallback frgo_helper :void ((a-cstr :string))
>   (frgo (cffi:foreign-string-to-lisp a-cstr)))
> 
> In a C dynamic library I have:
> 
> * file frgo_c.h:
> 
> extern void frgo_helper( char * a );
> 
> * file frgo_c.c:
> 
> void frgo( char * a )
> {
>   frgo_helper( a );
> }
> 
> Now, the library does not compile - undefined symbol _frgo_helper() ! 
> 
> How do I make functions "known" to C land that are purely defined as
> callbacks in Lisp land? 

You can't do that directly. Lisp callbacks must be passed to the C code
as function pointers. You could write a C wrapper that calls the
callback through a global variable and have the Lisp-side store the
address of the callback in that variable.

-- 
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.
http://common-lisp.net/project/iolib

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20120922/44093513/attachment.sig>


More information about the cffi-devel mailing list