Page 1 of 3

Middleclass 4.x Object-Orientation for Lua

Posted: Thu Dec 31, 2015 6:26 pm
by kikito
Hi everyone,

I have just released version 4.0.0 of middleclass, my OOP library for lua. You can find it on github:

https://github.com/kikito/middleclass

Most people should be able to update to middleclass 4.x from 3.x without issues.

Here's a list of the main changes, which might affect the update for some:
  • There is a new way of doing the method lookup. This new way allows middleclass to support the __index metamethod, which was not possible before and had been a request since 2.0.
  • I have also done some cleanup in middleclass removing some methods that no one seemed to be using : the class:implements method has dissappeared in 4.0.
  • Finally, the other prominent change is that there is no global "Object" class any more, as it has been replaced by a hidden 'default mixin'. As a result, classes created with local X = class('X') will not have a superclass in 4.x, while in previous versions they had Object as a superclass.
You can read more in the changelog and the new updating file.

That's all, happy new year!

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Fri Jan 01, 2016 12:56 am
by Inny
Amazing. I love how tiny the source file is. Previous versions were a bit difficult for me to follow, this is more clear and concise. I did take me a moment to realize the recursive propagateInstanceMethod call going on was so that every class holds a copy of the methods, flattening the delegation chain to a single lookup, while allowing for monkey-patching a class after subclasses and instances have been created. Awesome work! Happy 2016!

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Fri Jan 01, 2016 12:17 pm
by kikito
Thanks! I can't talk all the credit for the new implementation. I got a pull request from mpeterv which did most of the legwork on the new lookup. My contribution was just realizing that it could be used for all the methods instead of just the metamethods :)

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Fri Jan 01, 2016 5:52 pm
by gomez
Dude, you rocks ! :D
Thanks for the new year gift

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Fri Jan 08, 2016 10:36 pm
by BlackBulletIV
Noice. Does it also support __newindex? If so, this should allow me to greatly simply the accessors hack in Ammo.

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Sat Jan 09, 2016 8:35 am
by kikito
I confirm it supports newindex.

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Sat Jan 09, 2016 12:25 pm
by BlackBulletIV
Excellent! I'll have to give it a look when I get the time.

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Sun Jan 10, 2016 8:40 pm
by EntranceJew
Amazing! I've been using middleclass for about as long as I knew it existed, as it was simple to use. Every time I ran into a design problem I found that it already had the feature set to solve the problem if I looked hard enough. It's also my recommended class library any time someone asks. :ultrahappy:

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Sat Mar 05, 2016 6:10 am
by pevzi
It's nice to see a new concise implementation of the same great functionality.
Just to be sure: does Stateful work correctly with the new version?

Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua

Posted: Sat Mar 05, 2016 9:18 am
by kikito
Hi, yes, Stateful works ok with the current middleclass. I was surprised (and happy!) when I tried them together for the first time and everything worked fine.