[Ecls-list] Embedding/ffi question

Seth Burleigh seth at tewebs.com
Fri Jun 25 06:15:49 UTC 2010


I dont know if this is the correct way to do it (or even if it works!),
but maybe you can do something like this (or you can try using callbacks
with the cffi library, does this work for ecl?) Once it works you can
actually 'wrap' a callback in a macro in a much more convenient way.

in one file together:

(ffi:clines
"
#include <ecl/ecl.h>
void my_callback (char* data) {

cl_funcall(c_string_to_object("MY-PACKAGE:MY-CALLBACK"),c_string_to_object(data));
}
")

(defun init-osc (port) 
  (cin "init_osc(#0,my_callback)" :int port))
(defun my-callback (string)
  ;;do something
)

You may want to look at the wiki to better understand what im suggesting
http://ecls.wikispaces.com/Easier+Embedding
http://ecls.wikispaces.com/Recipes

If  your using inline c, dont bother using slime for that part, it wont
pass through any c errors you receive from the inline c, which makes
debugging very hard. 

Then while  your at it set
(setf c:*user-ld-flags* '("-lio" "-L/location/of/lib/"))
and everything you compile will be linked with our library (so your cin
form above will work)

  




	
  
On Thu, 2010-06-24 at 22:31 -0700, Neil Baylis wrote:
> I'm making a program that receives messages from the iPhone App
> touchOSC. These messages are packaged into UPD datagrams. 
> 
> 
> There's an open-source library (liblo) that handles the details of
> receiving the UDP messages and decoding the OSC protocol.
> 
> 
> I want to make a c library that's callable from lisp. I was thinking
> of the following three functions, which capture everything I need for
> this project:
> 
> 
> void init_osc(int port, void(*callback)(char* data));
> 
> 
> void osc_done(void);
> 
> 
> init_osc() would be called to initialize liblo. It takes a port
> number, which is the port that liblo should listen on, and a function
> pointer. When liblo receives an OSC message, it will call this
> callback, passing it an ordinary c string representation of the
> message.
> 
> 
> This callback will be made in the context of a thread spawned by liblo
> during the init_osc() call.
> 
> 
> The other function osc_done() would be called when the program is
> exiting, to do any cleanup the library needs.
> 
> 
> 
> 
> Now to my question: Will this work? Is it possible for this liblo
> thread to call into my lisp program, passing a string?
> 
> 
> If no, what's a better way to do this?
> 
> 
> If yes, what syntax do I use to set up the callback?
> 
> 
> 
> 
> Thanks,
> 
> 
> Neil
>  
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate 
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
> lucky parental unit.  See the prize list and enter to win: 
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________ Ecls-list mailing list Ecls-list at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ecls-list






More information about the ecl-devel mailing list