pub struct Runtime { /* private fields */ }Expand description
Persistent state used to execute compiled MiraScript programs.
A Runtime owns all dynamically allocated values. Values containing handles therefore remain usable until this Runtime is dropped.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn insert_global(
&mut self,
name: impl Into<String>,
value: impl Into<MiraManageable>,
) -> Result<Option<MiraValue>>
pub fn insert_global( &mut self, name: impl Into<String>, value: impl Into<MiraManageable>, ) -> Result<Option<MiraValue>>
Insert or replace a global after converting it into a Runtime value.
Sourcepub fn insert_fn(
&mut self,
name: impl Into<String>,
function: impl Into<MiraNativeFn>,
) -> Result<Option<MiraValue>>
pub fn insert_fn( &mut self, name: impl Into<String>, function: impl Into<MiraNativeFn>, ) -> Result<Option<MiraValue>>
Insert a named native function into the global namespace.
Sourcepub fn get_global(&self, name: &str) -> Option<MiraValue>
pub fn get_global(&self, name: &str) -> Option<MiraValue>
Clone a global value by name.
Sourcepub fn contains_global(&self, name: &str) -> bool
pub fn contains_global(&self, name: &str) -> bool
Return whether a global name is defined.
Sourcepub fn remove_global(&mut self, name: &str) -> Option<MiraValue>
pub fn remove_global(&mut self, name: &str) -> Option<MiraValue>
Remove a global value by name, returning the previous value if it existed.
You shall call take_* to remove the value from the Runtime’s arena if you want to reclaim its memory.
Sourcepub fn global_names(&self) -> impl Iterator<Item = &str>
pub fn global_names(&self) -> impl Iterator<Item = &str>
Iterate over global names in insertion order.
Source§impl Runtime
impl Runtime
Sourcepub fn with_options(options: RunOptions) -> Self
pub fn with_options(options: RunOptions) -> Self
Create a Runtime using explicit execution limits and providers.
Sourcepub fn eval(&mut self, script: &str) -> Result<MiraValue>
pub fn eval(&mut self, script: &str) -> Result<MiraValue>
Compile and execute a MiraScript program in this Runtime.
Sourcepub fn eval_unchecked(&mut self, script: &str) -> MiraValue
pub fn eval_unchecked(&mut self, script: &str) -> MiraValue
Compile and execute a MiraScript program in this Runtime, returning the result or panicking on error.
Sourcepub fn run(&mut self, script: &MiraScript) -> Result<MiraValue>
pub fn run(&mut self, script: &MiraScript) -> Result<MiraValue>
Execute a compiled script in this Runtime.
Sourcepub fn options(&self) -> &RunOptions
pub fn options(&self) -> &RunOptions
Return the Runtime’s execution configuration.
Source§impl Runtime
Functions for working with string handles.
impl Runtime
Functions for working with string handles.
Sourcepub fn insert_string(
&mut self,
value: impl Into<String>,
) -> Result<MiraHandle<String>>
pub fn insert_string( &mut self, value: impl Into<String>, ) -> Result<MiraHandle<String>>
Insert an owned string and return its typed handle.
Sourcepub fn get_string(&self, handle: MiraHandle<String>) -> Result<&str>
pub fn get_string(&self, handle: MiraHandle<String>) -> Result<&str>
Read a string handle owned by this Runtime.
Sourcepub fn get_string_mut(
&mut self,
handle: MiraHandle<String>,
) -> Result<&mut String>
pub fn get_string_mut( &mut self, handle: MiraHandle<String>, ) -> Result<&mut String>
Mutably read a string handle owned by this Runtime.
Sourcepub fn take_string(&mut self, handle: MiraHandle<String>) -> Result<String>
pub fn take_string(&mut self, handle: MiraHandle<String>) -> Result<String>
Take a string handle owned by this Runtime, consuming the handle.
Source§impl Runtime
Functions for working with function handles.
impl Runtime
Functions for working with function handles.
Sourcepub fn insert_function<T: MiraFunction>(
&mut self,
value: T,
) -> Result<MiraHandle<T>>
pub fn insert_function<T: MiraFunction>( &mut self, value: T, ) -> Result<MiraHandle<T>>
Insert a function and return a concrete typed handle.
Sourcepub fn get_function<T: MiraFunction>(&self, handle: MiraHandle<T>) -> Result<&T>
pub fn get_function<T: MiraFunction>(&self, handle: MiraHandle<T>) -> Result<&T>
Read the concrete function stored behind a typed handle.
Sourcepub fn take_function<T: MiraFunction>(
&mut self,
handle: MiraHandle<T>,
) -> Result<Rc<T>>
pub fn take_function<T: MiraFunction>( &mut self, handle: MiraHandle<T>, ) -> Result<Rc<T>>
Take the concrete function stored behind a typed handle, consuming the handle.
Source§impl Runtime
Functions for working with array handles.
impl Runtime
Functions for working with array handles.
Sourcepub fn insert_array<T: MiraArray>(&mut self, value: T) -> Result<MiraHandle<T>>
pub fn insert_array<T: MiraArray>(&mut self, value: T) -> Result<MiraHandle<T>>
Insert a array and return a concrete typed handle.
Sourcepub fn get_array<T: MiraArray>(&self, handle: MiraHandle<T>) -> Result<&T>
pub fn get_array<T: MiraArray>(&self, handle: MiraHandle<T>) -> Result<&T>
Read the concrete target represented by a typed array handle.
Sourcepub fn get_array_mut<T: MiraArray>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T>
pub fn get_array_mut<T: MiraArray>( &mut self, handle: MiraHandle<T>, ) -> Result<&mut T>
Mutably read the concrete object stored directly behind a array handle.
Sourcepub fn take_array<T: MiraArray>(&mut self, handle: MiraHandle<T>) -> Result<T>
pub fn take_array<T: MiraArray>(&mut self, handle: MiraHandle<T>) -> Result<T>
Take the concrete object stored directly behind a array handle, consuming the handle.
Source§impl Runtime
Functions for working with record handles.
impl Runtime
Functions for working with record handles.
Sourcepub fn insert_record<T: MiraRecord>(
&mut self,
value: T,
) -> Result<MiraHandle<T>>
pub fn insert_record<T: MiraRecord>( &mut self, value: T, ) -> Result<MiraHandle<T>>
Insert a record and return a concrete typed handle.
Sourcepub fn get_record<T: MiraRecord>(&self, handle: MiraHandle<T>) -> Result<&T>
pub fn get_record<T: MiraRecord>(&self, handle: MiraHandle<T>) -> Result<&T>
Read the concrete target represented by a typed record handle.
Sourcepub fn get_record_mut<T: MiraRecord>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T>
pub fn get_record_mut<T: MiraRecord>( &mut self, handle: MiraHandle<T>, ) -> Result<&mut T>
Mutably read the concrete object stored directly behind a record handle.
Sourcepub fn take_record<T: MiraRecord>(&mut self, handle: MiraHandle<T>) -> Result<T>
pub fn take_record<T: MiraRecord>(&mut self, handle: MiraHandle<T>) -> Result<T>
Take the concrete object stored directly behind a record handle, consuming the handle.
Source§impl Runtime
Functions for working with module handles.
impl Runtime
Functions for working with module handles.
Sourcepub fn insert_module<T: MiraModule>(
&mut self,
value: T,
) -> Result<MiraHandle<T>>
pub fn insert_module<T: MiraModule>( &mut self, value: T, ) -> Result<MiraHandle<T>>
Insert a module and return a concrete typed handle.
Sourcepub fn get_module<T: MiraModule>(&self, handle: MiraHandle<T>) -> Result<&T>
pub fn get_module<T: MiraModule>(&self, handle: MiraHandle<T>) -> Result<&T>
Read the concrete target represented by a typed module handle.
Sourcepub fn get_module_mut<T: MiraModule>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T>
pub fn get_module_mut<T: MiraModule>( &mut self, handle: MiraHandle<T>, ) -> Result<&mut T>
Mutably read the concrete object stored directly behind a module handle.
Sourcepub fn take_module<T: MiraModule>(&mut self, handle: MiraHandle<T>) -> Result<T>
pub fn take_module<T: MiraModule>(&mut self, handle: MiraHandle<T>) -> Result<T>
Take the concrete object stored directly behind a module handle, consuming the handle.