From 04a5a938994ddb95cfaa9a74b180e457d3a2b5d0 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 2 Aug 2024 11:38:19 +0200 Subject: implement new lua interface --- src/state/log.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/state/log.rs (limited to 'src/state/log.rs') diff --git a/src/state/log.rs b/src/state/log.rs new file mode 100644 index 0000000..5afa8ca --- /dev/null +++ b/src/state/log.rs @@ -0,0 +1,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(()) + }); + } +} -- cgit v1.2.3-70-g09d2