Skip to content

Instantly share code, notes, and snippets.

@katlogic
Created May 10, 2014 18:42
Show Gist options
  • Save katlogic/f91e67b61cd3966ad67b to your computer and use it in GitHub Desktop.
Save katlogic/f91e67b61cd3966ad67b to your computer and use it in GitHub Desktop.
-- example class Foo
local Foo = {
attr1 = 1,
attr2 = 2,
}
Foo.__index = Foo
function Foo:getattr1()
return self.attr1
end
function Foo:getattr2()
return self.attr1
end
-- example class Bar which inherits from Foo
local Bar = {
attr3 = 3,
attr1 = 4,
}
for k,v in pairs(Foo) do Bar[k] = v end
Bar.__index = Bar
function Bar:getattr3()
return self.attr3
end
-- usage
inst = setmetatable({attr3=1337}, Bar)
print(inst:getattr3(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment