summaryrefslogtreecommitdiff
path: root/lualibs-dir.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-04-30 11:55:11 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-04-30 11:55:11 +0200
commit01fd63f17c80e81218b3d65f1455a62c411dc6ff (patch)
tree6e9fb79fa8f765605b997f802ed22f83fad44215 /lualibs-dir.lua
parent1e04ecc2c4918448e8ff30a2e6363025267cac79 (diff)
downloadlualibs-01fd63f17c80e81218b3d65f1455a62c411dc6ff.tar.gz
sync with Context from 2013-04-30
Diffstat (limited to 'lualibs-dir.lua')
-rw-r--r--lualibs-dir.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/lualibs-dir.lua b/lualibs-dir.lua
index 00cda38..3d0576e 100644
--- a/lualibs-dir.lua
+++ b/lualibs-dir.lua
@@ -10,7 +10,7 @@ if not modules then modules = { } end modules ['l-dir'] = {
local type, select = type, select
local find, gmatch, match, gsub = string.find, string.gmatch, string.match, string.gsub
-local concat, insert, remove = table.concat, table.insert, table.remove
+local concat, insert, remove, unpack = table.concat, table.insert, table.remove, table.unpack
local lpegmatch = lpeg.match
local P, S, R, C, Cc, Cs, Ct, Cv, V = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cv, lpeg.V
@@ -447,3 +447,24 @@ function dir.pop()
end
return d
end
+
+local function found(...) -- can have nil entries
+ for i=1,select("#",...) do
+ local path = select(i,...)
+ local kind = type(path)
+ if kind == "string" then
+ if isdir(path) then
+ return path
+ end
+ elseif kind == "table" then
+ -- here we asume no holes, i.e. an indexed table
+ local path = found(unpack(path))
+ if path then
+ return path
+ end
+ end
+ end
+ -- return nil -- if we want print("crappath") to show something
+end
+
+dir.found = found