Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

enum_values (module)

The enum field-constraint validator. Registers itself with field_constraints.module's registry on load so any component field carrying constraint = { kind = "enum", values = { ... } } — which is what Field.enum emits — is checked against it.

What it does

Given a field's written value and its constraint:

  1. Passes nil — an enum field may be left unset.
  2. Rejects a constraint carrying no members, since there is nothing to check against.
  3. Rejects a non-string value, naming the members and the type it got.
  4. Answers whether the value is one of constraint.values.

Every rejection lists the whole member set, so the message tells the caller what they may write instead of only what they may not.

Where the members come from

Field.enum(values, default, mode) validates the member list at construction: the members must be non-empty, distinct strings, and a non-nil default must be one of them. A field whose members are wrong is therefore a load-time error rather than a runtime surprise, and this validator only ever sees a well-formed set.

The engine carries constraint verbatim and never reads inside it, so the member list lives entirely in Luau.

Exports

  • M.check(value, constraint) -> ok, reason? — the validator function, also registered under the enum kind.