added list of subclasses per class

This commit is contained in:
Enrique García Cota 2011-08-14 18:39:57 +02:00
parent 252b63f8f6
commit 1df9ccf178
3 changed files with 10 additions and 0 deletions

View File

@ -31,6 +31,7 @@ end
local function _createClass(name, super)
local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
klass.subclasses = setmetatable({}, {__mode = "k"})
_setClassDictionariesMetatables(klass)
_setClassMetatable(klass)
@ -91,6 +92,7 @@ function Object.static:subclass(name)
local subclass = _createClass(name, self)
_setClassMetamethods(subclass)
_setDefaultInitializeMethod(subclass, self)
self.subclasses[subclass] = true
self:subclassed(subclass)
return subclass

View File

@ -48,6 +48,10 @@ context('Object', function()
assert_equal(SubClass.super, Object)
end)
test('it includes the subclass in the list of subclasses', function()
assert_true(Object.subclasses[SubClass])
end)
end)
end)

View File

@ -69,6 +69,10 @@ context('A Class', function()
assert_equal(SubClass, AClass.child)
end)
test('it includes the subclass in the list of subclasses', function()
assert_true(AClass.subclasses[SubClass])
end)
end)
end)