Skip to content

Commit

Permalink
feat: add kcl version api for the wasm host
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Sep 18, 2024
1 parent 79d047f commit 167f549
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions kclvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ pub unsafe extern "C" fn kcl_fmt(src_ptr: *const c_char) -> *const c_char {
}
}

fn intern_fmt(src: &str) -> Result<String, String> {
let api = API::default();
let args = &FormatCodeArgs {
source: src.to_string(),
};
match api.format_code(args) {
Ok(result) => String::from_utf8(result.formatted).map_err(|err| err.to_string()),
Err(err) => Err(err.to_string()),
}
}

/// Exposes a normal kcl version function to the WASM host.
#[no_mangle]
pub unsafe extern "C" fn kcl_version() -> *const c_char {
CString::new(kclvm_version::VERSION).unwrap().into_raw()
}

/// Exposes a normal kcl runtime error function to the WASM host.
#[no_mangle]
pub unsafe extern "C" fn kcl_runtime_err(buffer: *mut u8, length: usize) -> isize {
Expand All @@ -178,17 +195,6 @@ pub unsafe extern "C" fn kcl_runtime_err(buffer: *mut u8, length: usize) -> isiz
})
}

fn intern_fmt(src: &str) -> Result<String, String> {
let api = API::default();
let args = &FormatCodeArgs {
source: src.to_string(),
};
match api.format_code(args) {
Ok(result) => String::from_utf8(result.formatted).map_err(|err| err.to_string()),
Err(err) => Err(err.to_string()),
}
}

/// Exposes an allocation function to the WASM host.
///
/// _This implementation is copied from wasm-bindgen_
Expand Down

0 comments on commit 167f549

Please sign in to comment.