Type Alias NativeFunction

Source
pub type NativeFunction = for<'a> fn(NativeFunctionContext<'a>, &[Val<'a>]) -> VmResult<ValBuilder<'a>>;
Expand description

A function that can be executed by the Spore VM. Native functions can be registered with Vm::with_native_function.

§Argument

Native functions take a NativeFunctionContext as an argument. This contains the state of the VM.

§Return Value

VmResult<ValBuilder> is used to build a return value and insert it into the VM.

fn my_magic_string(ctx: spore_vm::val::NativeFunctionContext) -> spore_vm::error::VmResult<spore_vm::val::ValBuilder> {
    Ok(ctx.new_string("42".into()))
}