middleclass/README.textile

56 lines
2.7 KiB
Plaintext
Raw Normal View History

2010-04-21 22:08:02 +00:00
h1. MiddleClass
2010-04-21 22:06:04 +00:00
Lua OOP classes usually end being:
2010-04-21 22:08:02 +00:00
* multi-file libraries, too difficult to understand
* very small libraries, not very powerful
2010-04-21 22:06:04 +00:00
Middleclass attemps to be a mid-sized library (~120 lines of code, on a single file), with clean, easy to understand code, and yet powerful enough to be used in most cases.
2010-04-21 22:06:04 +00:00
2010-04-21 22:08:02 +00:00
h1. Documentation
2010-04-21 22:06:04 +00:00
2010-04-21 22:09:24 +00:00
See the "LÖVE wiki page":http://love2d.org/wiki/MiddleClass for examples & documentation.
2010-04-21 22:06:04 +00:00
2010-04-21 22:08:02 +00:00
h1. Features
2010-04-21 22:06:04 +00:00
* ~100 lines of code
* top-level Object class
* all methods are virtual
* instance.class returns the instance's class
* @Class.name@ returns the class name (a string)
* @Class.superclass@ returns its super class
* Subclassing:
** @class(name)@ creates a subclass of @Object@
** @class(name, Superclass)@ creates a subclass of the class @Class@
** @Class:subclass(name)@ also creates a subclass of the class @Class@
* Instantiation:
** Classes can define an @initialize@ method for initializing new instances. They can accept an arbitrary number of params.
** Instances are created by doing @Class:new(params)@ or also @Class(params)@
** It is recommended to use the @super@ facility inside all defined initializers: @super.initialize(self, params)@.
* support for Lua metamethods: just define a method called @__tostring@, @__add@, etc. and your instances will be able to use it.
* Mixins:
** A very simple mechanism for sharing functionality among a group of classes that are otherwise non-related.
** Mixins are just simple lua tables with functions inside them.
** @Class:include(mixin)@ will copy the function definitions of @mixin@ to @class@
** If @mixin@ contains a function, called @included@, that function will be invoked right after the functions have been copied. It allows for modifying the class more profoundly.
* The function @instanceOf(class, instance)@ returns @true@ if @instance@ is an instance of the class @Class@
* The function @subclassOf(Superclass, Class)@ returns @true@ if @Class@ is a subclass of @SuperClass@
* The function @includes(mixin, Class)@ returns @true@ if @Class@ (or one of its superclasses) includes @mixin@.
* The @super@ facility, can be used inside a method to call the same method as it's implemented by the superclass: @super.methodName(self, params)@
2010-04-21 22:06:04 +00:00
Features left out:
* metaclasses
* classes are not Objects (instances are)
h1. Extras
This library has a companion lib that adds a lot of interesting functionality to your objects. Give it a look at:
You may find the specs for this package in https://github.com/kikito/middleclass-extras
If you are looking for middeclass (now called Stateful), it's over there, too.
h1. Specs
You may find the specs for this library at: https://github.com/kikito/middleclass-specs