Added lua function to get the current hostname

This makes it possible to set options depending on what machine we are
running
This commit is contained in:
2024-05-03 19:37:16 +02:00
parent bb15558ab2
commit bf3d757710
4 changed files with 58 additions and 8 deletions

View File

@@ -84,6 +84,12 @@ async fn app() -> anyhow::Result<()> {
std::env::var(name).map_err(mlua::ExternalError::into_lua_err)
})?;
util.set("get_env", get_env)?;
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)
})?;
util.set("get_hostname", get_hostname)?;
automation.set("util", util)?;
lua.globals().set("automation", automation)?;