OS API

Access operating system information — platform detection, hardware stats, system paths, user info, and constants.

Overview

The OS API provides cross-platform queries for platform type and architecture, system directories, CPU count, memory statistics, uptime, load averages, user information, and system constants like endianness and line endings. Create an instance with OS().

var os = OS()

Platform Information

os.type()

Returns the operating system type.

Returns: "windows", "linux", "darwin", "freebsd", "openbsd", "netbsd", or "unknown".

var os = OS()
if (os.type() == "windows") {
    print("Running on Windows")
} else if (os.type() == "linux") {
    print("Running on Linux")
}
os.arch()

Returns the CPU architecture.

Returns: "x64", "x86", "arm64", "arm", or "unknown".

os.version()

Returns the OS version string. Platform-specific: Windows version number, Linux kernel version, macOS Darwin version.

os.release()

Returns the OS release name or number.

os.platform()

Returns a combined platform identifier (e.g. "windows-x64", "linux-arm64", "darwin-arm64").

System Directories

os.homeDir()

Returns the current user's home directory path.

os.tmpDir()

Returns the system temporary directory path.

os.execPath()

Returns the absolute path to the currently running executable.

var os = OS()
print("Home: " + os.homeDir())
print("Temp: " + os.tmpDir())
print("Executable: " + os.execPath())

CPU Information

os.cpuCount()

Returns the number of logical CPU cores (includes hyperthreading). Returns 0 if detection fails.

Memory Information

os.totalMem()

Returns total physical memory in bytes.

os.freeMem()

Returns free physical memory in bytes.

os.memory()

Returns a comprehensive memory statistics map.

Returns: Map with keys "total", "free", "used" (all in bytes), and "percent" (0–100).

var os = OS()
var mem = os.memory()
print("Total: %v", mem["total"])
print("Free: %v", mem["free"])
print("Usage: %v%%", mem["percent"])

if (mem["percent"] > 90) {
    print("WARNING: Memory usage is critical!")
}

System Status

os.hostname()

Returns the system hostname.

os.uptime()

Returns system uptime in seconds. Returns 0 if unavailable.

os.loadavg()

Returns system load averages as a list of 3 numbers (1 min, 5 min, 15 min). Returns [0.0, 0.0, 0.0] on Windows.

User Information

os.userInfo()

Returns information about the current user.

Returns: Map with "username", "uid" (−1 on Windows), "gid" (−1 on Windows), "homedir", and "shell" (empty on Windows).

var os = OS()
var user = os.userInfo()
print("Username: " + user["username"])
print("Home: " + user["homedir"])

System Constants

os.endianness()

Returns the system byte order: "LE" (little-endian) or "BE" (big-endian).

os.eol()

Returns the platform line ending sequence: "\r\n" on Windows, "\n" on Unix.

Examples

System Information Report

var os = OS()

print("=== System Information ===")
print("OS: " + os.type() + " " + os.arch())
print("Platform: " + os.platform())
print("Version: " + os.version())
print("Hostname: " + os.hostname())

print("=== Hardware ===")
print("CPU Cores: " + str(os.cpuCount()))
var mem = os.memory()
print("Memory Usage: " + str(mem["percent"]) + "%")

print("=== User ===")
var user = os.userInfo()
print("Username: " + user["username"])
print("Home: " + user["homedir"])

Platform-Specific Config Directory

var os = OS()

func getConfigDir() {
    var type = os.type()
    var home = os.homeDir()
    if (type == "windows") {
        return home + "\\AppData\\Local\\MyApp"
    } else if (type == "darwin") {
        return home + "/Library/Application Support/MyApp"
    } else {
        return home + "/.config/myapp"
    }
}

print("Config directory: " + getConfigDir())

Platform Notes

MethodWindowsLinuxmacOS
type(), arch(), version()
homeDir(), tmpDir(), execPath()
cpuCount(), totalMem(), freeMem()
uptime()✓ (10.15+)
loadavg()
userInfo()Limited