This is a set of additions to middleclass.
middleclass-extras was made for middleclass 1.x and it’s not under development any more.
middleclass 2.x has some features that make it incompatible with middleclass-extras.
middleclass-extras is being (slowly) re-done as a series of smaller libs. Right now, the only one completely finished is Stateful:
Other libraries might follow, but it might just take time. Sorry about that.
What follows is a brief description of each of the middleclass-extras modules. Each nodule is commented out with usage examples. You can find more examples on the /spec/ folder.
- Apply allows invoking a method in all the instances of a class (and its subclasses). It also allows sorting before executing.
- Beholder is a small signaling/event controller mixin. Your classes can ‘observe’ and ‘stop observing’ events. Note that Invoker must be required before Beholder, or the later will not work.
Branchy defines some useful methods for classes that behave like trees (
- Callbacks is a powerful mixin that allows you to add ‘hooks’ to any existing method. For example, you can specify on runtime that you want to call a method after initializing one object.
- GetterSetter just adds a couple convenience getXXX, setXXX methods to your class.
Indexable allows classes to have a ‘fallback’ method, similar to lua’s
__indexis reserved, the method used for lookup will be
index, whithout underscores.
- Invoker is a very small mixin that can be used to ‘send’ methods to instances. It’s main advantage is that it accepts both method names and lua functions on its parameters.
Stateful defines stateful objects. Classes receive a new method called
addState, and instances receive a new method called
gotoState. The behaviour of each of the instance methods can be redefined per-state.
The recommended way is using git.
In order to use middleclass-extras, you also need middleclass. You can download them both by doing:
git clone git://github.com/kikito/middleclass.git
git clone git://github.com/kikito/middleclass-extras.git
Alternatively, you can manually download them:
middleclass-extras is prepared to be required right after middleclass:
- You can remove the .init part from middleclass if you are using middleclass as a file (middleclass.lua) instead of as a dir (middleclass/)
- You can remove the .init part on both requires if your package.path setting already includes
You may find the specs for this library in middleclass-specs