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>) {
|
|
|
|
f.insert(
|
|
|
|
"if".to_owned(),
|
|
|
|
Box::new(|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)
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|