Skip to content
Enduriel edited this page Jun 1, 2024 · 5 revisions

File path: scripts/config/msu/semver.nut

Functions relating to semantic versioning, used by MSU when working with mod versions.

isSemver

::MSU.SemVer.isSemver( _string )
// _string is a string

Return true if _string is a valid semantic version.
Returns false otherwise.

getTable

::MSU.SemVer.getTable( _version )
// _version is a string

_version must be a semver version.
Returns a table representation of _version, with separate Version, PreRelease and Metadata arrays as values.

compare

::MSU.SemVer.compare( _version1, _version2 )
// _version1 and _version2 are tables

_version1 and _version are SemVer tables returned by getTable.
Returns the equivalent of _version1 <=> _version2 if they were integers:
Returns -1 if _version1 < _version2.
Returns 1 if _version1 > _version2.
Returns 0 if they are equal.

compareVersionWithOperator

::MSU.SemVer.compareVersionWithOperator( _version1, _operator, _version2 )
// _version1 and version2 are tables or strings
// _operator is a string or null

_version1 and _version are either SemVer tables returned by getTable, or Semantic Version strings.
_operator is one of the following symbols: < <= = null >= >
The function returns _version1 _operator _version2, null is considered equivalent to =.

Example

local table1 = ::MSU.SemVer.getTable("1.0.0");
local table2 = ::MSU.SemVer.getTable("1.0.2");
::logInfo(::MSU.compareVersionWithOperator(table1, "<", table2)); // prints true
::logInfo(::MSU.compareVersionWithOperator(table1, "=", table2)); // prints false
::logInfo(::MSU.compareVersionWithOperator(table1, ">", table2)); // prints false

compareMajorVersionWithOperator

::MSU.SemVer.compareMajorVersionWithOperator( _version1, _operator, _version2 )
// _version1 and version2 are tables or strings
// _operator is a string or null

_version1 and _version are either SemVer tables returned by getTable, or Semantic Version strings.
_operator is one of the following symbols: < <= = null >= >
The function compares the MAJOR sections of the Semantic Versions and returns true or false depending on the operator.

compareMinorVersionWithOperator

::MSU.SemVer.compareMinorVersionWithOperator( _version1, _operator, _version2 )
// _version1 and version2 are tables or strings
// _operator is a string or null

_version1 and _version are either SemVer tables returned by getTable, or Semantic Version strings.
_operator is one of the following symbols: < <= = null >= >
The function compares the MAJOR and MINOR sections of the Semantic Versions and returns true or false depending on the operator.

getVersionString

::MSU.SemVer.getVersionString( _version )
// _version is a table

_version is a table returned by getTable.
Returns the string version of the Semantic Version stored in the table.

getShortVersionString

::MSU.SemVer.getShortVersionString( _version )
// _version is a table

_version is a table returned by getTable.
Returns the string version of the Semantic Version stored in the table, without including the prerelease and metadata portions.

Clone this wiki locally