Skip to content

Export Method Nightly

The export method allows you to extract specific functions or logic registered within the VM's environment, exposing them to your host application. This effectively bridges the gap between the VM's isolated execution space and your primary code.

Using TypeScript

For TypeScript, the export method provides a seamless way to retrieve and invoke functions defined within the VM. By exporting a function, you can treat VM-side logic as native code, simplifying interaction and data processing between the two environments.

ts
const add = vm.export('add');
console.log(add(5, 6));

Using Rust

In Rust, the export method is used to map VM-side functions to Rust-callable interfaces. This mechanism allows you to leverage VM execution results directly within your main Rust application, enabling high-performance integration and modular architecture.

rust
let mut add = vm.export("add".to_string());
let args = vec![serde_json::json!(5), serde_json::json!(6)];
if let Some(result) = add(args) {
    println!("Result from VM: {}", result);
}

INFO

Capability Required: Control

Released under the Apache-2.0 License.