summaryrefslogtreecommitdiff
path: root/src/state/log.rs
blob: 5afa8ca0867165e74528238e600346d9ded8bbb6 (plain)
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
use mlua::UserData;
use super::GlobalState;

#[derive(Debug, Default)]
pub struct LogState {
    pub visible: bool,
}

impl LogState {
    pub const fn new() -> Self {
        Self { visible: false }
    }
}

macro_rules! cfg {
    () => {
        GlobalState::instance().log
    };
}

macro_rules! cfg_mut {
    () => {
        GlobalState::instance_mut().log
    };
}

impl UserData for LogState {
    fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
        fields.add_field_function_get("visible", |_, _| Ok(cfg!().visible));
        fields.add_field_function_set("visible", |_, _, visible: bool| {
            cfg_mut!().visible = visible;
            Ok(())
        });
    }
}