pub struct NativeFunctionContext<'a> { /* private fields */ }Expand description
The input parameter to native Spore VM functions registered with Vm::with_native_function.
fn my_magic_string(ctx: spore_vm::val::NativeFunctionContext) -> spore_vm::error::VmResult<spore_vm::val::ValBuilder> {
Ok(ctx.new_string("42".into()))
}Implementations§
Source§impl<'a> NativeFunctionContext<'a>
impl<'a> NativeFunctionContext<'a>
Source§impl<'a> NativeFunctionContext<'a>
impl<'a> NativeFunctionContext<'a>
Sourcepub unsafe fn with_unsafe_val(self, val: UnsafeVal) -> ValBuilder<'a>
pub unsafe fn with_unsafe_val(self, val: UnsafeVal) -> ValBuilder<'a>
Create a new value from an internal.
Consumes the self to ensure that the value isn’t garbage collected.
§Safety
InternalVal must be a valid value that has not been garbage collected.
Sourcepub fn new_string(self, s: CompactString) -> ValBuilder<'a>
pub fn new_string(self, s: CompactString) -> ValBuilder<'a>
Create a new string value.
Consumes self to ensure that the value isn’t garbage collected.
fn my_magic_string(ctx: spore_vm::val::NativeFunctionContext) -> spore_vm::error::VmResult<spore_vm::val::ValBuilder> {
Ok(ctx.new_string("42".into()))
}Sourcepub unsafe fn new_mutable_box(self, v: Val<'a>) -> ValBuilder<'a>
pub unsafe fn new_mutable_box(self, v: Val<'a>) -> ValBuilder<'a>
Create a new box from the unsafe val.
Consumes the self to ensure that the value isn’t garbage collected.
§Safety
v must be a valid value within the vm.
Sourcepub unsafe fn new_list(self, list: &[Val<'_>]) -> ValBuilder<'a>
pub unsafe fn new_list(self, list: &[Val<'_>]) -> ValBuilder<'a>
Create a new list from ListVal.
Consumes the self to ensure that the value isn’t garbage collected.
§Safety
list must contain valid values within the vm.
Sourcepub unsafe fn new_struct(self, strct: StructVal) -> ValBuilder<'a>
pub unsafe fn new_struct(self, strct: StructVal) -> ValBuilder<'a>
Create a new struct from StructVal.
Consumes the self to ensure that the value isn’t garbage collected.
§Safety
strct must contain valid values within the vm.
Sourcepub fn new_custom(self, obj: impl CustomType) -> ValBuilder<'a>
pub fn new_custom(self, obj: impl CustomType) -> ValBuilder<'a>
Create a new custom value from obj.