camlspotter avatar camlspotter committed 008debb Draft

java => ocaml example

Comments (0)

Files changed (6)

camljava-0.3/test_simple_call_from_java/Makefile

 	gcc -c -I $(JAVA)/include TestC.c
 
 libTestC.so: TestC.o
-	gcc -shared TestC.o -o $@
+	gcc -shared TestC.o -o $@ -lX11
 
 clean:
 	rm -f *.o *.so *.class Test.h

camljava-0.3/test_simple_call_from_java/TestC.c

 #include "Test.h"
+#include <X11/Xlib.h>
 
 JNIEXPORT jint JNICALL Java_Test_putchar(JNIEnv* env, jobject obj, jint c)
 {
+    c = c + (int)XOpenDisplay(NULL);
     return putchar(c);
 }

camljava-0.3/test_simple_call_from_java_to_ocaml/Makefile

+all: Test.class libOCaml.so
+	LD_LIBRARY_PATH=. java Test
+
+Test.class: Test.java
+	javac Test.java
+
+Test.h: Test.class
+	javah -jni Test
+
+JAVA=/usr/lib/jvm/java-6-openjdk-i386/
+
+OCaml.o: Test.h OCaml.c
+	gcc -c -I $(JAVA)/include -I `ocamlc -where` OCaml.c
+
+libOCaml.so: OCaml.o Makefile hello.o
+	gcc -shared  OCaml.o hello.o -L`ocamlc -where` -lcamlrun -ldl -lm -lncurses -o $@ 
+
+hello.o: hello.ml
+	ocamlc -output-obj $< -o $@
+
+clean:
+	rm -f *.o *.so *.class Test.h *.cm*
+
+
+

camljava-0.3/test_simple_call_from_java_to_ocaml/OCaml.c

+#include "Test.h"
+#include <caml/callback.h>
+#include <ncurses.h>
+
+JNIEXPORT void JNICALL Java_Test_caml_1startup(JNIEnv* env, jobject obj, jobjectArray a)
+{
+    char *ps[] = { NULL, NULL };
+    caml_startup(ps);
+    beep();
+}

camljava-0.3/test_simple_call_from_java_to_ocaml/Test.java

+public class Test {
+    public static void main (String[] args) {
+	System.loadLibrary("OCaml");
+	Test i = new Test();
+	String[] as = { "hello" };
+	i.caml_startup(as);
+	System.out.println("Hello world !!");
+    }
+
+    private native void caml_startup(String args[]);
+}

camljava-0.3/test_simple_call_from_java_to_ocaml/hello.ml

+let _ = prerr_endline "hello world"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.