Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bartbes/Class-Commons
An attempt at unifying lua class libraries to provide a common API.
https://github.com/bartbes/Class-Commons
Last synced: about 1 month ago
JSON representation
An attempt at unifying lua class libraries to provide a common API.
- Host: GitHub
- URL: https://github.com/bartbes/Class-Commons
- Owner: bartbes
- Created: 2011-06-24T07:21:55.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-01-13T14:05:27.000Z (almost 7 years ago)
- Last Synced: 2024-10-20T10:25:47.595Z (about 2 months ago)
- Homepage: http://love2d.org/wiki/Class_Commons
- Size: 16.6 KB
- Stars: 53
- Watchers: 8
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-love2d - Class-Commons
README
# Class Commons #
*Class Commons* is a project to provide a common compatibility interface for class systems. The goal of this is to make libraries independent of class libraries, a library using the Class Commons API can then be used with any class system adhering to it (albeit via a compatibility layer).## Specification ##
### Features ###
* Single-class inheritance
* Constructors
* Instance methods
* PolymorphismClass definition is single-write read-only, so the entire class has to be defined on creation.
### Functions ###
class = common.class(name, table, parents...)
instance = common.instance(class, ...)### Class constructors ###
Constructors are defined by the special `init` function:foo = {}
function foo:init()
self.bar = "baz"
end
foo = common.class("foo", foo)Derived classes may access the super class constructors by using `.init`, but
ONLY if the parent was created using common.class:foo = common.class("foo", {init = function(self) self.foo = true end})
bar = common.class("bar", {init = function(self) foo.init(self) end})NOTE: Accessing `.init` from classes not created with common.class yields
undefined behaviour.### Instances ###
Instances may be created using `common.instance`:foo = common.class("foo", {init = function(self, bar) self.bar = bar end})
baz = common.instance(foo, 'baz')#### Example ####
local Tree = {}
function Tree:grow()
print("Is a big tree now!")
endfunction Tree:chop()
print("Chopped down a tree.")
endlocal Ent = {}
function Ent:chop()
print("I am no tree, I am an ent!")
end
Tree = common.class("Tree", Tree)
Ent = common.class("Ent", Ent, Tree)local tree = common.instance(Ent)
tree:grow() --> Is a big tree now!
tree:chop() --> I am no tree, I am an ent!## Participating libraries ##
* [SECS][]
* [Slither][]
* [MiddleClass][]
* [hump.class][]
* [30log][]
* [oop.item][]## Repository information ##
This repository will both contain documentation (like this very document) and tests. (Note: located in a subrepository.)
The authors of participating libraries all get write access, and are free, and encouraged, to collaborate.[SECS]: http://love2d.org/wiki/Simple_Educative_Class_System
[Slither]: http://bitbucket.org/bartbes/slither
[MiddleClass]: http://github.com/kikito/middleclass/wiki
[hump.class]: http://vrld.github.com/hump/#class
[30log]: https://github.com/Yonaba/30log
[oop.item]: https://github.com/Wozzy06/lua-libs/tree/master/lua-libs/src/oop