diff options
| author | OpportunityLiu <[email protected]> | 2019-06-26 20:01:10 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-06-26 20:01:10 +0800 |
| commit | 318bb739dd64d19a4b4d91d8be49b22fc3403cff (patch) | |
| tree | 738798d2645128ad516f9db0a02ea4c477e279b3 /xmake/core/base/table.lua | |
| parent | 0dac0aec2688530d675d00df0debcd88226ff875 (diff) | |
improve tab complete
Diffstat (limited to 'xmake/core/base/table.lua')
| -rw-r--r-- | xmake/core/base/table.lua | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 3fd35c082..43e8b6db9 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -257,13 +257,41 @@ function table.unique(array, barrier) end -- pack arguments into a table +-- polyfill of lua 5.2, @see https://www.lua.org/manual/5.2/manual.html#pdf-table.pack function table.pack(...) return { n = select("#", ...), ... } end -- unpack table values -function table.unpack(list, i, j) - return unpack(list, i, j) +-- polyfill of lua 5.2, @see https://www.lua.org/manual/5.2/manual.html#pdf-table.unpack +table.unpack = unpack + +-- get keys of a table +function table.keys(tab) + + assert(tab) + + local keyset = {} + local n = 0 + for k, _ in pairs(tab) do + n = n + 1 + keyset[n] = k + end + return keyset, n +end + +-- get values of a table +function table.values(tab) + + assert(tab) + + local valueset = {} + local n = 0 + for _, v in pairs(tab) do + n = n + 1 + valueset[n] = v + end + return valueset, n end -- return module: table |
