#![feature(iterator_try_collect)] #![feature(with_negative_coherence)] use tracing::debug; pub mod action_callback; pub mod config; pub mod device; pub mod device_manager; pub mod error; pub mod event; pub mod helpers; pub mod lua; pub mod messages; pub mod mqtt; type RegisterFn = fn(lua: &mlua::Lua) -> mlua::Result; type DefinitionsFn = fn() -> String; pub struct Module { name: &'static str, register_fn: RegisterFn, definitions_fn: Option, } impl Module { pub const fn new( name: &'static str, register_fn: RegisterFn, definitions_fn: Option, ) -> Self { Self { name, register_fn, definitions_fn, } } pub const fn get_name(&self) -> &'static str { self.name } pub fn register(&self, lua: &mlua::Lua) -> mlua::Result { (self.register_fn)(lua) } pub fn definitions(&self) -> Option { self.definitions_fn.map(|f| f()) } } pub fn load_modules(lua: &mlua::Lua) -> mlua::Result<()> { for module in inventory::iter:: { debug!(name = module.get_name(), "Loading module"); let table = module.register(lua)?; lua.register_module(module.get_name(), table)?; } Ok(()) } inventory::collect!(Module);