Clisp and FFI's to C++ 
Author Message
 Clisp and FFI's to C++

I've been looking at FFI documentation in various implementations and all of
them seem to be 1) different and 2) not easy to implement.

Looked at the UFFI package to resolve this but that brings it down to the
LCD.

Is there a way to access and manipulate C++ classes/objects directly from
within Clisp/CMUCL? If yes, can someone give a decent example and if no,
how much effort would it take to write one??? Any ideas?

Thanks in advance

~sp



Sat, 30 Jul 2005 02:28:47 GMT  
 Clisp and FFI's to C++

Quote:

> I've been looking at FFI documentation in various implementations and all of
> them seem to be 1) different and 2) not easy to implement.

> Looked at the UFFI package to resolve this but that brings it down to the
> LCD.

> Is there a way to access and manipulate C++ classes/objects directly from
> within Clisp/CMUCL? If yes, can someone give a decent example and if no,
> how much effort would it take to write one??? Any ideas?

No, there's not.  C linkage is easy.  C++ includes all sorts of
horrors like name-mangling, and constant binary incompatabilities.  If
you've been lucky enough to only work in C++ when the system is fixed,
you probably haven't had the chance to appreciate the horror of
changing a minor version of any class library, the g++, or libstdc++.

The easiest thing to do is to write a simple C bridge, and use the FFI
to get to that.

If you really wanted to add basic C++ support to the CMUCL/SBCL alien
interface, it wouldn't be too hard.  The big practical problem would
be that distributed binaries would pretty much only be able to do C++
FFI on the system that built them.  But if you don't mind asking the
user to compile their own to get C++ support, it wouldn't be too bad.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              



Sat, 30 Jul 2005 03:03:18 GMT  
 Clisp and FFI's to C++

Quote:

> Is there a way to access and manipulate C++ classes/objects directly from
> within Clisp/CMUCL?

I doubt that, scince the ABIs of different compilers (and compiler
versions, e.g. GCC 2 vs. GCC 3) differ, so a C++ FFI would have to be
compiler specific.

You'll probably have to create a pure C wrapper first (this is how
Swig, Sip etc. do it, AFAIK).

Then again, I could be wrong.

Regards
Henrik



Sat, 30 Jul 2005 03:10:16 GMT  
 Clisp and FFI's to C++
Thats what I thought. And I really dislike C++.


Quote:

> > Is there a way to access and manipulate C++ classes/objects directly
from
> > within Clisp/CMUCL?

> I doubt that, scince the ABIs of different compilers (and compiler
> versions, e.g. GCC 2 vs. GCC 3) differ, so a C++ FFI would have to be
> compiler specific.

> You'll probably have to create a pure C wrapper first (this is how
> Swig, Sip etc. do it, AFAIK).

> Then again, I could be wrong.

> Regards
> Henrik



Sat, 30 Jul 2005 03:59:36 GMT  
 Clisp and FFI's to C++
The main purpose is trying to integrate the wxWindows API with an open
source lisp, preferably clisp (seems like the most portable).

http://sourceforge.net/projects/wxlisp/

Might have to write a C wrapper around it.

Thanks

~sp



Quote:

> > I've been looking at FFI documentation in various implementations and
all of
> > them seem to be 1) different and 2) not easy to implement.

> > Looked at the UFFI package to resolve this but that brings it down to
the
> > LCD.

> > Is there a way to access and manipulate C++ classes/objects directly
from
> > within Clisp/CMUCL? If yes, can someone give a decent example and if no,
> > how much effort would it take to write one??? Any ideas?

> No, there's not.  C linkage is easy.  C++ includes all sorts of
> horrors like name-mangling, and constant binary incompatabilities.  If
> you've been lucky enough to only work in C++ when the system is fixed,
> you probably haven't had the chance to appreciate the horror of
> changing a minor version of any class library, the g++, or libstdc++.

> The easiest thing to do is to write a simple C bridge, and use the FFI
> to get to that.

> If you really wanted to add basic C++ support to the CMUCL/SBCL alien
> interface, it wouldn't be too hard.  The big practical problem would
> be that distributed binaries would pretty much only be able to do C++
> FFI on the system that built them.  But if you don't mind asking the
> user to compile their own to get C++ support, it wouldn't be too bad.

> --
>            /|_     .-----------------------.
>          ,'  .\  / | No to Imperialist war |
>      ,--'    _,'   | Wage class war!       |
>     /       /      `-----------------------'
>    (   -.  |
>    |     ) |
>   (`-.  '--.)
>    `. )----'



Sat, 30 Jul 2005 03:58:11 GMT  
 Clisp and FFI's to C++

Quote:

> The main purpose is trying to integrate the wxWindows API with an open
> source lisp, preferably clisp (seems like the most portable).

> http://sourceforge.net/projects/wxlisp/

> Might have to write a C wrapper around it.

Good luck, but it's probably harder than you think.  Unless I'm
mistaken, wxWindows wants to hold the main driver loop for the
program, and calls back into your code.  Most Lisp implementations
want to be the main driver loop.  Because of this, you probably won't
be able to just make FFI bindings to wxWindows.  You might try an
approach like CLM (CL bindings for Motif), where you'd have a
wxWindows server application that the Lisp process would talk to along
a pipe, allowing both processes to have "the" main loop.
Incidentally, this would also make portability between Lisp
implementations a breeze.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              



Sat, 30 Jul 2005 04:24:06 GMT  
 Clisp and FFI's to C++

Quote:

> The main purpose is trying to integrate the wxWindows API with an open
> source lisp, preferably clisp (seems like the most portable).

> http://sourceforge.net/projects/wxlisp/

Good luck! That would surely be a nice thing to play with.

Quote:
> Might have to write a C wrapper around it.

It should be possible to re-use the wrappers other bindings,
e.g. wxPython, use, the problems with interfacing C++ are not
Lisp-specific, after all.

IIRC, the KDE guys provide a C-wrapper for all of QT, maybe there is
something like that for wxWindows, too?

Regards
Henrik

P.S.: Please don't fall in the same trap as wxPython and mimic the C++
      API too closely (for example, wxPython spells EVT_MENU etc. all
      in uppercase because they are macros in C++. There are no macros
      in Python, they are just a plain functions. It just feels
      weird.) Your users will be Lispers, and propably don't like C++
      too much, either.



Sat, 30 Jul 2005 04:27:25 GMT  
 Clisp and FFI's to C++

Quote:

> The main purpose is trying to integrate the wxWindows API with an open
> source lisp, preferably clisp (seems like the most portable).

> http://sourceforge.net/projects/wxlisp/

> Might have to write a C wrapper around it.

I have something like this going already, an unreleased project called
wxcl.

No time to work on it, though. It's quite boring, going class by class
and wrapping it up.

So far I can put up a main frame, with a few basic controls: menu bar,
button, text.

Messages originating from the controls are mapped to CLOS methods.

I should release the source to let others hack on it. :)



Sat, 30 Jul 2005 06:11:07 GMT  
 Clisp and FFI's to C++

Quote:


> > The main purpose is trying to integrate the wxWindows API with an open
> > source lisp, preferably clisp (seems like the most portable).

> > http://sourceforge.net/projects/wxlisp/

> I have something like this going already, an unreleased project called
> wxcl.

   CL bindings to wxWindows would be most interesting: A portable,
working GUI for Common Lisp.

---
[]s, Andrei de A. Formiga



Sat, 30 Jul 2005 12:40:53 GMT  
 Clisp and FFI's to C++
Do you plan to release the code for it??? Will it be GPL???



Quote:
> > The main purpose is trying to integrate the wxWindows API with an open
> > source lisp, preferably clisp (seems like the most portable).

> > http://sourceforge.net/projects/wxlisp/

> > Might have to write a C wrapper around it.

> I have something like this going already, an unreleased project called
> wxcl.

> No time to work on it, though. It's quite boring, going class by class
> and wrapping it up.

> So far I can put up a main frame, with a few basic controls: menu bar,
> button, text.

> Messages originating from the controls are mapped to CLOS methods.

> I should release the source to let others hack on it. :)



Sun, 31 Jul 2005 04:35:43 GMT  
 Clisp and FFI's to C++

Quote:


> > The main purpose is trying to integrate the wxWindows API with an open
> > source lisp, preferably clisp (seems like the most portable).

> > http://sourceforge.net/projects/wxlisp/

> > Might have to write a C wrapper around it.

> I have something like this going already, an unreleased project called
> wxcl.

Okay, here it is: http://users.footprints.net/~kaz/wxcl-0.tar.gz

Caveats and notes:

- CLISP only, but anticipates portability.
- uses require/provide to glue itself together; these are deprecated language
  features. Some better system construction is needed (mk::defsystem? ...)
- a few common language extensions (weak hashes, finalizers). Weak hashes
  are used to associate CL objects with C++ objects, and finalizers are used
  to destroy the C++ objects when the CL objects become garbage.
- only a very tiny, useless subset of wxWindows is wrapped---if you don't mind
  making a gui that only has menu items, text input controls and simple
  buttons.
- no documentation, and even fewer comments in the code.
- some use of symbolic links in the source tree.



Sun, 31 Jul 2005 04:47:21 GMT  
 Clisp and FFI's to C++

Quote:

>> I have something like this going already, an unreleased project called
>> wxcl.

> Okay, here it is: http://users.footprints.net/~kaz/wxcl-0.tar.gz

Thanks! Seems to be some interesting Lisp-GUI activity going on
lately.

So, we now have the beginnings of a wxWindows binding called wxcl, and
a domain and sourceforge project called wxlisp with no code yet. The
natural thing to do seems to be merging both projects, obviously.

Kaz, you didn't include a license note in your code. You said that you
don't have enough time to work on it, so would it be OK for you to
have Sanjay and hopefully others use it as a starting point for the
sourceforge project? (And, did you have the impression that the way
you started would work to build a usable binding?)

Sanjay, what do you think?

Regards
Henrik



Sun, 31 Jul 2005 06:18:39 GMT  
 
 [ 35 post ]  Go to page: [1] [2] [3]

 Relevant Pages 

1. FFI in CLISP for WIN32

2. Clisp FFI

3. FFI Calls in clisp

4. Clisp FFI

5. CLISP FFI: C enumerations

6. CLISP FFI (win32)

7. FFI for CLISP: UDP sockets

8. FFI for Clisp on PPC (OS X and Fink)

9. Announcement: Header2Scheme 1.3, a C++ FFI generator for Scheme

10. Announcement: Header2Scheme 1.0, a C++ FFI generator for Scheme

11. Announcement: Header2Scheme 1.3, a C++ FFI generator for Scheme

12. Announcement: Header2Scheme 1.2, a C++ FFI generator for Scheme

 

 
Powered by phpBB® Forum Software