@eryx/os Module

JSON

Summary

Classes

pid: number
status: number?
ProcessHandle:kill(signal: number?)()
ProcessHandle:write(data: string)()

Functions

os.getenv(key: string)string?
os.setenv(key: string, value: string?)()
os.environ(){ [string]: string }
os.luauVersion(){ release: string, hash: string }
os.hostname()string
os.tmpdir()string
os.homedir()string
os.cpucount()number
os.totalmem()number
os.freemem()number
os.uptime()number
os.pid()number
os.exit(code: number?)()
os.clock()number
os.cwd()string
os.chdir(path: string)()
os.cliargs(){ string }
os.exec(cmd: string, args: { string }, opts: SpawnOptions?)ExecResult
os.spawn(cmd: string, args: { string }, opts: SpawnOptions?)ProcessHandle
os.shell(cmd: string, opts: SpawnOptions?)number

API Reference

Classes

ProcessHandle

Properties

pid: number

Process ID

status: number?

Process return code, if it's exited

ProcessHandle:wait

Wait for the process to complete

ProcessHandle:wait()ExecResult

ProcessHandle:kill

Kill the process

ProcessHandle:kill(signal: number?)()

Parameters

signal: number?

Optional signal to raise in process

ProcessHandle:write

Write data to the process' stdin

ProcessHandle:write(data: string)()

Parameters

data: string

Data to write

ProcessHandle:closeStdin

Close the connecting to the process' stdin

ProcessHandle:closeStdin()()

ProcessHandle:readStdout

Read any data available on stdout

ProcessHandle:readStdout()string?

ProcessHandle:readStderr

Read any data available on stderr

ProcessHandle:readStderr()string?

Functions

os.getenv

Get a specific environment variable

os.getenv(key: string)string?

Parameters

key: string

string Environment variable to get

os.setenv

Set or unset a specific environment variable

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

Parameters

key: string

string Environment variable to set

value: string?

string? Value to set, or nil to unset

os.environ

Get all currently defined environment variables

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

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

os.arch

Get the current system arch

os.arch()Arch

os.hostname

Get the current system hostname

os.hostname()string

os.tmpdir

Get the current user's temporary directory

os.tmpdir()string

os.homedir

Get the current user's home directory

os.homedir()string

os.cpucount

Get the number of CPUs present

os.cpucount()number

os.totalmem

Get the total system memory in KiB

os.totalmem()number

os.freemem

Get the free system memory in KiB

os.freemem()number

os.uptime

Get the system uptime in seconds

os.uptime()number

os.pid

Get the current process PID

os.pid()number

os.exit

Exit the process with a specific status code

os.exit(code: number?)()

Parameters

code: number?

number? Process exit code

os.clock

Get the current time of the system clock

os.clock()number

os.cwd

Get the current working directory

os.cwd()string

os.chdir

Change the current working directory

os.chdir(path: string)()

Parameters

path: string

string New directory

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 }

os.exec

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

string The process to spawn. Can be either a complete path, or a name to be resolve on the PATH

args: { string }

SpawnOptions? Optional addition configuration

os.spawn

Spawn a process, returning an interactive handle to it

os.spawn(cmd: string, args: { string }, opts: SpawnOptions?)ProcessHandle

Parameters

cmd: string

string The process to spawn. Can be either a complete path, or a name to be resolve on the PATH

args: { string }

SpawnOptions? Optional addition configuration

os.shell

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

string The command to run

SpawnOptions? Optional addition configuration

Returns

number

number The process' status code after completion

Types

SpawnOptions

cwd: string?

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

stdout: string
stderr: string
code: number

Platform

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

Arch

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