[Ecls-list] Lisp callback from C

Goffioul Michael goffioul at imec.be
Tue Aug 23 05:18:57 UTC 2005


> -----Original Message-----
> From: der_julian at web.de [mailto:der_julian at web.de]
> Sent: Tuesday, August 23, 2005 13:49
> To: Goffioul Michael
> Subject: Re: [Ecls-list] Lisp callback from C
> 
> 
> On Tue, 23 Aug 2005 13:04:59 +0200
> "Goffioul Michael" <goffioul at imec.be> wrote:
> 
> [Callbacks in my X-Chat plugin]
> > Do you think about a possible integration into ECL?
> 
> The implementation is quite hackish in nature and relies on X-Chat
> passing an (void *) argument to all handlers which I use to identify
> the CL function to call.
> 
> I doubt this is a very useful facility for general use. :)

It would be nice then to think about how to implement it into ECL.
The first things that come to my mind are (concept code):
- let's take a simple example of
	(def-callback cb-plus ((a :int) (b :int)) :returning :int
	  (+ a b))
- this should be converted into a pure LISP function like:
	(defun <some-name> (a b)
	  (+ a b))
  which is compiled, possibly making use of (declare (si::c-local))
  (indeed, in ECL, we cannot build C/LISP interaction without compilation)
- a C wrapper should also be written, like
	int cb_plus(int a, int b) {
	  return object_to_integer(<some-name>(make_integer(a), make_integer(b)));
	}
- a foreign pointer can be constructed to get a reference to the callback
	ecl_make_foreign_data(@:void, 0, cb_plus)

I have the impression that all the needed parts are already present in the
compiler, but it requires some user-level interface and compiler hacking.

These are just raw ideas.

Michael.




More information about the ecl-devel mailing list