diff --git a/debug.lua b/debug.lua new file mode 100644 index 0000000..e357c47 --- /dev/null +++ b/debug.lua @@ -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() \ No newline at end of file diff --git a/schema.lua b/schema.lua index b378498..fdb610e 100644 --- a/schema.lua +++ b/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")