Work on builtin functions
This commit is contained in:
parent
52c9905b14
commit
8b26fabb62
@ -3,9 +3,41 @@ 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!()
|
||||
}));
|
||||
macro_rules! arg {
|
||||
($args:ident, $idx:literal, $name:literal) => {
|
||||
match $args.get(stringify!($idx)) {
|
||||
Some(v) => v,
|
||||
None => match $args.get($name) {
|
||||
Some(v) => v,
|
||||
None => panic!("missing variable"),
|
||||
},
|
||||
};
|
||||
};
|
||||
($args:ident, $idx:literal, $name:literal, $default:literal) => {
|
||||
match $args.get(stringify!($idx)) {
|
||||
Some(v) => v,
|
||||
None => match $args.get($name) {
|
||||
Some(v) => v,
|
||||
None => $default,
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
f.insert(
|
||||
"rgb".to_owned(),
|
||||
Box::new(|args| {
|
||||
let channels = args.get("channels").unwrap_or(&Value::Null);
|
||||
if channels.is_null() {
|
||||
let _red: &Value = arg!(args, 0, "red");
|
||||
let _green: &Value = arg!(args, 1, "green");
|
||||
let _blue: &Value = arg!(args, 2, "blue");
|
||||
// Value::Color()
|
||||
} else {
|
||||
todo!("channels variable in `rgb`")
|
||||
};
|
||||
todo!()
|
||||
}),
|
||||
);
|
||||
}
|
@ -2,13 +2,11 @@ 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;
|
||||
|
||||
mod color;
|
||||
|
||||
pub(crate) type Builtin = Box<dyn Fn(&CallArgs) -> Value + Send + Sync>;
|
||||
pub(crate) type Builtin = Box<dyn Fn(&CallArgs) -> Option<Value> + Send + Sync>;
|
||||
|
||||
lazy_static! {
|
||||
pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap<String, Builtin> = {
|
||||
@ -17,4 +15,3 @@ lazy_static! {
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user