Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

field_constraints (module)

Generic field-constraint dispatch. Installs _G.__zero_check_field_constraint(value, constraint), the Luau half of the opaque field-constraint primitive: a component field descriptor may carry a constraint value (an arbitrary table with a kind string), and the engine calls this hook whenever a constrained field's default resolves or a write lands. The engine copies constraint verbatim — it never reads inside it — and treats the hook's first return as accept/reject, the second as the rejection reason.

What it does

  1. Reads constraint.kind and looks up a registered validator for that kind.
  2. Built-in kinds (currently dataContract) resolve their validator module lazily on first use, so component registration never depends on load order.
  3. Calls the validator with (value, constraint) and returns its (ok, reason?) result.

The registry is held in the module's durable state (modules.state), so every run of this module, and the engine hook the first run installed, read and write the one registry.

A malformed constraint (not a table, or missing kind) and a missing validator both reject — the primitive fails closed rather than silently accepting an unconstrained value.

Exports

  • M.register(kind, fn) — register the validator for a constraint kind. fn(value, constraint) -> ok, reason?. A kind belongs to the chunk its validator is defined in: registering it again from that chunk (its module running again, on a hot reload or after its require cache entry was dropped) replaces the validator, and registering it with a validator defined in another chunk errors, naming both.
  • M.check(value, constraint) -> ok, reason? — run the check directly (same function installed as the engine hook).

Consumers

Field.dataRef (field.module) emits constraint = { kind = "dataContract", contract = ... }; data_contract.module registers the dataContract validator against this registry.