Command-line argument view construction and printing helpers.
Command view shape
CommandLineandtoCommandLine2return stateful command iterators of different schemas.CommandLineconstructs aDictwith the fields and methods below; of these, thetoCommandLine2iterator hasat,next, andsize.- Each item is a
StringView. - Copying either iterator preserves an independent position, while sharing the table and strings.
Fields
SCHEMA_NAME: staticTextschema-name field,"CommandLine".commandAddress:Natxaddress of the current position in the pointer table.commandCount: remaining argument count asInt32.
Methods
assign
(argv argc --) Stores argv as the pointer-table address and argc as the remaining argument count.- The address, count, and borrowing rules are those of
toCommandLine2.
at
(index -- command) Returns the argument at index, counted from the current position, without advancing.Preconditions
indexmust be anInt32in the remaining range.
atUnchecked
(index -- command) Returns the argument at index, counted from the current position, without advancing and without a bounds check; index is cast to Natx.next
(-- command cond) Advances through a mutable iterator view and returns a StringView value followed by Cond.Postconditions
- Exhaustion returns an empty
StringViewandFALSE.
to
(argv argc -- commands) Creates an iterator with CommandLine, passes argv and argc to its assign, and returns the iterator.- The address, count, and borrowing rules are those of
toCommandLine2.
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 either iterator uses a copy of its current position.
Examples
Example: constructed view size
toCommandLine2 builds a view over two zero-terminated argument strings, so its size is 2.
"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.