grass/src/builtin/meta.rs

17 lines
452 B
Rust
Raw Normal View History

2020-02-02 22:33:04 -05:00
use std::collections::BTreeMap;
2020-02-02 21:09:29 -05:00
2020-02-02 22:33:04 -05:00
use super::Builtin;
use crate::value::Value;
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
2020-02-03 07:11:35 -05:00
decl!(f "if", |args| {
let cond: &Value = arg!(args, 0, "condition");
let if_true = arg!(args, 1, "if-true").clone();
let if_false = arg!(args, 2, "if-false").clone();
if cond.is_true() {
Some(if_true)
} else {
Some(if_false)
}
});
2020-02-02 22:33:04 -05:00
}