refactor(config)!: Moved Timeout into utils module and moved module
The module is now setup in automation_lib::lua::utils.
This commit is contained in:
31
automation_lib/src/lua/utils/mod.rs
Normal file
31
automation_lib/src/lua/utils/mod.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
mod timeout;
|
||||
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub use timeout::Timeout;
|
||||
|
||||
use crate::Module;
|
||||
|
||||
fn create_module(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
|
||||
let utils = lua.create_table()?;
|
||||
|
||||
utils.set("Timeout", lua.create_proxy::<Timeout>()?)?;
|
||||
|
||||
let get_hostname = lua.create_function(|_lua, ()| {
|
||||
hostname::get()
|
||||
.map(|name| name.to_str().unwrap_or("unknown").to_owned())
|
||||
.map_err(mlua::ExternalError::into_lua_err)
|
||||
})?;
|
||||
utils.set("get_hostname", get_hostname)?;
|
||||
let get_epoch = lua.create_function(|_lua, ()| {
|
||||
Ok(SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("Time is after UNIX EPOCH")
|
||||
.as_millis())
|
||||
})?;
|
||||
utils.set("get_epoch", get_epoch)?;
|
||||
|
||||
Ok(utils)
|
||||
}
|
||||
|
||||
inventory::submit! {Module::new("utils", create_module)}
|
||||
Reference in New Issue
Block a user