This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Using GCC-java as a scripting language on top of C++ - possible?
- From: Bryce McKinlay <bryce at mckinlay dot net dot nz>
- To: Asfand Yar Qazi <gcc-java at asfandyar dot cjb dot net>
- Cc: java at gcc dot gnu dot org
- Date: Tue, 21 Oct 2003 11:35:59 +1300
- Subject: Re: Using GCC-java as a scripting language on top of C++ - possible?
- References: <3F91C156.9030701@asfandyar.cjb.net>
On Oct 19, 2003, at 11:40 AM, Asfand Yar Qazi wrote:
I want to use gcj as a scripting language on top of a c++-written
engine: is this possible?
I don't know what you mean by "scripting language", but if you mean
putting a Java wrapper around some existing C++ classes, then yes,
sure!
Assuming the ABIs are compatible, I'm assuming I just need to find a
way to generate java source files from C++ header files, and I'll be
able to use the C++ classes as normal java classes (for simple things,
anyway - no deriving, probably.)
I'm prepared to write java interfaces for the C++ classes manually, if
necessary.
You can't generate a Java interface automatically from C++ headers. The
ABIs for C++ and Java are compatible such that code in each of the two
languages can interoperate, but you can't call a non-Java C++ class
directly from Java. For one thing, not all C++ types are available in
Java.
The way to do this is to define an interface into your native code in
terms of "native" methods in a Java class, then implement those methods
in C++ such that they wrap your C++ classes.
Basically, with CNI, Java classes can be used as if they were C++
classes - but not vice-versa!
Regards,
Bryce.