[added] cleaner super call functionality to class

This commit is contained in:
Max Cahill 2020-05-19 15:17:55 +10:00
parent 1610092bd1
commit 700c7bc957

View File

@ -45,9 +45,18 @@ local function class(inherits)
--get the inherited class for super calls if/as needed
--allows overrides that still refer to superclass behaviour
function c:super()
return inherits
return inherits or c
end
--delegate a call to the super class, by name
--still a bit clumsy but cleaner than the inline equivalent
function c:super_call(func_name, ...)
local f = self:super()[func_name]
if f then
return f(self, ...)
end
error("failed super call - missing function "..tostring(func_name).." in superclass")
end
--done
return c