Builtin Library
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:
- Passes
nil— a ranged field may be left unset. - Rejects a constraint carrying neither bound and no
whole, since there is no interval to check against. - Rejects a non-number value, naming the interval and the type it got.
- Rejects a NaN or an infinity, which sits in no interval.
- Answers whether the value is inside
constraint.min..constraint.max, either of which may be absent to leave that side open. - With
constraint.whole = true(whatField.integeremits), 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 therangekind.