local util = {}
function util.fetch(url)
local handle = io.popen(string.format('curl -sfL "%s"', url))
if not handle then
return nil
end
local content = handle:read("*a")
handle:close()
if content == "" then
return nil
end
return content
end
function util.get_versions()
local versions = {}
local url = "https://api.github.com/repos/tavianator/bfs/tags?per_page=100"
local content = util.fetch(url)
if not content then
return versions
end
for tag in content:gmatch('"name"%s*:%s*"([^"]+)"') do
if tag:match("^%d+%.%d+") then
table.insert(versions, tag)
end
end
return versions
end
function util.version_compare(a, b)
local function parse_version(v)
local parts = {}
for num in v:gmatch("(%d+)") do
table.insert(parts, tonumber(num))
end
return parts
end
local pa = parse_version(a)
local pb = parse_version(b)
for i = 1, math.max(#pa, #pb) do
local na = pa[i] or 0
local nb = pb[i] or 0
if na ~= nb then
return na > nb
end
end
return false
end
return util