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>, Box<MiraError>>
pub fn insert_global( &mut self, name: impl Into<String>, value: impl Into<MiraManageable>, ) -> Result<Option<MiraValue>, Box<MiraError>>
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>, Box<MiraError>>
pub fn insert_fn( &mut self, name: impl Into<String>, function: impl Into<MiraNativeFn>, ) -> Result<Option<MiraValue>, Box<MiraError>>
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 new() -> Runtime
pub fn new() -> Runtime
Create a Runtime using default limits and install the standard library.
Sourcepub fn with_options(options: RunOptions) -> Runtime
pub fn with_options(options: RunOptions) -> Runtime
Create a Runtime using explicit execution limits and providers.
Sourcepub fn eval(&mut self, script: &str) -> Result<MiraValue, Box<MiraError>>
pub fn eval(&mut self, script: &str) -> Result<MiraValue, Box<MiraError>>
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, Box<MiraError>>
pub fn run(&mut self, script: &MiraScript) -> Result<MiraValue, Box<MiraError>>
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>, Box<MiraError>>
pub fn insert_string( &mut self, value: impl Into<String>, ) -> Result<MiraHandle<String>, Box<MiraError>>
Insert an owned string and return its typed handle.
Sourcepub fn get_string(
&self,
handle: MiraHandle<String>,
) -> Result<&str, Box<MiraError>>
pub fn get_string( &self, handle: MiraHandle<String>, ) -> Result<&str, Box<MiraError>>
Read a string handle owned by this Runtime.
Sourcepub fn get_string_mut(
&mut self,
handle: MiraHandle<String>,
) -> Result<&mut String, Box<MiraError>>
pub fn get_string_mut( &mut self, handle: MiraHandle<String>, ) -> Result<&mut String, Box<MiraError>>
Mutably read a string handle owned by this Runtime.
Sourcepub fn take_string(
&mut self,
handle: MiraHandle<String>,
) -> Result<String, Box<MiraError>>
pub fn take_string( &mut self, handle: MiraHandle<String>, ) -> Result<String, Box<MiraError>>
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>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraFunction,
pub fn insert_function<T>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraFunction,
Insert a function and return a concrete typed handle.
Sourcepub fn get_function<T>(
&self,
handle: MiraHandle<T>,
) -> Result<&T, Box<MiraError>>where
T: MiraFunction,
pub fn get_function<T>(
&self,
handle: MiraHandle<T>,
) -> Result<&T, Box<MiraError>>where
T: MiraFunction,
Read the concrete function stored behind a typed handle.
Sourcepub fn take_function<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<Rc<T>, Box<MiraError>>where
T: MiraFunction,
pub fn take_function<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<Rc<T>, Box<MiraError>>where
T: MiraFunction,
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>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraArray,
pub fn insert_array<T>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraArray,
Insert a array and return a concrete typed handle.
Sourcepub fn get_array<T>(&self, handle: MiraHandle<T>) -> Result<&T, Box<MiraError>>where
T: MiraArray,
pub fn get_array<T>(&self, handle: MiraHandle<T>) -> Result<&T, Box<MiraError>>where
T: MiraArray,
Read the concrete target represented by a typed array handle.
Sourcepub fn get_array_mut<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T, Box<MiraError>>where
T: MiraArray,
pub fn get_array_mut<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T, Box<MiraError>>where
T: MiraArray,
Mutably read the concrete object stored directly behind a array handle.
Sourcepub fn take_array<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<T, Box<MiraError>>where
T: MiraArray,
pub fn take_array<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<T, Box<MiraError>>where
T: MiraArray,
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>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraRecord,
pub fn insert_record<T>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraRecord,
Insert a record and return a concrete typed handle.
Sourcepub fn get_record<T>(&self, handle: MiraHandle<T>) -> Result<&T, Box<MiraError>>where
T: MiraRecord,
pub fn get_record<T>(&self, handle: MiraHandle<T>) -> Result<&T, Box<MiraError>>where
T: MiraRecord,
Read the concrete target represented by a typed record handle.
Sourcepub fn get_record_mut<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T, Box<MiraError>>where
T: MiraRecord,
pub fn get_record_mut<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T, Box<MiraError>>where
T: MiraRecord,
Mutably read the concrete object stored directly behind a record handle.
Sourcepub fn take_record<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<T, Box<MiraError>>where
T: MiraRecord,
pub fn take_record<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<T, Box<MiraError>>where
T: MiraRecord,
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>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraModule,
pub fn insert_module<T>(
&mut self,
value: T,
) -> Result<MiraHandle<T>, Box<MiraError>>where
T: MiraModule,
Insert a module and return a concrete typed handle.
Sourcepub fn get_module<T>(&self, handle: MiraHandle<T>) -> Result<&T, Box<MiraError>>where
T: MiraModule,
pub fn get_module<T>(&self, handle: MiraHandle<T>) -> Result<&T, Box<MiraError>>where
T: MiraModule,
Read the concrete target represented by a typed module handle.
Sourcepub fn get_module_mut<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T, Box<MiraError>>where
T: MiraModule,
pub fn get_module_mut<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<&mut T, Box<MiraError>>where
T: MiraModule,
Mutably read the concrete object stored directly behind a module handle.
Sourcepub fn take_module<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<T, Box<MiraError>>where
T: MiraModule,
pub fn take_module<T>(
&mut self,
handle: MiraHandle<T>,
) -> Result<T, Box<MiraError>>where
T: MiraModule,
Take the concrete object stored directly behind a module handle, consuming the handle.