Comparison

util/jsonschema.lua @ 12500:88e1b94105ae 0.12

util.jsonschema: Lua <5.3 compat here too
author Kim Alvefur <zash@zash.se>
date Mon, 09 May 2022 22:39:05 +0200
parent 12132:4ff0d33dfb2b
child 12579:ca6a43fe0231
comparison
equal deleted inserted replaced
12499:03e307952816 12500:88e1b94105ae
1 local m_type = math.type or function (n)
2 return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float";
3 end;
1 local json = require("util.json") 4 local json = require("util.json")
2 local null = json.null; 5 local null = json.null;
3 6
4 local pointer = require("util.jsonpointer") 7 local pointer = require("util.jsonpointer")
5 8
15 if schema == "object" and type(data) == "table" then 18 if schema == "object" and type(data) == "table" then
16 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string") 19 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string")
17 elseif schema == "array" and type(data) == "table" then 20 elseif schema == "array" and type(data) == "table" then
18 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number") 21 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number")
19 elseif schema == "integer" then 22 elseif schema == "integer" then
20 return math.type(data) == schema 23 return m_type(data) == schema
21 elseif schema == "null" then 24 elseif schema == "null" then
22 return data == null 25 return data == null
23 else 26 else
24 return type(data) == schema 27 return type(data) == schema
25 end 28 end