# Set the defaut config for a VM
# Can be called after setting the version
- fun set_default `{ JNI_GetDefaultJavaVMInitArgs(recv); `}
+ #
+ # Unavailable on Android, where you cannot instanciate a new JVM.
+ fun set_default `{
+ #ifndef ANDROID
+ JNI_GetDefaultJavaVMInitArgs(recv);
+ #endif
+ `}
fun version: Int `{ return recv->version; `}
fun version=(v: Int) `{ recv->version = v; `}
# Represents a jni JavaVM
extern class JavaVM `{JavaVM *`}
# Create the JVM, returns its handle and store the a pointer to JniEnv in `env_ref`
- new(args: JavaVMInitArgs, env_ref: JniEnvRef) import jni_error, JniEnvRef.jni_env=, JniEnv as nullable `{
+ #
+ # Unavailable on Android, where you cannot instanciate a new JVM.
+ new(args: JavaVMInitArgs, env_ref: JniEnvRef) import jni_error, JniEnvRef.jni_env=, JniEnv.as nullable `{
+
+ #ifdef ANDROID
+ JavaVM_jni_error(NULL, "JVM creation not supported on Android", 0);
+ return NULL;
+ #endif
+
JavaVM *jvm;
JNIEnv *env;
jint res;
fun attach_current_thread: JniEnv `{
JNIEnv *env;
+ #ifdef ANDROID
+ // the signature is different (better actually) on Android
+ int res = (*recv)->AttachCurrentThread(recv, &env, NULL);
+ #else
int res = (*recv)->AttachCurrentThread(recv, (void**)&env, NULL);
+ #endif
if (res != JNI_OK) {
JavaVM_jni_error(NULL, "Could not attach current thread to Java VM", res);
return NULL;
return (char*)(*recv)->GetStringUTFChars(recv, (jstring)jobj, NULL);
`}
- private fun convert_args_to_jni(args: nullable Array[nullable Object]): Pointer import Array[nullable Object] as not nullable, Array[nullable Object].[], Array[nullable Object].length, nullable Object.as(Int), nullable Object.as(Char), nullable Object.as(Bool), nullable Object.as(Float), nullable Object.as(JavaObject), nullable Object.as(String), String.to_cstring, String.length `{
+ private fun convert_args_to_jni(args: nullable Array[nullable Object]): Pointer import Array[nullable Object].as not nullable, Array[nullable Object].[], Array[nullable Object].length, nullable Object.as(Int), nullable Object.as(Char), nullable Object.as(Bool), nullable Object.as(Float), nullable Object.as(JavaObject), nullable Object.as(String), String.to_cstring, String.length `{
if(nullable_Array_of_nullable_Object_is_null(args)){
return NULL;
}
fun string_to_jobject(string: String): JavaObject `{
return (*recv)->NewStringUTF(recv, String_to_cstring(string));
`}
+
+ # Pushes a local reference frame on the JNI stack
+ fun push_local_frame(capacity: Int): Bool `{
+ return (*recv)->PushLocalFrame(recv, capacity);
+ `}
+
+ # Pops the current local reference frame on the JNI stack
+ fun pop_local_frame `{
+ (*recv)->PopLocalFrame(recv, NULL);
+ `}
end
# used to initialize a JavaVM
end
# Represens a jni jobject
-extern class JavaObject `{jobject`}
+extern class JavaObject in "Java" `{ java.lang.Object `}
end
# Represents a jni JNINNativeMethod