[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: [ANN] New lib: semver.lua
- From: "Thijs Schreijer" <thijs@...>
- Date: Mon, 16 Jan 2012 23:46:19 +0100
> - there is no way to get the version of your code programmatically (you
can?t use it on itself to compare semver.lua > code versions)
>
> Hmm I'm not sure about how to do that. Do you have anything in mind?
>
> I could include a field in all the versions - the same way
nextMajor/Minor/Patch are included - but that would
> be kind of weird, I think:
>
> v('2.5.6-alpha.1').__version -- 1.0.0 (version of the lib, not the
version itself)
>
> Perhaps there's a standard place to put the version of a lib that I don't
know about?
You now return only a function, if you return a module table, then you can
use the metatable of the module table to create an 'call' metamethod that
would behave the same as the function you return now, but also use the
module way of accessing.
local semver = require('semver')
print(semver._VERSION) --> print the value from the module table
local v1 = semver.newversion('0.1.2') --> create version using regular
module function
local v2 = semver('0.1.2') --> same but executes the 'call' meta
method on the module table
> - it would be nice to add some utility functions to compare lua modules
(based on a module table containing a
> _VERSION value)
>
> Compare how? The versions are already comparable. You can do
module1._VERSION < module2._VERSION and
> module1._VERSION ^ module2._VERSION. What else do you think is needed?
_VERSION uses a format (most common) of name followed by version; eg. 'Lua
5.2', so any utility function should first grab the last part (after the
last space) of the string and then perform comparisons.
Assert example;
-- mymodule version info assume _VERSION = 'mymodule 1.2.3'
local mymodule = require(mymodule)
print(semver.isvalid(mymodule._VERSION)) --> verify version is semver
parsable
print(semver.iscompatible(mymodule, '2.0.1')) --> easy readable source
code (opposed to ^ operator)
semver.assert(mymodule, '2.0.1')
would result in something like;
true
false
Assertion failed; module 'mymodule' has is incompatible (version '1.2.3'),
version '2.x.x' is required
Does that make sense?