Bring back version global

This commit is contained in:
Filip Tibell 2023-08-19 17:34:15 -05:00
parent 24b6498774
commit 7a63987cbe
2 changed files with 22 additions and 1 deletions

View file

@ -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()?;

View file

@ -1,5 +1,24 @@
use mlua::prelude::*;
pub fn create(lua: &'static Lua) -> LuaResult<impl IntoLua<'_>> {
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,
))
}