From fa8e429ccae76cf1bb497a8c68e1ce1f162975ec Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Sep 2022 00:51:12 +0800 Subject: improve json to support array --- xmake/core/base/json.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'xmake/core/base/json.lua') diff --git a/xmake/core/base/json.lua b/xmake/core/base/json.lua index 0b38df42a..e83f6b320 100644 --- a/xmake/core/base/json.lua +++ b/xmake/core/base/json.lua @@ -29,6 +29,20 @@ local utils = require("base/utils") -- export null json.null = cjson.null +-- support empty array +-- @see https://github.com/mpx/lua-cjson/issues/11 +function json.mark_as_array(luatable) + local mt = getmetatable(luatable) or {} + mt.__is_cjson_array = true + return setmetatable(luatable, mt) +end + +-- is marked as array? +function json.is_marked_as_array(luatable) + local mt = getmetatable(luatable) + return mt and mt.__is_cjson_array +end + -- decode json string to the lua table -- -- @param jsonstr the json string -- cgit v1.3.1