Crates.io | libhermesabi-sys |
lib.rs | libhermesabi-sys |
version | 0.1.1 |
source | src |
created_at | 2024-02-26 14:46:12.212152 |
updated_at | 2024-02-26 15:12:06.403865 |
description | Bindgen bindings for Hermes JavaScript engine |
homepage | |
repository | https://github.com/rust-hermes/rusty_hermes |
max_upload_size | |
id | 1153820 |
size | 8,160 |
Note: Currently only supports on Linux and macOS. Adding Windows support should be trivial.
This crate contains bindgen-generated Rust bindings for Hermes C ABI.
Before building Hermes, install the required dependencies:
Ubuntu
apt install cmake git ninja-build libicu-dev python zip libreadline-dev
Arch
pacman -S cmake git ninja icu python zip readline
macOS via Homebrew
brew install cmake git ninja
use libhermesabi_sys::*;
use std::ffi::CString;
unsafe extern "C" fn release_wrapper(_buf: *mut HermesABIBuffer) {}
fn main() {
unsafe {
let vtable_ptr = get_hermes_abi_vtable();
let vtable = &*vtable_ptr;
let config = std::ptr::null();
let runtime_ptr = (vtable.make_hermes_runtime.unwrap())(config);
let runtime = &*runtime_ptr;
let runtime_vt = &*runtime.vt;
let script = String::from("x = 1 + 2");
let script_url = CString::new("./src/test.js").expect("CString::new failed");
let vtable = HermesABIBufferVTable {
release: Some(release_wrapper),
};
let mut x = HermesABIBuffer {
vtable: &vtable,
data: script.as_ptr(),
size: script.len(),
};
let buffer_ptr = &mut x as *mut HermesABIBuffer;
let eval = runtime_vt.evaluate_javascript_source.unwrap();
let v = eval(
runtime_ptr,
buffer_ptr,
script_url.as_ptr(),
script_url.as_bytes().len(),
);
assert_eq!(v.value.data.number, 3.0);
}
}