Fix not inheriting metamethods from grandparent class

This commit is contained in:
mpeterv 2015-11-23 15:42:49 +03:00
parent b66ba54ccb
commit 524d0ddc8c
2 changed files with 8 additions and 1 deletions

View File

@ -97,7 +97,7 @@ local function _createClass(name, super)
end end
local function _setSubclassMetamethods(aClass, subclass) local function _setSubclassMetamethods(aClass, subclass)
for m in pairs(aClass.__metamethods) do for m in pairs(all_metamethods) do
subclass.__instanceDict[m] = aClass.__instanceDict[m] subclass.__instanceDict[m] = aClass.__instanceDict[m]
end end
end end

View File

@ -171,6 +171,13 @@ describe('Metamethods', function()
for k in pairs(c) do assert.not_table(k) end for k in pairs(c) do assert.not_table(k) end
end) end)
it('allows inheriting further', function()
local Vector3 = class('Vector3', Vector2)
local e = Vector3(1,2,3)
local f = Vector3(3,4,5)
assert.equal(e+f, Vector3(4,6,8))
end)
describe('Updates', function() describe('Updates', function()
it('overrides __add', function() it('overrides __add', function()
Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end