use std::ptr::addr_of_mut; use mlua::{UserData, UserDataFields}; use self::{keymap::KeyMap, theme::Theme}; pub mod env; pub mod theme; pub mod keymap; #[derive(Debug, Default)] pub struct GlobalConfig { pub theme: Theme, pub keymap: KeyMap, } const DUMMY_CONFIG: GlobalConfig = GlobalConfig::new(); impl GlobalConfig { const fn new() -> Self { Self { theme: Theme::new(), keymap: KeyMap::new(), } } pub fn get() -> &'static mut Self { static mut GLOBAL_CONFIG: GlobalConfig = GlobalConfig::new(); unsafe { &mut *addr_of_mut!(GLOBAL_CONFIG) } } } impl UserData for GlobalConfig { fn add_fields<'lua, F: UserDataFields<'lua, Self>>(fields: &mut F) { fields.add_field_function_get("theme", |_, _| Ok(DUMMY_CONFIG.theme)); fields.add_field_function_get("keymap", |_, _| Ok(DUMMY_CONFIG.keymap)); } }