[−][src]Struct rhai::plugin::Module
A module which may contain variables, sub-modules, external Rust functions, and/or script-defined functions.
Implementations
impl Module
[src]
pub fn new() -> Self
[src]
Create a new Module
.
Example
use rhai::Module; let mut module = Module::new(); module.set_var("answer", 42_i64); assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
pub fn new_with_capacity(capacity: usize) -> Self
[src]
Create a new Module
with a specified capacity for native Rust functions.
Example
use rhai::Module; let mut module = Module::new(); module.set_var("answer", 42_i64); assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
pub fn id(&self) -> Option<&str>
[src]
Get the ID of the Module
, if any.
Example
use rhai::Module; let mut module = Module::new(); module.set_id(Some("hello")); assert_eq!(module.id(), Some("hello"));
pub fn id_raw(&self) -> Option<&ImmutableString>
[src]
Get the ID of the Module
as an ImmutableString
, if any.
Example
use rhai::Module; let mut module = Module::new(); module.set_id(Some("hello")); assert_eq!(module.id_raw().map(|s| s.as_str()), Some("hello"));
pub fn set_id<S: Into<ImmutableString>>(&mut self, id: Option<S>)
[src]
Set the ID of the Module
.
Example
use rhai::Module; let mut module = Module::new(); module.set_id(Some("hello")); assert_eq!(module.id(), Some("hello"));
pub fn is_empty(&self) -> bool
[src]
Is the Module
empty?
Example
use rhai::Module; let module = Module::new(); assert!(module.is_empty());
pub fn is_indexed(&self) -> bool
[src]
Is the Module
indexed?
Example
use rhai::Module; let mut module = Module::new(); assert!(!module.is_indexed()); module.build_index(); assert!(module.is_indexed());
pub fn gen_fn_signatures<'a>(&'a self) -> impl Iterator<Item = String> + 'a
[src]
Generate signatures for all the functions in the Module
.
pub fn contains_var(&self, name: &str) -> bool
[src]
Does a variable exist in the Module
?
Example
use rhai::Module; let mut module = Module::new(); module.set_var("answer", 42_i64); assert!(module.contains_var("answer"));
pub fn get_var_value<T: Variant + Clone>(&self, name: &str) -> Option<T>
[src]
Get the value of a Module
variable.
Example
use rhai::Module; let mut module = Module::new(); module.set_var("answer", 42_i64); assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
pub fn get_var(&self, name: &str) -> Option<Dynamic>
[src]
Get a Module
variable as a Dynamic
.
Example
use rhai::Module; let mut module = Module::new(); module.set_var("answer", 42_i64); assert_eq!(module.get_var("answer").unwrap().cast::<i64>(), 42);
pub fn set_var(
&mut self,
name: impl Into<ImmutableString>,
value: impl Variant + Clone
) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
&mut self,
name: impl Into<ImmutableString>,
value: impl Variant + Clone
) -> &mut Selfⓘ
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Set a variable into the Module
.
If there is an existing variable of the same name, it is replaced.
Example
use rhai::Module; let mut module = Module::new(); module.set_var("answer", 42_i64); assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
pub fn get_script_fn(
&self,
name: &str,
num_params: usize,
public_only: bool
) -> Option<&ScriptFnDef>
[src]
&self,
name: &str,
num_params: usize,
public_only: bool
) -> Option<&ScriptFnDef>
Get a script-defined function in the Module
based on name and number of parameters.
pub fn contains_sub_module(&self, name: &str) -> bool
[src]
Does a sub-module exist in the Module
?
Example
use rhai::Module; let mut module = Module::new(); let sub_module = Module::new(); module.set_sub_module("question", sub_module); assert!(module.contains_sub_module("question"));
pub fn get_sub_module(&self, name: &str) -> Option<&Module>
[src]
Get a sub-module in the Module
.
Example
use rhai::Module; let mut module = Module::new(); let sub_module = Module::new(); module.set_sub_module("question", sub_module); assert!(module.get_sub_module("question").is_some());
pub fn set_sub_module(
&mut self,
name: impl Into<ImmutableString>,
sub_module: impl Into<Shared<Module>>
) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
&mut self,
name: impl Into<ImmutableString>,
sub_module: impl Into<Shared<Module>>
) -> &mut Selfⓘ
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Set a sub-module into the Module
.
If there is an existing sub-module of the same name, it is replaced.
Example
use rhai::Module; let mut module = Module::new(); let sub_module = Module::new(); module.set_sub_module("question", sub_module); assert!(module.get_sub_module("question").is_some());
pub fn contains_fn(&self, hash_fn: NonZeroU64, public_only: bool) -> bool
[src]
Does the particular Rust function exist in the Module
?
The NonZeroU64
hash is calculated by the function calc_native_fn_hash
.
It is also returned by the set_fn_XXX
calls.
Example
use rhai::Module; let mut module = Module::new(); let hash = module.set_fn_0("calc", || Ok(42_i64)); assert!(module.contains_fn(hash, true));
pub fn update_fn_metadata<'a>(
&mut self,
hash_fn: NonZeroU64,
arg_names: impl AsRef<[&'a str]>
) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
&mut self,
hash_fn: NonZeroU64,
arg_names: impl AsRef<[&'a str]>
) -> &mut Selfⓘ
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Update the metadata (parameter names/types and return type) of a registered function.
The NonZeroU64
hash is calculated either by the function
calc_native_fn_hash
or the function
calc_script_fn_hash
.
Parameter Names and Types
Each parameter name/type pair should be a single string of the format: var_name: type
.
Return Type
The last entry in the list should be the return type of the function. In other words, the number of entries should be one larger than the number of parameters.
pub fn update_fn_namespace(
&mut self,
hash_fn: NonZeroU64,
namespace: FnNamespace
) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
&mut self,
hash_fn: NonZeroU64,
namespace: FnNamespace
) -> &mut Selfⓘ
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Update the namespace of a registered function.
The NonZeroU64
hash is calculated either by the function
calc_native_fn_hash
or the function
calc_script_fn_hash
.
pub fn set_fn(
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
access: FnAccess,
arg_names: Option<&[&str]>,
arg_types: &[TypeId],
func: CallableFunction
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
access: FnAccess,
arg_names: Option<&[&str]>,
arg_types: &[TypeId],
func: CallableFunction
) -> NonZeroU64
Set a Rust function into the Module
, returning a hash key.
If there is an existing Rust function of the same hash, it is replaced.
WARNING - Low Level API
This function is very low level.
pub fn set_raw_fn<T: Variant + Clone>(
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
access: FnAccess,
arg_types: &[TypeId],
func: impl Fn(NativeCallContext<'_, '_, '_, '_, '_>, &mut FnCallArgs<'_>) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
access: FnAccess,
arg_types: &[TypeId],
func: impl Fn(NativeCallContext<'_, '_, '_, '_, '_>, &mut FnCallArgs<'_>) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking a reference to the scripting Engine
,
the current set of functions, plus a list of mutable Dynamic
references
into the Module
, returning a hash key.
Use this to register a built-in function which must reference settings on the scripting
Engine
(e.g. to prevent growing an array beyond the allowed maximum size),
or to call a script-defined function in the current evaluation context.
If there is a similar existing Rust function, it is replaced.
WARNING - Low Level API
This function is very low level.
A list of TypeId
's is taken as the argument types.
Arguments are simply passed in as a mutable array of &mut Dynamic
,
which is guaranteed to contain enough arguments of the correct types.
The function is assumed to be a method, meaning that the first argument should not be consumed. All other arguments can be consumed.
To access a primary parameter value (i.e. cloning is cheap), use: args[n].clone().cast::<T>()
To access a parameter value and avoid cloning, use std::mem::take(args[n]).cast::<T>()
.
Notice that this will consume the argument, replacing it with ()
.
To access the first mutable parameter, use args.get_mut(0).unwrap()
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, FnNamespace, FnAccess}; let mut module = Module::new(); let hash = module.set_raw_fn("double_or_not", FnNamespace::Internal, FnAccess::Public, // Pass parameter types via a slice with TypeId's &[std::any::TypeId::of::<i64>(), std::any::TypeId::of::<bool>()], // Fixed closure signature |context, args| { // 'args' is guaranteed to be the right length and of the correct types // Get the second parameter by 'consuming' it let double = std::mem::take(args[1]).cast::<bool>(); // Since it is a primary type, it can also be cheaply copied let double = args[1].clone().cast::<bool>(); // Get a mutable reference to the first argument. let mut x = args[0].write_lock::<i64>().unwrap(); let orig = *x; if double { *x *= 2; // the first argument can be mutated } Ok(orig) // return Result<T, Box<EvalAltResult>> }); assert!(module.contains_fn(hash, true));
pub fn set_fn_0<T: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn() -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn() -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking no parameters into the Module
, returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::Module; let mut module = Module::new(); let hash = module.set_fn_0("calc", || Ok(42_i64)); assert!(module.contains_fn(hash, true));
pub fn set_fn_1<A: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn(A) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn(A) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking one parameter into the Module
, returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::Module; let mut module = Module::new(); let hash = module.set_fn_1("calc", |x: i64| Ok(x + 1)); assert!(module.contains_fn(hash, true));
pub fn set_fn_1_mut<A: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking one mutable parameter into the Module
, returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, FnNamespace}; let mut module = Module::new(); let hash = module.set_fn_1_mut("calc", FnNamespace::Internal, |x: &mut i64| { *x += 1; Ok(*x) } ); assert!(module.contains_fn(hash, true));
pub fn set_getter_fn<A: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn(&mut A) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn(&mut A) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust getter function taking one mutable parameter, returning a hash key. This function is automatically exposed to the global namespace.
If there is a similar existing Rust getter function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::Module; let mut module = Module::new(); let hash = module.set_getter_fn("value", |x: &mut i64| { Ok(*x) }); assert!(module.contains_fn(hash, true));
pub fn set_fn_2<A: Variant + Clone, B: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn(A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn(A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking two parameters into the Module
, returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let hash = module.set_fn_2("calc", |x: i64, y: ImmutableString| { Ok(x + y.len() as i64) }); assert!(module.contains_fn(hash, true));
pub fn set_fn_2_mut<A: Variant + Clone, B: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking two parameters (the first one mutable) into the Module
,
returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, FnNamespace, ImmutableString}; let mut module = Module::new(); let hash = module.set_fn_2_mut("calc", FnNamespace::Internal, |x: &mut i64, y: ImmutableString| { *x += y.len() as i64; Ok(*x) } ); assert!(module.contains_fn(hash, true));
pub fn set_setter_fn<A: Variant + Clone, B: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn(&mut A, B) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn(&mut A, B) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust setter function taking two parameters (the first one mutable) into the Module
,
returning a hash key.
This function is automatically exposed to the global namespace.
If there is a similar existing setter Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let hash = module.set_setter_fn("value", |x: &mut i64, y: ImmutableString| { *x = y.len() as i64; Ok(()) }); assert!(module.contains_fn(hash, true));
pub fn set_indexer_get_fn<A: Variant + Clone, B: Variant + Clone, T: Variant + Clone>(
&mut self,
func: impl Fn(&mut A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
func: impl Fn(&mut A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust index getter taking two parameters (the first one mutable) into the Module
,
returning a hash key.
This function is automatically exposed to the global namespace.
If there is a similar existing setter Rust function, it is replaced.
Panics
Panics if the type is Array
or Map
.
Indexers for arrays, object maps and strings cannot be registered.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let hash = module.set_indexer_get_fn(|x: &mut i64, y: ImmutableString| { Ok(*x + y.len() as i64) }); assert!(module.contains_fn(hash, true));
pub fn set_fn_3<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn(A, B, C) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn(A, B, C) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking three parameters into the Module
, returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let hash = module.set_fn_3("calc", |x: i64, y: ImmutableString, z: i64| { Ok(x + y.len() as i64 + z) }); assert!(module.contains_fn(hash, true));
pub fn set_fn_3_mut<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A, B, C) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A, B, C) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking three parameters (the first one mutable) into the Module
,
returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, FnNamespace, ImmutableString}; let mut module = Module::new(); let hash = module.set_fn_3_mut("calc", FnNamespace::Internal, |x: &mut i64, y: ImmutableString, z: i64| { *x += y.len() as i64 + z; Ok(*x) } ); assert!(module.contains_fn(hash, true));
pub fn set_indexer_set_fn<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone>(
&mut self,
func: impl Fn(&mut A, B, C) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
func: impl Fn(&mut A, B, C) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust index setter taking three parameters (the first one mutable) into the Module
,
returning a hash key.
This function is automatically exposed to the global namespace.
If there is a similar existing Rust function, it is replaced.
Panics
Panics if the type is Array
or Map
.
Indexers for arrays, object maps and strings cannot be registered.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let hash = module.set_indexer_set_fn(|x: &mut i64, y: ImmutableString, value: i64| { *x = y.len() as i64 + value; Ok(()) }); assert!(module.contains_fn(hash, true));
pub fn set_indexer_get_set_fn<A: Variant + Clone, B: Variant + Clone, T: Variant + Clone>(
&mut self,
getter: impl Fn(&mut A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static,
setter: impl Fn(&mut A, B, T) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> (NonZeroU64, NonZeroU64)
[src]
&mut self,
getter: impl Fn(&mut A, B) -> Result<T, Box<EvalAltResult>> + SendSync + 'static,
setter: impl Fn(&mut A, B, T) -> Result<(), Box<EvalAltResult>> + SendSync + 'static
) -> (NonZeroU64, NonZeroU64)
Set a pair of Rust index getter and setter functions, returning both hash keys.
This is a short-hand for set_indexer_get_fn
and
set_indexer_set_fn
.
If there are similar existing Rust functions, they are replaced.
Panics
Panics if the type is Array
or Map
.
Indexers for arrays, object maps and strings cannot be registered.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let (hash_get, hash_set) = module.set_indexer_get_set_fn( |x: &mut i64, y: ImmutableString| { Ok(*x + y.len() as i64) }, |x: &mut i64, y: ImmutableString, value: i64| { *x = y.len() as i64 + value; Ok(()) } ); assert!(module.contains_fn(hash_get, true)); assert!(module.contains_fn(hash_set, true));
pub fn set_fn_4<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, D: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
func: impl Fn(A, B, C, D) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
func: impl Fn(A, B, C, D) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking four parameters into the Module
, returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, ImmutableString}; let mut module = Module::new(); let hash = module.set_fn_4("calc", |x: i64, y: ImmutableString, z: i64, _w: ()| { Ok(x + y.len() as i64 + z) }); assert!(module.contains_fn(hash, true));
pub fn set_fn_4_mut<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, D: Variant + Clone, T: Variant + Clone>(
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A, B, C, D) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
[src]
&mut self,
name: impl Into<String>,
namespace: FnNamespace,
func: impl Fn(&mut A, B, C, D) -> Result<T, Box<EvalAltResult>> + SendSync + 'static
) -> NonZeroU64
Set a Rust function taking four parameters (the first one mutable) into the Module
,
returning a hash key.
If there is a similar existing Rust function, it is replaced.
Function Metadata
No metadata for the function is registered. Use update_fn_metadata
to add metadata.
Example
use rhai::{Module, FnNamespace, ImmutableString}; let mut module = Module::new(); let hash = module.set_fn_4_mut("calc", FnNamespace::Internal, |x: &mut i64, y: ImmutableString, z: i64, _w: ()| { *x += y.len() as i64 + z; Ok(*x) } ); assert!(module.contains_fn(hash, true));
pub fn contains_qualified_fn(&self, hash_fn: NonZeroU64) -> bool
[src]
Does the particular namespace-qualified function exist in the Module
?
The NonZeroU64
hash is calculated by the function
calc_native_fn_hash
and must match
the hash calculated by build_index
.
pub fn combine(&mut self, other: Self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
pub fn combine_flatten(&mut self, other: Self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Combine another Module
into this Module
.
The other Module
is consumed to merge into this Module
.
Sub-modules are flattened onto the root Module
, with higher level overriding lower level.
pub fn fill_with(&mut self, other: &Self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
pub fn merge(&mut self, other: &Self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
pub fn count(&self) -> (usize, usize, usize)
[src]
Get the number of variables, functions and type iterators in the Module
.
pub fn iter_sub_modules(&self) -> impl Iterator<Item = (&str, Shared<Module>)>
[src]
Get an iterator to the sub-modules in the Module
.
pub fn iter_var(&self) -> impl Iterator<Item = (&str, &Dynamic)>
[src]
Get an iterator to the variables in the Module
.
pub fn iter_script_fn_info(
&self
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize, &ScriptFnDef)>
[src]
&self
) -> impl Iterator<Item = (FnNamespace, FnAccess, &str, usize, &ScriptFnDef)>
Get an iterator over all script-defined functions in the Module
.
Function metadata includes:
- Namespace (
FnNamespace::Global
orFnNamespace::Internal
). - Access mode (
FnAccess::Public
orFnAccess::Private
). - Function name (as string slice).
- Number of parameters.
- (INTERNALS) Shared reference to function definition
ScriptFnDef
. Exported under theinternals
feature only.
pub fn eval_ast_as_new(
mut scope: Scope<'_>,
ast: &AST,
engine: &Engine
) -> Result<Self, Box<EvalAltResult>>
[src]
mut scope: Scope<'_>,
ast: &AST,
engine: &Engine
) -> Result<Self, Box<EvalAltResult>>
Create a new Module
by evaluating an AST
.
The entire AST
is encapsulated into each function, allowing functions
to cross-call each other. Functions in the global namespace, plus all functions
defined in the Module
, are merged into a unified namespace before each call.
Therefore, all functions will be found.
Example
use rhai::{Engine, Module, Scope}; let engine = Engine::new(); let ast = engine.compile("let answer = 42; export answer;")?; let module = Module::eval_ast_as_new(Scope::new(), &ast, &engine)?; assert!(module.contains_var("answer")); assert_eq!(module.get_var_value::<i64>("answer").unwrap(), 42);
pub fn build_index(&mut self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Scan through all the sub-modules in the Module
and build a hash index of all
variables and functions as one flattened namespace.
If the Module
is already indexed, this method has no effect.
pub fn contains_qualified_iter(&self, id: TypeId) -> bool
[src]
Does a type iterator exist in the entire module tree?
pub fn contains_iter(&self, id: TypeId) -> bool
[src]
Does a type iterator exist in the module?
pub fn set_iter(
&mut self,
typ: TypeId,
func: fn(_: Dynamic) -> Box<dyn Iterator<Item = Dynamic>>
) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
&mut self,
typ: TypeId,
func: fn(_: Dynamic) -> Box<dyn Iterator<Item = Dynamic>>
) -> &mut Selfⓘ
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Set a type iterator into the Module
.
pub fn set_iterable<T>(&mut self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
where
T: Variant + Clone + IntoIterator,
<T as IntoIterator>::Item: Variant + Clone,
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
T: Variant + Clone + IntoIterator,
<T as IntoIterator>::Item: Variant + Clone,
Set a type iterator into the Module
.
pub fn set_iterator<T>(&mut self) -> &mut SelfⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
where
T: Variant + Clone + Iterator,
<T as Iterator>::Item: Variant + Clone,
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
T: Variant + Clone + Iterator,
<T as Iterator>::Item: Variant + Clone,
Set an iterator type into the Module
as a type iterator.
Trait Implementations
impl<M: AsRef<Module>> Add<M> for &Module
[src]
type Output = Module
The resulting type after applying the +
operator.
pub fn add(self, rhs: M) -> Self::Output
[src]
impl<M: AsRef<Module>> Add<M> for Module
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(mut self: Self, rhs: M) -> Self::Output
[src]
impl<M: Into<Module>> AddAssign<M> for Module
[src]
pub fn add_assign(&mut self, rhs: M)
[src]
impl AsRef<Module> for AST
[src]
impl AsRef<Module> for Module
[src]
impl Clone for Module
[src]
impl Debug for Module
[src]
impl Default for Module
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Module
[src]
impl !Send for Module
[src]
impl !Sync for Module
[src]
impl Unpin for Module
[src]
impl !UnwindSafe for Module
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow(&self) -> &TⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut TⓘNotable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut W
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,