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