Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

range_bounds (module)

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

What it does

Given a field's written value and its constraint:

  1. Passes nil — a ranged field may be left unset.
  2. Rejects a constraint carrying neither bound and no whole, since there is no interval to check against.
  3. Rejects a non-number value, naming the interval and the type it got.
  4. Rejects a NaN or an infinity, which sits in no interval.
  5. Answers whether the value is inside constraint.min .. constraint.max, either of which may be absent to leave that side open.
  6. With constraint.whole = true (what Field.integer emits), rejects a value that is not a whole number, naming the interval.

Every rejection names the interval, so the message tells the caller what they may write instead of only what they may not.

What a range is for

A field whose value means something only inside an interval — a normalized amplitude, a fraction, a probability, a count that starts at zero — declares that interval once, and every write is held to it. What the field reads back is then a value the system consuming it can use, and a number that lands outside is reported where it was written rather than wherever it is eventually read.

Where the bounds come from

Field.range(min, max, default, mode) validates the interval at construction: at least one bound is required, both must be numbers when given, min may not sit above max, and a non-nil default must be inside. A field whose interval is wrong is therefore a load-time error rather than a runtime surprise, and this validator only ever sees a well-formed interval.

The engine carries constraint verbatim and never reads inside it, so the bounds live entirely in Luau.

Exports

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