summaryrefslogtreecommitdiff
path: root/lualibs-file.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-05-21 20:57:12 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-05-21 20:57:12 +0200
commitb95a6d8e0607155b2419e3731b8e4a050183a42c (patch)
treed3ffdc7f7e2610282e49f332c9b449096bff128a /lualibs-file.lua
parent260c0a1c6f7e41618d08519c2e5db70409742b37 (diff)
downloadlualibs-b95a6d8e0607155b2419e3731b8e4a050183a42c.tar.gz
sync with Context as of 2013-05-21
Diffstat (limited to 'lualibs-file.lua')
-rw-r--r--lualibs-file.lua40
1 files changed, 34 insertions, 6 deletions
diff --git a/lualibs-file.lua b/lualibs-file.lua
index acb4216..deaaca7 100644
--- a/lualibs-file.lua
+++ b/lualibs-file.lua
@@ -62,7 +62,7 @@ elseif not lfs.isfile then
end
local insert, concat = table.insert, table.concat
-local match, find = string.match, string.find
+local match, find, gmatch = string.match, string.find, string.gmatch
local lpegmatch = lpeg.match
local getcurrentdir, attributes = lfs.currentdir, lfs.attributes
local checkedsplit = string.checkedsplit
@@ -115,11 +115,23 @@ local function suffixonly(name)
return name and lpegmatch(pattern,name) or ""
end
-file.pathpart = pathpart
-file.basename = basename
-file.nameonly = nameonly
-file.suffixonly = suffixonly
-file.suffix = suffixonly
+local pattern = (noslashes^0 * slashes)^0 * noperiod^1 * ((period * C(noperiod^1))^1) * -1 + Cc("")
+
+local function suffixesonly(name)
+ if name then
+ return lpegmatch(pattern,name)
+ else
+ return ""
+ end
+end
+
+file.pathpart = pathpart
+file.basename = basename
+file.nameonly = nameonly
+file.suffixonly = suffixonly
+file.suffix = suffixonly
+file.suffixesonly = suffixesonly
+file.suffixes = suffixesonly
file.dirname = pathpart -- obsolete
file.extname = suffixonly -- obsolete
@@ -572,3 +584,19 @@ end
-- return f(...)
-- end
-- end
+
+-- a goodie: a dumb version of mkdirs:
+
+function lfs.mkdirs(path)
+ local full
+ for sub in gmatch(path,"([^\\/]+)") do
+ if full then
+ full = full .. "/" .. sub
+ else
+ full = sub
+ end
+ if not lfs.isdir(full) then
+ lfs.mkdir(full)
+ end
+ end
+end