Command-line argument view construction and printing helpers.
Command view shape
CommandLineandtoCommandLine2return the same stateful command iterator.- Each item is a
StringView. sizereturns the remaining argument count asInt32.next(-- command cond) advances through a mutable iterator view and returns aStringViewvalue followed byCond. Exhaustion returns an emptyStringViewandFALSE.at(index -- command) reads relative to the current position without advancing;indexmust be anInt32in the remaining range.- Copying the iterator preserves an independent position, while sharing the table and strings.
Functions
CommandLine
(-- commands) Constructs an empty command iterator.- Its size is zero and
nextreturns an emptyStringViewfollowed byFALSE. To view process arguments, pass the argc/argv pair received bymaintotoCommandLine2;CommandLinedoes not obtain that pair.
toCommandLine2
(argumentAddress argumentCount -- commands) Builds a command view from a contiguous sequence of zero-terminated string addresses.argumentAddressis aNatxaddress andargumentCountis a nonnegativeInt32. For a positive count, the address must identify that many contiguous, alignedNatxpointer entries.- Each accessed entry must point to readable zero-terminated bytes whose length fits
Int32; bytes are not UTF-8 validated. - The iterator borrows both the pointer table and the addressed bytes. It reads a pointer and measures its string when that argument is accessed, without copying either allocation.
- Keep the table alive while the iterator may read it, and keep the bytes alive while any returned
StringViewis used. A returned view has a fixed byte count and immutable byte access. - A zero count reads neither table nor strings. A negative count violates the nonnegative-count contract; no eager nonnegative check is performed.
printCommandLine
(commands --) Prints the count and each command in guillemets.- Writes ‘Commands provided: ’ followed by
commands.size. For each item, writes a line feed, two spaces, ‘«’, the item's printable bytes, and ‘»’. It adds no final line feed and does not escape item contents. Printing a CommandLine iterator uses a copy of its current position.
Examples
Runtime example: constructed view size
"Array" use
"CommandLine" use
"String" use
"control" use
{} Int32 {} [
addresses: Natx Array;
"alpha\00" storageAddress @addresses.append
"beta\00" storageAddress @addresses.append
commands: addresses.data storageAddress 2 toCommandLine2;
commands.size toString print
LF print
0
] "main" exportFunction
Expected Output
2
See also
- String: UTF-8 string views, owned strings, formatting helpers, and text conversion utilities.
- linux/Process · macos/Process · windows/Process: Cross-platform process wrapper with explicit creation, waiting, and termination helpers.