summaryrefslogtreecommitdiff
path: root/xmake/core/base/table.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-26 23:51:57 +0800
committerruki <[email protected]>2023-10-26 23:51:57 +0800
commit311171bcd0cee217855858b9c94502a40fbfad56 (patch)
treeecee776b38e23ca4a4e62aad070dee67a9181a16 /xmake/core/base/table.lua
parentd867bea8765d546abdbad08a3e573a88a8553b1c (diff)
fix sort and extra
Diffstat (limited to 'xmake/core/base/table.lua')
-rw-r--r--xmake/core/base/table.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index a8050f0a3..0b368524a 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
@@ -431,7 +433,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