Created
May 20, 2018 09:36
-
-
Save ochaton/9dccdd4b82b5732cbd3e7c689fe14020 to your computer and use it in GitHub Desktop.
example for metaclass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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