Skip to content

Commit

Permalink
✨ feat: Add mod core to JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 7, 2024
1 parent 86452c4 commit adf8333
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
29 changes: 29 additions & 0 deletions rust/src/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024. caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use jni::sys::jstring;
use jni::JNIEnv;
use std::ptr::null_mut;

pub const VERSION: &'static str = "0.1.0";

pub fn get_version<'local>(env: JNIEnv<'local>) -> jstring {
match env.new_string(VERSION) {
Ok(s) => s.into_raw(),
Err(_) => null_mut(),
}
}
9 changes: 5 additions & 4 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use jni::objects::JClass;
use jni::sys::jstring;
use jni::JNIEnv;

pub const VERSION: &'static str = "0.1.0";
mod core;

pub use core::VERSION;

#[no_mangle]
pub extern "system" fn Java_com_caoccao_javet_swc4j_Swc4jNative_getVersion<'local>(
jni_env: JNIEnv<'local>,
env: JNIEnv<'local>,
_: JClass<'local>,
) -> jstring {
let output = jni_env.new_string(VERSION).expect("Couldn't get version!");
output.into_raw()
core::get_version(env)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @since 0.1.0
*/
public class Swc4jException extends Exception {
public abstract class Swc4jException extends Exception {
/**
* Instantiates a new Swc4j exception.
*
Expand Down

0 comments on commit adf8333

Please sign in to comment.