pub struct EvalContext<'a, 's, 'ps, 'g, 'c, 't> { /* private fields */ }Expand description
Context of a script evaluation process.
Implementations§
Source§impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't>
impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't>
Sourcepub fn new(
engine: &'a Engine,
global: &'g mut GlobalRuntimeState,
caches: &'c mut Caches,
scope: &'s mut Scope<'ps>,
this_ptr: Option<&'t mut Dynamic>,
) -> Self
pub fn new( engine: &'a Engine, global: &'g mut GlobalRuntimeState, caches: &'c mut Caches, scope: &'s mut Scope<'ps>, this_ptr: Option<&'t mut Dynamic>, ) -> Self
Create a new EvalContext.
Sourcepub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)>
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &Module)>
Get an iterator over the current set of modules imported via import statements,
in reverse order (i.e. modules imported last come first).
Sourcepub fn tag_mut(&mut self) -> &mut Dynamic
pub fn tag_mut(&mut self) -> &mut Dynamic
Mutable reference to the custom state kept in a Dynamic.
Sourcepub const fn global_runtime_state(&self) -> &GlobalRuntimeState
pub const fn global_runtime_state(&self) -> &GlobalRuntimeState
(internals) The current GlobalRuntimeState.
Exported under the internals feature only.
Sourcepub fn global_runtime_state_mut(&mut self) -> &mut GlobalRuntimeState
pub fn global_runtime_state_mut(&mut self) -> &mut GlobalRuntimeState
(internals) Get a mutable reference to the current GlobalRuntimeState.
Exported under the internals feature only.
Sourcepub fn iter_namespaces(&self) -> impl Iterator<Item = &Module>
pub fn iter_namespaces(&self) -> impl Iterator<Item = &Module>
Get an iterator over the namespaces containing definition of all script-defined functions.
Not available under no_function.
Sourcepub fn namespaces(&self) -> &[Shared<Module>]
pub fn namespaces(&self) -> &[Shared<Module>]
(internals) The current set of namespaces containing definitions of all script-defined functions.
Exported under the internals feature only.
Not available under no_function.
Sourcepub fn this_ptr_mut(&mut self) -> Option<&mut Dynamic>
pub fn this_ptr_mut(&mut self) -> Option<&mut Dynamic>
Mutable reference to the current bound this pointer, if any.
Sourcepub const fn call_level(&self) -> usize
pub const fn call_level(&self) -> usize
The current nesting level of function calls.
Sourcepub fn eval_expression_tree(
&mut self,
expr: &Expression<'_>,
) -> Result<Dynamic, Box<EvalAltResult>>
pub fn eval_expression_tree( &mut self, expr: &Expression<'_>, ) -> Result<Dynamic, Box<EvalAltResult>>
Evaluate an expression tree within this evaluation context.
§WARNING - Low Level API
This function is very low level. It evaluates an expression from an AST.
Sourcepub fn eval_expression_tree_raw(
&mut self,
expr: &Expression<'_>,
rewind_scope: bool,
) -> Result<Dynamic, Box<EvalAltResult>>
👎Deprecated: This API is NOT deprecated, but it is considered volatile and may change in the future.
pub fn eval_expression_tree_raw( &mut self, expr: &Expression<'_>, rewind_scope: bool, ) -> Result<Dynamic, Box<EvalAltResult>>
Evaluate an expression tree within this evaluation context.
The following option is available:
§WARNING - Unstable API
This API is volatile and may change in the future.
§WARNING - Low Level API
This function is extremely low level. It evaluates an expression from an AST.
Sourcepub fn call_fn<T: Variant + Clone>(
&mut self,
fn_name: impl AsRef<str>,
args: impl FuncArgs,
) -> Result<T, Box<EvalAltResult>>
pub fn call_fn<T: Variant + Clone>( &mut self, fn_name: impl AsRef<str>, args: impl FuncArgs, ) -> Result<T, Box<EvalAltResult>>
Call a function inside the evaluation context with the provided arguments.
Sourcepub fn call_native_fn<T: Variant + Clone>(
&mut self,
fn_name: impl AsRef<str>,
args: impl FuncArgs,
) -> Result<T, Box<EvalAltResult>>
pub fn call_native_fn<T: Variant + Clone>( &mut self, fn_name: impl AsRef<str>, args: impl FuncArgs, ) -> Result<T, Box<EvalAltResult>>
Call a registered native Rust function inside the evaluation context with the provided arguments.
This is often useful because Rust functions typically only want to cross-call other registered Rust functions and not have to worry about scripted functions hijacking the process unknowingly (or deliberately).
Sourcepub fn call_fn_raw(
&mut self,
fn_name: impl AsRef<str>,
is_ref_mut: bool,
is_method_call: bool,
args: &mut [&mut Dynamic],
) -> Result<Dynamic, Box<EvalAltResult>>
pub fn call_fn_raw( &mut self, fn_name: impl AsRef<str>, is_ref_mut: bool, is_method_call: bool, args: &mut [&mut Dynamic], ) -> Result<Dynamic, Box<EvalAltResult>>
Call a function (native Rust or scripted) inside the evaluation context.
If is_method_call is true, the first argument is assumed to be the this pointer for
a script-defined function (or the object of a method call).
§WARNING - Low Level API
This function is very low level.
§Arguments
All arguments may be consumed, meaning that they may be replaced by (). This is to avoid
unnecessarily cloning the arguments.
DO NOT reuse the arguments after this call. If they are needed afterwards, clone them before calling this function.
If is_ref_mut is true, the first argument is assumed to be passed by reference and is
not consumed.
Sourcepub fn call_native_fn_raw(
&mut self,
fn_name: impl AsRef<str>,
is_ref_mut: bool,
args: &mut [&mut Dynamic],
) -> Result<Dynamic, Box<EvalAltResult>>
pub fn call_native_fn_raw( &mut self, fn_name: impl AsRef<str>, is_ref_mut: bool, args: &mut [&mut Dynamic], ) -> Result<Dynamic, Box<EvalAltResult>>
Call a registered native Rust function inside the evaluation context.
This is often useful because Rust functions typically only want to cross-call other registered Rust functions and not have to worry about scripted functions hijacking the process unknowingly (or deliberately).
§WARNING - Low Level API
This function is very low level.
§Arguments
All arguments may be consumed, meaning that they may be replaced by (). This is to avoid
unnecessarily cloning the arguments.
DO NOT reuse the arguments after this call. If they are needed afterwards, clone them before calling this function.
If is_ref_mut is true, the first argument is assumed to be passed by reference and is
not consumed.