pub struct ScriptHost { /* private fields */ }Expand description
High-level scripting host. Owns the VM and provides ergonomic registration APIs.
Implementations§
Source§impl ScriptHost
impl ScriptHost
Sourcepub fn register<F>(&mut self, name: &str, f: F)
pub fn register<F>(&mut self, name: &str, f: F)
Register a Rust closure as a global script function.
Sourcepub fn register_fn<F>(&mut self, name: &str, f: F)
pub fn register_fn<F>(&mut self, name: &str, f: F)
Register a simple 1-argument Rust function.
Sourcepub fn register_module(&mut self, name: &str, funcs: Vec<(&str, HostFunction)>)
pub fn register_module(&mut self, name: &str, funcs: Vec<(&str, HostFunction)>)
Expose a Rust table of functions as a named module.
ⓘ
host.register_module("engine", vec![
("spawn", Arc::new(|_vm, args| { ... })),
]);Sourcepub fn exec(&mut self, source: &str) -> Result<Vec<Value>, ScriptError>
pub fn exec(&mut self, source: &str) -> Result<Vec<Value>, ScriptError>
Execute a script string, returning all return values.
Sourcepub fn exec_named(
&mut self,
name: &str,
source: &str,
) -> Result<Vec<Value>, ScriptError>
pub fn exec_named( &mut self, name: &str, source: &str, ) -> Result<Vec<Value>, ScriptError>
Execute a named script (for better error messages).
Sourcepub fn call(
&mut self,
func_name: &str,
args: Vec<Value>,
) -> Result<Vec<Value>, ScriptError>
pub fn call( &mut self, func_name: &str, args: Vec<Value>, ) -> Result<Vec<Value>, ScriptError>
Call a previously defined script function by name.
Sourcepub fn call_method(
&mut self,
table_name: &str,
method_name: &str,
args: Vec<Value>,
) -> Result<Vec<Value>, ScriptError>
pub fn call_method( &mut self, table_name: &str, method_name: &str, args: Vec<Value>, ) -> Result<Vec<Value>, ScriptError>
Call a method on a table: table_name.method_name(args).
Sourcepub fn get_string(&self, name: &str) -> Option<String>
pub fn get_string(&self, name: &str) -> Option<String>
Get a global as a string.
Sourcepub fn drain_output(&mut self) -> Vec<String>
pub fn drain_output(&mut self) -> Vec<String>
Drain all lines produced by print() calls.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScriptHost
impl !RefUnwindSafe for ScriptHost
impl !Send for ScriptHost
impl !Sync for ScriptHost
impl Unpin for ScriptHost
impl UnsafeUnpin for ScriptHost
impl !UnwindSafe for ScriptHost
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.