Crates.io | tanxium |
lib.rs | tanxium |
version | 0.2.1 |
source | src |
created_at | 2024-09-14 10:28:46.062923 |
updated_at | 2024-10-27 08:36:35.889999 |
description | Embeddable JavaScript/TypeScript runtime for Yasumu powered by Deno |
homepage | |
repository | https://github.com/yasumu-org/tanxium |
max_upload_size | |
id | 1374655 |
size | 202,331 |
Embeddable JavaScript/TypeScript runtime for Yasumu powered by Deno.
[!CAUTION] This project is still in development and not ready for production use.
cargo add tanxium
This is an example of how to use Tanxium to run JavaScript/TypeScript code. You
can also find this example in the examples
directory.
use tanxium::tanxium::{run_current_thread, Tanxium, TanxiumOptions};
fn main() {
let future = async {
let cwd = std::env::current_dir().unwrap();
let target_file = std::env::args().nth(1).expect("missing target file");
let target_file = cwd.join(target_file);
let main_module = deno_core::ModuleSpecifier::from_file_path(target_file).unwrap();
// Create a new Tanxium runtime instance
let mut tanxium = Tanxium::new(TanxiumOptions {
main_module: main_module.clone(),
cwd: cwd.to_string_lossy().to_string(),
extensions: vec![],
test: true,
stdout: None,
stderr: None,
stdin: None,
})
.unwrap();
// load runtime apis
match tanxium.load_runtime_api(None).await {
Err(e) => eprintln!("{}", e.to_string()),
_ => (),
};
// set runtime data
let rt_data = r#"{ "foo": "bar" }"#.to_string();
match tanxium.set_runtime_data(rt_data) {
Err(e) => eprintln!("{}", e.to_string()),
_ => (),
}
// run main module
match tanxium.execute_main_module(&main_module).await {
Err(e) => eprintln!("{}", e.to_string()),
_ => (),
};
// run event loop
match tanxium.run_event_loop(false).await {
Err(e) => eprintln!("{}", e.to_string()),
_ => (),
}
// get runtime data
match tanxium.get_runtime_data() {
Err(e) => eprintln!("{}", e.to_string()),
Ok(data) => println!("Runtime Data:\n{}", data),
};
};
run_current_thread(future);
}
Now you can run your JavaScript/TypeScript code using Tanxium:
cargo run ./file.ts