Version Convert (code snippet)

Description

Function to convert a version number in up to 3 parts to a simple number for comparison.

Parameter Version number string in format of either 1 or 1.1 or 1.1.1 a special value of fh can also be passed to process the Family Historian version number.

Requires: None

Code

VersionConvert.fh_lua
function cvtVer(s)
if s:lower() == 'fh' then
   s = table.concat({fhGetAppVersion()},'.')
end
local ver,factor,max = 0,10000,3
local t = {}
for word in s:gmatch("%w+") do
 table.insert(t,tonumber(word)) 
end
for j = 1,max do
t[j] = t[j] or 0
ver = ver + (t[j] * factor^(max-j))
end
return ver
end

Usage

v1 = '1.10'
v2 = '1.3'
if cvtVer(v1) < cvtVer(v2) then
   print(v1..'is less than '..v2)
end
 
if cvtVer('fh') < cvtVer('5.0.8') then
   fhMessageBox('This plug in requires at least 5.0.8 of Family Historian, please upgrade')
   return
end