pub struct Machine { /* private fields */ }
Expand description
Executes an EndBASIC program and tracks its state.
Implementations§
Source§impl Machine
impl Machine
Sourcepub fn with_signals_chan(signals: (Sender<Signal>, Receiver<Signal>)) -> Self
pub fn with_signals_chan(signals: (Sender<Signal>, Receiver<Signal>)) -> Self
Constructs a new empty machine with the given signals communication channel.
Sourcepub fn with_signals_chan_and_yield_now_fn(
signals: (Sender<Signal>, Receiver<Signal>),
yield_now_fn: Option<YieldNowFn>,
) -> Self
pub fn with_signals_chan_and_yield_now_fn( signals: (Sender<Signal>, Receiver<Signal>), yield_now_fn: Option<YieldNowFn>, ) -> Self
Constructs a new empty machine with the given signals communication channel and yielding function.
Sourcepub fn add_clearable(&mut self, clearable: Box<dyn Clearable>)
pub fn add_clearable(&mut self, clearable: Box<dyn Clearable>)
Registers the given clearable.
In the common case, functions and commands hold a reference to the out-of-machine state
they interact with. This state is invisible from here, but we may need to have access
to it to reset it as part of the clear
operation. In those cases, such state must be
registered via this hook.
Sourcepub fn add_callable(&mut self, callable: Rc<dyn Callable>)
pub fn add_callable(&mut self, callable: Rc<dyn Callable>)
Registers the given builtin callable, which must not yet be registered.
Sourcepub fn get_signals_tx(&self) -> Sender<Signal>
pub fn get_signals_tx(&self) -> Sender<Signal>
Obtains a channel via which to send signals to the machine during execution.
Sourcepub fn last_error(&self) -> Option<&str>
pub fn last_error(&self) -> Option<&str>
Returns the last execution error.
Sourcepub fn get_data(&self) -> &[Option<Value>]
pub fn get_data(&self) -> &[Option<Value>]
Obtains immutable access to the data values available during the current execution.
Sourcepub fn get_symbols(&self) -> &Symbols
pub fn get_symbols(&self) -> &Symbols
Obtains immutable access to the state of the symbols.
Sourcepub fn get_mut_symbols(&mut self) -> &mut Symbols
pub fn get_mut_symbols(&mut self) -> &mut Symbols
Obtains mutable access to the state of the symbols.
Sourcepub fn get_var_as_bool(&self, name: &str) -> Result<bool>
pub fn get_var_as_bool(&self, name: &str) -> Result<bool>
Retrieves the variable name
as a boolean. Fails if it is some other type or if it’s not
defined.
Sourcepub fn get_var_as_int(&self, name: &str) -> Result<i32>
pub fn get_var_as_int(&self, name: &str) -> Result<i32>
Retrieves the variable name
as an integer. Fails if it is some other type or if it’s not
defined.
Sourcepub fn get_var_as_string(&self, name: &str) -> Result<&str>
pub fn get_var_as_string(&self, name: &str) -> Result<&str>
Retrieves the variable name
as a string. Fails if it is some other type or if it’s not
defined.
Sourcepub fn drain_signals(&mut self)
pub fn drain_signals(&mut self)
Consumes any pending signals so that they don’t interfere with an upcoming execution.
Sourcepub async fn exec(&mut self, input: &mut dyn Read) -> Result<StopReason>
pub async fn exec(&mut self, input: &mut dyn Read) -> Result<StopReason>
Executes a program extracted from the input
readable.
Note that this does not consume self
. As a result, it is possible to execute multiple
different programs on the same machine, all sharing state.