Skip to content

Commit

Permalink
all: run v fmt -w . in project root
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Jan 16, 2024
1 parent cddadfd commit b62d36e
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 74 deletions.
4 changes: 1 addition & 3 deletions c/declarations.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions examples/android/keyboard/keyboard.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions examples/android/toast/toast.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/desktop/simple/build_and_run.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions examples/desktop/simple/libv.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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)
return int(jni.Version.v1_6)
}

// 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')
Expand Down
4 changes: 2 additions & 2 deletions examples/desktop/v_as_library/build_and_run.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions examples/desktop/v_as_library/libvlang.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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
Expand Down
44 changes: 22 additions & 22 deletions jni.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,70 +39,70 @@ 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
fn_ptr voidptr
}

// 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
Expand Down
8 changes: 4 additions & 4 deletions jni.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion object.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/*
Expand Down
Loading

0 comments on commit b62d36e

Please sign in to comment.