schema: key & value checks before entry checks

This commit is contained in:
Lars Mueller 2021-03-31 22:15:38 +02:00
parent bf2ba5be9d
commit 69067579e5
2 changed files with 44 additions and 10 deletions

34
debug.lua Normal file

@ -0,0 +1,34 @@
local function gather_info()
local locals = {}
local index = 1
while true do
local name, value = debug.getlocal(2, index)
if not name then break end
table.insert(locals, {name, value})
index = index + 1
end
local upvalues = {}
local func = debug.getinfo(2).func
local envs = getfenv(func)
index = 1
while true do
local name, value = debug.getupvalue(func, index)
if not name then break end
table.insert(upvalues, {name, value})
index = index + 1
end
return {
locals = locals,
upvalues = upvalues,
[envs == _G and "globals" or "envs"] = envs
}
end
local c = 3
function test()
local a = 1
b = 2
error(gather_info().upvalues[1][1])
end
test()

@ -258,6 +258,16 @@ function load(self, override, params)
assert(self.nan or override == override, "nan") assert(self.nan or override == override, "nan")
end end
elseif self.type == "table" then elseif self.type == "table" then
if self.keys then
for key, value in pairs(override) do
override[load(self.keys, key, params)], override[key] = value, nil
end
end
if self.values then
for key, value in pairs(override) do
override[key] = load(self.values, value, params)
end
end
if self.entries then if self.entries then
for key, schema in pairs(self.entries) do for key, schema in pairs(self.entries) do
if schema.required and override[key] == nil then if schema.required and override[key] == nil then
@ -273,16 +283,6 @@ function load(self, override, params)
end end
end end
end end
if self.keys then
for key, value in pairs(override) do
override[load(self.keys, key, params)], override[key] = value, nil
end
end
if self.values then
for key, value in pairs(override) do
override[key] = load(self.values, value, params)
end
end
assert((not self.list) or modlib.table.count(override) == #override, "list") assert((not self.list) or modlib.table.count(override) == #override, "list")
else else
assert((not self.values) or self.values[override], "values") assert((not self.values) or self.values[override], "values")