summaryrefslogtreecommitdiff
path: root/lib.rs-part1
diff options
context:
space:
mode:
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()
+ }
+}