summaryrefslogtreecommitdiff
path: root/xmake/core/base/table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/core/base/table.lua')
-rw-r--r--xmake/core/base/table.lua18
1 files changed, 17 insertions, 1 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index a8050f0a3..f954596b8 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -349,6 +349,7 @@ function table.wrap_lock(value)
if type(value) == "table" then
value.__wrap_locked__ = true
end
+ return value
end
-- unlock table value to unwrap
@@ -356,6 +357,7 @@ function table.wrap_unlock(value)
if type(value) == "table" then
value.__wrap_locked__ = nil
end
+ return value
end
-- remove repeat from the given array
@@ -375,6 +377,9 @@ function table.unique(array, barrier)
table.insert(unique, v)
end
end
+ if array.__wrap_locked__ then
+ table.wrap_lock(unique)
+ end
array = unique
end
end
@@ -400,6 +405,9 @@ function table.reverse_unique(array, barrier)
table.insert(unique, 1, v)
end
end
+ if array.__wrap_locked__ then
+ table.wrap_lock(unique)
+ end
array = unique
end
end
@@ -431,7 +439,15 @@ end
function table.orderkeys(tbl, callback)
local callback = type(callback) == "function" and callback or nil
local keys = table.keys(tbl)
- table.sort(keys, callback)
+ if callback then
+ table.sort(keys, callback)
+ else
+ local ok = pcall(table.sort, keys)
+ if not ok then
+ -- maybe sort strings and numbers, {1, 2, "a"}
+ table.sort(keys, function (a, b) return tostring(a) < tostring(b) end)
+ end
+ end
return keys
end