www.digitalmars.com         C & C++   DMDScript  

D - SWIG for D

reply "Walter" <walter digitalmars.com> writes:
I am reposting Benji's message in a new thread:

---------------------------------------------------------------
Holy cow. I just downloaded the SWIG sources and I've been looking around at
what it would take to write a SWIG extension for D. And this is the answer:

NOT VERY MUCH

In order to customize SWIG for any given language, there is only one source
file

it's a
file called "csharp.cxx". Each of these files is moderately complex. The
java
file, with all of the comments and newlines stripped out, is about 1400
lines of
code (in C++). The csharp file is about 1600 lines.

That's not very much code.

Plus, I'm guessing that much of the code for the D extension would look an
awful

from the existing implementation.

However, this project is not for the faint of heart. Even if it only
requires
writing 1500 or so lines of code, the author will have to have a pretty good
command of C++ (I'm already out of the running) and an excellent
understanding
of D semantics (that eliminately most of us).

But, on the upside, once it's done we'll have access to millions of lines of
C++
code to use as imports and libraries for our own projects. I'm just giddy at
the
notion that we could suddenly have access to the entire wxWindows library,
after
writing only 1500 lines of code.

--Benji Smith
Sep 18 2003
parent reply Ant <Ant_member pathlink.com> writes:
Who is takening this SWIG project?
This is too exciting to let it fade out.

I'm on the same category as Benji (not enough C++),
But here we differ is that that want stop me from give it a try
(and maybe more free time...).
I'm still working for DUI and DPQ because I can see the
first beta version for them (this weekend, next?)
and I'm getting a bit tired to have 3 projects going.
If you see an announcement for those betas and nobody
else declared to taking on SWIG you can consired that I
have.

D will have two big names:
- Walter for creating it
- <someone> for opening it to the world with SWIG

If SWIG really works for us is there any reason at all
for keep using C/C++!? (ok, ok not serious)

Soon all other languages will be "D"eprecated...
(see previous note)

SWIG was referenced on the NG back in march (before I 
was a regular here).

I'm copying the conversation.

Ant



Subject:      SWIG can provide C++ class wrapping and header import.
From:         Ilya Minkov <midiclub 8ung.at>
Newsgroups:   D
Date:         Fri, 07 Mar 2003 00:50:04 +0100

http://www.swig.org/exec.html

Is probably worth taking a look.

This utility has been developed to allow to use native-compiled 
libraries written in C and C++ from scripting languages. It has a 
powerful parser which deals with any imaginable problem, and currently 
has export modules not only for scripting languages such as Python, 
Perl, and others, but also to statically typed languages such as Java 
and OCaml.

I can see 2 uses for it - first, to generate D import units, including 
the code to wrap C++ classes into D classes (dunno whether it actually 
works), and OTOH to allow scripting languages to use D libraries.

It has more than 7 years of development in it - and a lot of thought. 
Definately more than i could spend for a similar project. :) It handles 
all the things which are not at all trivial. Overwhelming.

-i.

Subject:      Re: SWIG can provide C++ class wrapping and header import.
From:         Bill Cox <Bill_member pathlink.com>
Newsgroups:   D
Date:         Fri, 7 Mar 2003 03:21:41 +0000 (UTC)


We use it for our TCL scripting.  I'm currently stuck on a problem, though.  I 
haven't been able to figure out how to pass variable parameters to my 
routines so I can deal with options.

We may have to drop it, if it get's in the way of parameter parsing, but for 
the most part, it's been very useful.  I'm sure a D version will be available 
soon enough.  They seem to add support for just about everything.

Bill


Subject:      Re: SWIG can provide C++ class wrapping and header import.
From:         Mark Evans <Mark_member pathlink.com>
Newsgroups:   D
Date:         Fri, 7 Mar 2003 01:41:14 +0000 (UTC)

SWIG is a fantastic tool and well-known in the scripting world, e.g. for
interfacing C++ GUI libraries to alien tongues.  It even supports O'Caml!

Only in the case of Python would I recommend an alternative, the Boost Python
Library, and then only because BPL is custom-made for Python.

SWIG support for D is a good idea.  Still...I wonder a bit.  D is already so
close to C/C++ that interfacing should be built directly into the language.  To
an extent it is; D can invoke C code directly.  Yet it cannot invoke C++ code,
that is the lack.

Walter might be able to cook up something in the special case when the C++ code
is compiled by DMC++.  What intrigues me here is the concept of porting C++ code
to D.  That seamless capability would make porting C++ to D much easier, and
would be a good selling point to people with an interest in D but much legacy
C++ code on their hands.

Mark
Sep 19 2003
parent reply Andy Friesen <andy ikagames.com> writes:
Ant wrote:

 Who is takening this SWIG project?
 This is too exciting to let it fade out.
hm. Benji Smith wasn't kidding. This really *is* easy. I have a module thing that creates bindings for a (blessedly) mythical hybrid Either I'll (likely) have this done before the weekend is through, or someone will beat me to it. Either way is fine by me. ;) -- andy
Sep 19 2003
parent reply Benji Smith <dlanguage xxagg.com> writes:
In article <bkgr9b$bkl$1 digitaldaemon.com>, Andy Friesen says...
hm.  Benji Smith wasn't kidding.  This really *is* easy.  I have a 
module thing that creates bindings for a (blessedly) mythical hybrid 


Either I'll (likely) have this done before the weekend is through, or 
someone will beat me to it.  Either way is fine by me. ;)
That's awesome. I hope you get something working that we can all use within a pretty short period of time. I assume that you're working with the code from the 1.3.19 release (available on their download site). And that's a good thing, because it's an official release, and it actually compiles. However, from what have been lots of changes made to the core sources and the language modules since then. Following his advice, I checked the most recent sources out of CVS, but I couldn't get them to compile on my machine. So we should stay away from the CVS sources until they hit their next release (in a month or two). However, there may be some work involved in updating the D module when the next swig release is finished. Are you willing to be the SWIG guy? Are you willing to field bug reports and maintenance for the D swig module for the next six months or so? If so, when the repository site is ready, I'll make you the project owner for the D swig project. And, if Andy isn't able to take on that responsibility, is there someone else who can? --Benji Smith
Sep 20 2003
next sibling parent reply Andy Friesen <andy ikagames.com> writes:
Benji Smith wrote:
 That's awesome. I hope you get something working that we can all use within a
 pretty short period of time. 
You bet. http://ikagames.com/andy/d/swig-with-d.tar.bz2 Precompiled win32 binary included. Unix people are encouraged to do the configure && make dance. It's pretty nasty, and not tested very well, but my head is about to implode from the sheer effort required just to get the stupid thing to compile with the addition of dmd.cxx (remember kids, friends don't let friends use .cxx for C++ source)
 I assume that you're working with the code from the
 1.3.19 release (available on their download site). And that's a good thing,
 because it's an official release, and it actually compiles. However, from what

 have been lots of changes made to the core sources and the language modules
 since then. Following his advice, I checked the most recent sources out of CVS,
 but I couldn't get them to compile on my machine. So we should stay away from
 the CVS sources until they hit their next release (in a month or two).
 However, there may be some work involved in updating the D module when the next
 swig release is finished. Are you willing to be the SWIG guy? Are you willing
to
 field bug reports and maintenance for the D swig module for the next six months
 or so?
Sounds good to me.
Sep 20 2003
next sibling parent reply Ant <Ant_member pathlink.com> writes:
In article <bkj34t$gte$1 digitaldaemon.com>, Andy Friesen says...
You bet.  http://ikagames.com/andy/d/swig-with-d.tar.bz2
I guess you mean http://ikagames.com/andy/d/swig-with-dmd.tar.bz2
Precompiled win32 binary included.  Unix people are encouraged to do the 
configure && make dance.
make fails. quick changes just to make it run: 1 - get Andy's SWID for D 2 - remove the .deps directories in Source/* 3 - add dmd to the lib-languages variable in Makefile.in line 298/299 thanks Andy. Ant
Sep 20 2003
parent reply Andy Friesen <andy ikagames.com> writes:
Ant wrote:
 
 I guess you mean
 
 http://ikagames.com/andy/d/swig-with-dmd.tar.bz2
 
 make fails. quick changes just to make it run:
 
 1 - get Andy's SWID for D
 2 - remove the .deps directories in Source/*
 3 - add dmd to the lib-languages variable in Makefile.in line 298/299
Fixed. (I hope) Thanks! -- andy
Sep 20 2003
parent reply Ant <Ant_member pathlink.com> writes:
In article <bkjbqh$1fjt$1 digitaldaemon.com>, Andy Friesen says...
Ant wrote:
 
 I guess you mean
 
 http://ikagames.com/andy/d/swig-with-dmd.tar.bz2
 
 make fails. quick changes just to make it run:
 
 1 - get Andy's SWID for D
 2 - remove the .deps directories in Source/*
 3 - add dmd to the lib-languages variable in Makefile.in line 298/299
Fixed. (I hope)
Sorry, my fault, by "directories" instead of "directory" I meant all ".deps" in the Source tree: Source |-- Source/CParse | `-- Source/CParse/.deps |-- Source/DOH | `-- Source/DOH/.deps |-- Source/Include |-- Source/Modules | `-- Source/Modules/.deps |-- Source/Preprocessor | `-- Source/Preprocessor/.deps `-- Source/Swig `-- Source/Swig/.deps (testing now ... configure ... yep, that does it, make is running.) Ant
Sep 20 2003
parent reply Andy Friesen <andy ikagames.com> writes:
Ant wrote:
 Sorry, my fault, by "directories" instead of "directory" I meant
 all ".deps" in the Source tree:
 
 (testing now ... configure ... yep, that does it, make is running.)
 
 Ant
 
Alright, fixed. -- andy
Sep 21 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
I dont know if its just me, but my version of Internet Explorer tries to
save the file as XXX.tar.tar and not the bz2 interface.  Using winzip on it
gives an error, have to use cygwin and bunzip it.

C

"Andy Friesen" <andy ikagames.com> wrote in message
news:bkm2p9$2njv$1 digitaldaemon.com...
 Ant wrote:
 Sorry, my fault, by "directories" instead of "directory" I meant
 all ".deps" in the Source tree:

 (testing now ... configure ... yep, that does it, make is running.)

 Ant
Alright, fixed. -- andy
Sep 22 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Also it doesnt contain an executable for win32?

C
"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bko436$mat$1 digitaldaemon.com...
 I dont know if its just me, but my version of Internet Explorer tries to
 save the file as XXX.tar.tar and not the bz2 interface.  Using winzip on
it
 gives an error, have to use cygwin and bunzip it.

 C

 "Andy Friesen" <andy ikagames.com> wrote in message
 news:bkm2p9$2njv$1 digitaldaemon.com...
 Ant wrote:
 Sorry, my fault, by "directories" instead of "directory" I meant
 all ".deps" in the Source tree:

 (testing now ... configure ... yep, that does it, make is running.)

 Ant
Alright, fixed. -- andy
Sep 22 2003
parent Andy Friesen <andy ikagames.com> writes:
Charles Sanders wrote:

 Also it doesnt contain an executable for win32?
 
 C
Whoops, it doesn't. Sorry about that. You can grab a prebuilt executable at http://ikagames.com/andy/d/swig-dmd-win32.zip -- andy
Sep 23 2003
prev sibling parent reply Benji Smith <dlanguage xxagg.com> writes:
On Sat, 20 Sep 2003 19:54:19 -0700, Andy Friesen <andy ikagames.com>
wrote:
It's pretty nasty, and not tested very well, but my head is about to 
implode from the sheer effort required just to get the stupid thing to 
compile with the addition of dmd.cxx (remember kids, friends don't let 
friends use .cxx for C++ source)
Did you make all of your changes in just the .cxx file? Having looked at the sources, I got the impression that the file that needed the most changes was actually the .swg file instead. Did you need to make any changes in the .swg files?
 Are you willing to field bug reports and maintenance for the D swig module for
the
 next six months or so?
Sounds good to me.
Thanks!!!!!
Sep 22 2003
parent Andy Friesen <andy ikagames.com> writes:
Benji Smith wrote:

 Did you make all of your changes in just the .cxx file? Having looked
 at the sources, I got the impression that the file that needed the
 most changes was actually the .swg file instead. Did you need to make
 any changes in the .swg files?
Nothing catastrophic. Just little things like swapping 'bool' for 'bit'. I did wind up hacking the heck out of it, but it was more about figuring out how SWIG works than anything else. -- andy
Sep 22 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Benji Smith" <dlanguage xxagg.com> wrote in message
news:bkigq7$2pvo$1 digitaldaemon.com...
 That's awesome. I hope you get something working that we can all use
within a
 pretty short period of time. I assume that you're working with the code
from the
 1.3.19 release (available on their download site). And that's a good
thing,
 because it's an official release, and it actually compiles. However, from
what

there
 have been lots of changes made to the core sources and the language
modules
 since then. Following his advice, I checked the most recent sources out of
CVS,
 but I couldn't get them to compile on my machine. So we should stay away
from
 the CVS sources until they hit their next release (in a month or two).

 However, there may be some work involved in updating the D module when the
next
 swig release is finished. Are you willing to be the SWIG guy? Are you
willing to
 field bug reports and maintenance for the D swig module for the next six
months
 or so? If so, when the repository site is ready, I'll make you the project
owner
 for the D swig project.

 And, if Andy isn't able to take on that responsibility, is there someone
else
 who can?
Even if the D personality module for SWIG only works with the 1.3.19 release, that's good enough. It'll solve our problem for the foreseeable future. Don't need to swing for a home run just yet!
Sep 21 2003