Middleclass 4.x Object-Orientation for Lua

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Middleclass 4.x Object-Orientation for Lua

Post by kikito » Thu Dec 31, 2015 6:26 pm

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!
Last edited by kikito on Tue Feb 21, 2017 12:50 pm, edited 1 time in total.
When I write def I mean function.

User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

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

Post by Inny » Fri Jan 01, 2016 12:56 am

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!

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito » Fri Jan 01, 2016 12:17 pm

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 :)
When I write def I mean function.

User avatar
gomez
Citizen
Posts: 65
Joined: Mon Feb 18, 2013 12:23 am
Location: Sao Luís, Brazil

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

Post by gomez » Fri Jan 01, 2016 5:52 pm

Dude, you rocks ! :D
Thanks for the new year gift
Hey dude :D
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001

User avatar
BlackBulletIV
Inner party member
Posts: 1260
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

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

Post by BlackBulletIV » Fri Jan 08, 2016 10:36 pm

Noice. Does it also support __newindex? If so, this should allow me to greatly simply the accessors hack in Ammo.

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito » Sat Jan 09, 2016 8:35 am

I confirm it supports newindex.
When I write def I mean function.

User avatar
BlackBulletIV
Inner party member
Posts: 1260
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

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

Post by BlackBulletIV » Sat Jan 09, 2016 12:25 pm

Excellent! I'll have to give it a look when I get the time.

User avatar
EntranceJew
Prole
Posts: 31
Joined: Fri Apr 03, 2015 10:02 pm
Location: Saint Petersburg, Florida
Contact:

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

Post by EntranceJew » Sun Jan 10, 2016 8:40 pm

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:
sandsmas: A LÖVE Editor
My Libraries: Imgur, Palettes, Music Macros, Timer, Hooks

pevzi
Prole
Posts: 27
Joined: Tue Apr 02, 2013 4:09 pm
Contact:

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

Post by pevzi » Sat Mar 05, 2016 6:10 am

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?

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito » Sat Mar 05, 2016 9:18 am

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.
When I write def I mean function.

Post Reply

Who is online

Users browsing this forum: No registered users and 112 guests