Skip to content

Provide Method

After defining your functions or logic, the provide method is used to register them into the VM's context, making them accessible during execution.

Using TypeScript

For TypeScript, you can provide functions or data structures directly into the VM context. Ensure that the types provided align with the expected interface of the LightVM instance.

ts
vm.provide({
  name: 'John Doe',
  force: 2021,
});
let raw = [['get', 'name'], ['println'], ['get', 'force'], ['println']];

Using Rust

In Rust, you can provide your logic using raw string representations or by utilizing serde_json for more complex data structures. This allows the VM to seamlessly integrate Rust-defined logic into its operational scope.

rust
vm.provide(serde_json::json!({
  "name": "John Doe",
  "force": 2021
}));
let raw = r#"[
  ["get", "name"],
  ["println"],
  ["get", "force"],
  ["println"]
]"#;
rust
vm.provide(serde_json::json!({
  "name": "John Doe",
  "force": 2021
}));
let raw = serde_json::json!([
  ["get", "name"],
  ["println"],
  ["get", "force"],
  ["println"]
]);

INFO

Capability Required: no specific capability

Released under the Apache-2.0 License.