Version
SemVer version as defined by https://semver.org.
Spec: https://docs.rs/semver/1.0.20/semver/struct.Version.html
Properties
major
This item is read only and cannot be modified. Read OnlyVersion.major:
number
minor
This item is read only and cannot be modified. Read OnlyVersion.minor:
number
patch
This item is read only and cannot be modified. Read OnlyVersion.patch:
number
pre
This item is read only and cannot be modified. Read OnlyVersion.pre:
Prerelease
build
This item is read only and cannot be modified. Read OnlyVersion.build:
BuildMetadata
Functions
new
parse
Possible reasons for the parse to fail include:
Errors
Type | Description |
---|---|
UnexpectedEnd ("1.0") | too few numeric components. A SemVer version must have exactly three. If you are looking at something that has fewer than three numbers in it, it’s possible it is a VersionReq instead (with an implicit default ^ comparison operator). |
LeadingZero ("1.0.01") | a numeric component has a leading zero. |
UnexpectedChar ("1.0.unknown") | unexpected character in one of the components. |
EmptySegment ("1.0.0-" or "1.0.0+") | the pre-release or build metadata are indicated present but empty. |
UnexpectedCharAfter ("1.0.0-alpha_123") | pre-release or build metadata have something outside the allowed characters, which are 0-9, A-Z, a-z, -, and . (dot). |
Overflow ("9007199254740992.0.0") | value of major, minor or patch exceeds LUAU_MAX_PRECISE_INT (2^53 - 1). |
MaxIdentifierLength ("1.0.0-" .. string.rep("a", 513)) | identifier length exceeds MAX_IDENTIFIER_LENGTH (512). |
is
Version.
is
(
obj:
any
) →
boolean
Returns true
if obj
is a Version.
__tostring
Version:
__tostring
(
) →
string
This metamethod transforms self
into a string.
__eq
This metamethod tests for self
and other
values to be equal and is used by the operators ==
and ~=
.
__lt
This metamethod tests less than (for self
and other
) and is used by the operators <
and >
.
__le
This metamethod tests less than or equal to (for self
and other
) and is used by the operators <=
and >=
.
cmp_precedence
Compare the major, minor, patch and Prerelease value of self
and other
. Unlike the relational operators,
this method disregards BuildMetadata and considers Versions that differ only in BuildMetadata
equal. This comparison is what the SemVer spec refers to as "precedence".
Returns:
- -1 if
self
has lower precedence thanother
- 0 if
self
andother
have the same precedence - 1 if
self
has higher precedence thanother
The CargoSemver.Ordering
enum (with the fields: Less
= -1, Equal
= 0, Greater
= 1) can be used to clarify code using this method.
Usage:
if removedVersion:cmp_precedence(addedVersion) == Ordering.Greater then
warn("Downgrading", msg)
else
print("Updating", msg)
end