From 8f54522e2020cbefba74f088ab0a15a16358e72d Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:18:35 -0700 Subject: [PATCH] Create file_path.lua --- .../utils/format/file_path.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 worldeditadditions_core/utils/format/file_path.lua diff --git a/worldeditadditions_core/utils/format/file_path.lua b/worldeditadditions_core/utils/format/file_path.lua new file mode 100644 index 0000000..751ed49 --- /dev/null +++ b/worldeditadditions_core/utils/format/file_path.lua @@ -0,0 +1,17 @@ +--- +-- @module worldeditadditions_core +local wea_c = worldeditadditions_core + +--- Joins the given path segments into a single path with dirsep. +-- @param ... string The path fragments to process and join. +-- @return string The joined path. +-- @example Basic usage +-- local path = file_path("C:\\Users", "me", "/Documents/code.lua") +local file_path = function( ... ) + local path = { ... } + for i, v in ipairs(path) do path[i] = tostring(v) end + return ({table.concat(path, wea_c.dirsep) + :gsub("[/\\]+", wea_c.dirsep)})[1] +end + +return file_path \ No newline at end of file