pub struct Host { /* private fields */ }Expand description
A Context and a Registry paired up, ready to call functions.
This is the application side of a scripting solution: register your native types and functions, install your scripts, then call in.
The registry is shared through an Arc, so forks and worker threads all
see the same definitions. It must be complete before the first call, since
a registry in use can no longer be modified.
Implementations§
Source§impl Host
impl Host
Sourcepub fn fork(&self) -> Host
pub fn fork(&self) -> Host
Builds a host with a fresh context of the same capacities, sharing this registry.
Sourcepub fn push_global(self) -> Result<ID<Host>, Host>
pub fn push_global(self) -> Result<ID<Host>, Host>
Pushes this host onto the current thread’s global stack and returns its id.
Gives the host back when the stack is already borrowed. Useful for code that cannot pass a host down by argument, such as a native callback.
Sourcepub fn pop_global() -> Option<Host>
pub fn pop_global() -> Option<Host>
Takes the topmost host off the current thread’s global stack.
Sourcepub fn remove_global(id: ID<Host>) -> Option<Host>
pub fn remove_global(id: ID<Host>) -> Option<Host>
Takes a specific host off the current thread’s global stack.
Sourcepub fn with_global<T>(f: impl FnOnce(&mut Host) -> T) -> Option<T>
pub fn with_global<T>(f: impl FnOnce(&mut Host) -> T) -> Option<T>
Runs f with the topmost host of the current thread.
Returns None when the stack is empty or already borrowed.
Sourcepub fn context_and_registry(&mut self) -> (&mut Context, &Registry)
pub fn context_and_registry(&mut self) -> (&mut Context, &Registry)
Returns context and registry at once, as function bodies need both.
Sourcepub fn find_function(
&self,
name: &str,
module_name: &str,
type_name: Option<&str>,
) -> Option<Arc<Function>>
pub fn find_function( &self, name: &str, module_name: &str, type_name: Option<&str>, ) -> Option<Arc<Function>>
Looks a function up by name, module and optionally owning type.
Sourcepub fn call_function<O, I>(
&mut self,
name: &str,
module_name: &str,
type_name: Option<&str>,
) -> Option<HostFunctionCall<'_, I, O>>where
O: DataStackPack,
I: DataStackPack,
pub fn call_function<O, I>(
&mut self,
name: &str,
module_name: &str,
type_name: Option<&str>,
) -> Option<HostFunctionCall<'_, I, O>>where
O: DataStackPack,
I: DataStackPack,
Prepares a call to a function, matching it on argument and result types as well as its name.
Returns None when no function matches. Call
HostFunctionCall::run on the result with the arguments.
let (result,) = host
.call_function::<(i32,), _>("add", "lib", None)
.unwrap()
.run((40_i32, 2_i32));