From 40d1e4f2e6619c28c39cfa203900cf920775b343 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 2 Oct 2017 20:38:57 -0300 Subject: Use __tostring to represent versions as strings. --- src/luarocks/core/vers.lua | 8 +++++++- src/luarocks/vers.lua | 21 ++------------------- 2 files changed, 9 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/vers.lua b/src/luarocks/core/vers.lua index 66fa28a0..1c016bbb 100644 --- a/src/luarocks/core/vers.lua +++ b/src/luarocks/core/vers.lua @@ -54,7 +54,13 @@ local version_mt = { return (v1.revision < v2.revision) end return false - end + end, + --- Return version as a string. + -- @param v The version table. + -- @return The string representation. + __tostring = function(v) + return v.string + end, } local version_cache = {} diff --git a/src/luarocks/vers.lua b/src/luarocks/vers.lua index 6ce5d738..d37690a8 100644 --- a/src/luarocks/vers.lua +++ b/src/luarocks/vers.lua @@ -101,33 +101,16 @@ function vers.parse_dep(dep) return { name = name, constraints = constraints } end ---- Convert a version table to a string. --- @param v table: The version table --- @param internal boolean or nil: Whether to display versions in their --- internal representation format or how they were specified. --- @return string: The dependency information pretty-printed as a string. -function vers.show_version(v, internal) - assert(type(v) == "table") - assert(type(internal) == "boolean" or not internal) - - return (internal - and table.concat(v, ":")..(v.revision and tostring(v.revision) or "") - or v.string) -end - --- Convert a dependency in table format to a string. -- @param dep table: The dependency in table format --- @param internal boolean or nil: Whether to display versions in their --- internal representation format or how they were specified. -- @return string: The dependency information pretty-printed as a string. -function vers.show_dep(dep, internal) +function vers.show_dep(dep) assert(type(dep) == "table") - assert(type(internal) == "boolean" or not internal) if #dep.constraints > 0 then local pretty = {} for _, c in ipairs(dep.constraints) do - table.insert(pretty, c.op .. " " .. vers.show_version(c.version, internal)) + table.insert(pretty, c.op .. " " .. tostring(c.version)) end return dep.name.." "..table.concat(pretty, ", ") else -- cgit v1.2.3-55-g6feb