Skip to content

Commit 6c83cb1

Browse files
committed
change: supported Lua 5.2, 5.3 and LuaJIT 2.1 beta.
1 parent 3643b60 commit 6c83cb1

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ possible.
1414
Installation
1515
------------
1616

17-
This module is pure Lua in OpenResty.
17+
This module is pure Lua/LuaJIT project, it support Lua 5.2, Lua 5.3, LuaJIT 2.1 beta.
1818

1919
The preferred way to install this library is to use Luarocks:
2020

@@ -26,6 +26,12 @@ Running the tests:
2626
make dev
2727
make test
2828

29+
The project references the pcre regular library.
30+
31+
If you were using the LuaJIT of OpenResty, it will use the built-in `ngx.re.find` automaticly.
32+
But if you are using Lua 5.2, 5.3 or LuaJIT 2.1 beta, you will need to install `lrexlib-pcre`.
33+
34+
In addition, the project also relies on the `net_url` library, which you need to install anyway.
2935

3036
Usage
3137
-----

resty/jsonschema.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ do
3636
end
3737
end
3838

39+
local match_pattern
40+
if ngx then
41+
match_pattern = ngx.re.find
42+
else
43+
local ok, rex = pcall(require, "rex_pcre")
44+
if not ok then
45+
error("depends on lrexlib-pcre, please install it first: " .. rex)
46+
end
47+
match_pattern = rex.find
48+
end
49+
3950
--
4051
-- Code generation
4152
--
@@ -970,7 +981,7 @@ return {
970981
generate_validator = function(schema, custom)
971982
local customlib = {
972983
null = custom and custom.null or default_null,
973-
match_pattern = custom and custom.match_pattern or string.find
984+
match_pattern = custom and custom.match_pattern or match_pattern
974985
}
975986
local name = custom and custom.name
976987
return generate_main_validator_ctx(schema, custom):as_func(name, validatorlib, customlib)

t/draft4.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ for _, descriptor in ipairs(supported) do
115115
if skipped ~= true then
116116
local validator = jsonschema.generate_validator(suite.schema, {
117117
name = suite.description,
118-
match_pattern = ngx.re.find,
119118
})
120119
for _, case in ipairs(suite.tests) do
121120
if skipped[case.description] then

t/draft6.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ for _, descriptor in ipairs(supported) do
120120
if skipped ~= true then
121121
local validator = jsonschema.generate_validator(suite.schema, {
122122
name = suite.description,
123-
match_pattern = ngx.re.find,
124123
})
125124
for _, case in ipairs(suite.tests) do
126125
if skipped[case.description] then

t/draft7.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ for _, descriptor in ipairs(supported) do
123123
if skipped ~= true then
124124
local validator = jsonschema.generate_validator(suite.schema, {
125125
name = suite.description,
126-
match_pattern = ngx.re.find,
127126
})
128127
for _, case in ipairs(suite.tests) do
129128
if skipped[case.description] then

0 commit comments

Comments
 (0)