mirror of
https://github.com/1bardesign/batteries.git
synced 2024-09-20 00:42:15 +00:00
[added] cleaner super call functionality to class
This commit is contained in:
parent
1610092bd1
commit
700c7bc957
11
class.lua
11
class.lua
@ -45,9 +45,18 @@ local function class(inherits)
|
|||||||
--get the inherited class for super calls if/as needed
|
--get the inherited class for super calls if/as needed
|
||||||
--allows overrides that still refer to superclass behaviour
|
--allows overrides that still refer to superclass behaviour
|
||||||
function c:super()
|
function c:super()
|
||||||
return inherits
|
return inherits or c
|
||||||
end
|
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
|
--done
|
||||||
return c
|
return c
|
||||||
|
Loading…
Reference in New Issue
Block a user