Made filesystem.concat() work with more than 2 paths

Also made the code a bit cleaner.
This commit is contained in:
2026-03-04 17:42:06 +02:00
parent 9581d5ce52
commit 2a2b27a827
+8 -8
View File
@@ -30,16 +30,16 @@ function filesystem.canonical(path)
return "/" .. table.concat(segList, "/") return "/" .. table.concat(segList, "/")
end end
function filesystem.concat(path1, path2) function filesystem.concat(...)
checkArg(1, path1, "string") local paths = {...}
checkArg(2, path2, "string") for i, path in ipairs(paths) do
if path1:sub(-1, -1) == "/" then checkArg(i, path, "string")
path1 = path1:sub(1, -2)
end end
if path2:sub(1, 1) ~= "/" then local currentPath = paths[1]:match("(.+)/?$")
path2 = "/" .. path2 for i = 2, #paths do
currentPath = currentPath .. "/" .. paths[i]:match("^/?(.+)/?$")
end end
return path1 .. path2 return currentPath
end end
function filesystem.absolutePath(path) -- returns the address and absolute path of an object function filesystem.absolutePath(path) -- returns the address and absolute path of an object