std.os Module Reference
The std.os module enables inspecting environment variables, host operating system properties, and controlling process termination.
os_example.sp
1import std.io;2import std.os;34fn main() -> void {5 let platform = os.platform();6 let user = os.env("USER") ?? os.env("USERNAME") ?? "Unknown";78 println("Platform: ${platform}");9 println("Active User: ${user}");10}
Exported Functions
os.platform
Native Builtinfn os.platform() -> string
Returns the host operating system string ('windows', 'linux', or 'macos').
Returns:
stringos.env
Native Builtinfn os.env(string name) -> string?
Retrieves the value of an environment variable, returning null if unset.
Parameters
name(string)
Environment variable key.Returns:
string?os.exit
Native Builtinfn os.exit(int code) -> void
Terminates the host process immediately with the specified exit status.
Parameters
code(int)
Process return code.Returns:
void