use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use mlua::{UserData, UserDataFields}; use self::theme::Theme; pub mod constants; pub mod theme; #[derive(Debug, Default)] pub struct GlobalConfig { pub theme: Theme, } static GLOBAL_CONFIG: RwLock = RwLock::new(GlobalConfig::new()); const DUMMY_CONFIG: GlobalConfig = GlobalConfig::new(); impl GlobalConfig { const fn new() -> Self { Self { theme: Theme::new(), } } pub fn instance() -> RwLockReadGuard<'static, Self> { GLOBAL_CONFIG.read().unwrap() } pub fn instance_mut() -> RwLockWriteGuard<'static, Self> { GLOBAL_CONFIG.write().unwrap() } } 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)) } }