Rick and All,
Thanks for your help last fall on this issue.
Here is what I did and it works. It was given as a paper at the Asilomar
FORML in 1999.
Contents of the Java main program source file:
// HELLOWORLD.JAVA
import java.io.*;
class HelloWorld {
private native int testOne(int x);
private native int testTwo(int y);
public static void main(String[] args){
System.out.println(new HelloWorld().testOne(5));
System.out.println(new HelloWorld().testTwo(6));
}
static {
System.loadLibrary("HelloWorldF");
}
}
// HELLOWORLD.JAVA - end
Contents of the Forth file to be compiled into a DLL:
\ HelloWorld.f
empty
REQUIRES PROTECTION
include c:\apps\swiftforth\lib\samples\win32\hexcalc.f
: testcall ( n - n2)
3 +
hexcalc
;
variable vtest
: test1 ( 'env 'obj n -- n2 ) 2ROT 2DROP
testcall dup vtest !
Z(.) 1
Z\" Hello World from Forth!\n\t" dup >r zappend
0 r> Z" JNI Project" MB_OK MessageBox
0 vtest @
;
: test2 ( 'env 'obj n -- n2 ) 2ROT 2DROP
10 +
0 swap
;
AS Java_HelloWorld_testOne 3 EXPORT: test1 ( 'env 'obj n -- n2 )
AS Java_HelloWorld_testTwo 3 EXPORT: test2 ( 'env 'obj n - n2 )
PROGRAM HelloWorldF.dll
\ HelloWorld.f - end
Note that the DLL from Forth will contain two methods externally callable by
a Java program
from a class HelloWorld as testOne and testTwo.
This tests the ability of passing parameters in both directions. Any SDIO
stuff is replaced by dialog boxes, menus, etc in the world of GUI and if it
is needed then the Java code can handle it. Note that only single
parameters are returned to the Java program from each of the two DLL
methods. Java is a child of the C world which has dealt with functions
which returns only a single parameter and therefore expects only a single
return value.
Cheers,
.
Received on Sat Mar 11 2000 - 15:30:14 PST
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 09-Feb-2012. Archive updated nightly.