diff options
Diffstat (limited to 'src/base/path.lua')
-rw-r--r-- | src/base/path.lua | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/base/path.lua b/src/base/path.lua index 95a1102..14d00f6 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -217,34 +217,41 @@ return table.contains(extensions, ext) end - -- --- Join two pieces of a path together into a single path. +-- Join one or more pieces of a path together into a single path. +-- +-- @param ... +-- One or more path strings. +-- @return +-- The joined path. -- - function path.join(leading, trailing) - leading = leading or "" - - if (not trailing) then - return leading - end - - if (path.isabsolute(trailing)) then - return trailing - end - - if (leading == ".") then - leading = "" + function path.join(...) + local numargs = select("#", ...) + if numargs == 0 then + return ""; end - if (leading:len() > 0 and not leading:endswith("/")) then - leading = leading .. "/" + local allparts = {} + for i = numargs, 1, -1 do + local part = select(i, ...) + if part and #part > 0 and part ~= "." then + -- trim off trailing slashes + while part:endswith("/") do + part = part:sub(1, -2) + end + + table.insert(allparts, 1, part) + if path.isabsolute(part) then + break + end + end end - return leading .. trailing + return table.concat(allparts, "/") end - + -- -- Takes a path which is relative to one location and makes it relative |