pub struct Function { /* private fields */ }Expand description
A live script or Rust function kept alive by a Rust handle.
Call it with ordinary Rust arguments using call, or preserve
script object identity with call_values. Clones refer
to the same function. A handle belongs to one VM, survives module replacement,
and becomes invalid after Rustia::reset_decision. Using it with another
VM or after reset returns an error.
use rustia::Rustia;
let mut lua = Rustia::builder().build()?;
let exports = lua.load("return { double = function(n) return n * 2 end }").install()?;
let double = exports.function(&mut lua, "double")?;
assert_eq!(double.call::<_, i64>(&mut lua, 21)?, 42);Implementations§
Source§impl Function
impl Function
Sourcepub fn decision_epoch(&self) -> u64
pub fn decision_epoch(&self) -> u64
Returns the decision epoch in which this handle was retained.
Sourcepub fn call<Args, Return>(
&self,
rustia: &mut Rustia,
args: Args,
) -> Result<Return>where
Args: IntoRustiaMulti,
Return: FromRustiaMulti,
pub fn call<Args, Return>(
&self,
rustia: &mut Rustia,
args: Args,
) -> Result<Return>where
Args: IntoRustiaMulti,
Return: FromRustiaMulti,
Calls the function with Rust arguments and copies its results into Rust.
Pass () for no arguments or a tuple for multiple arguments. The return
type selects the results through FromRustiaMulti. Use
call_values for results that cannot be copied into
OwnedValue, such as functions or cyclic tables. Every result is copied
before selection, including extra results and results discarded by ().
Sourcepub fn call_values(
&self,
rustia: &mut Rustia,
args: &[LiveValue],
) -> Result<Vec<LiveValue>>
pub fn call_values( &self, rustia: &mut Rustia, args: &[LiveValue], ) -> Result<Vec<LiveValue>>
Calls the function with live arguments and returns live handles for every result.
All handles must belong to this VM and its current decision epoch.
Sourcepub fn call_in<C, Args, Return>(
&self,
invocation: &mut Invocation<'_, C>,
args: Args,
) -> Result<Return>
pub fn call_in<C, Args, Return>( &self, invocation: &mut Invocation<'_, C>, args: Args, ) -> Result<Return>
Calls the function within a typed host invocation’s shared budget.
If argument conversion, execution, or result conversion fails, records
staged by this call are discarded. Guest table writes and external host
changes are not rolled back by this operation.
As with call, every returned value must fit OwnedValue
before the requested return type selects or discards results.
Sourcepub fn call_values_in<C>(
&self,
invocation: &mut Invocation<'_, C>,
args: &[LiveValue],
) -> Result<Vec<LiveValue>>where
C: HostSchema,
pub fn call_values_in<C>(
&self,
invocation: &mut Invocation<'_, C>,
args: &[LiveValue],
) -> Result<Vec<LiveValue>>where
C: HostSchema,
Calls this function with live values inside a typed host invocation.