Skip to content

Instantly share code, notes, and snippets.

@ochaton
Created May 20, 2018 09:36
Show Gist options
  • Save ochaton/9dccdd4b82b5732cbd3e7c689fe14020 to your computer and use it in GitHub Desktop.
Save ochaton/9dccdd4b82b5732cbd3e7c689fe14020 to your computer and use it in GitHub Desktop.
example for metaclass
local class = require 'metaclass'
local class1 = class "Person"
print(class1)
function class.Person:sayHello( ... )
print(self, "Hello!")
end
function class1:HelloMazafaka( ... )
print(self, "Hello, mazafaka!")
end
local class2 = class "Woman" : inherits(class.Person)
print(class2)
function class.Woman:constructor( ... )
print(...)
end
local o = class2(1, 2, 3)
o:sayHello()
o:HelloMazafaka()
--[[ stdout:
Person: 0x564b2ffe88d0
Woman: 0x564b2ffe8a70
1 2 3
Woman: 0x564b2ffe8e60 Hello!
Woman: 0x564b2ffe8e60 Hello, mazafaka!
[Finished in 0.0s]
]]--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment