Implement basic builtin functions
This commit is contained in:
parent
16d7dec4cc
commit
4cbbff259c
11
src/builtin/color.rs
Normal file
11
src/builtin/color.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::Builtin;
|
||||
use crate::value::Value;
|
||||
|
||||
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
f.insert("rgb".to_owned(), Box::new(|args| {
|
||||
let red = args.get("red");
|
||||
todo!()
|
||||
}));
|
||||
}
|
@ -1,15 +1,20 @@
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::args::CallArgs;
|
||||
use crate::common::Scope;
|
||||
use crate::function::Function;
|
||||
use crate::value::Value;
|
||||
|
||||
pub(crate) type Builtin = dyn Fn(&Scope) -> Value + Send + Sync;
|
||||
mod color;
|
||||
|
||||
pub(crate) type Builtin = Box<dyn Fn(&CallArgs) -> Value + Send + Sync>;
|
||||
|
||||
lazy_static! {
|
||||
pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap<String, Function> = {
|
||||
let m = BTreeMap::new();
|
||||
pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap<String, Builtin> = {
|
||||
let mut m = BTreeMap::new();
|
||||
color::register(&mut m);
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ impl Value {
|
||||
let func = match scope.functions.get(&s) {
|
||||
Some(f) => f,
|
||||
None => match GLOBAL_FUNCTIONS.get(&s) {
|
||||
Some(f) => f,
|
||||
Some(f) => return Some(f(&args)),
|
||||
None => todo!("called undefined function"),
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user