std:io
The std:io
module provides functions for console and file input/output.
String arguments containing literal escape sequences (e.g., \\n
, \\e
) passed to functions like io.print
or used as content for io.writeFile
will be processed into actual control characters.
Importing
Section titled “Importing”import "std:io" as io;
Functions
Section titled “Functions”io.print(value1, value2, ...)
Section titled “io.print(value1, value2, ...)”Prints string representations of values to stdout, space-separated, followed by a newline. Processes escapes in string arguments.
- Returns:
nyx_null
. - Example:
io.print("Status:", status, "\\nDone.");
io.input([prompt_string])
Section titled “io.input([prompt_string])”Reads a line from stdin.
- Parameters:
prompt_string
(optionalstring
, escapes processed). - Returns:
string
(line read) ornyx_null
on EOF. - Example:
auto name = io.input("Name: ");
io.readFile(filepath_string)
Section titled “io.readFile(filepath_string)”Reads entire file content into a string. Preserves actual newlines from file.
- Parameters:
filepath_string
(string
). - Returns:
string
(content). Runtime error on failure. - Example:
auto data = io.readFile("data.txt");
io.writeFile(filepath_string, content_string)
Section titled “io.writeFile(filepath_string, content_string)”Writes/overwrites file with content_string
. Processes escapes in content_string
.
- Parameters:
filepath_string
(string
),content_string
(string
). - Returns:
true
on success. Runtime error on failure. - Example:
io.writeFile("log.txt", "Error: #{code}\\n");
io.appendFile(filepath_string, content_string)
Section titled “io.appendFile(filepath_string, content_string)”Appends content_string
to file (creates if non-existent). Processes escapes in content_string
.
- Parameters:
filepath_string
(string
),content_string
(string
). - Returns:
true
on success. Runtime error on failure. - Example:
io.appendFile("log.txt", "Update processed.\\n");
io.fileExists(filepath_string)
Section titled “io.fileExists(filepath_string)”Checks if path exists.
- Parameters:
filepath_string
(string
). - Returns:
true
orfalse
. - Example:
if (io.fileExists("config.dat")) { ... }
io.deleteFile(filepath_string)
Section titled “io.deleteFile(filepath_string)”Deletes a file.
- Parameters:
filepath_string
(string
). - Returns:
true
if deleted,false
if not found. Runtime error on other failures. - Example:
io.deleteFile("temp_file.tmp");