Builtin Library
- ..
- README.md7.3 KB
- about.yaml662 B
- behavior.luau8.8 KB
- inspector.luau3.0 KB
- template
- type.yaml3.0 KB
README.md
interface (asset type)
An interface is a named guarantee, defined once as an asset. A type that lists
it under interfaces: guarantees that its members exist with the interface's
signatures and keep its meaning. A consumer that accepts the interface calls
those members on any asset of such a type without checking, and it works for
types the consumer has never heard of, including types published later by
someone else.
The indexing: role named interface is a different thing: it names the file
that states the signatures a caller of an asset uses.
What an interface holds
applicable.interface/
interface.yaml # the members and properties (required)
README.md # the guarantee and how to implement it (required)
.metadata # description and tags (required)
contract.module/ # the shared half (optional)
applicableConformance.testSuite/ # the required behaviour as tests (optional)
# interface.yaml
description: "The guarantee, in one paragraph."
members:
glow:
signature: "(self, owner: string, strength: number) -> boolean"
inputs:
owner: "Who asks for the glow; with the asset, it identifies the glow."
strength: "How strong, from 0 to 1."
returns: "Whether the asset is glowing now."
properties:
presence:
type: number
default: 0
meaning: "How prominently a consumer presents the asset among others."
type_keys: [settings]
contract: "~.contract"
conformance: "~.applicableConformance"
| Key | Meaning |
|---|---|
description | Required. The guarantee, stated once, read by people, agents and search. |
members | Required. Every member a type meets, by name: signature (the parameters, self first, then -> returns), inputs (each base input and its one meaning for every implementer) and returns. |
properties | Optional. Named, typed values every implementer exposes. type is string, number, boolean, { enum: [...] } or { asset: <category> }; default is optional, and a property with none must be met by the type. |
type_keys | Optional. type.yaml keys every implementing type states. The README line that starts with the key in backticks says what the key states, and a refusal quotes it. |
contract | Optional. The module holding the shared half: the gate every call of a member passes through. ~.contract names the interface's own contract.module. |
conformance | Optional. The testSuite stating the required behaviour as tests, run over every implementer or over the types a run names (Test.subjects()), named by its place in the interface (~.<name>Conformance, a <name>Conformance.testSuite the interface holds) or by identity. It is test content, which the built library leaves out; it is named by path and recorded in no reference table. An interface whose conformance or contract names nothing is refused (interfaces.conformance, interfaces.contract), and asset.validate of a world's own type runs the suite over that type (interfaces.conformanceFailed). |
legacy | Optional. { implied_by: <member> }: a type that lists no interfaces: key and defines this member implements the interface, with a warning. |
An unknown key is a warning (interface.key.unknown), so a definition written
for a later engine loads on an earlier one.
Implementing an interface
A type lists the interfaces it implements in its type.yaml:
interfaces: [glowable]
and meets each member in its behavior.luau, implicitly with its own method of
the member's name and signature:
M.ref = {
glow = function(self, owner, strength) ... end,
}
or explicitly, when the type's own method of that name means something else:
M.ref = { glow = function(self, kind) ... end } -- the type's own meaning
M.interfaces = {
glowable = { glow = function(self, owner, strength) ... end },
}
M.interfaces is keyed by the interface's name as the type lists it. A
property is met by a value or a getter (self) -> value in the same two places,
else by its default.
Every asset of the type implements every interface the type lists, and an
asset of a type that lists nothing never implements it. ref:implements(x)
asks, and ref:as(x):member(...) calls through the interface.
What registration checks
Every listed name resolves to an interface; every member is met with at least
the signature's number of parameters (a function taking ... meets any
count); every property is met or has a default and holds its type; every
type_keys key is in type.yaml; every entry under M.interfaces names a
listed interface and one of its members. A declaration that breaks a check
carries no marks until every problem is fixed, asset.validate reports each
problem as an error that refuses a push, and the engine log states each once.
| Code | The fault |
|---|---|
interfaces.shape | interfaces is not a list of names |
interfaces.unknown | a name answers to no interface |
interfaces.ambiguous | a name answers to more than one interface |
interfaces.duplicate | a name is listed twice |
interfaces.missing | a member is met by neither M.ref nor M.interfaces |
interfaces.arity | a member's function takes fewer parameters than the signature |
interfaces.typeKey | a type_keys key is missing from type.yaml |
interfaces.explicitUnclaimed | M.interfaces meets an interface the type does not list |
interfaces.explicitUnknown | M.interfaces meets a name the interface does not have |
interfaces.propertyMissing | a property is met by nothing and has no default |
interfaces.propertyType | a property's value is not its type |
interfaces.conflict | one function meets one member of two interfaces whose signatures differ |
interfaces.unloadable | the type's behavior.luau did not load |
interfaces.implied (warning) | a legacy type defines the member and lists nothing |
An interface's own faults are interface.definition (the file does not read),
interface.contract (the contract module does not load),
interface.key.unknown (warning) and interface.breakingEdit (warning: this
version changes a member of a version other content pins).
Versioning
An interface is versioned like any asset, and an implementer pins the version it was written against. Adding a member, removing one, or changing a signature or an input's meaning breaks every implementer that moves, so publish such a change as a new interface. Wording that keeps the meaning is an ordinary edit.
The shared half
The contract module exports gate(member, self, impl, ...). Every call of a
member of an interface the asset implements passes through it: the gate checks
the inputs, calls impl, and checks the output, so a type that breaks the shape
fails at its own call and names itself. Base inputs mean the same for every
implementer; a type's own extras travel in opts, are always optional, and never
change a base input's meaning.
Discovery
asset.resolve("<name>", "interface"):definition(): the definition as written.asset.resolve("<name>", "interface"):implementers(): the types that list it.asset.inspect("<name>", "interface"): the same in one record.