Module: nupp

The always-available standard-library namespace.

nupp is a table the prelude declares, so its fields are in scope everywhere without a require; each implementation loads only if the checked program actually uses it. A binding called nupp shadows it deliberately, the way a binding called string would.

Its public namespaces are nupp.data (JSON, UTF-8, UUIDs, hashes and checksums), nupp.io (buffers, byte views, readers and writers), nupp.io.Path and nupp.io.URI (filesystem paths and resource identifiers), nupp.math (scalar helpers and two-dimensional vectors), nupp.peg (textual parsing-expression grammars compiled at either phase), and nupp.fieldcodec (reflection-driven keyed codecs).

The compiler-provided ownership operations also live under this global: nupp.drop, nupp.borrow, nupp.intoRaw, nupp.fromRaw, nupp.borrowFrom, and nupp.pin. The compiler implements them, so they type nothing like ordinary functions and are not values you can pass around. The old bare spellings remain aliases, but new code should use nupp.*.

This module's siblings are ordinary modules shipped with the compiler, reached with require and separate from the fields of the ambient global: nupp.bytes, nupp.profile, nupp.resources, nupp.zone, and nupp.compiler, which holds the self-hosted compiler implementation and is hidden from public API documentation by its @!internal namespace root.

Submodules

ModuleDescription
nupp.bytesTyped binary reads and writes over a string.buffer.Buffer.
nupp.dataJSON, UTF-8, UUIDs, hashes and checksums.
nupp.fieldcodecType-directed keyed codecs materialized from semantic reflection.
nupp.ioBuffers, byte views, readers and writers.
nupp.logLeveled logging over a swappable destination.
nupp.mathScalar helpers and two-dimensional vectors.
nupp.pegCompiles textual parsing-expression grammars into reusable matchers.
nupp.profileProfiling, in two channels.
nupp.resource_set
nupp.resourcesOwning wrappers for Lua's file handles.
nupp.spanBounds-carrying borrowed pointer views.
nupp.suspensionWaiting, as an operation with an installable handler.
nupp.workersIsolated worker threads.
nupp.zoneGated LuaJIT profiler zones: the stack work is skipped until a profiler asks for it.

Module contents

Types

TypeKindDescription
BufferinterfaceAn owned growable byte sequence.
ByteViewinterfaceAn immutable snapshot of bytes.
DebuginterfaceValues with deterministic compiler-generated debug formatting.
FieldCodecrecordTypes for materialized keyed field codecs.
FilesrecordFilesystem metadata and directory contents.
JSONinterfaceOne independently configured JSON encoder and decoder.
JSONEncodableinterfaceValues that can encode themselves as JSON text.
LogrecordLeveled logging over a swappable destination.
PathrecordAn immutable platform-native UTF-8 filesystem path.
ReaderinterfaceA forward-only byte source.
URIrecordAn immutable normalized absolute URI.
WriterinterfaceA forward-only byte destination.

Types#

Bufferinterface#

An owned growable byte sequence. All offsets are zero-based.

interface nupp.Buffer
    newReader: function(self: nupp.Buffer): nupp.Reader
    newWriter: function(self: nupp.Buffer): nupp.Writer
    length: function(self: nupp.Buffer): integer
    capacity: function(self: nupp.Buffer): integer
    clear: function(self: nupp.Buffer)
    ensureCapacity: function(self: nupp.Buffer, minimum: integer)
    resize: function(self: nupp.Buffer, length: integer)
    getString: function(self: nupp.Buffer, offset: integer?, count: integer?): string
    setString: function(self: nupp.Buffer, bytes: string, offset: integer?)
    view: function(self: nupp.Buffer, offset: integer?, count: integer?): nupp.ByteView
    isReleased: function(self: nupp.Buffer): boolean
    close: function(self: nupp.Buffer): (boolean, string?)
end

Methods

newReader

Opens a reader over a snapshot of the current bytes.

newReader: function(self: nupp.Buffer): nupp.Reader
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

Returns
TypeDescription
nupp.Reader

the new reader

newWriter

Clears the buffer and opens a writer that targets it.

newWriter: function(self: nupp.Buffer): nupp.Writer
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

Returns
TypeDescription
nupp.Writer

the new writer

length

Reports the logical byte length.

length: function(self: nupp.Buffer): integer
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

Returns
TypeDescription
integer

the byte length

capacity

Reports the reserved byte capacity.

capacity: function(self: nupp.Buffer): integer
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

Returns
TypeDescription
integer

the byte capacity

clear

Removes every byte without discarding reserved capacity.

clear: function(self: nupp.Buffer)
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

ensureCapacity

Reserves at least a byte capacity without changing the length.

ensureCapacity: function(self: nupp.Buffer, minimum: integer)
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

minimuminteger

the minimum capacity

resize

Changes the byte length, truncating or zero-filling as needed.

resize: function(self: nupp.Buffer, length: integer)
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

lengthinteger

the new byte length

getString

Copies a byte range into a string.

getString: function(self: nupp.Buffer, offset: integer?, count: integer?): string
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

offsetinteger?

the zero-based start, or zero when omitted

countinteger?

the number of bytes, or the rest of the buffer when omitted

Returns
TypeDescription
string

the copied bytes

setString

Overwrites bytes at an offset, growing and zero-filling any gap.

setString: function(self: nupp.Buffer, bytes: string, offset: integer?)
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

bytesstring

the bytes to write

offsetinteger?

the zero-based start, or zero when omitted

view

Retains an immutable snapshot of a byte range.

view: function(self: nupp.Buffer, offset: integer?, count: integer?): nupp.ByteView
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

offsetinteger?

the zero-based start, or zero when omitted

countinteger?

the number of bytes, or the rest of the buffer when omitted

Returns
TypeDescription
nupp.ByteView

the retained byte view

isReleased

Reports whether this buffer has been released.

isReleased: function(self: nupp.Buffer): boolean
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

Returns
TypeDescription
boolean

whether the buffer is released

close

Releases this buffer. Repeated calls are safe.

close: function(self: nupp.Buffer): (boolean, string?)
Arguments
NameTypeDescription
selfnupp.Buffer

this buffer

Returns
TypeDescription
boolean

whether the release succeeded

string?

a failure reason, when unsuccessful

ByteViewinterface#

An immutable snapshot of bytes.

interface nupp.ByteView
    newReader: function(self: nupp.ByteView): nupp.Reader
    length: function(self: nupp.ByteView): integer
    getString: function(self: nupp.ByteView): string
    view: function(self: nupp.ByteView, offset: integer?, count: integer?): nupp.ByteView
    isReleased: function(self: nupp.ByteView): boolean
    close: function(self: nupp.ByteView): (boolean, string?)
end

Methods

newReader

Opens a reader over this snapshot.

newReader: function(self: nupp.ByteView): nupp.Reader
Arguments
NameTypeDescription
selfnupp.ByteView

this byte view

Returns
TypeDescription
nupp.Reader

the new reader

length

Reports the number of bytes in this snapshot.

length: function(self: nupp.ByteView): integer
Arguments
NameTypeDescription
selfnupp.ByteView

this byte view

Returns
TypeDescription
integer

the byte length

getString

Copies all bytes into a string.

getString: function(self: nupp.ByteView): string
Arguments
NameTypeDescription
selfnupp.ByteView

this byte view

Returns
TypeDescription
string

the copied bytes

view

Retains an immutable subrange of this snapshot.

view: function(self: nupp.ByteView, offset: integer?, count: integer?): nupp.ByteView
Arguments
NameTypeDescription
selfnupp.ByteView

this byte view

offsetinteger?

the zero-based start, or zero when omitted

countinteger?

the number of bytes, or the rest of the view when omitted

Returns
TypeDescription
nupp.ByteView

the retained subrange

isReleased

Reports whether this snapshot has been released.

isReleased: function(self: nupp.ByteView): boolean
Arguments
NameTypeDescription
selfnupp.ByteView

this byte view

Returns
TypeDescription
boolean

whether the view is released

close

Releases this snapshot. Repeated calls are safe.

close: function(self: nupp.ByteView): (boolean, string?)
Arguments
NameTypeDescription
selfnupp.ByteView

this byte view

Returns
TypeDescription
boolean

whether the release succeeded

string?

a failure reason, when unsuccessful

Debuginterface#

Values with deterministic compiler-generated debug formatting.

interface nupp.Debug
    debug: function(self): string
end

Methods

debug
debug: function(self): string
Arguments
NameTypeDescription
?self
Returns
TypeDescription
string

FieldCodecrecord#

Types for materialized keyed field codecs.

record nupp.FieldCodec
    record Blueprint
    end

    record KeyedCodec<T>
        encode: function(self, value: T): {[string]: any}
        decode: function(self, value: {[string]: any}): (T?, string?)
        fingerprint: string
    end

    record Library
        compile: function(info: TypeInfo): Blueprint
    end
end

Fields

NameTypeDescription
BlueprintrecordDecl
KeyedCodecrecordDecl
LibraryrecordDecl

Filesrecord#

Filesystem metadata and directory contents.

Every operation here answers before a transfer could have started: it reads a name, a listing, or an attribute. Reading and writing a file's bytes is a separate layer.

record nupp.Files
    type Kind = "file" | "directory" | "symlink" | "other"
    type UserFolder = "home" | "documents" | "downloads" | "desktop" | "pictures" | "music" | "videos"
    record Info
        kind: nupp.Files.Kind
        size: integer
        modified: number
        readOnly: boolean
    end
    type Mode = "r" | "w" | "a" | "r+" | "w+" | "a+"
    type Origin = "set" | "current" | "end"
    type LineIterator = function(): string?
    record File
        newReader: nosuspend function(self: nupp.Files.File): nupp.Reader
        newWriter: nosuspend function(self: nupp.Files.File): nupp.Writer
        size: nosuspend function(self: nupp.Files.File): (integer?, string?)
        seek: nosuspend function(
            self: nupp.Files.File,
            offset: integer?,
            origin: nupp.Files.Origin?
        ): (integer?, string?)
        position: nosuspend function(self: nupp.Files.File): (integer?, string?)
        flush: nosuspend function(self: nupp.Files.File): (boolean, string?)
        isReleased: nosuspend function(self: nupp.Files.File): boolean
        @drop

        close: nosuspend function(takes self: nupp.Files.File): boolean
    end
    record TemporaryPath
        toString: nosuspend function(self: nupp.Files.TemporaryPath): string
        persist: nosuspend function(self: nupp.Files.TemporaryPath, destination: string | nupp.Path): (boolean, string?)
        isReleased: nosuspend function(self: nupp.Files.TemporaryPath): boolean
        @drop

        close: nosuspend function(takes self: nupp.Files.TemporaryPath): boolean
    end
    record Entry
        name: string
        kind: nupp.Files.Kind
    end
    record TemporaryOptions
        directory: (string | nupp.Path)?
        prefix: string?
        suffix: string?
    end
end

Fields

NameTypeDescription
KindtypeAlias

What a resolved path refers to. A symlink answer only ever comes from isSymlink, since every other operation follows the link first.

UserFoldertypeAlias

A well-known user folder. Resolved from the environment, so a desktop that records its folders elsewhere is not consulted.

InforecordDecl

One resolved path's attributes.

ModetypeAlias

How an open file may be used. The three update modes read and write: r+ needs an existing file, w+ truncates one, and a+ appends.

OrigintypeAlias

What a seek offset is measured from.

LineIteratortypeAlias

Answers each line in turn, and nil at the end of the file.

FilerecordDecl

An open file, and the obligation to close it.

Readers and writers opened from it satisfy the same nupp.Reader and nupp.Writer contracts a buffer's do, so code written against those works over a file without knowing one is there.

TemporaryPathrecordDecl

A created temporary path, and the obligation to settle it.

Closing removes it. persist moves it somewhere permanent instead and discharges the obligation, which is the whole reason to make one: write to a name nobody else can take, then put it where it belongs.

EntryrecordDecl

One directory child, as the directory itself describes it.

TemporaryOptionsrecordDecl

The generated part of a temporary name.

JSONinterface#

One independently configured JSON encoder and decoder.

interface nupp.JSON
    encodeJSON: function(value: any): string
    decodeJSON: function(text: string): any
    null: any
    emptyArray: any
    arrayMt: metatable<{any}>
    emptyArrayMt: metatable<{any}>
    encodeEmptyTableAsObject: function(setting: boolean | string?): boolean
    decodeArrayWithArrayMt: function(setting: boolean | string?): boolean
    decodeAllowComment: function(setting: boolean | string?): boolean
    encodeSparseArray: function(convert: boolean?, ratio: integer?, safe: integer?): (boolean, integer, integer)
    encodeMaxDepth: function(depth: integer?): integer
    decodeMaxDepth: function(depth: integer?): integer
    encodeNumberPrecision: function(precision: integer?): integer
    encodeKeepBuffer: function(keep: boolean | string?): boolean
    encodeInvalidNumbers: function(setting: boolean | string?): boolean | string
    decodeInvalidNumbers: function(setting: boolean | string?): boolean
    encodeEscapeForwardSlash: function(setting: boolean | string?): boolean
    encodeSkipUnsupportedValueTypes: function(setting: boolean | string?): boolean
    encodeIndent: function(indent: string?): string
end

Methods

encodeJSON

Encodes a Lua value as JSON text.

encodeJSON: function(value: any): string
Arguments
NameTypeDescription
valueany

the value to encode

Returns
TypeDescription
string

the encoded JSON document

decodeJSON

Decodes one JSON document into Lua values.

decodeJSON: function(text: string): any
Arguments
NameTypeDescription
textstring

the JSON document to decode

Returns
TypeDescription
any

the decoded value

encodeEmptyTableAsObject

Sets whether an empty table encodes as an object, or reads the current setting when omitted.

encodeEmptyTableAsObject: function(setting: boolean | string?): boolean
Arguments
NameTypeDescription
settingboolean | string?

true or "on" for {}, false or "off" for []

Returns
TypeDescription
boolean

whether empty tables encode as objects

decodeArrayWithArrayMt

Sets whether decoded arrays carry arrayMt, or reads the current setting when omitted.

decodeArrayWithArrayMt: function(setting: boolean | string?): boolean
Arguments
NameTypeDescription
settingboolean | string?

the new setting

Returns
TypeDescription
boolean

whether decoded arrays carry arrayMt

decodeAllowComment

Sets whether the decoder accepts comments, or reads the current setting when omitted.

decodeAllowComment: function(setting: boolean | string?): boolean
Arguments
NameTypeDescription
settingboolean | string?

the new setting

Returns
TypeDescription
boolean

whether comments are accepted

encodeSparseArray

Configures how excessively sparse arrays are encoded, or reads the current settings when every argument is omitted.

encodeSparseArray: function(convert: boolean?, ratio: integer?, safe: integer?): (boolean, integer, integer)
Arguments
NameTypeDescription
convertboolean?

whether sparse arrays become JSON objects instead of raising

ratiointeger?

the maximum ratio between the highest index and item count

safeinteger?

the array size below which sparsity is always accepted

Returns
TypeDescription
boolean

whether sparse arrays are converted

integer

the current ratio limit

integer

the current safe size

encodeMaxDepth

Sets the maximum nested-container depth accepted by the encoder, or reads the current limit when omitted.

encodeMaxDepth: function(depth: integer?): integer
Arguments
NameTypeDescription
depthinteger?

the new maximum depth

Returns
TypeDescription
integer

the current maximum depth

decodeMaxDepth

Sets the maximum nested-container depth accepted by the decoder, or reads the current limit when omitted.

decodeMaxDepth: function(depth: integer?): integer
Arguments
NameTypeDescription
depthinteger?

the new maximum depth

Returns
TypeDescription
integer

the current maximum depth

encodeNumberPrecision

Sets the significant-digit precision used to encode numbers, or reads the current precision when omitted.

encodeNumberPrecision: function(precision: integer?): integer
Arguments
NameTypeDescription
precisioninteger?

the new number of significant digits

Returns
TypeDescription
integer

the current precision

encodeKeepBuffer

Sets whether the encoder reuses its internal buffer, or reads the current setting when omitted.

encodeKeepBuffer: function(keep: boolean | string?): boolean
Arguments
NameTypeDescription
keepboolean | string?

the new setting

Returns
TypeDescription
boolean

whether the internal buffer is retained

encodeInvalidNumbers

Configures encoding of NaN and infinities, or reads the current setting when omitted.

encodeInvalidNumbers: function(setting: boolean | string?): boolean | string
Arguments
NameTypeDescription
settingboolean | string?

false to reject them, true to emit them, or "null" to emit null

Returns
TypeDescription
boolean | string

the active invalid-number setting

decodeInvalidNumbers

Sets whether the decoder accepts NaN and infinities, or reads the current setting when omitted.

decodeInvalidNumbers: function(setting: boolean | string?): boolean
Arguments
NameTypeDescription
settingboolean | string?

the new setting

Returns
TypeDescription
boolean

whether invalid numbers are accepted

encodeEscapeForwardSlash

Sets whether / is escaped in JSON strings, or reads the current setting when omitted.

encodeEscapeForwardSlash: function(setting: boolean | string?): boolean
Arguments
NameTypeDescription
settingboolean | string?

the new setting

Returns
TypeDescription
boolean

whether forward slashes are escaped

encodeSkipUnsupportedValueTypes

Sets whether unsupported values are skipped instead of raising, or reads the current setting when omitted.

encodeSkipUnsupportedValueTypes: function(setting: boolean | string?): boolean
Arguments
NameTypeDescription
settingboolean | string?

the new setting

Returns
TypeDescription
boolean

whether unsupported values are skipped

encodeIndent

Sets the indentation used for encoded containers, or reads the current indentation when omitted.

encodeIndent: function(indent: string?): string
Arguments
NameTypeDescription
indentstring?

the indentation string

Returns
TypeDescription
string

the current indentation string

Fields

NameTypeDescription
nullany

Sentinel that decodes from and encodes as JSON null.

emptyArrayany

Sentinel that always encodes as an empty JSON array.

arrayMtmetatable<{any}>

Metatable marking a table to encode as a JSON array.

emptyArrayMtmetatable<{any}>

Metatable marking a table to encode as an empty JSON array.

JSONEncodableinterface#

Values that can encode themselves as JSON text.

interface nupp.JSONEncodable
    toJSON: function(self): string
end

Methods

toJSON
toJSON: function(self): string
Arguments
NameTypeDescription
?self
Returns
TypeDescription
string

Logrecord#

Leveled logging over a swappable destination.

The severity operations are compiler intrinsics. A call in statement position whose format is a literal compiles to a level test around a direct emit, so a filtered call evaluates none of its arguments. Every other spelling stays an ordinary call meaning the same thing, only slower: a value rather than a call, a computed format, a named argument, or a nupp some local has taken.

record nupp.Log
    type Level = "off" | "error" | "warn" | "info" | "debug"
    type Severity = integer
    type Sink = function(level: Severity, module: string, line: integer, message: string): nil
    type Formatter = function(level: Severity, module: string, line: integer, message: string, stamp: string): string
    type Target = Sink | LuaFile
    record Logger
        readonly name: string
        debug: function<F is string>(self: Logger, fmt: F, ...: unpackof __NuppFormatArguments<F>): nil
        info: function<F is string>(self: Logger, fmt: F, ...: unpackof __NuppFormatArguments<F>): nil
        warn: function<F is string>(self: Logger, fmt: F, ...: unpackof __NuppFormatArguments<F>): nil
        error: function<F is string>(self: Logger, fmt: F, ...: unpackof __NuppFormatArguments<F>): nil
        enabled: function(self: Logger, level: Level): boolean
    end
end

Fields

NameTypeDescription
LeveltypeAlias

The threshold, from silent to most verbose. Each level admits itself and everything above it, so "warn" emits warnings and errors.

SeveritytypeAlias

A level as a sink sees it: 1 error, 2 warn, 3 info, 4 debug.

SinktypeAlias

Receives one emitted line, already formatted. Replacing this replaces the back end, so a host logging through its own facility pays for nothing it discards -- no timestamp is passed, because a sink that wants one asks.

FormattertypeAlias

Renders one line for a file-like destination. Only consulted when the target is file-like; a sink function formats however it likes.

TargettypeAlias

Where lines go: a sink function, or anything file-like to write to.

LoggerrecordDecl

A logger carrying a fixed name, for subsystems and for call sites the intrinsic cannot rewrite. Changing the level or target restamps every logger, so a filtered call reaches an empty function rather than a test.

Pathrecord#

An immutable platform-native UTF-8 filesystem path.

record nupp.Path
    toString: function(self: nupp.Path): string
    join: function(self: nupp.Path, ...: string | nupp.Path): nupp.Path
    normalize: function(self: nupp.Path): nupp.Path
    absolute: function(self: nupp.Path): (nupp.Path?, string?)
    resolve: function(self: nupp.Path, ...: string | nupp.Path): (nupp.Path?, string?)
    canonicalize: function(self: nupp.Path): (nupp.Path?, string?)
    relativeTo: function(self: nupp.Path, base: string | nupp.Path): (nupp.Path?, string?)
    parent: function(self: nupp.Path): nupp.Path?
    fileName: function(self: nupp.Path): string?
    stem: function(self: nupp.Path): string?
    extension: function(self: nupp.Path): string?
    withFileName: function(self: nupp.Path, name: string): nupp.Path
    withExtension: function(self: nupp.Path, extension: string): nupp.Path
    isAbsolute: function(self: nupp.Path): boolean
    isRelative: function(self: nupp.Path): boolean
end

Methods

toString

Returns the native UTF-8 path text.

toString: function(self: nupp.Path): string
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
string

the path text

join

Appends path components using the current platform's rules.

join: function(self: nupp.Path, ...: string | nupp.Path): nupp.Path
Arguments
NameTypeDescription
selfnupp.Path

this path

...string | nupp.Path

the components to append

Returns
TypeDescription
nupp.Path

the joined path

normalize

Removes lexical . and .. components without accessing the filesystem.

normalize: function(self: nupp.Path): nupp.Path
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
nupp.Path

the normalized path

absolute

Resolves a relative path against the current working directory.

absolute: function(self: nupp.Path): (nupp.Path?, string?)
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
nupp.Path?

the absolute path, or nil on failure

string?

a failure reason, when unsuccessful

resolve

Makes this path absolute, appends components, and normalizes the result.

resolve: function(self: nupp.Path, ...: string | nupp.Path): (nupp.Path?, string?)
Arguments
NameTypeDescription
selfnupp.Path

this path

...string | nupp.Path

the components to append

Returns
TypeDescription
nupp.Path?

the resolved path, or nil on failure

string?

a failure reason, when unsuccessful

canonicalize

Resolves filesystem links and returns the real path.

canonicalize: function(self: nupp.Path): (nupp.Path?, string?)
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
nupp.Path?

the canonical path, or nil on failure

string?

a failure reason, when unsuccessful

relativeTo

Computes this path relative to a compatible base path.

relativeTo: function(self: nupp.Path, base: string | nupp.Path): (nupp.Path?, string?)
Arguments
NameTypeDescription
selfnupp.Path

this path

basestring | nupp.Path

the path to make this value relative to

Returns
TypeDescription
nupp.Path?

the relative path, or nil on failure

string?

a failure reason, when unsuccessful

parent

Returns the parent path, when one exists.

parent: function(self: nupp.Path): nupp.Path?
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
nupp.Path?

the parent path

fileName

Returns the final path component, when one exists.

fileName: function(self: nupp.Path): string?
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
string?

the file name

stem

Returns the file name without its final extension, when one exists.

stem: function(self: nupp.Path): string?
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
string?

the file stem

extension

Returns the final file-name extension without its separator.

extension: function(self: nupp.Path): string?
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
string?

the extension

withFileName

Replaces the final path component.

withFileName: function(self: nupp.Path, name: string): nupp.Path
Arguments
NameTypeDescription
selfnupp.Path

this path

namestring

the replacement file name, without path separators

Returns
TypeDescription
nupp.Path

the modified path

withExtension

Replaces the final file-name extension.

withExtension: function(self: nupp.Path, extension: string): nupp.Path
Arguments
NameTypeDescription
selfnupp.Path

this path

extensionstring

the replacement extension, without path separators

Returns
TypeDescription
nupp.Path

the modified path

isAbsolute

Reports whether this path is absolute.

isAbsolute: function(self: nupp.Path): boolean
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
boolean

whether the path is absolute

isRelative

Reports whether this path is relative.

isRelative: function(self: nupp.Path): boolean
Arguments
NameTypeDescription
selfnupp.Path

this path

Returns
TypeDescription
boolean

whether the path is relative

Readerinterface#

A forward-only byte source. An empty read or zero-byte readInto is EOF.

interface nupp.Reader
    read: function(self: nupp.Reader, count: integer): (string?, string?)
    readInto: function(
        self: nupp.Reader,
        destination: nupp.Buffer,
        offset: integer?,
        count: integer?
    ): (integer?, string?)
    transferTo: function(self: nupp.Reader, destination: nupp.Writer): (integer?, string?)
    close: function(self: nupp.Reader): (boolean, string?)
end

Methods

read

Reads the next bytes, returning an empty string at EOF.

read: function(self: nupp.Reader, count: integer): (string?, string?)
Arguments
NameTypeDescription
selfnupp.Reader

this reader

countinteger

the maximum number of bytes; non-positive values still read one

Returns
TypeDescription
string?

the bytes, or nil on failure

string?

a failure reason, when unsuccessful

readInto

Reads bytes into a buffer, returning zero at EOF.

readInto: function(
        self: nupp.Reader,
        destination: nupp.Buffer,
        offset: integer?,
        count: integer?
    ): (integer?, string?)
Arguments
NameTypeDescription
selfnupp.Reader

this reader

destinationnupp.Buffer

the buffer to append to or overwrite

offsetinteger?

the zero-based destination offset, or zero when omitted

countinteger?

the maximum bytes to read, or 64 KiB when omitted

Returns
TypeDescription
integer?

the number of bytes read, or nil on failure

string?

a failure reason, when unsuccessful

transferTo

Copies all remaining bytes into a writer.

transferTo: function(self: nupp.Reader, destination: nupp.Writer): (integer?, string?)
Arguments
NameTypeDescription
selfnupp.Reader

this reader

destinationnupp.Writer

the writer to receive the bytes

Returns
TypeDescription
integer?

the number of bytes copied, or nil on failure

string?

a failure reason, when unsuccessful

close

Closes this reader. Repeated calls are safe.

close: function(self: nupp.Reader): (boolean, string?)
Arguments
NameTypeDescription
selfnupp.Reader

this reader

Returns
TypeDescription
boolean

whether the close succeeded

string?

a failure reason, when unsuccessful

URIrecord#

An immutable normalized absolute URI.

record nupp.URI
    record Components
        scheme: string
        userInfo: string?
        host: string?
        port: integer?
        path: string?
        query: string?
        fragment: string?
    end
    toString: function(self: nupp.URI): string
    scheme: function(self: nupp.URI): string
    authority: function(self: nupp.URI): string?
    username: function(self: nupp.URI): string
    password: function(self: nupp.URI): string?
    host: function(self: nupp.URI): string?
    port: function(self: nupp.URI): integer?
    path: function(self: nupp.URI): string
    query: function(self: nupp.URI): string?
    fragment: function(self: nupp.URI): string?
    userInfo: function(self: nupp.URI): string?
    withScheme: function(self: nupp.URI, scheme: string): nupp.URI
    withUserInfo: function(self: nupp.URI, userInfo: string?): nupp.URI
    withHost: function(self: nupp.URI, host: string?): nupp.URI
    withPort: function(self: nupp.URI, port: integer?): nupp.URI
    withPath: function(self: nupp.URI, path: string): nupp.URI
    withQuery: function(self: nupp.URI, query: string?): nupp.URI
    withFragment: function(self: nupp.URI, fragment: string?): nupp.URI
    concatPath: function(self: nupp.URI, path: string): nupp.URI
    withEndpoint: function(self: nupp.URI, endpoint: nupp.URI): nupp.URI
    resolve: function(self: nupp.URI, reference: string): (nupp.URI?, string?)
end

Methods

toString

Returns the complete normalized URI text.

toString: function(self: nupp.URI): string
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string

the URI text

scheme

Returns the normalized URI scheme.

scheme: function(self: nupp.URI): string
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string

the scheme

authority

Returns the complete authority component, when present.

authority: function(self: nupp.URI): string?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string?

the authority

username

Returns the username component, or an empty string when absent.

username: function(self: nupp.URI): string
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string

the username

password

Returns the password component, when present.

password: function(self: nupp.URI): string?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string?

the password

host

Returns the normalized host, when present.

host: function(self: nupp.URI): string?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string?

the host

port

Returns the port, when explicitly present.

port: function(self: nupp.URI): integer?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
integer?

the port

path

Returns the URI path component.

path: function(self: nupp.URI): string
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string

the path

query

Returns the query without its leading ?, when present.

query: function(self: nupp.URI): string?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string?

the query

fragment

Returns the fragment without its leading #, when present.

fragment: function(self: nupp.URI): string?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string?

the fragment

userInfo

Returns the complete user-information component, when present.

userInfo: function(self: nupp.URI): string?
Arguments
NameTypeDescription
selfnupp.URI

this URI

Returns
TypeDescription
string?

the user information

withScheme

Returns a copy with a replacement scheme.

withScheme: function(self: nupp.URI, scheme: string): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

schemestring

the replacement scheme

Returns
TypeDescription
nupp.URI

the modified URI

withUserInfo

Returns a copy with replacement or removed user information.

withUserInfo: function(self: nupp.URI, userInfo: string?): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

userInfostring?

the replacement, or nil to remove it

Returns
TypeDescription
nupp.URI

the modified URI

withHost

Returns a copy with a replacement or removed host.

withHost: function(self: nupp.URI, host: string?): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

hoststring?

the replacement, or nil to remove it

Returns
TypeDescription
nupp.URI

the modified URI

withPort

Returns a copy with a replacement or removed port.

withPort: function(self: nupp.URI, port: integer?): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

portinteger?

the replacement from 0 through 65535, or nil to remove it

Returns
TypeDescription
nupp.URI

the modified URI

withPath

Returns a copy with a replacement path.

withPath: function(self: nupp.URI, path: string): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

pathstring

the replacement path

Returns
TypeDescription
nupp.URI

the modified URI

withQuery

Returns a copy with a replacement or removed query.

withQuery: function(self: nupp.URI, query: string?): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

querystring?

the replacement without ?, or nil to remove it

Returns
TypeDescription
nupp.URI

the modified URI

withFragment

Returns a copy with a replacement or removed fragment.

withFragment: function(self: nupp.URI, fragment: string?): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

fragmentstring?

the replacement without #, or nil to remove it

Returns
TypeDescription
nupp.URI

the modified URI

concatPath

Appends path text without interpreting it as a URI reference.

concatPath: function(self: nupp.URI, path: string): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

pathstring

the path text to append

Returns
TypeDescription
nupp.URI

the modified URI

withEndpoint

Replaces the scheme and authority while retaining resource components.

withEndpoint: function(self: nupp.URI, endpoint: nupp.URI): nupp.URI
Arguments
NameTypeDescription
selfnupp.URI

this URI

endpointnupp.URI

the URI supplying the scheme and authority

Returns
TypeDescription
nupp.URI

the endpoint-rerouted URI

resolve

Resolves a URI reference according to RFC reference-resolution rules.

resolve: function(self: nupp.URI, reference: string): (nupp.URI?, string?)
Arguments
NameTypeDescription
selfnupp.URI

this URI

referencestring

the URI reference to resolve

Returns
TypeDescription
nupp.URI?

the resolved URI, or nil on failure

string?

a failure reason, when unsuccessful

Fields

NameTypeDescription
ComponentsrecordDecl

Components accepted when constructing an absolute URI.

Writerinterface#

A forward-only byte destination.

interface nupp.Writer
    write: function(self: nupp.Writer, bytes: string): (boolean, string?)
    writeFrom: function(self: nupp.Writer, source: nupp.Buffer, offset: integer?, count: integer?): (integer?, string?)
    writeView: function(
        self: nupp.Writer,
        source: nupp.ByteView,
        offset: integer?,
        count: integer?
    ): (integer?, string?)
    flush: function(self: nupp.Writer): (boolean, string?)
    close: function(self: nupp.Writer): (boolean, string?)
end

Methods

write

Writes a string of bytes.

write: function(self: nupp.Writer, bytes: string): (boolean, string?)
Arguments
NameTypeDescription
selfnupp.Writer

this writer

bytesstring

the bytes to write

Returns
TypeDescription
boolean

whether the write succeeded

string?

a failure reason, when unsuccessful

writeFrom

Copies bytes from a mutable buffer.

writeFrom: function(self: nupp.Writer, source: nupp.Buffer, offset: integer?, count: integer?): (integer?, string?)
Arguments
NameTypeDescription
selfnupp.Writer

this writer

sourcenupp.Buffer

the source buffer

offsetinteger?

the zero-based start, or zero when omitted

countinteger?

the number of bytes, or the rest of the buffer when omitted

Returns
TypeDescription
integer?

the number of bytes written, or nil on failure

string?

a failure reason, when unsuccessful

writeView

Copies bytes from an immutable view.

writeView: function(
        self: nupp.Writer,
        source: nupp.ByteView,
        offset: integer?,
        count: integer?
    ): (integer?, string?)
Arguments
NameTypeDescription
selfnupp.Writer

this writer

sourcenupp.ByteView

the source byte view

offsetinteger?

the zero-based start, or zero when omitted

countinteger?

the number of bytes, or the rest of the view when omitted

Returns
TypeDescription
integer?

the number of bytes written, or nil on failure

string?

a failure reason, when unsuccessful

flush

Flushes any buffered output.

flush: function(self: nupp.Writer): (boolean, string?)
Arguments
NameTypeDescription
selfnupp.Writer

this writer

Returns
TypeDescription
boolean

whether the flush succeeded

string?

a failure reason, when unsuccessful

close

Closes this writer. Repeated calls are safe.

close: function(self: nupp.Writer): (boolean, string?)
Arguments
NameTypeDescription
selfnupp.Writer

this writer

Returns
TypeDescription
boolean

whether the close succeeded

string?

a failure reason, when unsuccessful