Let me reboot my topic.
Currently, Lua can get the Spring version number and that is very good. I like how Game.version is a complete string with all the details, including build version and compiler,
as it looks very nifty when I print it in the bottom of my menu.
However, sometimes I also need to fetch the engine version number to know if it is past or before a given update.
Sure we can already retrieve some info from the Game.version string and I already have a couple gadget or widget that use regular expressions to construct a version number out of the Game.version string.
However:
- It shouldn't require half a dozen line of code just to get a usable version number.
- The Game.version string may change format one day, making code that parse it error out.
- There are lots of corner case to cover, making the parsing very tricky.
So, I would like that in addition to Game.version, a new constant be added, that would be just an integer, that gets incremented every time buildbot builds. It would make comparing engine version much easier and
reliable.
________________________________________
Maybe I should also have posted my codes so you stop taking me for a lazy idiot:
Code: Select all
if (tonumber(string.sub(Game.version,1,3) or 0) or 0)>=0.80 and (tonumber(string.sub(Game.version,6,6) or 0) or 0)>=1 then
In August, back when jK broke gl.Text, I wrote code like that. It is pretty bad, as when the digit separating dot is misplaced, it errors out. I added the "or 0" so it wouldn't take down the whole widget/gadget after I had a Spring version with two dots within the first three characters.
Code: Select all
local function GetBetterSpringVersion()
local version=100*string.match(Game.version,"^(%d+%.%d+)")
local subversion=string.match(Game.version,"^%d+%.%d+%.(%d+)")
local subsubversion=string.match(Game.version,"^%d+%.%d+%.%d+%.(%d+)")
local TestBuild=string.match(Game.version,"^[%d%.]+(%+)")
if subversion then
version=version+subversion/100
end
if subsubversion then
version=version+subsubversion/10000
end
if TestBuild then
version=version+0.9
end
return version,test
end
This weekend I wrote that, when I found out then new Spring version want Mapname without the .smf suffix. Afterward I realised I forgot the tonumber(), but it somehows worked anyway. But I'm not proud of how I arbitrarly add 0.9 for test version. Also, Lua rounding errors on decimals number means you have to take care about using a little margin in your comparaison.
Please takes notes of how it uses at least four regular expression, Argh! That means I'm not asking for a lecture on them. Not from you anyway.
Code: Select all
local version=tonumber(string.match(Game.version,"^(%d+%.%d+)"))+(string.match(Game.version,"^[%d%.]+(%+)") and 0.009 or 0)
Later I realised I just needed to compare 0.81 to over 0.81 (betting on the new Spring being at least 0.82), so simplified my parsing to that single line.
Even though I managed to get it working for my current purposes, it's not the first time this problem cropped up before me, and I wish there was a clean way to get a numeric version number, instead of having to parse the string myself.
I do not doubt that jK could write a super efficient formula to parse the version string with much fewer operation and much greater elegance. I do not doubt that Argh could write a full page of kludge to cover every known format of the version string. But it seems a defiency that we need such code to get a usable version number in the first place. And covering the corner cases is not trivial, even aegis and jK failed to take into account fairly obvious ones in their first try. So expecting every Lua coder out there to be able to write a perfect version string parser is ludicrous. It should be implemented engine side, and
should not rely on string parsing in the first place.
Also, before someones says it: Yes, I know the Lua manual states that calling them regular expression is erroneous, and we're supposed to call them patterns in Lua. But I still call them regexp because anyway they're just like them and it's easier to understand what we're talking about.
Argh wrote:I agree with that request.
Thanks!