Redefine `_VERSION` for Luau to include version number.

https://github.com/khvzak/mlua/discussions/228
This commit is contained in:
Alex Orlenko 2022-12-03 21:04:21 +00:00
parent 6e95386f30
commit c88417a3b6
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
2 changed files with 10 additions and 1 deletions

View File

@ -22,6 +22,12 @@ impl Lua {
globals.raw_set("require", self.create_function(lua_require)?)?; globals.raw_set("require", self.create_function(lua_require)?)?;
globals.raw_set("vector", self.create_c_function(lua_vector)?)?; 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(()) Ok(())
} }
} }

View File

@ -276,7 +276,10 @@ fn test_error() -> Result<()> {
end, 3) end, 3)
local function handler(err) 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 -- Special case for Lua 5.1/5.2 and Luau
local caps = string.match(err, ': (%d+)$') local caps = string.match(err, ': (%d+)$')
if caps then if caps then