Skip to content

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.

std-io.nyx
import "std:io" as io;

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.");

Reads a line from stdin.

  • Parameters: prompt_string (optional string, escapes processed).
  • Returns: string (line read) or nyx_null on EOF.
  • Example: auto name = io.input("Name: ");

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");

Checks if path exists.

  • Parameters: filepath_string (string).
  • Returns: true or false.
  • Example: if (io.fileExists("config.dat")) { ... }

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");