Implement builtin function length()
This commit is contained in:
parent
38802b69c5
commit
b31c9587bc
@ -1 +1,15 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::Builtin;
|
||||
use crate::units::Unit;
|
||||
use crate::value::{Number, Value};
|
||||
|
||||
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "length", |args, _| {
|
||||
let len = match arg!(args, 0, "list").eval() {
|
||||
Value::List(v, _) => Number::from(v.len()),
|
||||
_ => Number::from(1)
|
||||
};
|
||||
Some(Value::Dimension(len, Unit::None))
|
||||
});
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ lazy_static! {
|
||||
pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap<String, Builtin> = {
|
||||
let mut m = BTreeMap::new();
|
||||
color::register(&mut m);
|
||||
list::register(&mut m);
|
||||
math::register(&mut m);
|
||||
meta::register(&mut m);
|
||||
string::register(&mut m);
|
||||
|
Loading…
x
Reference in New Issue
Block a user