pub struct Rant { /* fields omitted */ }
Expand description
A Rant execution context.
Implementations
Creates a new Rant context with the default seed (0) and loads the standard library.
Creates a new Rant context with the specified seed and loads the standard library.
Creates a new Rant context with a seed generated by a thread-local PRNG and loads the standard library.
Creates a new Rant context with the specified options.
pub fn compile<R: Reporter>(
&self,
source: &str,
reporter: &mut R
) -> Result<RantProgram, CompilerErrorKind>
pub fn compile<R: Reporter>(
&self,
source: &str,
reporter: &mut R
) -> Result<RantProgram, CompilerErrorKind>
Compiles a source string using the specified reporter.
pub fn compile_named<R: Reporter>(
&self,
source: &str,
reporter: &mut R,
name: &str
) -> Result<RantProgram, CompilerErrorKind>
pub fn compile_named<R: Reporter>(
&self,
source: &str,
reporter: &mut R,
name: &str
) -> Result<RantProgram, CompilerErrorKind>
Compiles a source string using the specified reporter and source name.
Compiles a source string without reporting problems.
Note
This method will not generate any compiler messages, even if it fails.
If you require this information, use the compile()
method instead.
pub fn compile_quiet_named(
&self,
source: &str,
name: &str
) -> Result<RantProgram, CompilerErrorKind>
pub fn compile_quiet_named(
&self,
source: &str,
name: &str
) -> Result<RantProgram, CompilerErrorKind>
Compiles a source string without reporting problems and assigns it the specified name.
Note
This method will not generate any compiler messages, even if it fails.
If you require this information, use the compile()
method instead.
pub fn compile_file<P: AsRef<Path>, R: Reporter>(
&self,
path: P,
reporter: &mut R
) -> Result<RantProgram, CompilerErrorKind>
pub fn compile_file<P: AsRef<Path>, R: Reporter>(
&self,
path: P,
reporter: &mut R
) -> Result<RantProgram, CompilerErrorKind>
Compiles a source file using the specified reporter.
pub fn compile_file_quiet<P: AsRef<Path>>(
&self,
path: P
) -> Result<RantProgram, CompilerErrorKind>
pub fn compile_file_quiet<P: AsRef<Path>>(
&self,
path: P
) -> Result<RantProgram, CompilerErrorKind>
Compiles a source file without reporting problems.
Note
This method will not generate any compiler messages, even if it fails.
If you require this information, use the compile_file()
method instead.
Sets a global variable. This will auto-define the global if it doesn’t exist.
If the global already exists and is a constant, the write will not succeed.
Returns true
if the write succeeded; otherwise, false
.
Sets a global constant. This will auto-define the global if it doesn’t exist.
If the global already exists and is a constant, the write will not succeed.
Returns true
if the write succeeded; otherwise, false
.
Sets a global’s value, forcing the write even if the existing global is a constant. This will auto-define the global if it doesn’t exist.
Gets the value of a global variable.
Returns true
if a global with the specified key exists.
Removes the global with the specified key. Returns true
if the global existed prior to removal.
Iterates over the names of all globals stored in the context.
Gets the options used to initialize the context.
Resets the RNG back to its initial state with the current seed.
pub fn add_data_source(
&mut self,
name: &str,
data_source: impl DataSource + 'static
) -> Option<Box<dyn DataSource + 'static>>
pub fn add_data_source(
&mut self,
name: &str,
data_source: impl DataSource + 'static
) -> Option<Box<dyn DataSource + 'static>>
Adds a data source to the context, making it available to scripts.
Removes the data source with the specified name from the context, making it no longer available to scripts.
Returns a bool
indicating whether a data source with the specified name is present in the context.
Removes all data sources from the context.
Returns a reference to the data source associated with the specified name.
pub fn iter_data_sources(
&self
) -> impl Iterator<Item = (&str, &Box<dyn DataSource + 'static>)>
pub fn iter_data_sources(
&self
) -> impl Iterator<Item = (&str, &Box<dyn DataSource + 'static>)>
Iterates over all data sources (and their names) in the context.
Runs a program and returns the output value.
pub fn run_with<A>(
&mut self,
program: &RantProgram,
args: A
) -> RuntimeResult<RantValue> where
A: Into<Option<HashMap<String, RantValue>>>,
pub fn run_with<A>(
&mut self,
program: &RantProgram,
args: A
) -> RuntimeResult<RantValue> where
A: Into<Option<HashMap<String, RantValue>>>,
Runs a program with the specified arguments and returns the output value.