summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-09-07 00:51:12 +0800
committerruki <[email protected]>2022-09-07 00:51:12 +0800
commitfa8e429ccae76cf1bb497a8c68e1ce1f162975ec (patch)
tree62de290de46b5f54f8f66f11231fae46a9ad0c7c
parent2468e9a86a0575dfee193ff5f7b9e0c11e337077 (diff)
improve json to support array
-rw-r--r--xmake/core/base/json.lua14
-rw-r--r--xmake/core/sandbox/modules/import/core/base/json.lua4
2 files changed, 17 insertions, 1 deletions
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
diff --git a/xmake/core/sandbox/modules/import/core/base/json.lua b/xmake/core/sandbox/modules/import/core/base/json.lua
index 04073ca0d..ed551993d 100644
--- a/xmake/core/sandbox/modules/import/core/base/json.lua
+++ b/xmake/core/sandbox/modules/import/core/base/json.lua
@@ -26,7 +26,9 @@ local json = require("base/json")
local raise = require("sandbox/modules/raise")
-- inherit some builtin interfaces
-sandbox_core_base_json.null = json.null
+sandbox_core_base_json.null = json.null
+sandbox_core_base_json.mark_as_array = json.mark_as_array
+sandbox_core_base_json.is_marked_as_array = json.is_marked_as_array
-- decode the json string to the lua table
function sandbox_core_base_json.decode(jsonstr, opt)