Skip to content

Instantly share code, notes, and snippets.

@ildar
Last active January 11, 2026 00:03
Show Gist options
  • Select an option

  • Save ildar/8e3ac46ccca2c1f2d6f5f99a7c1656e1 to your computer and use it in GitHub Desktop.

Select an option

Save ildar/8e3ac46ccca2c1f2d6f5f99a7c1656e1 to your computer and use it in GitHub Desktop.
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