TyOverby / ares

A Lisp made for easy integration with Rust.
9 stars 1 forks source link

Add with_other_state to loadedcontext #39

Closed TyOverby closed 9 years ago

TyOverby commented 9 years ago

This will let people swap the state out of an already loaded context.

This can be useful while inside of User Functions or Ast Functions.

let mut ctx = Context::new();
ctx.set_fn("something", ast_fn("something", |args, ctx| {
    let mut new_state = 0;
    ctx.with_other_state(&mut new_state, move |new_ctx| {
        for expr in args {
            new_ctx.eval(&expr);
        }
    }
}));
bwo commented 9 years ago

lgtm!