android: support FFI with Java
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 15 Mar 2014 12:24:14 +0000 (08:24 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 25 Apr 2014 19:18:55 +0000 (15:18 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android.nit
lib/mnit_android/android_app.nit
src/android_platform.nit

index 7f7883e..91e9f66 100644 (file)
@@ -20,3 +20,5 @@
 #
 # Will, in the near future, provide services specific to Android.
 module android is platform
+
+import java
index d396bd0..19b0c97 100644 (file)
@@ -588,3 +588,18 @@ redef class App
                }
        `}
 end
+
+redef class Sys
+       # Get the running JVM
+       redef fun create_default_jvm
+       do
+               var jvm = ndk_jvm
+               var jni_env = jvm.attach_current_thread
+               if jni_env.address_is_null then jni_env = jvm.env
+
+               self.jvm = jvm
+               self.jni_env = jni_env
+       end
+
+       protected fun ndk_jvm: JavaVM `{ return mnit_java_app->activity->vm; `}
+end
index 6dc34f8..6817d58 100644 (file)
@@ -19,6 +19,7 @@ module android_platform
 
 import platform
 import abstract_compiler
+import common_ffi
 
 redef class ToolContext
        redef fun platform_from_name(name)
@@ -233,3 +234,14 @@ $(call import-module,android/native_app_glue)
                toolcontext.exec_and_check(["mv", "{android_project_root}/bin/{compiler.mainmodule.name}-debug.apk", outname])
        end
 end
+
+redef class JavaClassTemplate
+       redef fun write_to_files(compdir)
+       do
+               var jni_path = "jni/nit_compile/"
+               if compdir.has_suffix(jni_path) then
+                       var path = "{compdir.substring(0, compdir.length-jni_path.length)}/src/"
+                       return super(path)
+               else return super
+       end
+end