summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2020-06-22 00:10:48 -0700
committerMichael Forney <mforney@mforney.org>2020-06-22 22:59:35 -0700
commit7d33f5bb5efaf880096e70da74cfb7e830ee7625 (patch)
tree3853b96474f613f74b848e8ab7cf1eed14f86b61
parentb4ced98b9dd28062a7990592b7723b8916448679 (diff)
Add sortedpairs helper function
-rw-r--r--ninja.lua12
-rwxr-xr-xsetup.lua3
2 files changed, 11 insertions, 4 deletions
diff --git a/ninja.lua b/ninja.lua
index 6cf3cabf..29e1ed31 100644
--- a/ninja.lua
+++ b/ninja.lua
@@ -20,12 +20,20 @@ local function collect(f, s, i)
end
-- collects the keys of a table into a sorted table
-function table.keys(t)
+function table.keys(t, f)
local keys = collect(next, t)
- table.sort(keys)
+ table.sort(keys, f)
return keys
end
+-- iterates over the sorted keys and values of a table
+function sortedpairs(t, f)
+ return function(s, i)
+ local k = s[i]
+ return k and i + 1, k, t[k]
+ end, table.keys(t, f), 1
+end
+
-- yields string values of table or nested tables
local function stringsgen(t)
for _, val in ipairs(t) do
diff --git a/setup.lua b/setup.lua
index 27984fa0..936a52a0 100755
--- a/setup.lua
+++ b/setup.lua
@@ -78,8 +78,7 @@ local function gen(gendir)
local out = outdir..'/local.fspec'
local tmp = out..'.tmp'
local f = assert(io.open(tmp, 'w'))
- for _, path in ipairs(table.keys(pkg.fspec)) do
- local fspec = pkg.fspec[path]
+ for _, path, fspec in sortedpairs(pkg.fspec) do
f:write(('/%s\n'):format(path))
for _, k in ipairs{'type', 'mode', 'source', 'target'} do
local v = fspec[k]