diff options
author | Jason Perkins <starkos@industriousone.com> | 2012-01-20 00:28:24 +0400 |
---|---|---|
committer | Jason Perkins <starkos@industriousone.com> | 2012-01-20 00:28:24 +0400 |
commit | 9e940156060455aa2d1c126063f1e3723fa01b1a (patch) | |
tree | a379d7a9b20140f5e689349651a1f5b22fb7e63d /src/base | |
parent | 06c55cc5f13a437ff9d70e8c79651081bf385b06 (diff) |
Patch 3111264: Allow path.join() to accept any number of args
Diffstat (limited to 'src/base')
-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 |