mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
fixed stack overflow for 3-or-deeper hierarchies on super construction
This commit is contained in:
parent
a339854651
commit
7813bf35a1
22
class.lua
22
class.lua
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user