Store function names

This commit is contained in:
numzero 2025-04-19 11:00:07 +03:00
parent 0b5e9a5f44
commit fe0d46ecf3

View File

@ -7,7 +7,7 @@ use crate::{
#[derive(Clone)]
struct Function {
name: &'static str,
name: String,
inner: Rc<dyn Fn(&mut Scope, Vec<Value>) -> Value>,
}
@ -20,7 +20,7 @@ impl Debug for Function {
#[derive(Debug, Clone, Default)]
pub struct Scope {
variables: HashMap<String, ValueInner>,
functions: HashMap<&'static str, Function>,
functions: HashMap<String, Function>,
}
impl Scope {
@ -43,11 +43,12 @@ impl Scope {
pub fn add_fn(
&mut self,
name: &'static str,
name: impl Into<String>,
f: impl Fn(&mut Scope, Vec<Value>) -> Value + 'static,
) {
let name = name.into();
self.functions.insert(
name,
name.clone(),
Function {
name,
inner: Rc::new(f),