diff --git a/src/lune/globals/mod.rs b/src/lune/globals/mod.rs index 18a70c4..dfcb928 100644 --- a/src/lune/globals/mod.rs +++ b/src/lune/globals/mod.rs @@ -4,10 +4,12 @@ use super::util::TableBuilder; mod g_table; mod require; +mod version; pub fn inject_all(lua: &'static Lua) -> LuaResult<()> { let all = TableBuilder::new(lua)? .with_value("_G", g_table::create(lua)?)? + .with_value("_VERSION", version::create(lua)?)? .with_value("require", require::create(lua)?)? .build_readonly()?; diff --git a/src/lune/globals/version.rs b/src/lune/globals/version.rs index c073bad..153350a 100644 --- a/src/lune/globals/version.rs +++ b/src/lune/globals/version.rs @@ -1,5 +1,24 @@ use mlua::prelude::*; pub fn create(lua: &'static Lua) -> LuaResult> { - lua.create_table() + let luau_version_full = lua + .globals() + .get::<_, LuaString>("_VERSION") + .expect("Missing _VERSION global"); + + let luau_version = luau_version_full + .to_str()? + .strip_prefix("Luau 0.") + .expect("_VERSION global is formatted incorrectly") + .trim(); + + if luau_version.is_empty() { + panic!("_VERSION global is missing version number") + } + + lua.create_string(format!( + "Lune {lune}+{luau}", + lune = env!("CARGO_PKG_VERSION"), + luau = luau_version, + )) }