@eryx/os Module

Summary

Functions

os.setenv(key: string, value: string?)()
os.environ(){ [string]: string }
os.luauVersion(){ release: string, hash: string }
os.exit(code: number?)()
os.cwd()Path
os.chdir(path: PathLike)()
os.cliargs(){ string }
os.exec(cmd: string, args: { string }, opts: SpawnOptions?)ExecResult
os.spawn(cmd: string, args: { string }, opts: SpawnOptions?)ProcessHandle

API Reference

Functions

os.getenv

Get a specific environment variable

os.getenv(key: string)string?

Parameters

key: string

Environment variable name.

Returns

Environment variable value, or nil when undefined.

os.setenv

Set or unset a specific environment variable

os.setenv(key: string, value: string?)()

Parameters

key: string

Environment variable name.

value: string?

Value to set, or nil to unset.

os.environ

Get all currently defined environment variables.

os.environ(){ [string]: string }

Returns

{ [string]: string }

A table of environment variables keyed by name.

os.luauVersion

Get the git hash of Luau

There are no official "proper" version numbers for Luau, so the values here are derived from git.

The hash is the most reliable value, and indicates the exact version of Luau compiled against

The release is based on most recent tag, and typically follows the format 0.xxx, but can include additional information if the tagged commit is not the most recent

os.luauVersion(){ release: string, hash: string }

os.platform

Get the current system platform.

os.platform()Platform

Returns

Current platform identifier.

os.arch

Get the current system architecture.

os.arch()Arch

Returns

Current CPU architecture identifier.

os.hostname

Get the current system hostname.

os.hostname()string

Returns

Hostname reported by the operating system.

os.tmpdir

Get the current user's temporary directory.

os.tmpdir()string

Returns

Absolute path to the temp directory.

os.homedir

Get the current user's home directory.

os.homedir()string

Returns

Absolute path to the home/profile directory.

os.cpucount

Get the number of CPUs present.

os.cpucount()number

Returns

Number of logical CPUs.

os.totalmem

Get the total system memory in KiB.

os.totalmem()number

Returns

Total memory in kibibytes.

os.freemem

Get the free system memory in KiB.

os.freemem()number

Returns

Free memory in kibibytes.

os.uptime

Get the system uptime in seconds.

os.uptime()number

Returns

Seconds since system boot.

os.pid

Get the current process PID.

os.pid()number

Returns

Current process identifier.

os.uid

Current process user identifier (uid on POSIX, SID string on Windows).

os.uid()PrincipalId

Returns

Current user identifier.

os.gid

Current process group identifier (gid on POSIX, SID string on Windows).

os.gid()PrincipalId

Returns

Current group identifier.

os.euid

Effective user identifier (euid on POSIX, SID string on Windows).

os.euid()PrincipalId

Returns

Effective user identifier.

os.egid

Effective group identifier (egid on POSIX, SID string on Windows).

os.egid()PrincipalId

Returns

Effective group identifier.

os.userInfo

Resolve user details for current user or an explicit subject.

os.userInfo(subject: PrincipalId?)PrincipalInfo?

Parameters

subject: PrincipalId?

Optional uid/SID or user name. Defaults to current user.

Returns

Resolved user details, or nil when not found.

os.groupInfo

Resolve group details for current group or an explicit subject.

os.groupInfo(subject: PrincipalId?)PrincipalInfo?

Parameters

subject: PrincipalId?

Optional gid/SID or group name. Defaults to current group.

Returns

Resolved group details, or nil when not found.

os.exit

Exit the process with a specific status code

os.exit(code: number?)()

Parameters

code: number?

Process exit code. Defaults to 0.

os.clock

Get the current monotonic system clock time in seconds.

os.clock()number

Returns

Monotonic clock value in seconds.

os.cwd

Get the current working directory.

os.cwd()Path

Returns

Absolute path to the current working directory.

os.chdir

Change the current working directory

os.chdir(path: PathLike)()

Parameters

path: PathLike

New working directory path.

os.cliargs

Get the command line arguments for this script.

Returns only the user-supplied arguments; the executable name, subcommand, and script path are automatically stripped.

For example, eryx run foo.luau --verbose bar returns {"--verbose", "bar"}.

os.cliargs(){ string }

Returns

{ string }

Ordered list of user-supplied command-line arguments.

os.exec

⚠ Yields

Execute a child process and wait for it to complete.

This function is equivalent to using:

os.spawn(...):wait()
os.exec(cmd: string, args: { string }, opts: SpawnOptions?)ExecResult

Parameters

cmd: string

Executable path or name to resolve on PATH.

args: { string }

Ordered argument list passed to the process.

Optional spawn configuration.

Returns

Process result containing captured output and exit code.

os.spawn

Spawn a process, returning an interactive handle to it

Use stream handles for child process stdio:

local p = os.spawn("cat")
p.stdin:write("hello\n")
p.stdin:close()
local chunk = p.stdout:read(4096)
os.spawn(cmd: string, args: { string }, opts: SpawnOptions?)ProcessHandle

Parameters

cmd: string

Executable path or name to resolve on PATH.

args: { string }

Ordered argument list passed to the process.

Optional spawn configuration.

Returns

Handle for interacting with the running child process.

os.shell

⚠ Yields

Run a command as if it was run on the shell. This is similar to setting shell=true in SpawnOptions, but does not attempt to capture input or output from the process.

SpawnOptions.shell is ignored when calling this function.

Warning

This function passes the provided argument directly to cmd.exe /C

os.shell(cmd: string, opts: SpawnOptions?)number

Parameters

cmd: string

Command string to execute through the shell.

Optional spawn configuration.

Returns

Process exit status code.

Types

SpawnOptions

Options controlling how a child process is spawned.

type SpawnOptions = { cwd: PathLike?, env: { [string]: string }?, shell: boolean? }
cwd: PathLike?

Specify the directory for the child process

env: { [string]: string }?

Specify additional environment variables for the child process

shell: boolean?

Run this as a shell command

Warning

This passes the provided command and arguments directly to cmd.exe /C

ExecResult

Result of os.exec(...).

type ExecResult = { stdout: string, stderr: string, code: number }
stdout: string

Captured stdout output.

stderr: string

Captured stderr output.

code: number

Process exit status code.

ProcessHandle

Handle to a running child process returned by os.spawn.

type ProcessHandle = { pid: number, status: number?, stdin: stream.WriteOnlyStream, stdout: stream.ReadOnlyStream, stderr: stream.ReadOnlyStream, wait: ((self: ProcessHandle) → ExecResult), kill: ((self: ProcessHandle, signal: number | string?) → ()) }
ProcessHandle:wait()ExecResult

Wait for the process to complete

ProcessHandle:kill(signal: number | string?)()

Kill the process

pid: number

Process ID

status: number?

Process return code, if it's exited

stdin: stream.WriteOnlyStream

Writable stream connected to the child process stdin.

stdout: stream.ReadOnlyStream

Readable stream connected to the child process stdout.

stderr: stream.ReadOnlyStream

Readable stream connected to the child process stderr.

PrincipalId

Cross-platform principal identifier. On POSIX this is typically numeric (uid/gid), and on Windows this is typically a SID string.

PrincipalInfo

Resolved user/group metadata. Fields may vary by platform.

type PrincipalInfo = { id: PrincipalId, name: string?, kind: "user" | "group", platform: Platform, uid: number?, gid: number?, sid: string?, home: string?, shell: string?, domain: string?, accountName: string? }

Canonical identifier for the principal.

name: string?

Friendly account/group name when available.

kind: "user" | "group"

Principal category.

platform: Platform

Platform that produced this identity record.

uid: number?

POSIX uid when available.

gid: number?

POSIX gid when available.

sid: string?

Windows SID when available.

home: string?

Home/profile directory when available.

shell: string?

Login shell when available (POSIX).

domain: string?

Windows account domain when available.

accountName: string?

Windows account name when available.

Platform

Supported host platforms.

type Platform = "windows" | "macos" | "linux" | nil

Arch

Supported CPU architecture identifiers.

type Arch = "x64" | "arm64" | "arm" | "x86" | nil