-
-
Save Frityet/149bc1a07e3ff3643ba708d0c6fc2cd5 to your computer and use it in GitHub Desktop.
a little modification of https://gist.github.com/ildar/e5e9676f62a6b96ef2ac7b81be74ca12
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 record Sheep | |
| _naked: boolean | |
| _name: string | |
| __index: Sheep | |
| end | |
| Sheep.__index = Sheep | |
| -- impl Sheep | |
| function Sheep:shear() | |
| print(self._name, "gets a haircut!"); | |
| self._naked = true; | |
| end | |
| function Sheep:create(x: Sheep): self | |
| return setmetatable(x, { __index = Sheep }) | |
| end | |
| -- fn main() | |
| local dolly = Sheep:create { _name = "Dolly" } | |
| dolly:shear(); |
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 interface Object is self.__name | |
| __index: self | |
| __name: string | |
| end | |
| local record Sheep is Object where self.__name == "Sheep" | |
| _naked: boolean | |
| _name: string | |
| end | |
| Sheep.__index = Sheep | |
| Sheep.__name = "Sheep" | |
| -- impl Sheep | |
| function Sheep:shear() | |
| print(self._name, "gets a haircut!"); | |
| self._naked = true; | |
| end | |
| function Sheep:create(x: Sheep): self | |
| x.__name = "Sheep" | |
| return setmetatable(x, { __index = Sheep }) | |
| end | |
| -- fn main() | |
| local dolly = Sheep:create { _name = "Dolly" } | |
| dolly:shear(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment