diff --git a/src/run.rs b/src/run.rs index 9403afb..550bac5 100644 --- a/src/run.rs +++ b/src/run.rs @@ -32,8 +32,8 @@ impl Debug for Function { #[derive(Debug, Clone, Default)] pub struct Scope { - pub variables: HashMap, - pub functions: HashMap, + variables: HashMap, + functions: HashMap, } impl Scope { @@ -48,6 +48,11 @@ impl Scope { self.variables.remove(&name); } } + + pub fn add_fn(&mut self, name: &'static str, f: impl Fn(Vec) -> Value + 'static) { + self.functions + .insert(name.into(), Function::new(name.into(), f)); + } } pub trait Eval {