From b95a6d8e0607155b2419e3731b8e4a050183a42c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 21 May 2013 20:57:12 +0200 Subject: sync with Context as of 2013-05-21 --- lualibs-file.lua | 40 ++++++++++++++++++++++++++++++++++------ lualibs-table.lua | 2 +- lualibs-util-tab.lua | 4 ++-- 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 -- cgit v1.2.3