Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 1.36 KB

File metadata and controls

55 lines (36 loc) · 1.36 KB

VersionInfo

Summary

geode.VersionInfo parses and compares version strings. It uses a small part of semver. A version looks like v1.2.3 or v1.2.3-beta.1. The functions take strings, so you do not build a version by hand. Bad inputs use the recoverable error shape. See globals Error shapes.

parse

geode.VersionInfo.parse(version: string) -> ({ major: number, minor: number, patch: number }?, string?)

Parses a version string into its parts. Returns a table, or nil and an error message.

compare

geode.VersionInfo.compare(a: string, b: string) -> (number?, string?)

Compares two versions. Returns -1 if a is older, 0 if equal, 1 if a is newer. Returns nil and an error message if either string is bad.

matches

geode.VersionInfo.matches(constraint: string, version: string) -> (boolean?, string?)

Tests a version against a constraint such as >=v1.2.0. Returns true or false, or nil and an error message.

Example

local v = geode.VersionInfo

local parts = v.parse("v1.2.3")
print(parts.major, parts.minor, parts.patch) -- 1 2 3

print(v.compare("v1.0.0", "v1.2.0"))   -- -1
print(v.matches(">=v1.2.0", "v1.3.0")) -- true

Related

Source

  • src/bindings/geode/GeodeSmallBindings.cpp