← Runtime data validation

Data.number

luastra/data
Data.number(optionsValue: NumberOptions?): Schema

Builds a schema that accepts finite numeric values and can enforce the documented minimum, maximum, or integer constraints. Non-numbers and non-finite values fail with structured validation information.

Before you use it

Add luastra/data to this module's dependencies in luastra.json, then import it with require("luastra/data"). No host capability is required. Define schemas outside render when they are reused.

How it fits

This pure constructor returns an immutable schema synchronously; Data.decode performs the actual validation later.

When to use it

Use Data.number whenever an external value becomes a score, index, duration, amount, or other numeric application value. Constrain the range before using it in layout, navigation, persistence, or calculations.

Parameters

ParameterType / valuesDescription
optionsValueNumberOptions?Optional finite range and integer constraints for accepted numbers.
optionsValue.integerboolean?Rejects fractional values when true; defaults to false.
optionsValue.minfinite number?Optional inclusive minimum value.
optionsValue.maxfinite number?Optional inclusive maximum value.

Returns

Schema — an immutable runtime schema that can be composed or passed to Data.decode.

What happens next

An immutable schema ready to compose or pass to Data.decode.

Failures and fixes

Ordinary invalid input is a Data.decode failure, not an exception. Invalid schema options are programmer errors and fail immediately. String bounds count UTF-8 bytes; Data.string has no pattern option in this alpha.

Availability

Public-source alpha API in 0.5.0-alpha; host-independent and synchronous.

Focused example

local Data = require("luastra/data")
local score = Data.number { integer = true, min = 0, max = 100 }

Complete inventory

View all pages in Runtime data validation
← Previous: Data.stringNext: Data.boolean →