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 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

View File

@ -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)

View File

@ -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)