diff --git a/c/declarations.c.v b/c/declarations.c.v index bdbf584..e8418ff 100644 --- a/c/declarations.c.v +++ b/c/declarations.c.v @@ -2,9 +2,7 @@ // Use of this source code is governed by an MIT license file distributed with this software package module c -pub const ( - used_import = 1 -) +pub const used_import = 1 ///usr/lib/jvm/java-11-openjdk-amd64/include/ $if linux { diff --git a/examples/android/keyboard/keyboard.v b/examples/android/keyboard/keyboard.v index 38de5e0..ad734f2 100644 --- a/examples/android/keyboard/keyboard.v +++ b/examples/android/keyboard/keyboard.v @@ -9,12 +9,10 @@ import jni import jni.auto import jni.android.keyboard -const ( - pkg = 'io.v.android.ex.VKeyboardActivity' - bg_color = gx.white -) +const pkg = 'io.v.android.ex.VKeyboardActivity' +const bg_color = gx.white -[export: 'JNI_OnLoad'] +@[export: 'JNI_OnLoad'] fn jni_on_load(vm &jni.JavaVM, reserved voidptr) int { println(@FN + ' called') jni.set_java_vm(vm) @@ -30,7 +28,7 @@ fn jni_on_load(vm &jni.JavaVM, reserved voidptr) int { // on_soft_keyboard_input is exported to the Java activity "VKeyboardActivity". // The method is called in Java to notify you that: // within `jstr`, the `count` characters beginning at `start` have just replaced old text that had `length` before. -[export: 'JNICALL Java_io_v_android_ex_VKeyboardActivity_onSoftKeyboardInput'] +@[export: 'JNICALL Java_io_v_android_ex_VKeyboardActivity_onSoftKeyboardInput'] fn on_soft_keyboard_input(env &jni.Env, thiz jni.JavaObject, app_ptr i64, jstr jni.JavaString, start int, before int, count int) { if app_ptr == 0 { return diff --git a/examples/android/toast/toast.v b/examples/android/toast/toast.v index 36a1dad..5e29e4a 100644 --- a/examples/android/toast/toast.v +++ b/examples/android/toast/toast.v @@ -10,12 +10,10 @@ import time import jni import jni.auto -const ( - pkg = 'io.v.android.ex.VToastActivity' - bg_color = gx.white -) +const pkg = 'io.v.android.ex.VToastActivity' +const bg_color = gx.white -[export: 'JNI_OnLoad'] +@[export: 'JNI_OnLoad'] fn jni_on_load(vm &jni.JavaVM, reserved voidptr) int { println(@FN + ' called') jni.set_java_vm(vm) diff --git a/examples/desktop/simple/build_and_run.vsh b/examples/desktop/simple/build_and_run.vsh index 44d0976..c873171 100644 --- a/examples/desktop/simple/build_and_run.vsh +++ b/examples/desktop/simple/build_and_run.vsh @@ -50,9 +50,9 @@ if os.is_file('${lib_name}' + '.so') { } eprintln('Compiling shared ${lib_name}' + '.so') $if debug { - os.system(vexe() + ' -d debug_signatures -cg -prod -shared $lib_name' + '.v') + os.system(vexe() + ' -d debug_signatures -cg -prod -shared ${lib_name}' + '.v') } $else { - os.system(vexe() + ' -prod -shared $lib_name' + '.v') + os.system(vexe() + ' -prod -shared ${lib_name}' + '.v') } eprintln('Compiling Java sources') diff --git a/examples/desktop/simple/libv.v b/examples/desktop/simple/libv.v index 9618dc9..4c7aa1b 100644 --- a/examples/desktop/simple/libv.v +++ b/examples/desktop/simple/libv.v @@ -5,7 +5,7 @@ module libv import jni // jni_on_load is called by the JavaVM upon setup -[export: 'JNI_OnLoad'] +@[export: 'JNI_OnLoad'] fn jni_on_load(vm &jni.JavaVM, reserved voidptr) int { println(@FN + ' called') jni.set_java_vm(vm) @@ -13,7 +13,7 @@ fn jni_on_load(vm &jni.JavaVM, reserved voidptr) int { } // get_string_from_v returns a string obtained from Java via a static method call -[export: 'JNICALL Java_io_v_V_getStringFromV'] +@[export: 'JNICALL Java_io_v_V_getStringFromV'] fn get_string_from_v(env &jni.Env, thiz jni.JavaObject) jni.JavaString { // Obtain the string "Hello from Java!" from the Java class... call_result := jni.call_static_method(env, 'io.v.V.getStringFromJava() string') diff --git a/examples/desktop/v_as_library/build_and_run.vsh b/examples/desktop/v_as_library/build_and_run.vsh index f195924..37ed8d4 100644 --- a/examples/desktop/v_as_library/build_and_run.vsh +++ b/examples/desktop/v_as_library/build_and_run.vsh @@ -50,9 +50,9 @@ if os.is_file('${lib_name}' + '.so') { } eprintln('Compiling shared ${lib_name}' + '.so') $if debug { - os.system(vexe() + ' -d debug_signatures -cg -prod -shared $lib_name' + '.v') + os.system(vexe() + ' -d debug_signatures -cg -prod -shared ${lib_name}' + '.v') } $else { - os.system(vexe() + ' -prod -shared $lib_name' + '.v') + os.system(vexe() + ' -prod -shared ${lib_name}' + '.v') } eprintln('Compiling Java sources with javac from "${javac}"') os.system(javac + ' ' + java_class.replace('.', '/') + '.java') diff --git a/examples/desktop/v_as_library/libvlang.v b/examples/desktop/v_as_library/libvlang.v index a935b6b..9b7e39b 100644 --- a/examples/desktop/v_as_library/libvlang.v +++ b/examples/desktop/v_as_library/libvlang.v @@ -7,14 +7,14 @@ import jni.auto const pkg = 'io.vlang.V' -[export: 'JNI_OnLoad'] +@[export: 'JNI_OnLoad'] fn jni_on_load(vm &jni.JavaVM, reserved voidptr) int { println(@FN + ' called') jni.set_java_vm(vm) return int(jni.Version.v1_6) } -[export: 'JNICALL Java_io_vlang_V_callStaticMethods'] +@[export: 'JNICALL Java_io_vlang_V_callStaticMethods'] fn call_static_methods(env &jni.Env, thiz jni.JavaObject) { // Object call style jo := jni.object(env, thiz) @@ -39,7 +39,7 @@ fn call_static_methods(env &jni.Env, thiz jni.JavaObject) { java_void_func('Void', 0) } -[export: 'JNICALL Java_io_vlang_V_callObjectMethods'] +@[export: 'JNICALL Java_io_vlang_V_callObjectMethods'] fn call_object_methods(env &jni.Env, thiz jni.JavaObject) { // Call method on the object passed in "thiz" (io.vlang.V.setInt(int)) jo := jni.object(env, thiz) @@ -61,7 +61,7 @@ fn call_object_methods(env &jni.Env, thiz jni.JavaObject) { jni.call_object_method(env, thiz, 'passInstance(io.vlang.V)', java_object) } -[export: 'JNICALL Java_io_vlang_V_vGetString'] +@[export: 'JNICALL Java_io_vlang_V_vGetString'] fn get_v_string(env &jni.Env, thiz jni.JavaObject) jni.JavaString { r := jni.call_static_method(env, 'io.vlang.V.getInt() int') r2 := jni.call_static_method(env, 'io.vlang.V.getBool() bool') @@ -72,14 +72,14 @@ fn get_v_string(env &jni.Env, thiz jni.JavaObject) jni.JavaString { return jni.jstring(env, s) } -[export: 'JNICALL Java_io_vlang_V_vGetInt'] +@[export: 'JNICALL Java_io_vlang_V_vGetInt'] fn get_v_int(env &jni.Env, thiz jni.JavaObject) int { thiz.call(env, .@static, 'jprintln(string)', 'called get_v_int()') i := 42 return i } -[export: 'JNICALL Java_io_vlang_V_vAddInt'] +@[export: 'JNICALL Java_io_vlang_V_vAddInt'] fn add_v_int(env &jni.Env, thiz jni.JavaObject, a int, b int) int { res := a + b return res diff --git a/jni.c.v b/jni.c.v index 7d1b2f1..bf18e0a 100644 --- a/jni.c.v +++ b/jni.c.v @@ -8,8 +8,8 @@ pub enum Version { v1_4 = 0x00010004 // C.JNI_VERSION_1_4 v1_6 = 0x00010006 // C.JNI_VERSION_1_6 v1_8 = 0x00010008 // C.JNI_VERSION_1_8 - v9 = 0x00090000 // C.JNI_VERSION_9 - v10 = 0x000a0000 // C.JNI_VERSION_10 + v9 = 0x00090000 // C.JNI_VERSION_9 + v10 = 0x000a0000 // C.JNI_VERSION_10 } type JavaVM = C.JavaVM @@ -39,35 +39,35 @@ type JavaObjectArray = C.jobjectArray pub type JavaValue = C.jvalue // jni.h -[typedef] +@[typedef] struct C.jstring {} -[typedef] +@[typedef] struct C.JNIEnv {} -[typedef] +@[typedef] struct C.JavaVM {} -[typedef] +@[typedef] struct C.jobject {} -[typedef] +@[typedef] struct C.jclass {} -[typedef] +@[typedef] struct C.jmethodID {} -[typedef] +@[typedef] struct C.jfieldID {} -[typedef] +@[typedef] struct C.jthrowable {} -[typedef] +@[typedef] struct C.jweak {} // -[typedef] +@[typedef] struct C.JNINativeMethod { name &char signature &char @@ -75,34 +75,34 @@ struct C.JNINativeMethod { } // Arrays -[typedef] +@[typedef] struct C.jarray {} -[typedef] +@[typedef] struct C.jbyteArray {} -[typedef] +@[typedef] struct C.jcharArray {} -[typedef] +@[typedef] struct C.jshortArray {} -[typedef] +@[typedef] struct C.jintArray {} -[typedef] +@[typedef] struct C.jlongArray {} -[typedef] +@[typedef] struct C.jfloatArray {} -[typedef] +@[typedef] struct C.jdoubleArray {} -[typedef] +@[typedef] struct C.jobjectArray {} -[typedef] +@[typedef] union C.jvalue { z C.jboolean b C.jbyte diff --git a/jni.v b/jni.v index 3ae939c..b56526e 100644 --- a/jni.v +++ b/jni.v @@ -51,7 +51,7 @@ pub fn sig(pkg string, f_name string, rt Type, args ...Type) string { return_type = '' } vtypargs = vtypargs.trim_right(', ') - jni_sig := pkg + '.' + jni.v2j_fn_name(f_name) + '(' + vtypargs + ')' + return_type + jni_sig := pkg + '.' + v2j_fn_name(f_name) + '(' + vtypargs + ')' + return_type // println(jni_sig) return jni_sig } @@ -313,7 +313,7 @@ fn get_object_class_and_method_id(env &Env, obj JavaObject, fqn_sig string) (Jav return jclazz, mid } -[inline] +@[inline] pub fn (jo JavaObject) class_name(env &Env) string { obj := jo mut cls := get_object_class(env, obj) @@ -328,7 +328,7 @@ pub fn (jo JavaObject) class_name(env &Env) string { return call_string_method_a(env, cls_obj, mid, jni.void_arg.data) // NOTE vfmt will cause a compile error here if you only use 'void_arg.data' } -[inline] +@[inline] pub fn (jo JavaObject) call(env &Env, typ MethodType, signature string, args ...Type) CallResult { pkg := jo.class_name(env) return match typ { @@ -337,7 +337,7 @@ pub fn (jo JavaObject) call(env &Env, typ MethodType, signature string, args ... } } -[inline] +@[inline] pub fn (jc JavaClass) get_name(env &Env) string { unsafe { o := &JavaObject(voidptr(&jc)) diff --git a/object.v b/object.v index ffb35fe..1d415a7 100644 --- a/object.v +++ b/object.v @@ -23,7 +23,7 @@ pub fn object(env &Env, obj JavaObject) Object { } } -[inline] +@[inline] pub fn (o Object) call(typ MethodType, signature string, args ...Type) CallResult { return o.obj.call(o.env, typ, signature, ...args) /* diff --git a/types.v b/types.v index 18116b5..de5f8e2 100644 --- a/types.v +++ b/types.v @@ -199,7 +199,7 @@ pub fn v2j_value(env &Env, vt Type) JavaValue { } } -[inline] +@[inline] pub fn v2j_signature(fqn_signature string) (string, string, string) { clazz := fqn_signature.all_before_last('.') fn_sig := fqn_signature.all_after_last('.') @@ -208,7 +208,7 @@ pub fn v2j_signature(fqn_signature string) (string, string, string) { return clazz, f_name, f_sig } -[inline] +@[inline] pub fn j2v_string(env &Env, jstr JavaString) string { mut cn := '' unsafe { @@ -219,52 +219,52 @@ pub fn j2v_string(env &Env, jstr JavaString) string { return cn } -[inline] +@[inline] pub fn j2v_char(jchar C.jchar) rune { return rune(u16(jchar)) } -[inline] +@[inline] pub fn j2v_byte(jbyte C.jbyte) u8 { return u8(i8(jbyte)) } -[inline] +@[inline] pub fn j2v_boolean(jbool C.jboolean) bool { return jbool == C.jboolean(C.JNI_TRUE) } -[inline] +@[inline] pub fn j2v_int(jint C.jint) int { return int(jint) } -[inline] +@[inline] pub fn j2v_size(jsize C.jsize) int { return int(jsize) } -[inline] +@[inline] pub fn j2v_short(jshort C.jshort) i16 { return i16(jshort) } -[inline] +@[inline] pub fn j2v_long(jlong C.jlong) i64 { return i64(jlong) } -[inline] +@[inline] pub fn j2v_float(jfloat C.jfloat) f32 { return f32(jfloat) } -[inline] +@[inline] pub fn j2v_double(jdouble C.jdouble) f64 { return f64(jdouble) } -[inline] +@[inline] pub fn jboolean(val bool) C.jboolean { if val { return C.jboolean(C.JNI_TRUE) @@ -272,47 +272,47 @@ pub fn jboolean(val bool) C.jboolean { return C.jboolean(C.JNI_FALSE) } -[inline] +@[inline] pub fn jbyte(val u8) C.jbyte { return C.jbyte(val) } -[inline] +@[inline] pub fn jfloat(val f32) C.jfloat { return C.jfloat(val) } -[inline] +@[inline] pub fn jdouble(val f64) C.jdouble { return C.jdouble(val) } -[inline] +@[inline] pub fn jint(val int) C.jint { return C.jint(val) } -[inline] +@[inline] pub fn jsize(val int) C.jsize { return C.jsize(val) } -[inline] +@[inline] pub fn jshort(val i16) C.jshort { return C.jshort(val) } -[inline] +@[inline] pub fn jlong(val i64) C.jlong { return C.jlong(val) } -[inline] +@[inline] pub fn jchar(val rune) C.jchar { return C.jchar(val) } -[inline] +@[inline] pub fn jstring(env &Env, val string) C.jstring { return new_string_utf(env, val) }