Skip to content

Commit

Permalink
remove path obj
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 26, 2024
1 parent a23ffcf commit 24a75df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 34 deletions.
5 changes: 2 additions & 3 deletions doc/luamake.lua
@@ -1,9 +1,8 @@
---@meta luamake

---@class fs.path
---@class LmPath
---@alias LmStrlist any
---@alias LmValue string | fs.path | LmPath
---@alias LmValue string | LmPath

---@class LmTargetAttri
---@field builddir string?
Expand Down Expand Up @@ -79,7 +78,7 @@ end
---
--- Create an absolute path, base is workdir.
---
---@param value string | fs.path
---@param value string
---@return LmPath
function lm:path(value)
end
Expand Down
37 changes: 7 additions & 30 deletions scripts/pathutil.lua
@@ -1,13 +1,7 @@
local fsutil = require "fsutil"

local mt = {}

local function create_internal(path)
return setmetatable({ value = path }, mt)
end
local fs = require "bee.filesystem"

local function path_normalize(base, path)
path = tostring(path)
if path:sub(1, 1) ~= "$" then
if not fsutil.is_absolute(path) then
path = fsutil.normalize(base, path)
Expand All @@ -18,40 +12,23 @@ local function path_normalize(base, path)
end

local function is(path)
return mt == getmetatable(path)
return type(path) == "userdata"
end

local function create(workdir, path)
if type(path) == "userdata" then
path = tostring(path)
else
path = path_normalize(workdir, path)
end
return create_internal(path)
return fs.path(path_normalize(workdir, path))
end

local function tostr(base, path)
if is(path) then
return path.value
return tostring(path)
else
return path_normalize(base, path)
end
return path_normalize(base, path)
end

local function tovalue(path)
if is(path) then
return true, path.value
end
return false, tostring(path)
end

function mt.__concat(lft, rht)
if type(lft) == "string" then
local path = lft..rht.value
return create_internal(path)
else
local path = lft.value..rht
return create_internal(path)
end
return is(path), tostring(path)
end

return {
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.lua
@@ -1 +1 @@
return "1.9"
return "1.10"

0 comments on commit 24a75df

Please sign in to comment.