From d1dc2b9f15eaae12610deee26c8eb8fd91d998fa Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Sun, 4 Aug 2024 16:22:11 +0300 Subject: type_check --- src/luarocks/type/rockspec.tl | 13 +++++++++++++ src/luarocks/type_check.lua | 12 ++++++------ src/luarocks/type_check.tl | 14 +++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/luarocks/type/rockspec.tl b/src/luarocks/type/rockspec.tl index 26f29587..fab87fd4 100644 --- a/src/luarocks/type/rockspec.tl +++ b/src/luarocks/type/rockspec.tl @@ -10,6 +10,19 @@ local util = require("luarocks.core.util") --! type_rockspec.rockspec_format = "3.0" +-- Syntax for type-checking tables: +-- +-- A type-checking table describes typing data for a value. +-- Any key starting with an underscore has a special meaning: +-- _type (string) is the Lua type of the value. Default is "table". +-- _mandatory (boolean) indicates if the value is a mandatory key in its container table. Default is false. +-- For "string" types only: +-- _pattern (string) is the string-matching pattern, valid for string types only. Default is ".*". +-- For "table" types only: +-- _any (table) is the type-checking table for unspecified keys, recursively checked. +-- _more (boolean) indicates that the table accepts unspecified keys and does not type-check them. +-- Any other string keys that don't start with an underscore represent known keys and are type-checking tables, recursively checked. + local rockspec_formats, versions = type_check.declare_schemas({ ["1.0"] = { fields = { diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 77f9ef24..50eceddf 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -31,9 +31,9 @@ type_check.MAGIC_PLATFORMS = {} do local function fill_in_version(tbl, version) - if not tbl.fields then - return - end + + + for _, v in pairs(tbl.fields) do if type(v) == "table" then @@ -191,10 +191,10 @@ function type_check.type_check_table(version, tbl, typetbl, context) return nil, errcheck end - if not typetbl.fields then - return true - end + + + for k, v in pairs(tbl) do local t = typetbl.fields[tostring(k)] or typetbl._any diff --git a/src/luarocks/type_check.tl b/src/luarocks/type_check.tl index 7c3c4064..6b5dbb16 100644 --- a/src/luarocks/type_check.tl +++ b/src/luarocks/type_check.tl @@ -31,9 +31,9 @@ type_check.MAGIC_PLATFORMS = {} do local function fill_in_version(tbl: TableSchema, version?: string) - if not tbl.fields then --! validation - return - end + -- if not tbl.fields then --! validation + -- return + -- end for _, v in pairs(tbl.fields) do if v is TableSchema then @@ -191,10 +191,10 @@ function type_check.type_check_table(version: string, tbl: {any: any}, typetbl: return nil, errcheck end - if not typetbl.fields then --! validation - -- if there are no fields, exit the checker - return true - end + -- if not typetbl.fields then --! validation + -- -- if there are no fields, exit the checker + -- return true + -- end for k, v in pairs(tbl) do local t = typetbl.fields[tostring(k)] or typetbl._any --! tostring -- cgit v1.2.3-55-g6feb