/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/lua/lua-515-171-022/main.lua
29 строк
661 B
Spirzen
OOP
09 июн 2026, 20:58
09 июн 2026, 20:58
1dca232
Код
Авторство
О чём код?
local Figure = {} function Figure:new(name, color) local obj = setmetatable({name = name, color = color}, {__index = self}) return obj end function Figure:describe() print("Фигура «" .. self.name .. "», цвет: " .. self.color) end local Circle = {} setmetatable(Circle, {__index = Figure}) function Circle:new(color) return Figure.new(self, "Круг", color) end local Square = {} setmetatable(Square, {__index = Figure}) function Square:new(color) return Figure.new(self, "Квадрат", color) end local circle = Circle:new("красный") local square = Square:new("синий") circle:describe() square:describe()