Skip to content

Commit

Permalink
Allow Class to inherit init over >=2 levels (#3290)
Browse files Browse the repository at this point in the history
* Allow Class to inherit init over >=2 levels

* Update class.lua

* Update class.lua

* already retested
  • Loading branch information
hjpalpha authored Oct 3, 2023
1 parent ba1b5e9 commit 239b36b
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions standard/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,20 @@ function Class.new(base, init)
local object = {}
setmetatable(object, instance)

-- Call constructors
if init and base and base.init then
-- If the base class has a constructor,
-- make sure to call that first
instance.init(object, ...)

return object
end

instance.init = function(object, ...)
if base then
base.init(object, ...)
end
if init then
init(object, ...)
elseif init then
-- Else we just call our own
init(object, ...)
else
-- And in cases where we don't have one but the
-- base class does, call that one
if base and base.init then
base.init(object, ...)
end
end
return object
end

instance.init = init
instance.export = function(options)
return Class.export(instance, options)
end
Expand Down

0 comments on commit 239b36b

Please sign in to comment.