use mlua::prelude::*;
const APP_NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
const REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
const LICENSE_SPDX: &str = env!("CARGO_PKG_LICENSE");
const LICENSE: &str = include_str!("../../LICENSE.md");
pub fn register_version_apis(lua: &Lua) -> LuaResult<()> {
let about: LuaTable = lua.create_table()?;
set_version_info(&about)?;
let version_func: LuaFunction = lua.create_function(move |_, ()| {
print_version_info();
Ok(())
})?;
let license_func: LuaFunction = lua.create_function(move |_, ()| {
print_license();
Ok(())
})?;
let globals: LuaTable = lua.globals();
globals.set("about", about)?;
globals.set("version", version_func)?;
globals.set("license", license_func)
}
fn set_version_info(table: &LuaTable) -> LuaResult<()> {
table.set("app_name", APP_NAME)?;
table.set("version", VERSION)?;
table.set("authors", AUTHORS)?;
table.set("description", DESCRIPTION)?;
table.set("repository", REPOSITORY)?;
table.set("license_spdx", LICENSE_SPDX)?;
table.set("license", LICENSE)
}
fn print_version_info() {
println!(
"{} v{} - {}\nRepository: {}\nAuthors: {}\nLicense: {}",
APP_NAME, VERSION, DESCRIPTION, REPOSITORY, AUTHORS, LICENSE_SPDX,
);
}
fn print_license() {
println!("{}", LICENSE);
}