migrate json module to global
This commit is contained in:
parent
3239d6ac95
commit
8b4a3b27c0
@ -1,4 +1,3 @@
|
|||||||
local json = require("json")
|
|
||||||
local http = {}
|
local http = {}
|
||||||
|
|
||||||
-- Global routing tables
|
-- Global routing tables
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local json = {}
|
json = {}
|
||||||
|
|
||||||
function json.encode(value)
|
function json.encode(value)
|
||||||
local buffer = {}
|
local buffer = {}
|
||||||
@ -596,5 +596,3 @@ function json.validate(data, schema)
|
|||||||
|
|
||||||
return validate_value(data, schema)
|
return validate_value(data, schema)
|
||||||
end
|
end
|
||||||
|
|
||||||
return json
|
|
@ -1,6 +1,5 @@
|
|||||||
local kv = require("kv")
|
local kv = require("kv")
|
||||||
local crypto = require("crypto")
|
local crypto = require("crypto")
|
||||||
local json = require("json")
|
|
||||||
|
|
||||||
local sessions = {}
|
local sessions = {}
|
||||||
local stores = {}
|
local stores = {}
|
||||||
|
@ -273,17 +273,23 @@ function string.slice(s, start, end_pos)
|
|||||||
end
|
end
|
||||||
getmetatable("").__index.slice = string.slice
|
getmetatable("").__index.slice = string.slice
|
||||||
|
|
||||||
-- Custom find that returns matched substring instead of position
|
|
||||||
function string.find(s, pattern, init, plain)
|
function string.find(s, pattern, init, plain)
|
||||||
if type(s) ~= "string" then error("string.find: first argument must be a string", 2) end
|
if type(s) ~= "string" then error("string.find: first argument must be a string", 2) end
|
||||||
if type(pattern) ~= "string" then error("string.find: second argument must be a string", 2) end
|
if type(pattern) ~= "string" then error("string.find: second argument must be a string", 2) end
|
||||||
|
return _orig_find(s, pattern, init, plain)
|
||||||
|
end
|
||||||
|
getmetatable("").__index.find = string.find
|
||||||
|
|
||||||
|
function string.find_match(s, pattern, init, plain)
|
||||||
|
if type(s) ~= "string" then error("string.find_match: first argument must be a string", 2) end
|
||||||
|
if type(pattern) ~= "string" then error("string.find_match: second argument must be a string", 2) end
|
||||||
local start_pos, end_pos = _orig_find(s, pattern, init, plain)
|
local start_pos, end_pos = _orig_find(s, pattern, init, plain)
|
||||||
if start_pos then
|
if start_pos then
|
||||||
return s:sub(start_pos, end_pos)
|
return s:sub(start_pos, end_pos)
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
getmetatable("").__index.find = string.find
|
getmetatable("").__index.find_match = string.find_match
|
||||||
|
|
||||||
function string.find_all(s, pattern)
|
function string.find_all(s, pattern)
|
||||||
if type(s) ~= "string" then error("string.find_all: first argument must be a string", 2) end
|
if type(s) ~= "string" then error("string.find_all: first argument must be a string", 2) end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
require("tests")
|
require("tests")
|
||||||
local json = require("json")
|
--local json = require("json")
|
||||||
|
|
||||||
-- Test data
|
-- Test data
|
||||||
local test_data = {
|
local test_data = {
|
||||||
|
@ -290,11 +290,11 @@ test("string.match", function()
|
|||||||
assert_equal(true, string.match("testing", "test") ~= nil)
|
assert_equal(true, string.match("testing", "test") ~= nil)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("string.find", function()
|
test("string.find_match", function()
|
||||||
assert_equal("123", string.find("hello123world", "%d+"))
|
assert_equal("123", string.find_match("hello123world", "%d+"))
|
||||||
assert_equal(nil, string.find("hello", "%d+"))
|
assert_equal(nil, string.find_match("hello", "%d+"))
|
||||||
assert_equal("test", string.find("testing", "test"))
|
assert_equal("test", string.find_match("testing", "test"))
|
||||||
assert_equal("world", string.find("hello world", "world"))
|
assert_equal("world", string.find_match("hello world", "world"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("string.find_all", function()
|
test("string.find_all", function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user