From 5151e6766f3686a8bef475fc90aee794274ab3c9 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 22 Mar 2020 19:08:12 +0100 Subject: Initial (and likely only) commit --- lib.rs-part1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib.rs-part1 (limited to 'lib.rs-part1') diff --git a/lib.rs-part1 b/lib.rs-part1 new file mode 100644 index 0000000..cec0883 --- /dev/null +++ b/lib.rs-part1 @@ -0,0 +1,21 @@ +#[cfg(target_os="android")] +#[allow(non_snake_case)] +pub mod android { + extern crate jni; + + use super::*; + use self::jni::JNIEnv; + use self::jni::objects::{JClass, JString}; + use self::jni::sys::{jstring}; + + #[no_mangle] + pub unsafe extern fn Java_rs_cph_hellorust_FFI_func(env: JNIEnv, _: JClass, java_pattern: JString) + -> jstring { + let world = rust_func(env.get_string(java_pattern).expect("invalid pattern string").as_ptr()); + // Retake pointer, to use it below and allow memory to be freed when it goes out of scope. + let world_ptr = CString::from_raw(world); + let output = env.new_string(world_ptr.to_str().unwrap()).expect("Couldn't create java string!"); + + output.into_inner() + } +} -- cgit v1.2.3