Search code examples
luaversionlua-4.0

How to check for the version number?


I've written a small program in Lua 4. In the output it produces I have the program version number stored as a string as follows:

AppVersion = "1.6.2"

How do I parse this string to check whether the recorded version number is equal to or less than the current program version number?


Solution

  • You can use this code:

    AppVersion = "1.6.2"
    recordedVersion = "1.7.2"
    
    _, _, v1, v2, v3 = strfind( AppVersion, "(%d+)%.(%d+)%.(%d+)" )
    _, _, r1, r2, r3 = strfind( recordedVersion, "(%d+)%.(%d+)%.(%d+)" )
    

    (The relevant section of the manual is here).

    Then you can convert the three components of each version to numbers and compare them.