![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Hi Roger,
Roger Dube (2004-03-12 10:56):
> Has anyone tried to interface a Forth-generated DLL to Java so that
> Java can call it?
Not until right now, but it turns out that it is quite doable.
Assuming you have the following Java code
class ForthTest {
public native static int fsquare(int x);
static {
System.loadLibrary("jniforth");
}
public static void main(String args[]) {
System.out.println("2*2=" + fsquare(2));
}
}
you can compile it
javac ForthTest.java
javah -jni ForthTest
and take a look at the newly generated ForthTest.h
So with the following piece of Forth code
: SQUARE ( jni class n -- n )
>R 2DROP R> \ no callbacks to java needed
DUP * ;
AS Java_ForthTest_fsquare 3 EXPORT: SQUARE
PROGRAM jniforth.dll
you can compile the DLL needed to run the program.
CMD> java ForthTest
2*2=4
There is a JNI intro in the Java docs and some tutorials on the web on
JNI can be found, too.
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html
is quite good.
> I hear that Java has specific demands for headers in
> DLL's that it will "talk to", and it would be helpful to know how to
> create such a header or interface. - Roger
You need "fully specified and mangled" names ...
Basically it's Java_package_package_Class_method, and you'll have to
look up what you need to do when overloading native methods :-)
HTH,
s.
-- Stefan Schmiedl +-------------------------------+----------------------------------------+ |Approximity GmbH | EDV-Beratung Schmiedl | |http://www.approximity.com | Am Bräuweiher 4, 93499 Zandt, Germany | |mailto:stefan_at_approximity.com | Tel. (09944) 3068-98, Fax -97 | +-------------------------------+----------------------------------------+ ---------------------------------------------------------------------- sftalk_at_forth.com The SwiftForth programming discussion email list To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com For list command help, send subject "help" to sftalk-request_at_forth.com Message archives are located at http://www.forth.com/archive/sftalk ---------------------------------------------------------------------- This list is a forum for SwiftForth users. For product support and bug reports, please send email to support_at_forth.com ----------------------------------------------------------------------Received on Sat Mar 13 2004 - 02:25:07 PST
This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:12 PST