Skip to content

Instantly share code, notes, and snippets.

@Frityet
Forked from ildar/traits2.tl
Last active January 11, 2026 00:06
Show Gist options
  • Select an option

  • Save Frityet/149bc1a07e3ff3643ba708d0c6fc2cd5 to your computer and use it in GitHub Desktop.

Select an option

Save Frityet/149bc1a07e3ff3643ba708d0c6fc2cd5 to your computer and use it in GitHub Desktop.
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();
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