Embedded Method
The .embedded() method executes the program currently loaded in the VM and returns its defined value, current execution outputs, and VM halted state. An undefined result or halted VM supplies null for value.
Using TypeScript
For TypeScript, create the VM with Control and Observe, load a raw bytecode array, and call .embedded().
const raw = [
['push', 42],
['stop'],
];
const optimized = tools.optimizeBytecode(raw);
vm.load(optimized)
const result = vm.embedded();
console.log(result);2
3
4
5
6
7
8
Using Rust
In Rust, you can load a serialized bytecode string or a serde_json value before calling .embedded().
let raw = r#"[
["push", 42],
["stop"]
]"#;
let optimized = tools.optimize_bytecode(raw);
vm.load(optimized.clone())
let result = vm.embedded();
println!("value: {}", result["value"]);
println!("outputs: {}", result["outputs"]);
println!("halted: {}", result["halted"]);2
3
4
5
6
7
8
9
10
let raw = serde_json::json!([
["push", 42],
["stop"]
]);
let optimized = tools.optimize_bytecode(raw);
vm.load(optimized.clone())
let result = vm.embedded();
println!("value: {}", result["value"]);
println!("outputs: {}", result["outputs"]);
println!("halted: {}", result["halted"]);2
3
4
5
6
7
8
9
10
INFO
Capabilities Required: Control executes the program, and Observe retrieves its outputs.
TIP
Before each embedded execution, .embedded() clears outputs left by the prior embedded execution. The returned outputs belong to the current execution, value contains a defined result or null for an undefined result or halted VM, and halted reports the VM halt state. Native execution failures return { status: "error", message }, while N-API and WebAssembly propagate failures through their binding error mechanisms.