std.env

The std.env module provides functions for interacting with environment variables and command-line arguments.

args()

Returns command-line arguments as an array of strings.

Return Type: Array<string>

Example:

use std.env;

// If you run: aiscript script.ai arg1 arg2
let args = env.args();
// args will be: ["aiscript", "script.ai", "arg1", "arg2"]

vars()

Returns all environment variables as an object where keys are variable names and values are their corresponding values.

Return Type: Object<string, string>

Example:

use std.env;

let variables = env.vars();
// Example output:
// {
//   "PATH": "/usr/local/bin:/usr/bin",
//   "HOME": "/home/user",
//   "USER": "username"
// }

get_env(name: string)

Gets the value of an environment variable.

Parameters:

  • name: The name of the environment variable to retrieve

Return Type: string | nil

Example:

use std.env;

let home = env.get_env("HOME");
// If HOME is set: "/home/user"
// If HOME is not set: nil

set_env(name: string, value: string)

Sets the value of an environment variable.

Parameters:

  • name: The name of the environment variable to set
  • value: The value to set

Return Type: nil

Example:

use std.env;

env.set_env("MY_VAR", "my_value");
let value = env.get_env("MY_VAR") // Returns "my_value"