diff --git a/middleclass.lua b/middleclass.lua index 8cba0ce..da66a9a 100644 --- a/middleclass.lua +++ b/middleclass.lua @@ -97,7 +97,7 @@ local function _createClass(name, super) end 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] end end diff --git a/spec/metamethods_spec.lua b/spec/metamethods_spec.lua index f9a79a9..0ab4f30 100644 --- a/spec/metamethods_spec.lua +++ b/spec/metamethods_spec.lua @@ -171,6 +171,13 @@ describe('Metamethods', function() for k in pairs(c) do assert.not_table(k) 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() it('overrides __add', function() Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end