From c88417a3b6585885d069ff9043cc54e799fbcb33 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 3 Dec 2022 21:04:21 +0000 Subject: [PATCH] Redefine `_VERSION` for Luau to include version number. https://github.com/khvzak/mlua/discussions/228 --- src/luau.rs | 6 ++++++ tests/tests.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/luau.rs b/src/luau.rs index 768c8cf..e7f397b 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -22,6 +22,12 @@ impl Lua { globals.raw_set("require", self.create_function(lua_require)?)?; globals.raw_set("vector", self.create_c_function(lua_vector)?)?; + // Set `_VERSION` global to include version number + // The environment variable `LUAU_VERSION` set by the build script + if let Some(version) = option_env!("LUAU_VERSION") { + globals.raw_set("_VERSION", format!("Luau {version}"))?; + } + Ok(()) } } diff --git a/tests/tests.rs b/tests/tests.rs index a71691e..7d24656 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -276,7 +276,10 @@ fn test_error() -> Result<()> { end, 3) local function handler(err) - if string.match(_VERSION, ' 5%.1$') or string.match(_VERSION, ' 5%.2$') or _VERSION == "Luau" then + if string.match(_VERSION, " 5%.1$") + or string.match(_VERSION, " 5%.2$") + or string.match(_VERSION, "Luau") + then -- Special case for Lua 5.1/5.2 and Luau local caps = string.match(err, ': (%d+)$') if caps then