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 »

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 »

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 »

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 »

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: 1261
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 »

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 »

I confirm it supports newindex.
When I write def I mean function.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
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 »

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 »

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 »

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 »

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 3 guests