diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2017-10-02 20:38:57 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2017-10-03 11:54:13 -0300 |
| commit | 40d1e4f2e6619c28c39cfa203900cf920775b343 (patch) | |
| tree | 44764730403aa307ddad13babcbd040c15de9c97 | |
| parent | 2903d8ee8f151bbc94f4e03f7dd360d2a88a7e9a (diff) | |
| download | luarocks-40d1e4f2e6619c28c39cfa203900cf920775b343.tar.gz luarocks-40d1e4f2e6619c28c39cfa203900cf920775b343.tar.bz2 luarocks-40d1e4f2e6619c28c39cfa203900cf920775b343.zip | |
Use __tostring to represent versions as strings.
| -rw-r--r-- | src/luarocks/core/vers.lua | 8 | ||||
| -rw-r--r-- | src/luarocks/vers.lua | 21 |
2 files changed, 9 insertions, 20 deletions
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 = { | |||
| 54 | return (v1.revision < v2.revision) | 54 | return (v1.revision < v2.revision) |
| 55 | end | 55 | end |
| 56 | return false | 56 | return false |
| 57 | end | 57 | end, |
| 58 | --- Return version as a string. | ||
| 59 | -- @param v The version table. | ||
| 60 | -- @return The string representation. | ||
| 61 | __tostring = function(v) | ||
| 62 | return v.string | ||
| 63 | end, | ||
| 58 | } | 64 | } |
| 59 | 65 | ||
| 60 | local version_cache = {} | 66 | 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) | |||
| 101 | return { name = name, constraints = constraints } | 101 | return { name = name, constraints = constraints } |
| 102 | end | 102 | end |
| 103 | 103 | ||
| 104 | --- Convert a version table to a string. | ||
| 105 | -- @param v table: The version table | ||
| 106 | -- @param internal boolean or nil: Whether to display versions in their | ||
| 107 | -- internal representation format or how they were specified. | ||
| 108 | -- @return string: The dependency information pretty-printed as a string. | ||
| 109 | function vers.show_version(v, internal) | ||
| 110 | assert(type(v) == "table") | ||
| 111 | assert(type(internal) == "boolean" or not internal) | ||
| 112 | |||
| 113 | return (internal | ||
| 114 | and table.concat(v, ":")..(v.revision and tostring(v.revision) or "") | ||
| 115 | or v.string) | ||
| 116 | end | ||
| 117 | |||
| 118 | --- Convert a dependency in table format to a string. | 104 | --- Convert a dependency in table format to a string. |
| 119 | -- @param dep table: The dependency in table format | 105 | -- @param dep table: The dependency in table format |
| 120 | -- @param internal boolean or nil: Whether to display versions in their | ||
| 121 | -- internal representation format or how they were specified. | ||
| 122 | -- @return string: The dependency information pretty-printed as a string. | 106 | -- @return string: The dependency information pretty-printed as a string. |
| 123 | function vers.show_dep(dep, internal) | 107 | function vers.show_dep(dep) |
| 124 | assert(type(dep) == "table") | 108 | assert(type(dep) == "table") |
| 125 | assert(type(internal) == "boolean" or not internal) | ||
| 126 | 109 | ||
| 127 | if #dep.constraints > 0 then | 110 | if #dep.constraints > 0 then |
| 128 | local pretty = {} | 111 | local pretty = {} |
| 129 | for _, c in ipairs(dep.constraints) do | 112 | for _, c in ipairs(dep.constraints) do |
| 130 | table.insert(pretty, c.op .. " " .. vers.show_version(c.version, internal)) | 113 | table.insert(pretty, c.op .. " " .. tostring(c.version)) |
| 131 | end | 114 | end |
| 132 | return dep.name.." "..table.concat(pretty, ", ") | 115 | return dep.name.." "..table.concat(pretty, ", ") |
| 133 | else | 116 | else |
