pub struct Spaik { /* private fields */ }
Expand description
A SPAIK Context, this is the main way to use SPAIK
Implementations§
source§impl Spaik
impl Spaik
sourcepub fn new_no_core() -> Spaik
pub fn new_no_core() -> Spaik
Create a new SPAIK VM
sourcepub fn get<R>(&mut self, var: impl AsSym) -> Result<R>where
PV: FromLisp<R>,
pub fn get<R>(&mut self, var: impl AsSym) -> Result<R>where PV: FromLisp<R>,
Return a clone of var
sourcepub unsafe fn objref<T>(&mut self, var: impl AsSym) -> Result<*const T>where
T: Userdata,
pub unsafe fn objref<T>(&mut self, var: impl AsSym) -> Result<*const T>where T: Userdata,
Get a reference to a user-defined object type stored in the vm.
Arguments
var
: Variable name
Safety
The returned pointer may not be dereferenced after a garbage-collection cycle runs, which also means that no SPAIK code may run on this VM before the pointer is dereferenced. A gc cycle may leave the returned pointer dangling.
Safe Alternative
Use Gc<T>
, like this:
use spaik::prelude::*;
use spaik::ExampleObject;
let mut vm = Spaik::new_no_core();
vm.set("obj", ExampleObject { x: 1.0, y: 3.3 });
let mut obj: Gc<ExampleObject> = vm.get("obj").unwrap();
assert_eq!(obj.with(|r| (r.x, r.y)), (1.0, 3.3));
sourcepub fn obj<T: Userdata>(&mut self, var: impl AsSym) -> Result<T>
pub fn obj<T: Userdata>(&mut self, var: impl AsSym) -> Result<T>
Get a clone of a user-defined object type stored in the vm.
sourcepub unsafe fn objref_mut<T>(&mut self, var: impl AsSym) -> Result<*mut T>where
T: Userdata,
pub unsafe fn objref_mut<T>(&mut self, var: impl AsSym) -> Result<*mut T>where T: Userdata,
Retrieve a variable as a mutable reference.
Arguments
var
: Variable name
Safety
The returned pointer may not be dereferenced after a garbage-collection cycle runs, which also means that no SPAIK code may run on this VM before the pointer is dereferenced. A gc cycle may leave the returned pointer dangling.
Safe Alternative
Use Gc<T>
, like this:
use spaik::prelude::*;
use spaik::ExampleObject;
let mut vm = Spaik::new_no_core();
vm.set("obj", ExampleObject { x: 1.0, y: 3.3 });
let mut obj: Gc<ExampleObject> = vm.get("obj").unwrap();
assert_eq!(obj.with(|r| (r.x, r.y)), (1.0, 3.3));
sourcepub fn exec(&mut self, expr: impl AsRef<str>) -> Result<()>
pub fn exec(&mut self, expr: impl AsRef<str>) -> Result<()>
Run an expression and ignore the result (unless there was an error.)
Arguments
expr
: Lisp expression
pub fn trace_report(&self)
sourcepub fn load(&mut self, lib: impl AsSym) -> Result<SymRef>
pub fn load(&mut self, lib: impl AsSym) -> Result<SymRef>
Load library from the load-path, by default this is ./lisp/
.
Arguments
lib
: If the library is stored at"<name>.lisp"
, thenlib
should be<name>
as either a string or symbol
sourcepub fn load_with<S>(&mut self, _src_path: S, _lib: Sym, _code: S) -> Result<Sym>where
S: AsRef<str>,
pub fn load_with<S>(&mut self, _src_path: S, _lib: Sym, _code: S) -> Result<Sym>where S: AsRef<str>,
Load a SPAIK library from a string, this is useful both for embedding code
into your binary with e.g load_with(x, y, include_str!(...))
or when
loading from a virtual filesystem.
Arguments
src_path
: File-system path to the.lisp
file, needed for source-file/line error messages.lib
: Library symbol name, i.e the argument to(load ...)
code
: The source-code contents insidesrc_path
sourcepub fn query<R>(&mut self, enm: impl EnumCall) -> Result<R>where
PV: FromLisp<R>,
pub fn query<R>(&mut self, enm: impl EnumCall) -> Result<R>where PV: FromLisp<R>,
Call a function by-enum and return the result
Use Spaik::cmd
if don’t care about the result.
sourcepub fn cmd(&mut self, enm: impl EnumCall) -> Result<()>
pub fn cmd(&mut self, enm: impl EnumCall) -> Result<()>
Call a function by-enum and ignore the result
Use Spaik::query
if you need the result.
sourcepub fn call<R>(&mut self, sym: impl AsSym, args: impl Args) -> Result<R>where
PV: FromLisp<R>,
pub fn call<R>(&mut self, sym: impl AsSym, args: impl Args) -> Result<R>where PV: FromLisp<R>,
Call a function by-name an args and return the result.
Use Spaik::run
if don’t care about the result.
sourcepub fn run(&mut self, sym: impl AsSym, args: impl Args) -> Result<()>
pub fn run(&mut self, sym: impl AsSym, args: impl Args) -> Result<()>
Call a function by-name an args and ignore the result.
Use Spaik::call
if you need the result.
sourcepub fn gc(&mut self)
pub fn gc(&mut self)
Perform a full GC collection, this may finish a currently ongoing collection and start a new one afterwards.
sourcepub fn fulfil<R, A, T>(&mut self, pr: Promise<T>, ans: A) -> Result<R>where
PV: FromLisp<R>,
A: IntoLisp + Clone + Send + 'static,
pub fn fulfil<R, A, T>(&mut self, pr: Promise<T>, ans: A) -> Result<R>where PV: FromLisp<R>, A: IntoLisp + Clone + Send + 'static,
Fulfil a Promise<T>
by running its continuation with value ans
sourcepub fn add_load_path(&mut self, path: impl AsRef<str>)
pub fn add_load_path(&mut self, path: impl AsRef<str>)
Add to load path, this influences where Spaik::load
will search for
spaik files.
Panics
Panics if the sys/load-path
variable is not defined, or is not a
vector.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Spaik
impl Send for Spaik
impl !Sync for Spaik
impl Unpin for Spaik
impl !UnwindSafe for Spaik
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where C: Color,
source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where C: Color,
source§fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
source§fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
source§fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
source§fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
source§fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
source§fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
source§fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
source§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
source§fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
source§fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
source§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
source§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
source§fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
source§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
source§fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
source§fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
source§fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
source§fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
source§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
source§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
source§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
source§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
source§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
source§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
source§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
source§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
source§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
source§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
source§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
source§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
source§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
source§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
source§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
source§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
source§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
source§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
source§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
source§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
source§fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
source§fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
source§fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
source§fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
source§fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
source§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
source§fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
source§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moresource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more