summaryrefslogtreecommitdiff
path: root/src/library/mod.rs
blob: 7d266eb5f0489590770982f1f01b128d663306d6 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! The standard library.

mod align;
mod boxed;
mod color;
mod font;
mod page;
mod spacing;

pub use align::*;
pub use boxed::*;
pub use color::*;
pub use font::*;
pub use page::*;
pub use spacing::*;

use std::rc::Rc;

use crate::compute::scope::Scope;
use crate::prelude::*;

macro_rules! std {
    ($($name:literal => $func:expr),* $(,)?) => {
        /// Create a scope with all standard library functions.
        pub fn _std() -> Scope {
            let mut std = Scope::new();
            $(std.insert($name, wrap!($func));)*
            std
        }
    };
}

macro_rules! wrap {
    ($func:expr) => {
        Rc::new(|name, args, ctx| Box::pin($func(name, args, ctx)))
    };
}

std! {
    "align" => align,
    "box" => boxed,
    "font" => font,
    "h" => h,
    "page" => page,
    "pagebreak" => pagebreak,
    "rgb" => rgb,
    "v" => v,
}