From: Vsevolod Stakhov Date: Tue, 18 Nov 2025 11:09:22 +0000 (+0000) Subject: [Feature] Add T.callable() type to lua_shape X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0662b8dd3f4b4fe12c2ebcf075287508ec23319;p=thirdparty%2Frspamd.git [Feature] Add T.callable() type to lua_shape Add function/callable type validator to lua_shape core. Implementation: - check_callable(): Validates value is of type 'function' - T.callable(opts): Constructor for callable type - Returns type_mismatch error if value is not a function This was missing from the initial implementation and is needed by lua_meta.lua which validates callback functions in metafunction schemas. Documentation added to README.md scalar types section. --- diff --git a/lualib/lua_shape/README.md b/lualib/lua_shape/README.md index 32fcf732a8..812bed5161 100644 --- a/lualib/lua_shape/README.md +++ b/lualib/lua_shape/README.md @@ -55,6 +55,7 @@ local ok, config = config_schema:transform({ - `T.number(opts)` - Number with optional range constraints (min, max) - `T.integer(opts)` - Integer (number with integer constraint) - `T.boolean()` - Boolean value +- `T.callable()` - Function/callable value - `T.enum(values)` - One of a fixed set of values - `T.literal(value)` - Exact value match diff --git a/lualib/lua_shape/core.lua b/lualib/lua_shape/core.lua index 977cd9691e..4ee1d32e54 100644 --- a/lualib/lua_shape/core.lua +++ b/lualib/lua_shape/core.lua @@ -293,6 +293,25 @@ function T.boolean(opts) }) end +local function check_callable(node, value, ctx) + if type(value) ~= "function" then + return false, make_error("type_mismatch", ctx.path, { + expected = "function", + got = type(value) + }) + end + + return true, value +end + +function T.callable(opts) + return make_node("scalar", { + kind = "callable", + opts = opts or {}, + _check = check_callable + }) +end + function T.enum(values, opts) opts = opts or {} opts.enum = values