From 16bec29274fec2c681a0f2b7caa735ad591a5f5d Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 7 Jun 2023 12:35:45 +0100 Subject: [PATCH] Fix setting Luau version number in `_VERSION` env var --- mlua-sys/src/luau/lua.rs | 5 +++++ src/luau.rs | 2 +- tests/luau.rs | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mlua-sys/src/luau/lua.rs b/mlua-sys/src/luau/lua.rs index 9556a4f..12c2e08 100644 --- a/mlua-sys/src/luau/lua.rs +++ b/mlua-sys/src/luau/lua.rs @@ -84,6 +84,11 @@ pub type lua_Alloc = unsafe extern "C" fn( nsize: usize, ) -> *mut c_void; +/// Returns Luau release version (eg. `0.xxx`). +pub const fn luau_version() -> Option<&'static str> { + option_env!("LUAU_VERSION") +} + extern "C" { // // State manipulation diff --git a/src/luau.rs b/src/luau.rs index bc4b2d0..f64e3a3 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -24,7 +24,7 @@ impl Lua { // 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") { + if let Some(version) = ffi::luau_version() { globals.raw_set("_VERSION", format!("Luau {version}"))?; } diff --git a/tests/luau.rs b/tests/luau.rs index 05390c7..33fa335 100644 --- a/tests/luau.rs +++ b/tests/luau.rs @@ -9,6 +9,16 @@ use std::sync::Arc; use mlua::{Compiler, CoverageInfo, Error, Lua, Result, Table, ThreadStatus, Value, VmState}; +#[test] +fn test_version() -> Result<()> { + let lua = Lua::new(); + assert!(lua + .globals() + .get::<_, String>("_VERSION")? + .starts_with("Luau 0.")); + Ok(()) +} + #[test] fn test_require() -> Result<()> { let lua = Lua::new();