Make _VERSION global consistently formatted and add runtime version to it

This commit is contained in:
Filip Tibell 2023-04-20 08:52:54 +02:00
parent a1c78c4ab9
commit 0d06e096c5
No known key found for this signature in database
4 changed files with 81 additions and 0 deletions

View file

@ -10,6 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Changed
- The `_VERSION` global now follows a consistent format `Lune x.y.z+luau` to allow libraries to check against it for version requirements.
Examples:
- `Lune 0.0.0+0`
- `Lune 1.0.0+500`
- `Lune 0.11.22+9999`
### Fixed ### Fixed
- Fixed using instances as keys in tables - Fixed using instances as keys in tables

View file

@ -119,6 +119,26 @@ pub fn create() -> LuaResult<&'static Lua> {
.set_environment(dbg_trace_env)? .set_environment(dbg_trace_env)?
.into_function()?; .into_function()?;
lua.set_named_registry_value("dbg.trace", dbg_trace_fn)?; lua.set_named_registry_value("dbg.trace", dbg_trace_fn)?;
// Modify the _VERSION global to also contain the current version of Lune
let luau_version_full = 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")
}
globals.set(
"_VERSION",
lua.create_string(&format!(
"Lune {lune}+{luau}",
lune = env!("CARGO_PKG_VERSION"),
luau = luau_version,
))?,
)?;
// All done // All done
Ok(lua) Ok(lua)
} }

View file

@ -75,6 +75,7 @@ create_tests! {
global_pcall: "globals/pcall", global_pcall: "globals/pcall",
global_type: "globals/type", global_type: "globals/type",
global_typeof: "globals/typeof", global_typeof: "globals/typeof",
global_version: "globals/version",
serde_json_decode: "serde/json/decode", serde_json_decode: "serde/json/decode",
serde_json_encode: "serde/json/encode", serde_json_encode: "serde/json/encode",
serde_toml_decode: "serde/toml/decode", serde_toml_decode: "serde/toml/decode",

View file

@ -0,0 +1,50 @@
-- _VERSION global should follow the following format:
--[[
_VERSION global must have the following format:
Lune LUNE_MAJOR.LUNE_MINOR.LUNE_PATCH+LUAU_VERSION
Examples:
Lune 0.0.0+0
Lune 1.0.0+500
Lune 0.11.22+9999
]]
assert(_VERSION ~= nil, "_VERSION global is missing")
assert(type(_VERSION) == "string", "_VERSION global must be a string")
assert(string.sub(_VERSION, 1, 5) == "Lune ", "_VERSION global must start with 'Lune '")
local withoutPrefix = string.sub(_VERSION, 6)
local versions = string.split(withoutPrefix, "+")
assert(versions[1] ~= nil, "_VERSION global does not contain lune version")
assert(versions[2] ~= nil, "_VERSION global does not contain luau version")
local luneVersion = string.split(versions[1], ".")
assert(luneVersion[1] ~= nil, "_VERSION global is missing lune major version")
assert(luneVersion[2] ~= nil, "_VERSION global is missing lune minor version")
assert(luneVersion[3] ~= nil, "_VERSION global is missing lune patch version")
assert(
string.find(versions[2], ".", 1, true) == nil,
"_VERSION global contains more than one semver partial for luau version"
)
assert(tonumber(luneVersion[1]) ~= nil, "_VERSION global lune major version is not a number")
assert(tonumber(luneVersion[2]) ~= nil, "_VERSION global lune minor version is not a number")
assert(tonumber(luneVersion[3]) ~= nil, "_VERSION global lune patch version is not a number")
assert(tonumber(versions[2]) ~= nil, "_VERSION global luau version is not a number")
local rebuilt = string.format(
"Lune %d.%d.%d+%d",
tonumber(luneVersion[1]) :: number,
tonumber(luneVersion[2]) :: number,
tonumber(luneVersion[3]) :: number,
tonumber(versions[2]) :: number
)
print("_VERSION:", _VERSION)
print("Rebuilt:", rebuilt)
assert(rebuilt == _VERSION)