summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-05-21 12:37:57 -0700
committerPhilipp Gesang <phg42.2a@gmail.com>2013-05-21 12:37:57 -0700
commit814392cdbd7fb04508e8def277b9620d1254ab60 (patch)
treed3ffdc7f7e2610282e49f332c9b449096bff128a
parentf8214ffa33cdbab047551e1b49e3b2a0e852dd3e (diff)
parentb95a6d8e0607155b2419e3731b8e4a050183a42c (diff)
downloadlualibs-814392cdbd7fb04508e8def277b9620d1254ab60.tar.gz
Merge pull request #12 from phi-gamma/master
sync
-rw-r--r--lualibs-file.lua40
-rw-r--r--lualibs-table.lua2
-rw-r--r--lualibs-util-tab.lua4
3 files changed, 37 insertions, 9 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
diff --git a/lualibs-table.lua b/lualibs-table.lua
index e57abe8..9a1b97f 100644
--- a/lualibs-table.lua
+++ b/lualibs-table.lua
@@ -120,7 +120,7 @@ local function sortedhash(t,cmp)
if t then
local s
if cmp then
- -- it would be nice if teh sort function would accept a third argument (or nicer, an optional first)
+ -- it would be nice if the sort function would accept a third argument (or nicer, an optional first)
s = sortedhashkeys(t,function(a,b) return cmp(t,a,b) end)
else
s = sortedkeys(t) -- the robust one
diff --git a/lualibs-util-tab.lua b/lualibs-util-tab.lua
index ecf36b1..a47c0cb 100644
--- a/lualibs-util-tab.lua
+++ b/lualibs-util-tab.lua
@@ -406,9 +406,9 @@ end
-- inspect(table.fastserialize { a = 1, b = { 4, { 5, 6 } }, c = { d = 7, e = 'f"g\nh' } })
-function table.load(filename)
+function table.load(filename,loader)
if filename then
- local t = io.loaddata(filename)
+ local t = (loader or io.loaddata)(filename)
if t and t ~= "" then
t = load(t)
if type(t) == "function" then