mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-25 02:44:20 +00:00
added list of subclasses per class
This commit is contained in:
parent
252b63f8f6
commit
1df9ccf178
@ -31,6 +31,7 @@ end
|
|||||||
|
|
||||||
local function _createClass(name, super)
|
local function _createClass(name, super)
|
||||||
local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
|
local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
|
||||||
|
klass.subclasses = setmetatable({}, {__mode = "k"})
|
||||||
|
|
||||||
_setClassDictionariesMetatables(klass)
|
_setClassDictionariesMetatables(klass)
|
||||||
_setClassMetatable(klass)
|
_setClassMetatable(klass)
|
||||||
@ -91,6 +92,7 @@ function Object.static:subclass(name)
|
|||||||
local subclass = _createClass(name, self)
|
local subclass = _createClass(name, self)
|
||||||
_setClassMetamethods(subclass)
|
_setClassMetamethods(subclass)
|
||||||
_setDefaultInitializeMethod(subclass, self)
|
_setDefaultInitializeMethod(subclass, self)
|
||||||
|
self.subclasses[subclass] = true
|
||||||
self:subclassed(subclass)
|
self:subclassed(subclass)
|
||||||
|
|
||||||
return subclass
|
return subclass
|
||||||
|
@ -48,6 +48,10 @@ context('Object', function()
|
|||||||
assert_equal(SubClass.super, Object)
|
assert_equal(SubClass.super, Object)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
test('it includes the subclass in the list of subclasses', function()
|
||||||
|
assert_true(Object.subclasses[SubClass])
|
||||||
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
@ -69,6 +69,10 @@ context('A Class', function()
|
|||||||
assert_equal(SubClass, AClass.child)
|
assert_equal(SubClass, AClass.child)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
test('it includes the subclass in the list of subclasses', function()
|
||||||
|
assert_true(AClass.subclasses[SubClass])
|
||||||
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user