01 / std/atomic_go.zi

atomic_go

Go unsigned 64-bit atomic counters. Keep counters in shared storage and pass their addresses.

Import with #import "atomic_go" and pass --module-path std.

Uint64 :: struct
Add :: (value: *Uint64, delta: u64) -> u64
Load :: (value: *Uint64) -> u64

Source ↗

02 / std/binary_linux.zi

binary_linux

Little-endian binary fields for native Linux programs. No file format or application record layout is imposed by this module.

Import with #import "binary_linux" and pass --module-path std.

ReadU64LE :: (bytes: []u8, at: s32) -> u64
WriteU64LE :: (bytes: []u8, at: s32, value: u64) -> bool
ReadF64LE :: (bytes: []u8, at: s32) -> float64
WriteF64LE :: (bytes: []u8, at: s32, value: float64) -> bool

Source ↗

03 / std/bundle_host.zi

bundle_host

Native C ABI for embedding a portable Ziran bundle. The runtime owns the bundle and instance; callers own binding contexts and borrowed result data.

Import with #import "bundle_host" and pass --module-path std.

HostValueKind :: enum { HostVoid = 0; HostInteger = 1; HostUnsigned = 2; HostReal = 3; HostString = 4; HostRecord = 5; HostSlice = 6; HostPointer = 7; HostArray = 8; }
HostValue :: struct { kind: s32; type_name: *u8; integer: s64; bits: u64; real: float64; data: *u8; length: u64; fields: *HostField; field_count: u64; elements: *HostValue; pointer: *void; }
HostField :: struct { name: *u8; value: HostValue; }
HostCall :: #type (context: *void, module: *u8, function: *u8, arguments: *HostValue, count: s32, result: *HostValue) -> s32
HostBinding :: struct { module: *u8; function: *u8; call: HostCall; context: *void; }
OpenBundle :: (path: *u8) -> *void
CloseBundle :: (bundle: *void)
InstantiateBundle :: (bundle: *void, bindings: *HostBinding, count: u64) -> *void
RunBundleInstance :: (instance: *void, result: *s64, has_result: *s32) -> s32
CloseBundleInstance :: (instance: *void)

Source ↗

04 / std/byte_text_linux.zi

byte_text_linux

Borrow UTF-8 bytes as a Ziran string at native foreign-function boundaries. The caller must keep the byte storage alive while the string is in use.

Import with #import "byte_text_linux" and pass --module-path std.

TextDescriptor :: struct { data: *u8; length: usize; }
ByteDescriptor :: struct { data: *u8; length: s64; }
TextFromBytes :: (buffer: []u8) -> string
BytesFromPointer :: (data: *u8, count: u64) -> []u8

Borrow native storage at a foreign-function boundary. The caller must keep it allocated and writable throughout the slice's use.

TextFromCString :: (value: *u8) -> string

The returned string borrows the C buffer and retains its lifetime.

Source ↗

05 / std/c_string.zi

c_string

Copies a borrowed Ziran string into caller-owned, NUL-terminated storage. Reject embedded NUL bytes and insufficient capacity before exposing the buffer to a native C API.

Import with #import "c_string" and pass --module-path std.

CopyCString :: (value: string, output: []u8) -> bool

Source ↗

06 / std/calendar.zi

calendar

Import with #import "calendar" and pass --module-path std.

LeapYear :: (year: s32) -> bool
DaysInMonth :: (year: s32, month: s32) -> s32
DayOfWeek :: (year: s32, month: s32, day: s32) -> s32

Sunday is zero. Gregorian arithmetic avoids mktime's timezone changes when asking for the weekday of a calendar date.

DayOfYear :: (year: s32, month: s32, day: s32) -> s32
DateTimeValid :: (value: LocalDateTime) -> bool
FormatDateTime :: (value: LocalDateTime, pattern: string, output: []u8) -> string

Locale-independent English names and common strftime-style civil tokens. Unsupported tokens, invalid readings, or insufficient space return an empty view and clear output[0]. A successful result is NUL-terminated.

Source ↗

07 / std/channel_go.zi

channel_go

Native Go channels with runtime element types. Keep the reflective channel value as the handle; Interface supplies its native value to select_go.

Import with #import "channel_go" and pass --module-path std.

Channel :: struct
ElementType :: struct
Direction :: struct
New :: (element: Any, capacity: isize) -> Channel
Interface :: (channel: Channel) -> Any
TrySend :: (channel: Channel, value: Any) -> bool
Close :: (channel: Channel)

Source ↗

08 / std/constant_time.zi

constant_time

Constant-time equality for caller-owned byte spans. The length check is intentionally explicit; callers protecting secret tags should use fixed-size buffers so unequal lengths do not become an oracle.

Import with #import "constant_time" and pass --module-path std.

ConstantTimeEqual :: (left: []u8, right: []u8) -> bool
ConstantTimeTextEqual :: (left: string, right: string) -> bool

Text carries arbitrary bytes without a mutable borrowed view. Compare every byte of equal-length tags just as for caller-owned byte spans.

Source ↗

09 / std/context_go.zi

context_go

Native Go contexts retain cancellation, deadlines and interface identity.

Import with #import "context_go" and pass --module-path std.

Context :: struct
CancelFunc :: struct
Cancellation :: struct { value: Context; cancel: CancelFunc; }
Background :: () -> Context
Canceled :: () -> Error
DeadlineExceeded :: () -> Error
Done :: (value: Context) -> Any
WithCancel :: (value: Context) -> Cancellation
WithTimeout :: (value: Context, duration: clock.Duration) -> Cancellation
Cancel :: (callback: CancelFunc)

Source ↗

10 / std/date_parse.zi

date_parse

UTC calendar parsing for feeds and dated data sources.

Import with #import "date_parse" and pass --module-path std.

DateDigit :: (value: u8) -> s32
DateNumber :: (value: string, start: s32, count: s32) -> s32
DaysFromCivil :: (year: s32, month: s32, day: s32) -> s64
DateValid :: (year: s32, month: s32, day: s32) -> bool
UtcDate :: struct { year: s32; month: s32; day: s32; hour: s32; minute: s32; second: s32; }
CivilFromUnix :: (timestamp: s64) -> UtcDate
DateWriteDigits :: (output: []u8, at: s32, value: s32, digits: s32) -> s32
WriteCompactUtc :: (timestamp: s64, output: []u8) -> s32
WriteIsoDay :: (timestamp: s64, output: []u8) -> s32
UtcSeconds :: (year: s32, month: s32, day: s32, hour: s32, minute: s32, second: s32) -> s64
ParseCompactUtc :: (value: string) -> s64
DateMonth :: (value: string, at: s32) -> s32
ParseRfc822Utc :: (value: string) -> s64

Source ↗

11 / std/date_time.zi

date_time

Import with #import "date_time" and pass --module-path std.

LocalNow :: () -> LocalDateTime

Needs a host capability.

UnixNow :: () -> s64

Needs a host capability.

Source ↗

12 / std/date_time_linux.zi

date_time_linux

Import with #import "date_time_linux" and pass --module-path std.

UnixNow :: () -> s64
UnixMilliseconds :: () -> s64
LocalAt :: (seconds: s64) -> LocalDateTime
UtcAt :: (seconds: s64) -> LocalDateTime
LocalNow :: () -> LocalDateTime

Source ↗

13 / std/date_time_plan9.zi

date_time_plan9

Import with #import "date_time_plan9" and pass --module-path std.

UnixNow :: () -> s64
UnixMilliseconds :: () -> s64

Plan 9 libc interprets the signed long argument as an unsigned 32-bit epoch count. Preserve its full 1970..2106 range, including after 2038,

LocalAt :: (seconds: s64) -> LocalDateTime

Plan 9 libc interprets the signed long argument as an unsigned 32-bit epoch count. Preserve its full 1970..2106 range, including after 2038, and reject seconds outside that range instead of silently wrapping.

UtcAt :: (seconds: s64) -> LocalDateTime
LocalNow :: () -> LocalDateTime

Source ↗

14 / std/date_time_types.zi

date_time_types

A local or UTC civil clock reading. Months and days are one-based; day_of_year is zero-based. Timezone rules belong to the clock provider.

Import with #import "date_time_types" and pass --module-path std.

LocalDateTime :: struct { year: s32; month: s32; day: s32; day_of_year: s32; hour: s32; minute: s32; second: s32; valid: bool; }

Source ↗

15 / std/ed25519_go.zi

ed25519_go

Ed25519 keys and signatures retain Go's native types and validation behavior.

Import with #import "ed25519_go" and pass --module-path std.

PublicKey :: struct
PrivateKey :: struct
KeyPairResult :: struct { publicKey: PublicKey; privateKey: PrivateKey; error: Error; }
GenerateKey :: () -> KeyPairResult
NewKeyFromSeed :: (seed: []u8) -> PrivateKey
Sign :: (key: PrivateKey, message: []u8) -> []u8
Verify :: (key: PublicKey, message: []u8, signature: []u8) -> bool
Equal :: (key: PublicKey, other: PublicKey) -> bool

Source ↗

16 / std/errors_go.zi

errors_go

Native Go error creation, identity, wrapping and exact error messages.

Import with #import "errors_go" and pass --module-path std.

New :: (message: string) -> Error
Is :: (error: Error, target: Error) -> bool
Unwrap :: (error: Error) -> Error
Message :: (error: Error) -> string

Source ↗

17 / std/file.zi

file

Files on every native C target under one import: Linux, Android, the web, and Windows use file_linux, and Plan 9 (--target=plan9-c defines PLAN9) uses file_plan9. Both provide OpenRead, OpenWrite, OpenUpdate, OpenReplace, Read, Write, ReadAt, WriteAt, FileSize, CloseFile, RemoveFile, RenameNoReplace, PathExists, DirectoryExists, CreateDirectory, CreatePrivateDirectory, OpenDirectory, NextDirectoryEntry, and CloseDirectory, plus the whole-file helpers here. ok := WriteEntireFile("notes.txt", "hello\n") text, found := ReadEntireFile("notes.txt")

Import with #import "file" and pass --module-path std.

ReadEntireFile :: (path: string) -> (string, bool)

The whole file's bytes as text, and whether it could be read.

WriteEntireFile :: (path: string, text: string) -> bool

Replace the file at PATH with TEXT; false when it cannot be written whole.

Source ↗

18 / std/file_go.zi

file_go

Native Go file operations preserve filesystem permissions and error identity.

Import with #import "file_go" and pass --module-path std.

FileMode :: struct
FileReadResult :: struct { value: []u8; error: Error; }
ReadFile :: (path: string) -> FileReadResult
WriteFile :: (path: string, data: []u8, mode: FileMode) -> Error
MkdirAll :: (path: string, mode: FileMode) -> Error
Rename :: (oldPath: string, newPath: string) -> Error
Remove :: (path: string) -> Error
Dir :: (path: string) -> string
NotExist :: () -> Error

Source ↗

19 / std/file_linux.zi

file_linux

Import with #import "file_linux" and pass --module-path std.

FileHandle :: struct { fd: s32; valid: bool; }
DirectoryCursor :: struct { storage: *void; valid: bool; }
DirectoryEntry :: struct { name: [256]u8; name_count: s32; valid: bool; }
OpenRead :: (path: string) -> FileHandle
OpenUpdate :: (path: string) -> FileHandle
OpenWrite :: (path: string) -> FileHandle
OpenReplace :: (path: string) -> FileHandle
OpenExclusivePrivate :: (path: string) -> FileHandle
RemoveFile :: (path: string) -> bool
PathExists :: (path: string) -> bool
DirectoryExists :: (path: string) -> bool
RenamePath :: (source: string, destination: string) -> bool
RenameNoReplace :: (source: string, destination: string) -> bool
LinkFile :: (source: string, destination: string) -> bool
CreateDirectory :: (path: string) -> bool
CreatePrivateDirectory :: (path: string) -> bool
FileSize :: (file: FileHandle) -> s64
ReadAt :: (file: FileHandle, output: []u8, offset: s64) -> s64
WriteAt :: (file: FileHandle, input: []u8, offset: s64) -> s64
WriteTextAt :: (file: FileHandle, input: string, offset: s64) -> s64

Copy immutable text through a bounded buffer before writing it. The string may borrow read-only storage, so it must not be exposed as a mutable slice.

CloseFile :: (file: FileHandle) -> bool
SyncFile :: (file: FileHandle) -> bool
Read :: (file: FileHandle, output: []u8) -> s64
Write :: (file: FileHandle, input: []u8) -> s64
OpenDirectory :: (path: string) -> DirectoryCursor
NextDirectoryEntry :: (cursor: *DirectoryCursor) -> DirectoryEntry
CloseDirectory :: (cursor: *DirectoryCursor) -> bool

Source ↗

20 / std/file_plan9.zi

file_plan9

Import with #import "file_plan9" and pass --module-path std.

FileHandle :: struct { fd: s32; valid: bool; }
FileInfo :: struct { valid: bool; type: u16; device: u32; identity: u64; version: u32; identity_type: u8; mode: u32; modified: u32; length: s64; }

A value snapshot owns no libc allocation. The device and Qid fields identify a file; its version/length/timestamp can detect changed content.

LastError :: (output: []u8) -> string
PathInfo :: (path: string) -> FileInfo
HandleInfo :: (file: FileHandle) -> FileInfo
SetFileAttributes :: (file: FileHandle, permissions: u32, modified: u32) -> bool

Apply ordinary permissions and a timestamp to an already-open file. Special mode flags cannot be introduced through this operation.

CurrentDirectory :: (output: []u8) -> string
DirectoryCursor :: struct { storage: *void; count: s64; next: s64; valid: bool; failed: bool; }

A cursor owns the native directory snapshot. Close it exactly once.

DirectoryEntry :: struct { name: [256]u8; name_count: s32; valid: bool; }
OpenRead :: (path: string) -> FileHandle
OpenUpdate :: (path: string) -> FileHandle
OpenWrite :: (path: string) -> FileHandle
OpenReplace :: (path: string) -> FileHandle
OpenPrivateReplace :: (path: string) -> FileHandle

Atomically create an owner-only file, refusing an existing name. A temporary lease is removed when its last descriptor closes, including

CreatePrivateExclusive :: (path: string, remove_on_close: bool) -> FileHandle

Atomically create an owner-only file, refusing an existing name. A temporary lease is removed when its last descriptor closes, including process exit. OCEXEC prevents a lease from leaking into an executed child.

PathExists :: (path: string) -> bool
DirectoryExists :: (path: string) -> bool
CreateDirectory :: (path: string) -> bool
CreatePrivateDirectory :: (path: string) -> bool
CreatePrivateDirectoryExclusive :: (path: string) -> bool

Create a new directory without accepting or replacing an existing name.

CreatePrivateDirectoryHandle :: (path: string) -> FileHandle

Keep the descriptor from an exclusive directory create. Its identity and attributes remain accessible even after restrictive permissions are set.

RemoveFile :: (path: string) -> bool
RenameNoReplace :: (source: string, destination: string) -> bool

Plan 9 wstat changes the basename within its current directory. Refuse cross-directory requests instead of silently moving to the wrong path.

FileSize :: (file: FileHandle) -> s64
ReadAt :: (file: FileHandle, output: []u8, offset: s64) -> s64
WriteAt :: (file: FileHandle, input: []u8, offset: s64) -> s64
CloseFile :: (file: FileHandle) -> bool
Read :: (file: FileHandle, output: []u8) -> s64

Stream operations read/write at the descriptor's current position. This supports devices whose first read is a snapshot and whose next read blocks.

Write :: (file: FileHandle, input: []u8) -> s64
OpenDirectory :: (path: string) -> DirectoryCursor
NextDirectoryEntry :: (cursor: *DirectoryCursor) -> DirectoryEntry
CloseDirectory :: (cursor: *DirectoryCursor) -> bool

Source ↗

21 / std/format.zi

format

Text built on an owned Vec(u8) builder. Append adds one value's text, and BuilderPrint(*builder, "x=%\n", x) appends a whole formatted piece: each % takes the next argument's text and %% writes one percent. BuilderFinish turns the builder into a string. line: Vec(u8) BuilderPrint(*line, "% of % done\n", finished, total) text := BuilderFinish(line) Integers are written in base ten, bools as true or false, and floats with up to six digits after the point, trailing zeros dropped.

Import with #import "format" and pass --module-path std.

Append :: (builder: *Vec(u8), text: string)
Append :: (builder: *Vec(u8), value: s64)
Append :: (builder: *Vec(u8), value: u32)

Unsigned values up to 32 bits; also the closest match for u8 and u16.

Append :: (builder: *Vec(u8), value: u64)
Append :: (builder: *Vec(u8), value: bool)
Append :: (builder: *Vec(u8), value: float64)

Source ↗

22 / std/go_types.zi

go_types

Predeclared Go interface types at the foreign-library boundary.

Import with #import "go_types" and pass --module-path std.

Any :: struct
Error :: struct

Source ↗

23 / std/hash_map.zi

hash_map

A hash map from keys to values that runs the same on every target and the portable runner. Keys are strings or integers. The table doubles when half its slots are in use, and HashMapFree releases it. ages: HashMap(string, s32) HashMapSet(*ages, "ada", 36) age: s32 if HashMapGet(*ages, "ada", *age) { print("%\n", age) } HashMapFree(*ages)

Import with #import "hash_map" and pass --module-path std.

HashMap :: struct($K: Type, $V: Type) { keys: Vec(K); values: Vec(V); states: Vec(u8); count: s64; }
HashKey :: (key: string) -> u64

FNV-1a over the key's bytes.

HashKey :: (key: u64) -> u64

SplitMix64's finalizer spreads nearby integers across the table.

HashKey :: (key: s64) -> u64
HashKey :: (key: u32) -> u64
HashMapFind :: (map: *HashMap($K, $V), key: K) -> s64

The slot holding KEY, or -1.

HashMapHas :: (map: *HashMap($K, $V), key: K) -> bool
HashMapGet :: (map: *HashMap($K, $V), key: K, value: *V) -> bool

Copies KEY's value into VALUE and returns true, or returns false.

HashMapSet :: (map: *HashMap($K, $V), key: K, value: V)
HashMapRemove :: (map: *HashMap($K, $V), key: K) -> bool

Removes KEY and returns whether it was present.

HashMapFree :: (map: *HashMap($K, $V))
HashMapGrow :: (map: *HashMap($K, $V))

Doubles the table, to at least 8 slots, and reinserts every entry.

Source ↗

24 / std/hmac_sha256_go.zi

hmac_sha256_go

Import with #import "hmac_sha256_go" and pass --module-path std.

DigestResult :: struct { value: string; error: string; }
HMACSHA256 :: (key: []u8, message: string) -> DigestResult

HMAC over arbitrary text bytes. SHA-256 itself comes from Go's crypto package; this module owns only RFC 2104's key normalization and pads.

Source ↗

25 / std/http_get_linux.zi

http_get_linux

Import with #import "http_get_linux" and pass --module-path std.

GetHttps :: (url: string, output: []u8) -> CaptureResult

Native HTTPS GET. curl owns TLS and redirects; the caller owns storage.

Source ↗

26 / std/http_go.zi

http_go

Go HTTP requests, response writers and headers retain their native types and behavior.

Import with #import "http_go" and pass --module-path std.

Request :: struct
Header :: struct
ResponseWriter :: struct
Client :: struct
Response :: struct
RequestResult :: struct { value: *Request; error: Error; }
ResponseResult :: struct { value: *Response; error: Error; }
RemoteAddress :: (request: *Request) -> string
Headers :: (request: *Request) -> Header
Method :: (request: *Request) -> string
RequestURL :: (request: *Request) -> *url.URL
Body :: (request: *Request) -> io.ReadCloser
Context :: (request: *Request) -> ctx.Context
MaxBytesReader :: (writer: ResponseWriter, reader: io.ReadCloser, limit: s64) -> io.ReadCloser
WriteHeader :: (writer: ResponseWriter, status: isize)
HeaderValue :: (header: Header, name: string) -> string
ResponseHeaders :: (writer: ResponseWriter) -> Header
SetHeader :: (header: Header, name: string, value: string)
NewClient :: (timeout: clock.Duration) -> *Client
ClientTimeout :: (client: *Client) -> clock.Duration
NewRequest :: (context: ctx.Context, method: string, target: string, body: io.Reader) -> RequestResult
Do :: (client: *Client, request: *Request) -> ResponseResult
ResponseBody :: (response: *Response) -> io.ReadCloser
Status :: (response: *Response) -> string
StatusCode :: (response: *Response) -> isize

Source ↗

27 / std/io_go.zi

io_go

Native Go stream interfaces retain resource ownership and error identity.

Import with #import "io_go" and pass --module-path std.

Reader :: struct
ReadCloser :: struct
Writer :: struct
BytesReader :: struct
ReadAllResult :: struct { value: []u8; error: Error; }
ReadAll :: (reader: Reader) -> ReadAllResult
Close :: (reader: ReadCloser) -> Error
LimitReader :: (reader: Reader, count: s64) -> Reader
FromBytes :: (data: []u8) -> Reader

Source ↗

28 / std/json_go.zi

json_go

Go JSON serialization keeps native error values, field tags and byte storage.

Import with #import "json_go" and pass --module-path std.

Encoder :: struct
Decoder :: struct
JSONResult :: struct { value: []u8; error: Error; }
Marshal :: (value: Any) -> JSONResult
Unmarshal :: (data: []u8, value: Any) -> Error
Valid :: (data: []u8) -> bool
NewEncoder :: (writer: io.Writer) -> *Encoder
Encode :: (encoder: *Encoder, value: Any) -> Error
NewDecoder :: (reader: io.Reader) -> *Decoder
Decode :: (decoder: *Decoder, value: Any) -> Error

Source ↗

29 / std/json_scan.zi

json_scan

Import with #import "json_scan" and pass --module-path std.

JsonSpan :: struct { start: s32; end: s32; after: s32; valid: bool; }

A small allocation-free JSON scanner. Positions are UTF-8 byte offsets. String spans retain escapes; member lookup matches unescaped ASCII names.

JsonNumber :: struct { value: float64; after: s32; valid: bool; }
Space :: (text: string, at: s32) -> s32
Digit :: (ch: u8) -> bool
Hex :: (ch: u8) -> bool
ReadString :: (text: string, at: s32) -> JsonSpan
HexValue :: (ch: u8) -> s32
ReadHex4 :: (text: string, at: s32, end: s32) -> s32

The four hex digits at `at` as a number, or -1.

AppendUtf8 :: (output: []u8, length: s32, codepoint: s32) -> s32

Appends codepoint as UTF-8, leaving room for a NUL. Returns the new length, or -1 when it does not fit.

ReadStringText :: (text: string, at: s32, output: []u8) -> s32

Copies the JSON string at `at` into output as UTF-8 with its escapes decoded, including \uXXXX surrogate pairs; a lone surrogate becomes U+FFFD. Returns the byte length, or -1 when the value is not a string or does not fit. Output is always NUL-terminated.

SpanEqualsASCII :: (text: string, span: JsonSpan, expected: string) -> bool
SpanContainsFoldASCII :: (text: string, span: JsonSpan, needle: string) -> bool
ReadNumber :: (text: string, at: s32) -> JsonNumber
MatchLiteral :: (text: string, at: s32, literal: string) -> bool
ValueEnd :: (text: string, at: s32, depth: s32) -> s32
FieldAt :: (text: string, object_at: s32, name: string) -> s32
ElementAt :: (text: string, array_at: s32, index: s32) -> s32
ArrayCount :: (text: string, array_at: s32) -> s32

Source ↗

30 / std/map_go.zi

map_go

Go maps share their storage when copied or passed to a function. The private fields describe type arguments; access goes through Map operations. Go target only. Import option to use MapLookup, whose result is Option(V). MapSet initializes nil storage; MapInit preserves an existing map. MapGet returns a zero value for absent keys. MapKeys returns an unordered snapshot.

Import with #import "map_go" and pass --module-path std.

Map :: struct($K: Type, $V: Type) { key: K; value: V; }

Source ↗

31 / std/mapped_file_linux.zi

mapped_file_linux

Import with #import "mapped_file_linux" and pass --module-path std.

MappedFile :: struct { data: *u8; length: u64; valid: bool; }
MapPrivate :: (path: string) -> MappedFile
MappedBytes :: (file: MappedFile) -> []u8
UnmapFile :: (file: MappedFile) -> bool

Source ↗

32 / std/math.zi

math

Portable float32 helpers for native and bundled Ziran programs.

Import with #import "math" and pass --module-path std.

Finite32 :: (value: float32) -> bool
FloorInteger :: (value: float32) -> s32
CeilInteger :: (value: float32) -> s32
SineDegrees :: (degrees: float32) -> float32

Reduce to [-pi/2, pi/2] before the Taylor polynomial.

CosineDegrees :: (degrees: float32) -> float32

Source ↗

33 / std/net_go.zi

net_go

Go IP parsing, canonical formatting, loopback classification and host/port splitting.

Import with #import "net_go" and pass --module-path std.

IP :: struct
HostPort :: struct { host: string; port: string; error: Error; }
SplitHostPort :: (address: string) -> HostPort
ParseIP :: (address: string) -> IP
ValidIP :: (value: IP) -> bool
FormatIP :: (value: IP) -> string
IsLoopback :: (value: IP) -> bool

Source ↗

34 / std/net_http.zi

net_http

Import with #import "net_http" and pass --module-path std.

HttpHeader :: struct { name: string; value: string; }

Network transport is an explicit host capability. The host adds a Bearer Authorization header when token is nonempty. It must not log that token. The request and response records have the same meaning in native targets and portable bundles.

HttpRequest :: struct { method: string; url: string; token: string; accept: string; content_type: string; body: string; headers: []HttpHeader; }
HttpResponse :: struct { status: s32; body: string; error: string; }
Send :: (request: HttpRequest) -> HttpResponse

Needs a host capability.

Source ↗

35 / std/net_http_curl_linux.zi

net_http_curl_linux

Import with #import "net_http_curl_linux" and pass --module-path std.

CurlInitRoutine :: #type ()
CurlUrl :: 10002
CurlMethod :: 10036
CurlWriteData :: 10001
CurlWriteFunction :: 20011
CurlHeaders :: 10023
CurlAcceptEncoding :: 10102
CurlPostFields :: 10015
CurlPostSize :: 30120
CurlTimeoutMs :: 155
CurlConnectTimeoutMs :: 156
CurlNoSignal :: 99
CurlResponseCode :: 2097154
curl_once: s32
curl_init_result: s32
InitCurl :: ()
CurlReady :: () -> bool
StartsWith :: (value: string, prefix: string) -> bool
MethodToken :: (value: string) -> bool
HeaderName :: (value: string) -> bool
CurlResult :: struct { status: s32; length: s64; code: s32; truncated: bool; }
CurlOutput :: struct { data: *u8; capacity: s64; length: s64; truncated: bool; }
CurlWriteCallback64 :: #type (data: *u8, size: u64, count: u64, user: *void) -> u64
CurlWriteCallback32 :: #type (data: *u8, size: u32, count: u32, user: *void) -> u32
AppendCurlOutput :: (data: *u8, size: u64, count: u64, context: *CurlOutput) -> u64
CurlWrite64 :: (data: *u8, size: u64, count: u64, user: *void) -> u64
CurlWrite32 :: (data: *u8, size: u32, count: u32, user: *void) -> u32
SetCurlLong :: (handle: *void, option: s32, value: s32) -> bool
ReadCurlStatus :: (handle: *void) -> s32
HeaderText :: (prefix: string, value: string, output: []u8) -> bool
AddCurlHeader :: (headers: **void, prefix: string, value: string, buffer: []u8) -> bool
AddNamedHeader :: (headers: **void, name: string, value: string, buffer: []u8) -> bool
SendCurl :: (request: HttpRequest, output: []u8) -> CurlResult

The caller owns output. It remains NUL terminated, including on failure. HTTP errors retain their status and body for protocol-level decisions.

Source ↗

36 / std/net_http_linux.zi

net_http_linux

Import with #import "net_http_linux" and pass --module-path std.

PostJson :: (url: string, body: string, output: []u8) -> CaptureResult

Native HTTPS JSON transport. curl owns TLS and HTTP framing; Ziran owns the request arguments and caller-provided response buffer.

Source ↗

37 / std/net_ws_curl_linux.zi

net_ws_curl_linux

Blocking, bounded WebSocket text receive for native libcurl hosts. The protocol consumer owns URL construction and JSON validation.

Import with #import "net_ws_curl_linux" and pass --module-path std.

PollDescriptor :: struct { fd: s32; events: s16; returned: s16; }
PollRead :: 1
NoSocket :: () -> PollDescriptor
ValidSocket :: (descriptor: PollDescriptor) -> bool
CurlWsFrame :: struct { age: s32; flags: s32; offset: s64; bytes_left: s64; length: u64; }
CurlConnectOnly :: 141
CurlActiveSocket :: 5242924
CurlAgain :: 81
CurlWsText :: 1
CurlWsContinue :: 4
CurlWsClose :: 8

Output is NUL terminated on success. status is 401 on an unauthorized

ReceiveWebSocketCurl :: (context: *void, url: string, token: string, output: []u8, status: *s32) -> bool

Source ↗

38 / std/number_text.zi

number_text

Import with #import "number_text" and pass --module-path std.

FormatInteger :: (value: s64, output: []u8) -> string

A whole number in base ten. The buffer needs 21 bytes for any s64.

FormatDecimal :: (value: float64, places: s32, output: []u8) -> string

A number rounded to `places` digits after the point (at most 9), with trailing zeros dropped: 0.5, 12, -3.25. The buffer needs 32 bytes.

Source ↗

39 / std/option.zi

option

Import with #import "option" and pass --module-path std.

Option :: struct($T: Type) { has_value: bool; value: T; }

Source ↗

40 / std/pair.zi

pair

Import with #import "pair" and pass --module-path std.

Pair :: struct($A: Type, $B: Type) { first: A; second: B; }

Source ↗

41 / std/path.zi

path

Import with #import "path" and pass --module-path std.

CleanAbsolute :: (value: string, output: []u8) -> string

Lexical slash-path operations. These do not resolve links or mount points. Returned text borrows output until the caller changes that storage.

WithinDirectory :: (value: string, directory: string) -> bool

Both arguments must be canonical absolute slash paths. A directory prefix matches only itself or a complete component boundary, never a sibling.

Source ↗

42 / std/process.zi

process

Import with #import "process" and pass --module-path std.

ProcessRequest :: struct { executable: string; cwd: string; stdin: string; credential_name: string; credential_value: string; isolate_desktop: bool; timeout_ms: s64; }

A line-oriented child-process capability. The host receives explicit arguments, stdin, and one optional secret environment binding. Hosts must honor isolate_desktop before starting any child. Handles are host-owned; callers consume lines and then wait exactly once.

ProcessStart :: struct { handle: s32; error: string; }
ProcessLine :: struct { text: string; eof: bool; error: string; }
ProcessExit :: struct { code: s32; stderr: string; error: string; }
Start :: (request: ProcessRequest, args: []string) -> ProcessStart

Needs a host capability.

NextLine :: (handle: s32) -> ProcessLine

Needs a host capability.

Wait :: (handle: s32) -> ProcessExit

Needs a host capability.

Source ↗

43 / std/process_capture_linux.zi

process_capture_linux

Import with #import "process_capture_linux" and pass --module-path std.

CapturePointer :: struct { value: *u8; }
CaptureArgument :: struct { bytes: [4096]u8; }
CaptureResult :: struct { code: s32; length: s32; error: bool; truncated: bool; }
CaptureOutput :: (arguments: []string, output: []u8) -> CaptureResult

Source ↗

44 / std/process_plan9.zi

process_plan9

Import with #import "process_plan9" and pass --module-path std.

ProcessGroup :: struct { pid: s32; note_id: s32; valid: bool; }

A detached child has its own descriptor, environment, and note groups. The note ID identifies the child and descendants that inherit its group.

CurrentProcessId :: () -> s32

Plan 9's path environment is a NUL-separated list, including directory

ExecutablePath :: (name: string, output: []u8) -> string

Plan 9's path environment is a NUL-separated list, including directory names with spaces. Resolve an executable before passing its argv to exec.

StartDetached :: (arguments: []string) -> ProcessGroup
ProcessInGroup :: (group: ProcessGroup, pid: s32) -> bool

Source ↗

45 / std/py_types.zi

py_types

A Python value at the py: foreign boundary, for the Python target only. null is None. Every foreign Python type with the same py: target is the same type, so modules may also declare Object themselves.

Import with #import "py_types" and pass --module-path std.

Object :: struct

Source ↗

46 / std/queue.zi

queue

Allocation-free bounded FIFO queue over caller-owned byte storage. Queue state is passed and returned by value; every operation receives the backing bytes explicitly so their lifetime remains visible to the caller.

Import with #import "queue" and pass --module-path std.

BoundedQueue :: struct { capacity: s64; head: s64; count: s64; }
QueueByte :: struct { queue: BoundedQueue; valid: bool; value: u8; }
QueueBytes :: struct { queue: BoundedQueue; count: s64; }
QueueStart :: (storage: []u8) -> BoundedQueue
QueueCapacity :: (queue: BoundedQueue) -> s64
QueueCount :: (queue: BoundedQueue) -> s64
QueuePush :: (queue: BoundedQueue, storage: []u8, value: u8) -> BoundedQueue
QueuePushBytes :: (queue: BoundedQueue, storage: []u8, input: []u8) -> BoundedQueue
QueuePop :: (queue: BoundedQueue, storage: []u8) -> QueueByte
QueuePopBytes :: (queue: BoundedQueue, storage: []u8, output: []u8) -> QueueBytes
QueueClear :: (queue: BoundedQueue) -> BoundedQueue

Source ↗

47 / std/random_go.zi

random_go

Cryptographic random bytes from Go, preserving its count and error results.

Import with #import "random_go" and pass --module-path std.

ReadResult :: struct { count: isize; error: Error; }
Fill :: (output: []u8) -> ReadResult

Source ↗

48 / std/random_linux.zi

random_linux

Secure operating-system randomness for native Linux programs. The caller owns the destination bytes and no fallback generator is permitted.

Import with #import "random_linux" and pass --module-path std.

FillSecure :: (output: []u8) -> bool

Source ↗

49 / std/result.zi

result

Import with #import "result" and pass --module-path std.

Result :: struct($T: Type, $E: Type) { is_ok: bool; value: T; error: E; }

Source ↗

50 / std/rss_scan.zi

rss_scan

Import with #import "rss_scan" and pass --module-path std.

FeedSpan :: struct { start: s32; end: s32; after: s32; valid: bool; }
FeedMatch :: (document: string, at: s32, needle: string) -> bool
FeedFind :: (document: string, from: s32, needle: string) -> s32
FeedNextItem :: (document: string, from: s32) -> FeedSpan
FeedTag :: (document: string, item: FeedSpan, tag: string) -> FeedSpan
FeedEntity :: (document: string, at: s32, end: s32, output: *u8) -> s32
FeedCopyText :: (document: string, span: FeedSpan, output: []u8) -> s32

Copies a text or CDATA field into caller-owned storage. Tags in summaries become spaces, and a malformed/truncated field is rejected.

Source ↗

51 / std/select_go.zi

select_go

Select native Go channels through their boxed interface values. Channels retain native storage and direction; reflect.Select validates the channel and send-value types at runtime and preserves Go's ready-case selection.

Import with #import "select_go" and pass --module-path std.

Case :: struct
Direction :: struct
Value :: struct
SelectResult :: struct { chosen: isize; value: Value; receiveOK: bool; }
Receive :: (channel: Any) -> Case
Send :: (channel: Any, send: Any) -> Case
Default :: () -> Case
Select :: (cases: []Case) -> SelectResult

Source ↗

52 / std/socket_linux.zi

socket_linux

Bounded, cancellation-aware TCP client sockets for native Linux programs. The caller supplies a literal IPv4 address; this module performs no DNS, HTTP, TLS, or plaintext-protocol fallback.

Import with #import "socket_linux" and pass --module-path std.

LinuxSocket :: struct { fd: s32; valid: bool; error: s32; }
LinuxSocketEvent :: struct { ready: s32; error: s32; }
LinuxSocketAddress :: struct { family: u16; port: u16; address: u32; zero: [8]u8; }
LinuxPollFd :: struct { fd: s32; events: s16; revents: s16; }
LinuxErrno :: () -> s32
SocketWaitForEvents :: (socket: LinuxSocket, events: s32, timeout_ms: s32) -> LinuxSocketEvent
SocketConnectError :: (socket: LinuxSocket) -> s32
OpenTCPv4 :: (address: [4]u8, port: u16, timeout_ms: s32) -> LinuxSocket
SocketCancel :: (socket: LinuxSocket) -> bool
SocketSendAll :: (socket: LinuxSocket, input: []u8, timeout_ms: s32) -> s64
SocketReceive :: (socket: LinuxSocket, output: []u8, timeout_ms: s32) -> s64
SocketClose :: (socket: *LinuxSocket) -> bool

Source ↗

53 / std/sort.zi

sort

Sorting and searching for slices of any type ordered by the < operator. Sorting is an in-place heapsort: O(n log n) comparisons, no allocation, no recursion, and not stable.

Import with #import "sort" and pass --module-path std.

Sort :: (values: []$T)

Sorts values in ascending order.

IsSorted :: (values: []$T) -> bool

Reports whether values are in ascending order.

LowerBound :: (values: []$T, target: T) -> s64

Returns the first index whose value is not less than target, or values.count when every value is less. values must be sorted.

BinarySearch :: (values: []$T, target: T) -> s64

Returns an index holding target, or -1 when values has none. values must be sorted.

Source ↗

54 / std/sql_go.zi

sql_go

Native Go SQL handles, nullable strings and transaction cleanup primitives.

Import with #import "sql_go" and pass --module-path std.

Database :: struct
Transaction :: struct
TransactionOptions :: struct
Row :: struct
Rows :: struct
Result :: struct
NullString :: struct
AffectedRowsResult :: struct { value: s64; error: Error; }
Next :: (rows: *Rows) -> bool
RowsError :: (rows: *Rows) -> Error
CloseRows :: (rows: *Rows) -> Error
Commit :: (transaction: *Transaction) -> Error
Rollback :: (transaction: *Transaction) -> Error
NullStringValid :: (value: NullString) -> bool
NullStringValue :: (value: NullString) -> string
NoRows :: () -> Error
TransactionDone :: () -> Error
RowsAffected :: (result: Result) -> AffectedRowsResult

Source ↗

55 / std/string_range.zi

string_range

A byte range of an immutable borrowed string. Bounds are checked by Ziran. Callers working with UTF-8 text should choose codepoint boundaries.

Import with #import "string_range" and pass --module-path std.

Substring :: (source: string, start: s32, length: s32) -> string

Source ↗

56 / std/sync_go.zi

sync_go

Go mutexes. Keep one mutex in shared storage and pass its address.

Import with #import "sync_go" and pass --module-path std.

Mutex :: struct
Lock :: (mutex: *Mutex)
Unlock :: (mutex: *Mutex)

Source ↗

57 / std/text.zi

text

ASCII-only case folding keeps the result identical across native targets and the portable runner. UTF-8 bytes outside ASCII compare unchanged.

Import with #import "text" and pass --module-path std.

LowerASCII :: (value: u8) -> u8
StartsWithFoldASCII :: (value: string, prefix: string) -> bool
ContainsFoldASCII :: (value: string, needle: string) -> bool

Source ↗

58 / std/text_buffer.zi

text_buffer

Bounded NUL-terminated byte buffer to borrowed text. The caller keeps the buffer alive until the returned view is no longer used.

Import with #import "text_buffer" and pass --module-path std.

TextUntilNul :: (buffer: []u8) -> string

Source ↗

59 / std/text_go.zi

text_go

Copy between Go-owned byte slices and strings, preserving every byte.

Import with #import "text_go" and pass --module-path std.

FromBytes :: (value: []u8) -> string
ToBytes :: (value: string) -> []u8

Source ↗

60 / std/text_py.zi

text_py

Copy between Python bytes and Ziran strings, preserving every byte, on the Python target. A string crosses into Python as str decoded with surrogateescape, so encoding it the same way returns its exact bytes.

Import with #import "text_py" and pass --module-path std.

FromBytes :: (value: []u8) -> string
ToBytes :: (value: string) -> []u8

Source ↗

61 / std/thread_linux.zi

thread_linux

Background work for native Linux and Android programs. A thread runs one procedure while the thread that started it keeps going, and that thread can ask whether the work has finished without waiting, so a frame loop keeps drawing while a request is in flight. A Thread record must stay at one address from ThreadStart until ThreadFinished or ThreadWait reports the end. Once it has, everything the procedure wrote is visible to the thread that asked, and the record can start another procedure.

Import with #import "thread_linux" and pass --module-path std.

ThreadProcedure :: #type (argument: *void)
PosixThreadEntry :: #type (argument: *void) -> *void
Thread :: struct { handle: usize; lock: [8]u64; procedure: ThreadProcedure; argument: *void; running: bool; finished: bool; }
ThreadLock :: (thread: *Thread) -> *void
ThreadRun :: (argument: *void) -> *void
ThreadStart :: (thread: *Thread, procedure: ThreadProcedure, argument: *void) -> bool
ThreadRunning :: (thread: *Thread) -> bool

Whether the record is running a procedure that has not been reported finished yet.

ThreadFinished :: (thread: *Thread) -> bool

Whether the procedure started on `thread` has finished. Never waits; the first time it reports true the thread is joined and the record is free.

ThreadWait :: (thread: *Thread)

Waits until the procedure started on `thread` has finished.

Source ↗

62 / std/time_go.zi

time_go

Go wall-clock and monotonic timestamps retain their native time.Time behavior.

Import with #import "time_go" and pass --module-path std.

Time :: struct
Duration :: struct
Ticker :: struct
ParseResult :: struct { value: Time; error: Error; }
Now :: () -> Time
After :: (value: Time, other: Time) -> bool
Add :: (value: Time, duration: Duration) -> Time
Parse :: (layout: string, value: string) -> ParseResult
UTC :: (value: Time) -> Time
Format :: (value: Time, layout: string) -> string
Unix :: (value: Time) -> s64
FromUnix :: (seconds: s64, nanos: s64) -> Time
Until :: (value: Time) -> Duration
NewTicker :: (duration: Duration) -> *Ticker
StopTicker :: (ticker: *Ticker)
TickerChannel :: (ticker: *Ticker) -> Any

Source ↗

63 / std/timer_linux.zi

timer_linux

Monotonic timing and interruptible sleeps for native glibc Linux programs. Wall-clock time is intentionally unavailable from this module.

Import with #import "timer_linux" and pass --module-path std.

ClockValue :: struct { seconds: s64; nanoseconds: s64; }
MonotonicMilliseconds :: () -> s64
MakeClockValue :: (milliseconds: s64) -> ClockValue
SleepMilliseconds :: (milliseconds: s64) -> bool

Source ↗

64 / std/update.zi

update

Import with #import "update" and pass --module-path std.

Artifact :: struct { url: [512]u8; sha256: [65]u8; size: s64; available: bool; }

Release metadata and version decisions are portable. Downloading and installing an artifact remain explicit host operations.

Appcast :: struct { version: [32]u8; notes_url: [512]u8; artifact: Artifact; valid: bool; }
CompareVersions :: (left: string, right: string) -> s32
ParseAppcast :: (json: string, channel: string) -> Appcast

Select one channel from the release manifest. A missing channel still yields a valid appcast: package-managed installs show the release page.

Source ↗

65 / std/url_go.zi

url_go

Native Go URLs preserve escaped-path selection and their original encoding.

Import with #import "url_go" and pass --module-path std.

URL :: struct
Values :: struct
ParseURLResult :: struct { value: *URL; error: Error; }
Parse :: (value: string) -> ParseURLResult
Host :: (value: *URL) -> string
Scheme :: (value: *URL) -> string
Path :: (value: *URL) -> string
EscapedPath :: (value: *URL) -> string
Query :: (value: *URL) -> Values
Value :: (values: Values, name: string) -> string

Source ↗

66 / std/utf8.zi

utf8

Advance one Unicode scalar in an immutable UTF-8 string. An invalid byte advances by one so callers always make progress and never split a valid multibyte sequence.

Import with #import "utf8" and pass --module-path std.

Continuation :: (byte: u8) -> bool
Decoded :: struct { value: u32; after: s32; valid: bool; }
Decode :: (text: string, at: s32) -> Decoded

Decode one scalar. A malformed sequence consumes its lead byte and yields U+FFFD so callers can continue scanning without splitting valid text.

Next :: (value: string, at: s32) -> s32
Count :: (value: string) -> s32

Source ↗

67 / std/vec.zi

vec

Owned growable storage. Operations on Vec values are compiler primitives; the data pointer is private to those operations.

Import with #import "vec" and pass --module-path std.

Vec :: struct($T: Type) { data: *T; count: s64; capacity: s64; }

Source ↗

68 / std/web.zi

web

Browser access for Ziran code compiled to WebAssembly. Any Web API is reachable through objects held in the page's handle table: read and write properties, call methods, construct objects, pass Ziran functions as callbacks, and wait on promises. The page side is web/ziran_web.js. A handle is an s32; 0 means null or undefined, 1 is the global object, and 2 is Emscripten's Module. Names are interned once with WebName and reused, which keeps each call cheap. Handles the bridge returns are temporary: they all die when the current scope ends. A callback is its own scope; a long-running loop should wrap each pass in WebScope and WebEnd. WebKeep turns a temporary handle into one that lasts until WebRelease, for objects a program holds on to.

Import with #import "web" and pass --module-path std.

WebValue :: struct { tag: s32; aux: s32; number: float64; }

A value crossing the boundary: a tag, a length or handle, and a number.

WebUndefinedTag :: 0
WebNullTag :: 1
WebBoolTag :: 2
WebNumberTag :: 3
WebTextTag :: 4
WebObjectTag :: 5
WebStringTag :: 6
WebGlobal :: 1
WebModule :: 2
WebBytesUint8 :: 0

The kinds of typed array WebBytes builds.

WebBytesUint8Clamped :: 1
WebBytesInt16 :: 2
WebBytesInt32 :: 3
WebBytesFloat32 :: 4
WebTypeUndefined :: 0

What WebTypeOf reports.

WebTypeNull :: 1
WebTypeBool :: 2
WebTypeNumber :: 3
WebTypeString :: 4
WebTypeObject :: 5
WebTypeFunction :: 6

Receives a JS function's first three arguments as handles that are valid

WebCallback :: #type (context: s32, first: s32, second: s32, third: s32)
web_failed: bool
WebName :: (text: string) -> s32

Interns a name for property and method access. Do this once per name.

WebUndefined :: () -> WebValue
WebNull :: () -> WebValue
WebBool :: (value: bool) -> WebValue
WebNumber :: (value: float64) -> WebValue
WebText :: (text: string) -> WebValue

The text is read while the call it is passed to runs, so it must stay alive until then.

WebObject :: (handle: s32) -> WebValue
WebAsNumber :: (value: WebValue) -> float64
WebAsBool :: (value: WebValue) -> bool
WebAsObject :: (value: WebValue) -> s32

The handle of an object or string result, or 0.

WebIsUndefined :: (value: WebValue) -> bool
WebFailed :: () -> bool

Whether the last property access, call, or construction threw. The exception is WebLastError.

WebLastError :: () -> s32
WebGet :: (object: s32, name: s32) -> WebValue
WebGetNumber :: (object: s32, name: s32) -> float64
WebGetObject :: (object: s32, name: s32) -> s32
WebSet :: (object: s32, name: s32, value: WebValue)
WebAt :: (object: s32, index: s32) -> WebValue
WebSetAt :: (object: s32, index: s32, value: WebValue)
WebCall :: (object: s32, name: s32, args: *WebValue, count: s32) -> WebValue
WebCall0 :: (object: s32, name: s32) -> WebValue
WebCall1 :: (object: s32, name: s32, a: WebValue) -> WebValue
WebCall2 :: (object: s32, name: s32, a: WebValue, b: WebValue) -> WebValue
WebCall3 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue) -> WebValue
WebCall4 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue) -> WebValue
WebCall5 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue, e: WebValue) -> WebValue
WebCall6 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue, e: WebValue, f: WebValue) -> WebValue
WebCall8 :: (object: s32, name: s32, a: WebValue, b: WebValue, c: WebValue, d: WebValue, e: WebValue, f: WebValue, g: WebValue, h: WebValue) -> WebValue
WebNew :: (constructor: s32, args: *WebValue, count: s32) -> s32

Constructs `new constructor(args...)`; returns the new object's handle.

WebNew0 :: (constructor: s32) -> s32
WebNew1 :: (constructor: s32, a: WebValue) -> s32
WebNew2 :: (constructor: s32, a: WebValue, b: WebValue) -> s32
WebNew3 :: (constructor: s32, a: WebValue, b: WebValue, c: WebValue) -> s32
WebValueOf :: (handle: s32) -> WebValue

The value a handle holds, such as the number a callback argument carries.

WebNewObject :: () -> s32
WebNewArray :: () -> s32
WebRelease :: (handle: s32)

Frees a handle made by WebKeep or WebFunction. Temporary handles need no release.

WebScope :: () -> s32

Starts a scope; WebEnd(mark) frees every temporary handle made since.

WebEnd :: (mark: s32)
WebKeep :: (handle: s32) -> s32

A handle to the same object that lasts until WebRelease, unlike the temporary one it came from.

WebLiveHandles :: () -> s32

How many handles are live, for checking a program does not leak them.

WebTypeOf :: (handle: s32) -> s32
WebInstanceOf :: (handle: s32, constructor: s32) -> bool
WebFunction :: (callback: WebCallback, context: s32) -> s32

A JS function that runs `callback` with `context` and up to three argument handles, kept until released.

WebStringLength :: (handle: s32) -> s32

The length in bytes of a string handle's text.

WebCopyString :: (handle: s32, buffer: []u8) -> s32

Copies a string handle's text into `buffer`, NUL-terminated, and returns its length in bytes.

WebBytes :: (kind: s32, data: *void, count: s32) -> s32

A typed array holding a copy of `count` elements from `data`.

WebCopyOut :: (handle: s32, data: *void, capacity: s32) -> s32

Copies a typed array's bytes into `data`, at most `capacity`; returns the number copied.

WebCopyIn :: (handle: s32, data: *void, length: s32) -> s32

Copies `length` bytes from `data` over the start of a typed array.

WebAwait :: (promise: s32, result: *WebValue) -> bool

Suspends until the promise settles. Returns whether it resolved, with its value in `result`.

WebSleep :: (milliseconds: s32)
WebNextFrame :: (minimum_delay: float64)

Suspends until the browser draws its next frame, and at least `minimum_delay` milliseconds have passed.

Source ↗

69 / std/zip.zi

zip

Classic ZIP directory reader for byte buffers. The caller owns the archive bytes and decides which named entries are allowed in its application. ZIP64, encrypted entries, split archives, and ambiguous names are rejected.

Import with #import "zip" and pass --module-path std.

ZipEntry :: struct { data_start: u64; compressed_size: u64; size: u64; crc32: u32; method: u32; found: bool; }
ZipDirectory :: struct { start: u64; end: u64; cursor: u64; count: u64; index: u64; valid: bool; }
ZipNamedEntry :: struct { directory: ZipDirectory; entry: ZipEntry; name_start: u64; name_size: u64; valid: bool; }
ZipWriteItem :: struct { name_start: u64; name_size: u64; data_start: u64; data_size: u64; }
ZipU16 :: (bytes: []u8, at: u64) -> u32
ZipU32 :: (bytes: []u8, at: u64) -> u32
ZipNameEqual :: (bytes: []u8, at: u64, size: u64, wanted: string) -> bool
OpenZipDirectory :: (bytes: []u8) -> ZipDirectory
ZipNamesMatch :: (bytes: []u8, first: u64, second: u64, size: u64) -> bool
NextZipEntry :: (bytes: []u8, directory: ZipDirectory) -> ZipNamedEntry

On malformed input, both the returned record and the cursor become invalid.

FindZipEntry :: (bytes: []u8, wanted: string) -> ZipEntry

A missing or invalid entry has found=false. Duplicate names are invalid.

ZipCRC32Update :: (crc_start: u32, bytes: []u8) -> u32
ZipCRC32 :: (bytes: []u8) -> u32
CopyStoredZipEntry :: (bytes: []u8, entry: ZipEntry, output: []u8) -> bool
ZipPut16 :: (output: []u8, at: u64, value: u32)
ZipPut32 :: (output: []u8, at: u64, value: u32)
StoredZipSize :: (input: []u8, items: []ZipWriteItem) -> u64

Returns the exact output size or zero when classic ZIP limits are exceeded.

ZipCopyBytes :: (output: []u8, at: u64, input: []u8, input_at: u64, size: u64)
ZipCRC32Range :: (bytes: []u8, at: u64, size: u64) -> u32
WriteStoredZip :: (output: []u8, input: []u8, items: []ZipWriteItem) -> u64

Writes uncompressed ZIP entries into caller-owned memory. An app can choose compression separately; this keeps the archive format portable and usable even where no native compression library is installed.

Source ↗

70 / std/zip_file_linux.zi

zip_file_linux

Import with #import "zip_file_linux" and pass --module-path std.

ZipFileRecord :: struct { local_offset: u64; size: u64; name_size: u32; crc32: u32; valid: bool; }
ZipFilePut16 :: (bytes: []u8, at: s32, value: u32)
ZipFilePut32 :: (bytes: []u8, at: s32, value: u32)
ZipFileWriteAll :: (file: FileHandle, bytes: []u8, at: u64) -> bool
ZipFileWriteName :: (file: FileHandle, name: string, at: u64) -> bool
WriteStoredZipFileEntry :: (file: FileHandle, at: u64, name: string, data: []u8) -> ZipFileRecord
StoredZipFileNext :: (record: ZipFileRecord) -> u64
WriteStoredZipFileDirectoryEntry :: (file: FileHandle, at: u64, name: string, record: ZipFileRecord) -> u64
FinishStoredZipFile :: (file: FileHandle, directory_start: u64, directory_end: u64, count: u32) -> bool

Source ↗

71 / std/zip_linux.zi

zip_linux

Import with #import "zip_linux" and pass --module-path std.

ZStream :: struct { next_in: *u8; avail_in: u32; total_in: usize; next_out: *u8; avail_out: u32; total_out: usize; msg: *u8; state: *void; zalloc: *void; zfree: *void; opaque: *void; data_type: s32; adler: usize; reserved: usize; }
ExtractZipEntry :: (archive: []u8, entry: ZipEntry, output: []u8) -> bool
ZipExtractWriteAll :: (file: FileHandle, bytes: []u8, offset: u64) -> bool
ExtractZipEntryToFile :: (archive: []u8, entry: ZipEntry, file: FileHandle) -> bool

Source ↗