From f73df8d5de30a7f3f320fccf5f57c13094940a6a Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Fri, 23 Jan 2026 12:22:57 +0000 Subject: Variadic functions + more docs --- docs/std/README.md | 1 + docs/std/io.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 docs/std/io.md (limited to 'docs') diff --git a/docs/std/README.md b/docs/std/README.md index f15b67a..6125a4e 100644 --- a/docs/std/README.md +++ b/docs/std/README.md @@ -2,6 +2,7 @@ - [Env (Environment)](./env.md) - Process environment variables. - [File System (FS)](./fs.md) - File I/O and directory operations. +- [IO](./io.md) - Standard Input/Output. - [Map](./map.md) - Hash map implementation. - [Option](./option.md) - Optional values (Some/None). - [Path](./path.md) - File path manipulation. diff --git a/docs/std/io.md b/docs/std/io.md new file mode 100644 index 0000000..825728d --- /dev/null +++ b/docs/std/io.md @@ -0,0 +1,44 @@ +# Standard Library: IO (`std/io.zc`) + +The `std/io` module provides standard input/output functionality, including printing to stdout and reading from stdin. + +## Usage + +```zc +import "std/io.zc" + +fn main() { + // Printing + io.println("Hello %s", "World"); + + // Formatting strings + autofree var s = io.format_new("Value: %d", 42); + + // Reading input + io.print("Enter name: "); + autofree var name = io.readln(); +} +``` + +## Functions + +### Output + +| Function | Signature | Description | +| :--- | :--- | :--- | +| **print** | `print(fmt: char*, ...) -> int` | Prints formatted output to stdout. | +| **println** | `println(fmt: char*, ...) -> int` | Prints formatted output to stdout with a newline. | + +### Formatting + +| Function | Signature | Description | +| :--- | :--- | :--- | +| **format** | `format(fmt: char*, ...) -> char*` | Formats string into a static buffer (returns pointer). **Not thread-safe**. | +| **format_into** | `format_into(buf: char*, size: usize, fmt: char*, ...) -> int` | Formats string into a user-provided buffer. | +| **format_new** | `format_new(fmt: char*, ...) -> char*` | Formats string into a newly allocated buffer (caller must free). | + +### Input + +| Function | Signature | Description | +| :--- | :--- | :--- | +| **readln** | `readln() -> char*` | Reads a line from stdin. Returns heap-allocated string (caller must free) or `NULL` on EOF/error. | -- cgit v1.2.3