Module system
Platform independent system calls for Lua.
environment Functions
getenv (name) | Gets the value of an environment variable. |
getenvs () | Returns a table with all environment variables. |
setenv (name[, value]) | Sets an environment variable. |
random Functions
random ([length=1]) | Generate random bytes. |
term Functions
isatty (file) | Checks if a file-handle is a TTY. |
time Functions
gettime () | Get system time. |
monotime () | Get monotonic time. |
sleep (seconds[, precision=16]) | Sleep without a busy loop. |
environment Functions
- getenv (name)
-
Gets the value of an environment variable.
NOTE: Windows has multiple copies of environment variables. For this reason, the setenv function will not work with Lua's os.getenv on Windows. If you want to use setenv then consider patching os.getenv with this implementation of getenv.
Parameters:
- name string name of the environment variable
Returns:
-
string or nil
value of the environment variable, or nil if the variable is not set
- getenvs ()
-
Returns a table with all environment variables.
Returns:
-
table
table with all environment variables and their values
- setenv (name[, value])
-
Sets an environment variable.
NOTE: Windows has multiple copies of environment variables. For this reason, the setenv function will not work with Lua's os.getenv on Windows. If you want to use it then consider patching os.getenv with the implementation of system.getenv.
Parameters:
- name string name of the environment variable
- value
string
value of the environment variable, if
nil
the variable will be deleted (on Windows, setting an empty string, will also delete the variable) (optional)
Returns:
-
boolean
success
random Functions
- random ([length=1])
-
Generate random bytes.
This uses
CryptGenRandom()
on Windows, and/dev/urandom
on other platforms. It will return the requested number of bytes, or an error, never a partial result.Parameters:
- length int number of bytes to get (default 1)
Returns:
-
string
string of random bytes
Or
- nil
- string error message
term Functions
- isatty (file)
-
Checks if a file-handle is a TTY.
Parameters:
- file file the file-handle to check
Returns:
-
boolean
true if the file is a tty
time Functions
- gettime ()
-
Get system time.
The time is returned as the seconds since the epoch (1 January 1970 00:00:00).
Returns:
-
number
seconds (fractional)
- monotime ()
-
Get monotonic time.
The time is returned as the seconds since system start.
Returns:
-
number
seconds (fractional)
- sleep (seconds[, precision=16])
-
Sleep without a busy loop.
This function will sleep, without doing a busy-loop and wasting CPU cycles.
Parameters:
- seconds number seconds to sleep (fractional).
- precision integer minimum stepsize in milliseconds (Windows only, ignored elsewhere) (default 16)
Returns:
true
on success, ornil+err
on failure