From 7a63987cbee519e9853e37f0a1d91a904a511d07 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 19 Aug 2023 17:34:15 -0500 Subject: [PATCH] Bring back version global --- src/lune/globals/mod.rs | 2 ++ src/lune/globals/version.rs | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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, + )) }