From 524d0ddc8c0b34a5c7c20e84ed0f464ff16588d9 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 23 Nov 2015 15:42:49 +0300 Subject: [PATCH] Fix not inheriting metamethods from grandparent class --- middleclass.lua | 2 +- spec/metamethods_spec.lua | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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