Expand description
Table validation module.
Validates Lua table structure against a schema definition. Schemas are plain Lua tables — no external schema language required.
§Schema formats
Shorthand — type name only (field is optional):
local schema = {name = "string", age = "number"}Full — table with constraints:
local schema = {
name = {type = "string", required = true, min_len = 1},
age = {type = "number", min = 0, max = 150},
status = {type = "string", one_of = {"active", "inactive"}},
tags = {type = "table"},
}§Supported constraints
| Key | Applies to | Description |
|---|---|---|
type | all | Expected Lua type name |
required | all | Field must be non-nil (default: false) |
min | number/integer | Minimum value (inclusive) |
max | number/integer | Maximum value (inclusive) |
min_len | string | Minimum string length |
max_len | string | Maximum string length |
one_of | string/number/integer/boolean | Allowed values list |
§Usage
local ok, errors = std.validate.check(data, schema)
if not ok then
for _, msg in ipairs(errors) do print(msg) end
end