Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mebens/closureclass
A Lua object-orientation library based on MiddleClass, except using the closure approach. More information soon.
https://github.com/mebens/closureclass
Last synced: about 1 month ago
JSON representation
A Lua object-orientation library based on MiddleClass, except using the closure approach. More information soon.
- Host: GitHub
- URL: https://github.com/mebens/closureclass
- Owner: mebens
- License: zlib
- Created: 2011-03-11T06:16:40.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-03-12T19:41:07.000Z (over 13 years ago)
- Last Synced: 2023-03-11T15:06:04.355Z (over 1 year ago)
- Language: Lua
- Homepage: http://www.nova-fusion.com
- Size: 97.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Description
ClosureClass is an experimental Lua object-orientation library, with the catch that it uses the [closure approach](http://lua-users.org/wiki/ObjectOrientationClosureApproach) instead of the traditional use of table indexing and such. It's based off [MiddleClass](http://github.com/kikito/middleclass) in design.
Note that performance isn't good for this library at present. When compared against MiddleClass, for creating instances of classes, it's about two times as slow, and takes more than two times as much memory. However, it does take about 4/5 the speed of MiddleClass when accessing and calling instance methods.
# Difference in Use
Take this code using MiddleClass for example:
Foo = class('Foo')
function Foo:initialize()
self.hello = 3
self.boo = 4
self:initSomeMore()
end
function Foo:initSomeMore()
-- blah!
end
function Foo:instanceFunc()
-- blah!
end
f = Foo:new()
f:instanceFunc()
Bar = class('Bar', Foo)
function Bar:initialize()
Foo.initialize(self)
self.bar = 5
end
We can do the same thing in ClosureClass using this:Foo = class('Foo', function(self)
function self.initSomeMore()
-- blah!
end
function self.instanceFunc()
-- blah!
end
self.hello = 3
self.boo = 4
self.initSomeMore()
end)
f = Foo.new()
f.instanceFunc()
Bar = class('Bar', Foo, function(self)
-- initialization function implicitly called for now
self.bar = 5
end)
Mixins are relatively the same in ClosureClass:Mixin = {}
function Mixin:something()
print('blah!')
end
Foo = class('Foo').include(Mixin)
f = Foo.new()
f.something() -- "blah!"
Notice how we declare mixin functions with self as a parameter. This is because mixin functions are outside the main closure. However, ClosureClass wraps these function so that using the colon syntax of calling methods isn't needed.