Last active
January 11, 2026 00:03
-
-
Save ildar/8e3ac46ccca2c1f2d6f5f99a7c1656e1 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 | |
| metamethod __call: function(Sheep, Sheep): Sheep | |
| end | |
| -- impl Sheep | |
| function Sheep:shear() | |
| print(self._name, "gets a haircut!"); | |
| self._naked = true; | |
| end | |
| local Sheep_mt: metatable<Sheep> = { | |
| __call = function(self, initvals: Sheep): Sheep | |
| local res: Sheep = { _name=initvals._name, _naked=false } | |
| return setmetatable(res, {__index=self}) | |
| end | |
| } | |
| setmetatable(Sheep, Sheep_mt) | |
| -- fn main() | |
| local dolly = Sheep { _name="Dolly" } | |
| dolly:shear(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment