Hi everyone, I've released version 2.0 of middleclass.
As always, it is on github:
https://github.com/kikito/middleclass
Version 2.0 is a complete re-write of the library. I've done my best to keep the changes as little as possible, but there are some backwards-incompatible changes. Sorry about that.
Here is the changelog:
- Static methods are now separated from instance methods
- class.superclass has now become class.super
- It's now possible to do class.subclasses
- middleclass is now a single file; init.lua has dissapeared
- I've moved the tests back to the project, where they should have been. I've also added some performance tests.
- license is changed from BSD to MIT. License included inside middleclass.lua
The most obvious change is the first one; now there is a way to declare class methods (called static methods). On middleclass 1.x there was no difference between them and instance methods:
Code: Select all
function MyClass:myClassMethod(...)
end
function MyClass:myInstanceMethod(...)
end
Now the recommended way of declaring class methods is using
static:
Code: Select all
function MyClass.static:myClassMethod(...)
end
function MyClass:myInstanceMethod(...)
end
Apart from the declaration, the usage is similar. You do instance:myInstanceMethod() and Class:myClassMethod(), just like before.
The advantage of this change is that now you can have a class method and a instance method called the same way. In that case, Class.methodName will refer to the instance method, and Class.static.methodName will refer to the class method. If methodName refers to a class method only, you can refer to it as Class.methodName, too.
An additional advantage is that the "old" way of declaring class methods (without using
static) is deprecated, but it should still work; it is recommended to update to the new one, but do so at your own pace.
I've also made middleclass a single file, so it is easier to include - this should get rid of those "could not find middleclass" errors that some of you are experiencing. Also, I've included the license inside middleclass.lua, so the legal aspects are easier to handle now.
Should I use middleclass 2.0 on my new projects?
You should, unless you plan to use middleclass-extras; I haven't updated it yet. I will make another announcement when it is done. It's possible that middleclass-extras gets divided into smaller projects.
I'm using middleclass 1.4 on my project. Should I update?
Middleclass 1.4 is very tested, and it works just fine. There is no reason to rush to update, especially if you need middleclass-extras. However, keep in mind that I will not support that version in the future; In the unlikely event that you run into a bug, I might just point you to the new version. I don't have the means to support multiple versions simultaneously, since I do this in my free time. But as I was saying, 1.4 is very stable, and you shouldn't have any problems with it.
I hope this covers it. Feel free to ask if you have any questions!