Files
automation_rs/automation_lib/src/lib.rs
Dreaded_X 1ffccd955c refactor(config)!: Move scheduler out of device_manager
Due to changes made in mlua the new scheduler is much simpler. It also
had no real business being part of the device manager, so it has now been
moved to be part of the returned config.
2025-10-20 04:48:28 +02:00

63 lines
1.3 KiB
Rust

#![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<mlua::Table>;
type DefinitionsFn = fn() -> String;
pub struct Module {
name: &'static str,
register_fn: RegisterFn,
definitions_fn: Option<DefinitionsFn>,
}
impl Module {
pub const fn new(
name: &'static str,
register_fn: RegisterFn,
definitions_fn: Option<DefinitionsFn>,
) -> 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<mlua::Table> {
(self.register_fn)(lua)
}
pub fn definitions(&self) -> Option<String> {
self.definitions_fn.map(|f| f())
}
}
pub fn load_modules(lua: &mlua::Lua) -> mlua::Result<()> {
for module in inventory::iter::<Module> {
debug!(name = module.get_name(), "Loading module");
let table = module.register(lua)?;
lua.register_module(module.get_name(), table)?;
}
Ok(())
}
inventory::collect!(Module);