[][src]Struct glsp::Runtime

pub struct 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(|| {

		//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


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() -> Result<R, GError>, 

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> IntoElement<Slot> for T where
    T: IntoVal

impl<T> IntoVal for T where
    T: StaticMarker, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.