Types
A POSIX signal subscription from std.os.signals.
An opaque handle: only std.os can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
Functions
Returns n fresh CSPRNG bytes (0..255); the maximum request is 1 MiB.
count: How many bytes to draw; at most 1 MiB.
println(std.os.entropy(16).len())
println(std.os.getcwd())
println(std.os.temp_dir())
println(std.os.platform() + "/" + std.os.arch())
println(std.os.hostname())
println(std.os.time_ms())Returns the current working directory.
Returns the absolute path of the running executable, independently of the working directory and command-line spelling. A compiled moon application can resolve installed assets relative to this path. In an embedded host, this identifies the host executable. Reports an I/O error when unavailable.
Returns wall-clock Unix time in milliseconds.
Returns an environment variable, or an empty string when absent.
name: Variable to read.
std.os.setenv("MOON_MODE", "tour")
println(std.os.has_env("MOON_MODE"))
println(std.os.getenv("MOON_MODE"))
println(std.os.getenv_or("MISSING", "development"))
std.os.unsetenv("MOON_MODE")Returns an environment variable or the supplied fallback.
name: Variable to read.default: Value returned when the variable is unset.
Reports whether an environment variable exists.
name: Variable to test for.
Sets an environment variable, returning false on failure.
name: Variable to set.value: Value to store.
Removes an environment variable, returning false on failure.
name: Variable to remove.
Returns the target operating-system name.
Returns the target architecture name.
Returns the local host name.
Returns the platform temporary-directory path.
Subscribes to POSIX signals by name (int, term, hup, usr1, usr2); every active subscription for a name receives each delivery. A second SIGINT while subscriptions exist still hard-kills.
names: Signal names to subscribe to:int,term,hup,usr1,usr2.
async fn wait_for_shutdown() {
let subscription = std.os.signals(["int", "term"])
let signal = await subscription.next()
println("received " + signal)
subscription.close()
}
async fn main() { await wait_for_shutdown() }Returns a future for the next delivered signal name; resolves with an empty string once the subscription is closed.
s: Subscription to take the next signal from.
Removes this subscriber and wakes its pending next calls. The previous process disposition is restored after the final subscriber closes. Repeated close calls are no-ops.
s: Subscription to end, restoring prior dispositions when it was last.