Store function names
This commit is contained in:
parent
0b5e9a5f44
commit
fe0d46ecf3
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Function {
|
struct Function {
|
||||||
name: &'static str,
|
name: String,
|
||||||
inner: Rc<dyn Fn(&mut Scope, Vec<Value>) -> Value>,
|
inner: Rc<dyn Fn(&mut Scope, Vec<Value>) -> Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ impl Debug for Function {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Scope {
|
pub struct Scope {
|
||||||
variables: HashMap<String, ValueInner>,
|
variables: HashMap<String, ValueInner>,
|
||||||
functions: HashMap<&'static str, Function>,
|
functions: HashMap<String, Function>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scope {
|
impl Scope {
|
||||||
|
|
@ -43,11 +43,12 @@ impl Scope {
|
||||||
|
|
||||||
pub fn add_fn(
|
pub fn add_fn(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &'static str,
|
name: impl Into<String>,
|
||||||
f: impl Fn(&mut Scope, Vec<Value>) -> Value + 'static,
|
f: impl Fn(&mut Scope, Vec<Value>) -> Value + 'static,
|
||||||
) {
|
) {
|
||||||
|
let name = name.into();
|
||||||
self.functions.insert(
|
self.functions.insert(
|
||||||
name,
|
name.clone(),
|
||||||
Function {
|
Function {
|
||||||
name,
|
name,
|
||||||
inner: Rc::new(f),
|
inner: Rc::new(f),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user