Love codepath switching based on version - "Sweet Diversion"

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Klowner
Prole
Posts: 7
Joined: Thu Mar 13, 2014 8:23 pm

Love codepath switching based on version - "Sweet Diversion"

Post by Klowner »

In attempts to make some of my things compatible with multiple versions of Love, and seeing how some people handle it with love._version == "0.9.0", and watching it suddenly fail those checks with the recent release of 0.9.1, I whipped up a tiny utility library for writing conditions based on love release expressions.

Code: Select all

local diversion = require('sweetdiversion')

if diversion('<0.9.0') then
   print('Put some pre-0.9 code here')
else
   print('Post 0.9 code!')
end

if diversion('0.9.*') then
   print("Specifically 0.9.x series, but not 0.8.x or 0.10.x")
end
Here's the github url:
https://github.com/Klowner/sweetdiversion/

Hopefully someone finds it useful! I'm really enjoying working with Love! :awesome:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love codepath switching based on version - "Sweet Divers

Post by Robin »

I tried it, and with 0.9.1 these are some of the results:

Code: Select all

0.9.1	true
0.9.*	true
0.*.1	false
*.9.1	false
0.*.*	true
*.9.*	false
*.*.1	false
*.*.*	false
That's strange, since you would expect them all to be true (although I realise that it's pretty nonsensical to use any of them except for the first two).

While I was investigating that, I discovered the reason. And I discovered a pretty big problem. First:

Code: Select all

0.91.*	true
Why is this a problem? Well, it means that it will stop working once we get LÖVE 0.10.0.

Since Sweet Diversion is on Github, I'll make you a pull request.
Help us help you: attach a .love.
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love codepath switching based on version - "Sweet Divers

Post by slime »

love._version_major, love._version_minor, and love._version_revision (all numbers) are also available to use along with the love._version string.
User avatar
Klowner
Prole
Posts: 7
Joined: Thu Mar 13, 2014 8:23 pm

Re: Love codepath switching based on version - "Sweet Divers

Post by Klowner »

The decimal expression drifted across my mind as I was falling asleep last night, that is indeed a significant bug :o: , thank you for the patch. :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest