fixed stack overflow for 3-or-deeper hierarchies on super construction

This commit is contained in:
Max Cahill 2021-07-16 19:33:47 +10:00
parent a339854651
commit 7813bf35a1

View File

@ -100,14 +100,24 @@ local function class(config)
--get the inherited class for super calls if/as needed
--allows overrides that still refer to superclass behaviour
c.__super = extends
--nop by default
function c:super() end
--perform a (partial) super construction for an instance
--for any nested super calls, it'll call the relevant one in the
--heirarchy, assuming no super calls have been missed
function c:super(...)
if not c.__super then return end
--hold reference so we can restore
local current_super = c.__super
--push next super
c.__super = c.__super.__super
--call
current_super.new(self, ...)
--restore
c.__super = current_super
end
if c.__super then
--perform a super construction for an instance
function c:super(...)
c.__super.new(self, ...)
end
--implement superclass interface
implement(c, c.__super)
end