os

Process info, environment variables, and filesystem utilities at the OS level.

Import

import os

Properties

os.platform

Platform string: "linux", "darwin", or "windows".

os.sep

Path separator ("/" or "\\").

os.args

Command-line arguments as an array of strings.

Functions

os.pid() -> int

Current process ID.

os.ppid() -> int

Parent process ID.

os.cwd() -> str

Current working directory.

os.chdir(path: str)

Change working directory.

os.home() -> str

Home directory path.

os.tempdir() -> str

Platform temp directory path.

os.cpu_count() -> int

Number of logical CPU cores.

os.exit(code: int)

Exit the process with the given exit code. Fires any @on_exit handlers first.

Filesystem

os.mkdir(path), os.rmdir(path), os.remove(path), os.rename(old, new), os.exists(path), os.is_file(path), os.is_dir(path), os.list_dir(path), os.glob(pattern)

Environment variables

os.env(key) / os.getenv(key) - get an environment variable.
os.setenv(key, val) - set an environment variable.
os.hasenv(key) - check if a variable is set.
os.environ() - all environment variables as a map.

Examples

import os

println(os.platform)             -- linux
println(os.cwd())                -- /home/user
println(os.env("HOME"))          -- /home/user
println(os.pid())                -- 12345
println(os.cpu_count())          -- 8

if os.hasenv("DEBUG") {
    println("debug mode")
}

let all = os.environ()
for k, v in all { println("{k}={v}") }