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
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") }
Returns the CPU architecture.
Returns: "x64", "x86", "arm64", "arm", or "unknown".
Returns the OS version string. Platform-specific: Windows version number, Linux kernel version, macOS Darwin version.
Returns the OS release name or number.
Returns a combined platform identifier (e.g. "windows-x64", "linux-arm64", "darwin-arm64").
System Directories
Returns the current user's home directory path.
Returns the system temporary directory path.
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
Returns the number of logical CPU cores (includes hyperthreading). Returns 0 if detection fails.
Memory Information
Returns total physical memory in bytes.
Returns free physical memory in bytes.
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
Returns the system hostname.
Returns system uptime in seconds. Returns 0 if unavailable.
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
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
Returns the system byte order: "LE" (little-endian) or "BE" (big-endian).
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
| Method | Windows | Linux | macOS |
|---|---|---|---|
type(), arch(), version() | ✓ | ✓ | ✓ |
homeDir(), tmpDir(), execPath() | ✓ | ✓ | ✓ |
cpuCount(), totalMem(), freeMem() | ✓ | ✓ | ✓ |
uptime() | ✓ | ✓ | ✓ (10.15+) |
loadavg() | ✗ | ✓ | ✓ |
userInfo() | Limited | ✓ | ✓ |