[Ecls-list] Easy way to bind c++ class instances in lisp?

Matthew Mondor mm_lists at pulsar-zone.net
Thu Dec 6 23:56:37 UTC 2012


On Fri, 7 Dec 2012 00:32:02 +0100
Peter Enerccio <enerccio at gmail.com> wrote:

> I am looking for easy way of wrapping around class instances of c++. I can
> wrap it in lisp with classes with slot containing fixnum of the pointer and
> then recast it in c++ but its cumberstone and has lot of boiler plate on
> both lisp and c++ side. Any other way of doing that? Could be even in lisp
> altogether, because then I could generate c code out of it or something.

The SI:FOREIGN-DATA ECL type (corresponding to the
FFI:C-INLINE :POINTER-VOID type, as well as to the C functions
ecl_to_pointer()/ecl_make_pointer()) are probably safer than using a
fixnum to store foreign data pointers.  A fixnum has some bits reserved
for type annotation.

It probably would be possible to develop an FFI wrapper around C++
classes, although it might mean some work.  ECL FFI:C-LINES and
FFI:C-INLINE allow to use arbitrary C code inline in CL code.  Accessor
functions using such C code could also be declaimed inline, in which
case the interpreter will call the function, but the compiler allowed
to inline calls in the target C code with speed=3.

Although incomplete, a work in progress example of an ECL specific FFI
system using these facilities is at
http://cvs.pulsar-zone.net/cgi-bin/cvsweb.cgi/~checkout~/mmondor/mmsoftware/cl/test/mmffi.lisp?content-type=text%2Fplain
With an also incomplete SDL layer example using it:
http://cvs.pulsar-zone.net/cgi-bin/cvsweb.cgi/~checkout~/mmondor/mmsoftware/cl/test/mmffi-sdl.lisp?content-type=text%2Fplain

Inside the ECL source itself, there also is an UFFI compatibility layer
using those facilities.
-- 
Matt




More information about the ecl-devel mailing list