Skip to content

Commit

Permalink
Make json support all cjson APIs
Browse files Browse the repository at this point in the history
The current `json` implementation only supports `encode` and `decode`. However, there're more `cjson` APIs (See the [document](https://www.kyne.com.au/~mark/software/lua-cjson-manual.html) ). And they had better been supported.
  • Loading branch information
yszheda committed Dec 14, 2016
1 parent e504ba7 commit bea0e0d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions framework/json.lua
Expand Up @@ -30,6 +30,20 @@ JSON 编码与解码
local json = {}
local cjson = require("cjson")


for k, v in pairs(cjson) do
if type(v) == "function" then
json[k] = function(...)
local status, result = pcall(v, ...)
if status then return result end
if DEBUG > 1 then
printError("json %s failed: %s", tostring(k), tostring(result))
end
end
end
end


--[[--
将表格数据编码为 JSON 字符串
Expand Down

0 comments on commit bea0e0d

Please sign in to comment.