summaryrefslogtreecommitdiff
path: root/src/library/utility/mod.rs
blob: 13220242bb09d61182c80d7cfa6356be131fe027 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Computational utility functions.

mod color;
mod math;
mod string;

pub use color::*;
pub use math::*;
pub use string::*;

use crate::library::prelude::*;

/// The name of a value's type.
pub fn type_(_: &mut Context, args: &mut Args) -> TypResult<Value> {
    Ok(args.expect::<Value>("value")?.type_name().into())
}

/// Ensure that a condition is fulfilled.
pub fn assert(_: &mut Context, args: &mut Args) -> TypResult<Value> {
    let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
    if !v {
        bail!(span, "assertion failed");
    }
    Ok(Value::None)
}