summaryrefslogtreecommitdiff
path: root/ninja.lua
diff options
context:
space:
mode:
Diffstat (limited to 'ninja.lua')
-rw-r--r--ninja.lua12
1 files changed, 10 insertions, 2 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