Host and build information.
-
platform.os()→ For example,"linux","macos","windows","ios","android","wasm". -
platform.arch()→ For example,"arm64","x86_64","wasm32". -
platform.hostVersion()→ The Varn version string, for example"0.0.1". -
platform.version→ The same version already split, as{ major, minor, patch, string }. The three numbers are integers, so a component can gate on the runtime it needs without parsing the string and without inventing its own comparison:local v = require("platform").version if v.major > 1 or (v.major == 1 and v.minor >= 2) then -- A feature that landed in 1.2 is available end
-
platform.cpuCount()→ The number of CPUs. -
platform.pointerSize()→4or8. -
platform.endianness()→"little"or"big". -
platform.libPrefix()andplatform.shlibSuffix()→ The shared-library naming pieces. -
platform.libraryFilename(name)→ For example,libz.sofor"z". -
platform.getLibraryPathByName(name, subdir?)→ Buildssubdir/filename(a dev helper).
-- Prints the pointer size and byte order of the host build.
local p = require("platform")
print("pointerSize()", p.pointerSize())
print("endianness() ", p.endianness())
assert(p.pointerSize() == 4 or p.pointerSize() == 8, "pointerSize")
assert(p.endianness() == "little" or p.endianness() == "big", "endianness")
print("platform byte layout ok")-- Prints the number of CPUs reported for the host.
local p = require("platform")
local cpus = p.cpuCount()
print("cpuCount()", cpus)
assert(type(cpus) == "number" and cpus >= 1, "cpuCount should be at least one")
print("platform cpu count ok")-- Prints semver baked in at configure time for the host binary.
local p = require("platform")
local v = p.hostVersion()
print("hostVersion", v)
assert(type(v) == "string" and #v > 0, "hostVersion")
assert(v:match("^%d+%.%d+%.%d+"), "expected semver x.y.z")-- Prints host identifiers, system data, and shared library naming hints.
local p = require("platform")
print("os() ", p.os())
print("arch() ", p.arch())
print("hostVersion()", p.hostVersion())
print("cpuCount() ", p.cpuCount())
print("pointerSize()", p.pointerSize())
print("endianness() ", p.endianness())
print("libPrefix() ", p.libPrefix())
print("shlibSuffix()", p.shlibSuffix())
assert(type(p.os()) == "string" and #p.os() > 0, "os")
assert(type(p.arch()) == "string", "arch")
assert(p.cpuCount() >= 1, "cpuCount")
assert(p.pointerSize() == 4 or p.pointerSize() == 8, "pointerSize")
assert(p.endianness() == "little" or p.endianness() == "big", "endianness")
print("platform info ok")-- Prints the shared library prefix and suffix pieces for the host.
local p = require("platform")
local prefix = p.libPrefix()
local suffix = p.shlibSuffix()
print("libPrefix() ", prefix)
print("shlibSuffix()", suffix)
assert(type(prefix) == "string", "libPrefix")
assert(type(suffix) == "string" and #suffix > 0, "shlibSuffix")
print("platform lib naming ok")-- Builds example filenames for a short logical library name.
local p = require("platform")
local name = "z"
local fn = p.libraryFilename(name)
print("libraryFilename('z') =", fn)
local rel = p.getLibraryPathByName(name, "vendor/libs")
print("getLibraryPathByName('z', 'vendor/libs') =", rel)
assert(fn:match("%."), "expected extension in filename")
print("platform library path helpers ok")-- Prints the host operating system and CPU architecture identifiers.
local p = require("platform")
print("os() ", p.os())
print("arch()", p.arch())
assert(type(p.os()) == "string" and #p.os() > 0, "os")
assert(type(p.arch()) == "string" and #p.arch() > 0, "arch")
print("platform system identity ok")Reads the host operating-system and build APIs directly, with no external dependency.