Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kcl_run_with_log_message API #1687

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions kclvm/src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ pub unsafe extern "C" fn kcl_run(
}
}

/// Exposes a normal kcl run function with the log message to the WASM host.
#[no_mangle]
pub unsafe extern "C" fn kcl_run_with_log_message(
filename_ptr: *const c_char,
src_ptr: *const c_char,
) -> *const c_char {
if filename_ptr.is_null() || src_ptr.is_null() {
return std::ptr::null();
}
let filename = unsafe { CStr::from_ptr(filename_ptr).to_str().unwrap() };
let src = unsafe { CStr::from_ptr(src_ptr).to_str().unwrap() };

match intern_run(filename, src) {
Ok(result) => CString::new(result.log_message + &result.yaml_result)
.unwrap()
.into_raw(),
Err(err) => CString::new(format!("ERROR:{}", err)).unwrap().into_raw(),
}
}

/// Exposes a normal kcl fmt function to the WASM host.
#[no_mangle]
pub unsafe extern "C" fn kcl_fmt(src_ptr: *const c_char) -> *const c_char {
Expand Down
Loading