nupp.derive

nupp.derive.Debug adds a checked debug method to a record or struct. Packages publish additional providers through the same recipe API.

@derive(nupp.derive.Debug)
local record User
    id: integer
    name: string = "anonymous"
    tags: {string} = {}
end
local user = new User(id = 1)
print(user:debug())

Applying a provider is a declaration-augmentation phase, not a text macro: it cannot add imports, top-level declarations, modules, records, interfaces, or independently nameable types. nupp.derive.Debug adds debug(self): string and nupp.Debug conformance. Serialization uses explicit bindings and needs no derive.

nupp.events.Event is applied the same way and marks a record or a fixed-layout struct as an event a nupp.events source constructs and delivers.

Generated members participate in normal member lookup, generic inference, and interface checking. A written member of the same name is a compile-time conflict. Stacked @derive applications combine, but a provider cannot be requested twice. See Annotations for where @derive sits among the built-in annotations.

Debug#

debug(self): string renders a record or fixed-layout struct the way the declaration reads, so what comes back names the declaration and its fields in declaration order. The method forwards the declaration witness to the value visitor, which caches its Debug policy on first use.

@derive(nupp.derive.Debug)
local record Point
    x: integer
    y: integer
end

local p = new Point(x = 3, y = -1)
print(p:debug())
Point { x = 3, y = -1 }

Strings are quoted, map keys are sorted by byte order so two runs agree, nested records render through their own debug, and a runtime table that reaches itself renders as <cycle>.

@derive(nupp.derive.Debug)
local record Tag
    name: string
end

@derive(nupp.derive.Debug)
local record Post
    title: string
    views: integer
    tags: {Tag}
    scores: {[string]: integer}
end

local post = new Post(
    title = "hello",
    views = 12,
    tags = {new Tag(name = "a"), new Tag(name = "b")},
    scores = {zeta = 1, alpha = 2}
)
print(post:debug())
Post { title = "hello", views = 12, tags = {Tag { name = "a" }, Tag { name = "b" }}, scores = {["alpha"] = 2, ["zeta"] = 1} }

Field visibility#

A @debug field annotation decides what a field contributes. redact keeps the name and replaces the value, which is what a secret wants; skip removes the field from the output entirely.

@derive(nupp.derive.Debug)
local record Credentials
    user: string
    @debug(redact = true)
    password: string
    @debug(skip = true)
    cache: any
end

local c = new Credentials(user = "ada", password = "hunter2", cache = {1, 2})
print(c:debug())
Credentials { user = "ada", password = <redacted> }

Debug owns its selection policy. Skipped and redacted fields are never read, and a field that Debug can render need not have a JSON representation. A caller can also render an explicit binding or append to an existing Buffer:

local serde = require("nupp.serde")
local debug = require("nupp.serde.debug")
local struct Vec2
    x: float
    y: float
end
local binding = serde.binding(Vec2)
local output = nupp.text.newBuffer()
debug.write(binding, new Vec2(1.25, 2.5), output)
assert(output:tostring() == "Vec2 { x = 1.25, y = 2.5 }")

Event#

nupp.events.Event records an event's name and representation and asks the compiler for the declaration's initializer, so a source can construct the event into storage it already holds. It generates no members; what it adds is the nupp.events.Emittable contract that every Type<E> an event source takes is bounded by.

local events = require("nupp.events")

@derive(events.Event)
@event(name = "combat.Damage")
local record Damage
    amount: number
    source: integer
    kind: string = "physical"
end

local bus: events.MessageBus<integer> = events.newMessageBus()
bus:observe(7, Damage, |event| -> print(event.kind))
bus:emit(7, Damage, amount = 10, source = 3)

@event(name = "...") sets the name events.name(Damage) returns; the declaration's own name is the default. The name is what something outside the program pins, such as a debug protocol, which is why it is written rather than derived from a path that a refactor would move.

The derive admits a concrete record or a fixed-layout struct with one construction contract. It refuses a declaration with several constructors, a constructor that lets self escape or moves an owned parameter into a field, an affine field, and a generic owner, because none of those can run against storage that is reused: the next lease would find the reference, the moved obligation, or the shared identity already there.

Package providers#

A package may export a derive provider as a @comptime function. Its exact signature names the one existing interface it implements:

@comptime
function M.derive(info: nupp.derive.Info): nupp.derive.Result<M.Inspect>
    -- inspect info and return a closed recipe
end

In a declared module, write @comptime export function derive(...) instead of qualifying the function through a module table. Exported annotation declarations may accompany the provider and remain compile-time metadata, not runtime values.

A consumer applies the resolved exported symbol, not a runtime function value:

local inspect = require("inspect")

@derive(inspect.derive)
local record Credentials
    username: string
    password: string
end

Applying the provider also claims M.Inspect. An equal written is inspect.Inspect is redundant and coalesced. Interface defaults are inherited normally and associated requirements are checked normally. A provider can fill a bodyless callable requirement or declare a new function member with a closed comptime-built signature. Generic, variadic, overloaded, and effectful provider declarations are not part of the first recipe version.

Dive deeper

Debug is an exported @comptime function in src/nupp/derive.nupp. It uses the same comptime worker, immutable Info, result envelope, cache, and recipe lowering as package providers. Its @debug configuration is part of the semantic annotations visible through Info.

That is also the boundary against source generation. Comptime evaluates closed value-producing programs after normal type checking, and derives run as part of declaration checking and may attach only validated member recipes. Neither becomes a way to emit arbitrary source.

Provider inputs#

Every provider on an owner receives the same immutable pre-merge Info view. It contains the owner and interface type handles, ordered stored fields with read/write handles, semantic identities, and opaque diagnostic references. It contains no tokens, locations, comments, AST, CST, mutable compiler objects, or previous provider output. nupp.derive.claims(T, I) asks whether a nominal type writes or requests contract I, which lets mutually recursive derives plan without depending on provider execution order.

Info.name names the declaration. Info.qualifiedName combines its module and declaration path, giving providers a default identity without a source filename. Packages that persist this identity should offer an explicit override: renaming a declaration or moving it to another module changes its qualified name.

A generic owner is planned once, not per instantiation. A type parameter exposes its bound, or unknown, so providers cannot specialize for future concrete arguments.

Providers run through the bounded comptime worker. Their sealed source and reachable comptime helper closure travel in the module interface; they do not remain runtime functions. A provider failure may return nupp.derive.error(message, reference, code) to point at the owner or contributing field without observing a filename or source position. The code is optional and defaults to the generic provider diagnostic NUPP2810.

Initializers#

A provider may ask for the owner's initializer with initializer = true beside methods, statics, and data. The compiler then mints the declaration's constructor body, or its field list when it declares none, as a hidden member taking the instance first: initializer(storage, ...) fills storage the caller already holds and returns it, and new allocates and calls the same body. The runtime reaches it through nupp.derive.initializer(Type). A field-list initializer applies a field default where its argument is nil, which is the one place that can, since a positional call never passes through the checker's default filling.

The compiler refuses the request on a declaration whose body could notice the reuse: several constructors, a constructor that lets self escape or moves a takes parameter into a field, an affine field, or a generic owner, each reported as NUPP2810 on the application.

Filesystem inputs#

A provider that generates a recipe from a schema or other immutable project file reads it with nupp.derive.file:

@comptime
function M.derive(info: nupp.derive.Info): nupp.derive.Result<M.Inspect>
    local schema = nupp.derive.file("schemas/inspect.txt")
    return nupp.derive.implement {
        methods = {
            inspect = nupp.derive.forward {
                helper = nupp.derive.helper(M, "renderSchema"),
                arguments = {nupp.derive.constant(schema)},
            },
        },
    }
end

The path must be a string literal and remain within the consumer project root. The compiler reads it before the isolated worker starts, fingerprints its bytes with the provider input, and records it in the incremental dependency graph. Changing the file invalidates only provider consumers, and watch mode observes the canonical path and refuses to patch over changed generated state without a restart. Missing files are diagnostics.

Providers have no general host I/O, so network resources, environment variables, clocks, mutable tables, and hidden filesystem reads cannot silently enter a cache or a hot-reload guarantee.

Closed forwarding recipes#

nupp.derive.implement returns instance methods and static functions. A bare Forward fills an interface requirement and inherits its signature. A nupp.derive.member supplies a function type built with nupp.types and its parameter names, allowing a provider to add a member that is not declared by the result interface. Parameter names are non-empty and unique, and every recipe array is dense.

return nupp.derive.implement {
    methods = {
        inspect = nupp.derive.forward {
            helper = nupp.derive.helper(M, "renderRecord"),
            arguments = {
                nupp.derive.constant(names),
                nupp.derive.array(values),
            },
        },
    },
}

Both forms lower through forward.v1, which names one ordinary runtime helper and supplies a closed argument list:

  • receiver() passes the generated method receiver.
  • argument(name) passes a named interface method parameter.
  • entry() passes the derived type's private runtime schema entry.
  • field(fieldInfo) directly reads one readable stored field.
  • constant(value) embeds a bounded quotable value.
  • witness(annotationType(argument)) passes the Type<T> witness named by an @ref annotation argument from the owner or one of its fields.
  • array(arguments) constructs a fresh array from argument recipes.

annotationType accepts only a kind = "type" argument taken from the provider's immutable Info. The referenced record remains typed across the comptime boundary instead of being reduced to a name string.

There are no nested calls, operators, branches, assignments, loops, arbitrary member accesses, or source fragments in a forwarding recipe. Table-shaped constants and arrays are fresh for each call, so mutation by one invocation cannot affect the next.

The first version refuses overloaded requirements, interface defaults, properties, setters, and metamethods. Those require separate versioned recipe capabilities rather than silently widening forward.v1.

Runtime helpers#

Runtime behavior stays in ordinary exported Nupp functions. Helpers are type checked at their declarations, and the generated call is checked again against the interface-owned argument and result packs, ownership, effects, and suspension contract. forward.v1 refuses generic runtime helpers; a later recipe version can admit them once symbolic helper identity and caching are specified. A helper module becomes an ordinary runtime dependency of the consumer even when the comptime provider itself would otherwise erase.

Dive deeper

Keeping behavior in the language makes arbitrary runtime control flow, optimization, effects, diagnostics, and future generic helpers available without turning them into a macro IR. A macro IR would have to grow its own version of each of those, and every one would then be a second implementation to keep agreeing with the first.

The generated wrapper is a semantic node the compiler may inline or sink when ordinary optimization proves that safe. Such optimization is not part of the provider contract, so a recipe cannot depend on it happening.

Generates checked members on a declaration while that declaration is checked.

@derive(Provider, ...) names providers on a record or struct. Each one reads an immutable semantic view of the declaration and returns a closed recipe; the compiler generates members from that recipe and checks them the way it checks written ones. This is a declaration-augmentation phase rather than a text macro. A provider adds no imports, top-level declarations, modules, or independently nameable types, and it observes no tokens, source positions, ordinary comments, mutable syntax objects, or another provider's output. It does see normalized declaration and field docblocks.

The shipped Debug provider crosses the same boundary as a package provider. Serialization uses explicit bindings instead of derive recipes.

Derive the shipped providers#

@derive(nupp.derive.Debug)
local record Settings
    host: string = "localhost"
    port: integer = 8080
end

local settings = new Settings()
assert(settings:debug() == 'Settings { host = "localhost", port = 8080 }')

Write a package provider#

A provider is an exported, nongeneric @comptime function whose signature names the one interface it implements. Info describes the owner, implement returns the recipe, and a consumer applies the resolved export rather than a runtime function value. Applying it also claims that interface.

local M = {}

interface M.Named
    named: function(self): string
end

function M.nameValue(value: string): string
    return "name=" .. value
end

@comptime function M.derive(info: nupp.derive.Info): nupp.derive.Result<M.Named>
    local field = info.fields[1]
    if not field or field.name ~= "name" then
        return nupp.derive.error("Named needs a first field named name", info.reference)
    end

    return nupp.derive.implement{
        methods = {
            named = nupp.derive.forward{
                helper = nupp.derive.helper(M, "nameValue"),
                arguments = {nupp.derive.field(field)},
            },
        },
    }
end

@derive(M.derive)
record M.User
    name: string
end

local user = new M.User(name = "ada")
assert(user:named() == "name=ada")

return M

Recipe vocabulary#

The interface owns every generated signature, so a recipe chooses only which runtime function stands behind a requirement and which values reach it. forward names one ordinary exported Nupp function and a closed argument list built from receiver, argument, field, constant, and array. There are no nested calls, operators, branches, loops, assignments, or provider-chosen signatures, so behavior stays in ordinary type-checked Nupp rather than in a macro IR, and the generated call is checked against the helper's declaration the way any other call is.

forward.v1 fills only bodyless, unoverloaded callable requirements, and cannot replace an interface default. A provider that refuses a declaration returns error rather than raising.

Providers run inside the bounded comptime worker, once per owner rather than once per generic instantiation, and a recipe is memoized on the Info fingerprint. claims asks whether a type already writes or requests an interface, which lets mutually recursive derives plan without depending on evaluation order.

Module contents

Types

TypeKindDescription
ArgumentrecordA value a generated call passes.
DebugOptionsinterfaceThe checked shape of @debug, written on a field.
Entryrecord
EventOptionsinterfaceThe checked shape of @event, written on a declaration deriving nupp.events.Event.
FieldrecordA written stored field in the immutable derive input projection.
ForwardrecordA requirement's implementation, from forward, to be placed in implement under the name of the requirement it fills.
InforecordThe immutable semantic view passed to an @comptime function provider.
MemberrecordA generated member with a comptime-built function signature and forward recipe.
ProviderrecordA comptime-only provider symbol accepted by @derive.
ReferencerecordAn opaque reference which a provider may attach to a diagnostic.
ResultrecordWhat a provider returns: the recipe implementing interface I.
RuntimeHelperrecordAn ordinary exported Nupp function a generated member calls, from helper.

Functions

FunctionKindDescription
annotationTypefunctionResolves a @ref annotation argument to its transported type handle.
argumentfunctionPasses a parameter of the generated method, under the name the interface requirement declares for it.
arrayfunctionBuilds a fresh array from argument recipes, once per call.
claimsfunctionAsks whether a type writes or requests an interface.
constantfunctionEmbeds a bounded quotable value.
Debugcomptime functionGenerates debug(self): string and nupp.Debug conformance for a record or struct.
debugfunctionRenders a declaration through its Debug binding.
installfunctionInstalls the runtime called by generated derive members.
entryfunctionPasses the record's registered derive entry.
errorfunctionRefuses the declaration with a diagnostic instead of returning a recipe.
fieldfunctionReads a stored field of the receiver directly.
filefunctionReads an immutable filesystem input admitted to this provider invocation.
forwardfunctionImplements a requirement by calling a runtime helper.
helperfunctionNames an ordinary exported Nupp function to forward to.
implementfunctionReturns forwarding implementations.
memberfunctionDeclares a generated member's function signature and forwarding recipe.
receiverfunctionPasses the generated method's receiver.
witnessfunctionPasses a named record's first-class Type witness to the runtime helper.

Types#

Argumentrecord#

record Argument

A value a generated call passes.

Built by receiver, entry, argument, field, constant, witness, or array. The compiler owns it: a provider may hold one and place it in an argument list, and nothing else.

DebugOptionsinterface#

interface DebugOptions ...

The checked shape of @debug, written on a field.

Members

NameKindDescription
skipfieldRemoves the field from the rendered output entirely.
redactfieldKeeps the field's name and renders its value as .

skipfield#

skip: boolean?

Removes the field from the rendered output entirely.

redactfield#

redact: boolean?

Keeps the field's name and renders its value as <redacted>.

Entryrecord#

record derive.Entry ...

Members

NameKindDescription
keyfield
mtfield
schemafield

keyfield#

key: string?

mtfield#

mt: any

schemafield#

schema: {
    data: {[string]: any},
    [string]: any
}

EventOptionsinterface#

interface EventOptions ...

The checked shape of @event, written on a declaration deriving nupp.events.Event.

Members

NameKindDescription
namefieldThe name the event registers under.

namefield#

name: string?

The name the event registers under. The declaration's own name when omitted; written when the name is an external surface something pins.

Fieldrecord#

record Field ...

A written stored field in the immutable derive input projection.

Fields arrive in declaration order. A generated member never reaches one by name; pass this value to field to read it.

Members

NameKindDescription
namefieldThe name as written.
documentationfieldThe field's --- documentation text, with markers and tags removed.
readablefieldWhether the field can be read, and so whether field admits it.
writablefieldWhether the field can be written.
readTypefieldA transported handle for the read type, or nil for a write-only field.
writeTypefieldA transported handle for the write type, or nil for a read-only field.
hasDefaultfieldWhether omission during construction supplies a declaration-owned default.
defaultValuefieldThe source-free constant default value.
annotationsfieldThe field's typed annotations in source order, @debug among them.
referencefieldPoints this provider's error at this field.

namefield#

name: string
@readonly

The name as written.

documentationfield#

documentation: string?
@readonly

The field's --- documentation text, with markers and tags removed.

readablefield#

readable: boolean
@readonly

Whether the field can be read, and so whether field admits it.

writablefield#

writable: boolean
@readonly

Whether the field can be written.

readTypefield#

readType: any?
@readonly

A transported handle for the read type, or nil for a write-only field.

writeTypefield#

writeType: any?
@readonly

A transported handle for the write type, or nil for a read-only field.

hasDefaultfield#

hasDefault: boolean
@readonly

Whether omission during construction supplies a declaration-owned default.

defaultValuefield#

defaultValue: any
@readonly

The source-free constant default value. Read only when hasDefault is true.

annotationsfield#

annotations: {nupp.reflect.Annotation}
@readonly

The field's typed annotations in source order, @debug among them.

referencefield#

reference: Reference
@readonly

Points this provider's error at this field.

Forwardrecord#

record Forward

A requirement's implementation, from forward, to be placed in implement under the name of the requirement it fills.

Inforecord#

record Info ...

The immutable semantic view passed to an @comptime function provider.

An Info describes an owner for a provider, and is built before any provider's output is merged, so two providers on the same declaration see the same thing whichever order they run in. A generic owner is projected once rather than per instantiation, and a type parameter exposes its bound, or unknown, so a provider cannot specialize for arguments a later instantiation supplies.

Members

NameKindDescription
schemafieldThe projection's schema version, currently 2.
kindfieldWhat the owner was declared as: record, struct, or interface.
namefieldThe owner's declared name.
qualifiedNamefieldThe declaration's module-qualified name, independent of filesystem paths.
visibilityfieldHow the declaration is bound: local, module, global, or nested.
documentationfieldThe declaration's --- documentation text, with markers and tags removed.
providerIdentityfieldThe stable identity of the provider being run.
ownerIdentityfieldThe stable identity of the owning declaration.
ownerTypefieldA transported handle for the owner's type, accepted by claims.
interfaceTypefieldA transported handle for the one interface this provider implements.
fieldsfieldThe written stored fields, in declaration order.
annotationsfieldThe owner's own typed annotations, in source order.
hasConstructorfieldWhether the declaration writes a constructor.
referencefieldPoints this provider's error at the declaration as a whole.
fingerprintfieldA digest of everything above.

schemafield#

schema: integer
@readonly

The projection's schema version, currently 2.

kindfield#

kind: string
@readonly

What the owner was declared as: record, struct, or interface.

namefield#

name: string
@readonly

The owner's declared name.

qualifiedNamefield#

qualifiedName: string
@readonly

The declaration's module-qualified name, independent of filesystem paths.

visibilityfield#

visibility: string
@readonly

How the declaration is bound: local, module, global, or nested.

documentationfield#

documentation: string?
@readonly

The declaration's --- documentation text, with markers and tags removed.

providerIdentityfield#

providerIdentity: string
@readonly

The stable identity of the provider being run.

ownerIdentityfield#

ownerIdentity: string
@readonly

The stable identity of the owning declaration.

ownerTypefield#

ownerType: any
@readonly

A transported handle for the owner's type, accepted by claims.

interfaceTypefield#

interfaceType: any
@readonly

A transported handle for the one interface this provider implements.

fieldsfield#

@readonly

The written stored fields, in declaration order.

annotationsfield#

annotations: {nupp.reflect.Annotation}
@readonly

The owner's own typed annotations, in source order.

hasConstructorfield#

hasConstructor: boolean
@readonly

Whether the declaration writes a constructor.

referencefield#

reference: Reference
@readonly

Points this provider's error at the declaration as a whole.

fingerprintfield#

fingerprint: string
@readonly

A digest of everything above. Two owners with one fingerprint share one evaluation, so a provider must decide from Info and nothing else.

Memberrecord#

record Member

A generated member with a comptime-built function signature and forward recipe. Use this when the provider declares a member that is not already an interface requirement.

Providerrecord#

record Provider

A comptime-only provider symbol accepted by @derive.

A shipped provider is one of the three values below; a package provider is the @comptime function a module exports. Neither survives into the program.

Referencerecord#

record Reference

An opaque reference which a provider may attach to a diagnostic.

Obtained from Info.reference for the declaration or Field.reference for one field, and accepted only by error. It carries no filename, line, or column: a provider says which part of the declaration is at fault and the compiler decides where to point.

Resultrecord#

record Result<I>

What a provider returns: the recipe implementing interface I.

I is the interface the provider implements, or any when every generated member supplies its own signature. Writing an interface in the return type is how @derive knows which contract applying the provider claims. Produce one with implement, or refuse the declaration with error. The compiler owns it and there is nothing on it to read: what it carries crosses the comptime boundary as a versioned recipe the compiler validates.

Type parameters

NameDescription
I

the interface this provider implements, or any

RuntimeHelperrecord#

record RuntimeHelper

An ordinary exported Nupp function a generated member calls, from helper.

The module owning it becomes a runtime dependency of the consumer, even when the comptime provider itself erases.

Functions#

annotationTypefunction#

Resolves a @ref annotation argument to its transported type handle.

The argument must come from Info.annotations or one of its fields. The returned handle can be inspected with nupp.types and passed to witness.

Arguments

NameTypeDescription
argumentnupp.reflect.AnnotationArgument

a reflected annotation argument whose kind is type

Returns

TypeDescription
any

the referenced type handle

argumentfunction#

local argument: function(name: string): Argument

Passes a parameter of the generated method, under the name the interface requirement declares for it.

Arguments

NameTypeDescription
namestring

the parameter's declared name

Returns

TypeDescription
Argument

the argument recipe

arrayfunction#

local array: function(arguments: {Argument}): Argument

Builds a fresh array from argument recipes, once per call.

Arguments

NameTypeDescription
arguments{Argument}

the element recipes, in order

Returns

TypeDescription
Argument

the argument recipe

claimsfunction#

local claims: function(subject: any, interface: any): boolean

Asks whether a type writes or requests an interface.

The answer does not depend on whether that type's own providers have run, so mutually recursive derives can plan against one another.

Arguments

NameTypeDescription
subjectany

a type handle, such as a Field.readType

interfaceany

a type handle, such as Info.interfaceType

Returns

TypeDescription
boolean

whether subject claims interface

constantfunction#

local constant: function(value: any): Argument

Embeds a bounded quotable value.

A table-shaped constant is rebuilt for every call, so mutation by one invocation cannot reach the next.

Arguments

NameTypeDescription
valueany

the value to embed

Returns

TypeDescription
Argument

the argument recipe

derive.Debugcomptime function#

@comptime function derive.Debug(info: nupp.derive.Info): nupp.derive.Result<nupp.Debug>
@comptime

Generates debug(self): string and nupp.Debug conformance for a record or struct. The method lazily prepares a schema-driven declaration-order formatter and shares its schema recipe with Serde when both are derived.

@debug(redact = true) keeps a field's name and hides its value, which is what a secret wants; @debug(skip = true) removes the field from the output entirely.

@derive(nupp.derive.Debug)
local record Credentials
    user: string
    @debug(redact = true)
    password: string
end

local credentials = new Credentials(user = "ada", password = "hunter2")
assert(credentials:debug() == 'Credentials { user = "ada", password = <redacted> }')

Arguments

NameTypeDescription
infonupp.derive.Info

Returns

TypeDescription
nupp.derive.Result<nupp.Debug>

derive.debugfunction#

function derive.debug(target: unknown, borrows value: unknown): string

Renders a declaration through its Debug binding.

Arguments

NameTypeDescription
targetunknown

the declaration witness

borrows valueunknown

the borrowed value to render

Returns

TypeDescription
string

derive.installfunction#

function derive.install(namespace: any): nil

Installs the runtime called by generated derive members.

Arguments

NameTypeDescription
namespaceany

the program's nupp table

Returns

TypeDescription
nil

entryfunction#

local entry: function(): Argument

Passes the record's registered derive entry.

Returns

TypeDescription
Argument

the argument recipe

errorfunction#

local error: function(message: string, reference: Reference?, code: string?): any

Refuses the declaration with a diagnostic instead of returning a recipe.

The reference decides what the diagnostic points at: Info.reference for the declaration, or the Field.reference of the field that made the recipe impossible. Returning this is how a provider fails; raising is a provider fault.

Arguments

NameTypeDescription
messagestring

what the consumer is told

referenceReference?

which part of the declaration is at fault

codestring?

the diagnostic code, defaulting to NUPP2810

Returns

TypeDescription
any

the refusal, as this provider's Result<I>

fieldfunction#

local field: function(field: Field): Argument

Reads a stored field of the receiver directly. The field must be readable.

Arguments

NameTypeDescription
fieldField

one of Info.fields

Returns

TypeDescription
Argument

the argument recipe

filefunction#

local file: function(path: string): string

Reads an immutable filesystem input admitted to this provider invocation.

The path must be a string literal in the provider's checked source. It resolves from the consumer project root, becomes an incremental query dependency, and is included in the provider recipe fingerprint. Watch mode therefore observes the file and rechecks only modules that consume the provider.

Arguments

NameTypeDescription
pathstring

project-relative path written as a literal

Returns

TypeDescription
string

the file's bytes

forwardfunction#

local forward: function(specification: any): Forward

Implements a requirement by calling a runtime helper.

helper names the function and arguments is the closed list it receives, in order. The interface owns the resulting signature, and the generated call is checked against the helper's declaration for types, ownership, effects, and its suspension contract.

Arguments

NameTypeDescription
specificationany

a table with helper and arguments

Returns

TypeDescription
Forward

the implementation, to place in implement

helperfunction#

local helper: function(module: any, name: string): RuntimeHelper

Names an ordinary exported Nupp function to forward to.

Runtime behavior stays in the language: helpers are checked at their own declarations, and a generic helper is refused by forward.v1.

Arguments

NameTypeDescription
moduleany

the module value holding the function

namestring

the name it is exported under

Returns

TypeDescription
RuntimeHelper

the helper handle

implementfunction#

local implement: function(specification: any): any

Returns forwarding implementations. methods fills instance members and statics fills static members.

Both are keyed by member name. A Forward fills a bodyless, unoverloaded callable requirement on the provider's interface; a Member supplies a new member's function signature and forwarding recipe. Generating a member that another provider on the same owner already generates is refused.

Arguments

NameTypeDescription
specificationany

a table with optional methods and statics maps

Returns

TypeDescription
any

the recipe, as this provider's Result<I>

memberfunction#

local member: function(specification: any): Member

Declares a generated member's function signature and forwarding recipe. Parameter names are non-empty and unique.

a forward recipe

Arguments

NameTypeDescription
specificationany

a table with signature, optional parameter names, and

Returns

TypeDescription
Member

the member recipe, to place in implement

receiverfunction#

local receiver: function(): Argument

Passes the generated method's receiver.

Returns

TypeDescription
Argument

the argument recipe

witnessfunction#

local witness: function(subject: any): Argument

Passes a named record's first-class Type<T> witness to the runtime helper.

Arguments

NameTypeDescription
subjectany

a transported nominal type handle

Returns

TypeDescription
Argument

the argument recipe