[Ecls-list] How do I call a C func from ECL when embedded in an app

David Creelman dave at geko.net.au
Wed Jan 11 19:51:08 UTC 2006


On Wed, 2006-01-11 at 18:54 +1100, Dean O'Connor wrote:
> Hi David,
> 
> To my limited understanding, you need to compile your Lisp to use that 
> ffi:def-function stuff. (I may be corrected here :)
> 
> We have a C++ app, with ECL embedded and we make our C functions 
> available to the interpreted Lisp scripts by using ECL C-API function 
> call "cl_def_c_function".
> 
> Probably one of my best sources of examples came from the XChatlisp 
> plugin that uses ECL.
> This C file has good stuff: 
> http://cvs.sourceforge.net/viewcvs.py/xchatlisp/eclplugin/plugin.c?rev=1.20&view=markup
> 
> eg. Xchat uses this:
> 
> cl_def_c_function(str_intern("%XCHAT-LIST-GET"),cl_xchat_list_get,1);
> 
> I use similar, but used c_string_to_object instead of str_intern:
> 
> static cl_object
> My_C_function(cl_object arg1, cl_object arg2)
> {
> 	return Cnil;
> }
> 
> cl_def_c_function((cl_lispunion*)c_string_to_object("MY-FUNCTION"), (cl_lispunion*)My_C_function, 2);
> 
> Note: I forget why I need to typecast to "cl_lispunion*", maybe that is 
> not needed ?
> 
> There are examples in the ECLS CVS file: msvc\c\cinit.c
> Also recently some examples of calling Lisp scripts from multiple C 
> threads was added to CVS, into subdir examples\threads\import.
> Note: The last arg of cl_def_c_function specifies how many args the 
> declared function has. This should match the number of cl_object args of 
> your C function.
> 
> Cheers
> Dean.
> 
> David Creelman wrote:
> 
> >Hi,
> >
> >I'm trying to call a C function from ECL. ECL is embedded into my
> >application (using WinXP).
> >
> >I looked through the mailing list and found something like the following
> >as an example of how to use FFI, but I get an error:-
> >
> >  
> >
> >>(ffi:def-function ("number_plus" number-plus) ((a :int)
> >>    
> >>
> >(b :int)) :returning :
> >int)
> >NUMBER-PLUS
> >  
> >
> >>(number-plus 1 2)
> >>    
> >>
> >The special form c-inline cannot be used in the interpreter.
> >Broken at NUMBER-PLUS.
> >  
> >
> >
> >I chose number-plus since it seemed most likely to be exported and
> >visible within ECL.
> >
> >How do I define a function in C so that it's visible and callable from
> >ECL ? Is this possible without compiling the LISP code ?
> >
> >Looked up the CFFI documentation, but it didn't seem to talk about how
> >to export the functions into ECL.
> >
> >Cheers
> >DC
> >  
> >
> 
Hi Dean,

That worked nicely. Thanks.

Cheers
DC

> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Ecls-list mailing list
> Ecls-list at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ecls-list
-- 
David Creelman
GPG: 11CC 0D54 D37A 4B9C 5C65  AB63 5B18 7F99 7D77 9CA5




More information about the ecl-devel mailing list