Fix setting Luau version number in `_VERSION` env var

This commit is contained in:
Alex Orlenko 2023-06-07 12:35:45 +01:00
parent 5a135a331a
commit 16bec29274
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
3 changed files with 16 additions and 1 deletions

View File

@ -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

View File

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

View File

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