diff options
| author | ruki <[email protected]> | 2022-10-25 00:28:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-10-25 00:28:29 +0800 |
| commit | fd0a6539d7ebb4fcea4a646bf3b8c51cce8067ca (patch) | |
| tree | 372c7c7e6e79b81aa0f3533a310f8bf2acf18d0c | |
| parent | 341cdf2f63c00b65568bb0f653f92d82161100b5 (diff) | |
add hashset:orderkeys
| -rw-r--r-- | xmake/core/base/hashset.lua | 49 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 2 |
2 files changed, 47 insertions, 4 deletions
diff --git a/xmake/core/base/hashset.lua b/xmake/core/base/hashset.lua index c2d5e131e..2a0449ad4 100644 --- a/xmake/core/base/hashset.lua +++ b/xmake/core/base/hashset.lua @@ -109,10 +109,53 @@ function hashset_impl:to_array() end -- iterate keys of hashtable --- for _, key in instance:keys() do ... end +-- +-- @code +-- for _, key in instance:keys() do +-- ... +-- end +-- @endcode +-- function hashset_impl:keys() - return function (table, key) - local k, _ = next(table._DATA, key) + return function (t, key) + local k, _ = next(t._DATA, key) + if k == hashset._NIL then + return k, nil + else + return k, k + end + end, self, nil +end + +-- order keys iterator +-- +-- @code +-- for _, key in instance:orderkeys() do +-- ... +-- end +-- @endcode +-- +function hashset_impl:orderkeys() + local orderkeys = table.keys(self._DATA) + table.sort(orderkeys, function (a, b) + if a == hashset._NIL then + a = math.inf + end + if b == hashset._NIL then + b = math.inf + end + if type(a) == "table" then + a = tostring(a) + end + if type(b) == "table" then + b = tostring(b) + end + return a < b + end) + local i = 1 + return function (t, k) + k = orderkeys[i] + i = i + 1 if k == hashset._NIL then return k, nil else diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 9fc02ff19..47d013cbb 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -979,7 +979,7 @@ function _instance:pkgenvs() end end end - for _, pkg in pkgs:keys() do + for _, pkg in pkgs:orderkeys() do local envs = pkg:get("envs") if envs then for name, values in pairs(envs) do |
