Version Numbers in Lua Projects

Today I present a short opinion on defining version numbers for Lua modules, packages, software, and so on.

I like to use the “standard” format Major.Minor.Patch for most version numbers. And on some projects I even make use of Semantic Versioning. There are different ways to represent such version numbers in Lua. Perhaps the most common is to add a _VERSION property to the table representing whatever Lua module or package you are releasing; Middleclass is an example of this.

I think that approach is fine. However, I like the idea of making the version numbers available for numeric comparison. This is exactly what I’ve done on LNVL. Its version information looks like this:

LNVL.Version = setmetatable(
        ["Major"] = 0,
        ["Minor"] = 1,
        ["Patch"] = 0,
        ["Label"] = "-unstable",
        __tostring = function()
            return string.format("%d.%d.%d%s",

Developers can numerically compare version numbers via LNVL.Version["Major"], for example. But they can also still display a string representation of the entire version number due to the metatable and custom __tostring() function. Therefore calling print(tostring(LNVL.Version)) would display 0.1.0-unstable.

So far I’ve been happy with this approach. I know it is a relatively trivial matter, but I wanted to talk about it anyway. If you have any other preferences for how you present version numbers in your Lua code please let me know in the comments below!


Add Your Thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s