diff --git a/class.lua b/class.lua index b0fec0c..38a8aa8 100644 --- a/class.lua +++ b/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