grass/src/builtin/mod.rs

47 lines
1.0 KiB
Rust
Raw Normal View History

2020-01-25 20:58:30 -05:00
use lazy_static::lazy_static;
use std::collections::BTreeMap;
2020-01-25 23:33:45 -05:00
use crate::args::CallArgs;
2020-01-25 20:58:30 -05:00
use crate::value::Value;
2020-02-02 22:33:04 -05:00
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,
},
};
};
}
2020-01-25 23:33:45 -05:00
mod color;
2020-02-02 18:05:36 -05:00
mod list;
mod map;
mod math;
mod meta;
mod selector;
mod string;
2020-01-25 23:33:45 -05:00
2020-01-26 15:28:39 -05:00
pub(crate) type Builtin = Box<dyn Fn(&CallArgs) -> Option<Value> + Send + Sync>;
2020-01-25 20:58:30 -05:00
lazy_static! {
2020-01-25 23:33:45 -05:00
pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap<String, Builtin> = {
let mut m = BTreeMap::new();
color::register(&mut m);
2020-02-02 22:33:04 -05:00
meta::register(&mut m);
2020-01-25 20:58:30 -05:00
m
};
}