Comparing LÖVE Versions

It's sometimes useful to check for certain LÖVE versions, for example, do automatic color conversion to 0..1 range in version 11.0 and later, and keep using 0..255 range in 0.10.2 and earlier.

Function

Synopsis

compare = compareLOVEVersion(major, minor, revision)

Arguments

number major
Major version
number minor (nil)
Minor version
number revision (nil)
Revision

Returns

number compare
-1 if current LÖVE version is lower than specified, 0 if exactly equal, 1 if it's later version

Examples

-- LÖVE version: 0.9.2
compareLOVEVersion(0, 9, 2) -- returns 0
 
-- LÖVE version: 0.10.0
compareLOVEVersion(11, 1) -- returns -1
 
-- LÖVE version: 0.10.2
compareLOVEVersion(0, 10, 0) -- returns 1

Source

function compareLOVEVersion(maj, min, rev)
	if love._version_major > maj then
		return 1
	elseif love._version_major < maj then
		return -1
	elseif min then
		if love._version_minor > min then
			return 1
		elseif love._version_minor < min then
			return -1
		elseif rev then
			if love._version_revision > rev then
				return 1
			elseif love._version_revision < rev then
				return -1
			end
		end
	end
	-- equal
	return 0
end