posfan12
posfan12

Reputation: 2651

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?

Upvotes: 1

Views: 2142

Answers (2)

Rovanion
Rovanion

Reputation: 4582

For Lua 5.1 I ended up using the below code:

AppVersion = "1.6.2"
local major, minor, patch = string.match(AppVersion, "(%d+)%.(%d+)%.(%d+)")

Upvotes: 3

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.

Upvotes: 2

Related Questions