mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 15:23:48 +01:00
schema: key & value checks before entry checks
This commit is contained in:
parent
bf2ba5be9d
commit
69067579e5
34
debug.lua
Normal file
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()
|
20
schema.lua
20
schema.lua
@ -258,6 +258,16 @@ function load(self, override, params)
|
||||
assert(self.nan or override == override, "nan")
|
||||
end
|
||||
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
|
||||
for key, schema in pairs(self.entries) do
|
||||
if schema.required and override[key] == nil then
|
||||
@ -273,16 +283,6 @@ function load(self, override, params)
|
||||
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")
|
||||
else
|
||||
assert((not self.values) or self.values[override], "values")
|
||||
|
Loading…
Reference in New Issue
Block a user