Skip to content

Instantly share code, notes, and snippets.

@svermeulen
Created July 26, 2017 19:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Lua OOP Inheritance Demo
Base = {}
function Base:new()
local obj = {foo = 'asdf'}
return setmetatable(obj, { __index = self })
end
function Base:run()
print(self.foo)
end
Derived1 = setmetatable({}, { __index = Base })
function Derived1:new()
local obj = {bar = 'bxzcv'}
return setmetatable(obj, { __index = Base.new(self) })
end
Derived2 = setmetatable({}, { __index = Derived1 })
function Derived2:new()
local obj = {quz = 'bhsdgfa'}
return setmetatable(obj, { __index = Derived1.new(self) })
end
thing = Derived2:new()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment