[−][src]Struct glsp_stdlib::Runtime
The GameLisp interpreter.
Runtime
owns all of the data required to interpret GameLisp code: a set of global variables,
a symbol table, a set of registered Rust functions, and much more.
To manipulate a GameLisp runtime, you don't call methods on the Runtime
type directly.
Instead, use the run
method to establish a particular Runtime
as the
"active runtime", and then manipulate it using free functions like glsp::sym
and glsp::load
.
If you attempt to execute any GameLisp-related code without an active runtime, it will almost always panic.
It's possible for multiple Runtimes
to coexist. Each runtime is strictly isolated from the
others - they don't share global variables, symbols, and so on. This means that it's possible
to run GameLisp code in isolated Runtimes
on multiple threads without requiring any
synchronization.
Most GameLisp programs should create a single Runtime
at the top of their main()
function,
immediately call Runtime::run()
, and keep the same runtime active for the entire duration
of the program.
use glsp::prelude::*; fn main() { let runtime = Runtime::new(); runtime.run(|| { glsp::load("main.glsp")?; //call the (main) function which was defined by main.glsp, //discarding its return value let main_gfn: Root<GFn> = glsp::global("main")?; let _: Val = glsp::call(&main_gfn, &())?; //the closure's return value must be a Result Ok(()) }); }
Implementations
impl Runtime
[src]
pub fn new() -> Runtime
[src]
Construct a Runtime
with default settings.
To construct a custom Runtime
, use RuntimeBuilder
instead.
pub fn run<F, R>(&self, f: F) -> Option<R> where
F: FnOnce() -> GResult<R>,
[src]
F: FnOnce() -> GResult<R>,
Establish this Runtime
as the active runtime.
For the duration of the f
closure, any calls to global functions like
glsp::sym
or glsp::set_global
will
manipulate this Runtime
.
The closure must return a GResult
. If the closure returns Ok(x)
, this method will
return Some(x)
. If the closure returns Err(err)
, this method will print a stack trace
and then return None
.
It's possible to use Runtime::run
to transfer GameLisp data, such as Syms
and Roots
,
from one Runtime
to another. This is memory-safe, but it should always be avoided. It may
cause unexpected behaviour, trigger a panic, or even cause the process to abort.
Auto Trait Implementations
impl !RefUnwindSafe for Runtime
[src]
impl !Send for Runtime
[src]
impl !Sync for Runtime
[src]
impl Unpin for Runtime
[src]
impl !UnwindSafe for Runtime
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoElement<Slot> for T where
T: IntoVal,
[src]
T: IntoVal,
pub fn into_element(self) -> Result<Slot, GError>
[src]
impl<T> IntoVal for T where
T: StaticMarker,
[src]
T: StaticMarker,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,