summaryrefslogtreecommitdiff
path: root/lib.rs-part1
diff options
context:
space:
mode:
authorcos <cos>2020-03-22 19:08:12 +0100
committercos <cos>2020-03-22 19:08:12 +0100
commit5151e6766f3686a8bef475fc90aee794274ab3c9 (patch)
tree21a6abfdce2ac6035a397a3e356e39485ca4df76 /lib.rs-part1
downloadhello_rust_example-android-master.zip
Initial (and likely only) commitHEADmaster
Diffstat (limited to 'lib.rs-part1')
-rw-r--r--lib.rs-part121
1 files changed, 21 insertions, 0 deletions
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()
+ }
+}