summaryrefslogtreecommitdiff
path: root/xmake/core/base/table.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-27 03:50:01 -0500
committerGitHub <[email protected]>2023-10-27 03:50:01 -0500
commit6af4b8528bfae7536fc77a5e7fb4341b3f11bc9a (patch)
tree45bb260efc422e8692fc664ed80d9ddc9b56cb3c /xmake/core/base/table.lua
parenteeda646a4e32b3d672a8097fe995cbdcf101c7aa (diff)
parent1cb74a5009d8fbcb792aa6cc787943453cc5234a (diff)
Merge pull request #4314 from xmake-io/package
Support linkgroups and linkorders for package
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