From 2a2b27a82782ceb0888ba65e58ecb13d78a20f9a Mon Sep 17 00:00:00 2001 From: WahPlus Date: Wed, 4 Mar 2026 17:42:06 +0200 Subject: [PATCH] Made filesystem.concat() work with more than 2 paths Also made the code a bit cleaner. --- halyde/lib/filesystem.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/halyde/lib/filesystem.lua b/halyde/lib/filesystem.lua index cbdd325..ec94613 100644 --- a/halyde/lib/filesystem.lua +++ b/halyde/lib/filesystem.lua @@ -30,16 +30,16 @@ function filesystem.canonical(path) return "/" .. table.concat(segList, "/") end -function filesystem.concat(path1, path2) - checkArg(1, path1, "string") - checkArg(2, path2, "string") - if path1:sub(-1, -1) == "/" then - path1 = path1:sub(1, -2) +function filesystem.concat(...) + local paths = {...} + for i, path in ipairs(paths) do + checkArg(i, path, "string") end - if path2:sub(1, 1) ~= "/" then - path2 = "/" .. path2 + local currentPath = paths[1]:match("(.+)/?$") + for i = 2, #paths do + currentPath = currentPath .. "/" .. paths[i]:match("^/?(.+)/?$") end - return path1 .. path2 + return currentPath end function filesystem.absolutePath(path) -- returns the address and absolute path of an object