From e3a0f4dab0439deb7e4173b85abd548cfa1ebd30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rley=20Adriano?= <96620547+g3rley@users.noreply.github.com> Date: Fri, 31 Dec 2021 11:36:26 -0300 Subject: [PATCH] Add pt-BR translation to README --- README.pt-BR.md | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 README.pt-BR.md diff --git a/README.pt-BR.md b/README.pt-BR.md new file mode 100644 index 0000000..dd96512 --- /dev/null +++ b/README.pt-BR.md @@ -0,0 +1,94 @@ +# Classic + +Uma pequena implementação da abstração do uso de classes para Lua. Se atentando em manter um simples e decente +desempenho evitando abstrações excessivamente desnecessárias. + + +## Modo de uso + +O [módulo](classic.lua) deve ser adicionado em um projeto já existente e declarado +da seguinte maneira abaixo: + +```lua +Object = require "classic" +``` + +O módulo retorna a classe base do objeto que pode posteriormente ser extendida para +quaisquer classes adicionais. + + +### Criando uma nova classe +```lua +Point = Object:extend() +function Point:new(x, y) + self.x = x or 0 + self.y = y or 0 +end +``` + +### Criando um novo objeto +```lua +local p = Point(10, 20) +``` + +### Extendendo uma classe já existente +```lua +Rect = Point:extend() +function Rect:new(x, y, width, height) + Rect.super.new(self, x, y) + self.width = width or 0 + self.height = height or 0 +end +``` + +### Verificando o tipo de um objeto +```lua +local p = Point(10, 20) +print(p:is(Object)) -- true +print(p:is(Point)) -- true +print(p:is(Rect)) -- false +``` + +### Usando mixins +```lua +PairPrinter = Object:extend() +function PairPrinter:printPairs() + for k, v in pairs(self) do + print(k, v) + end +end +Point = Object:extend() +Point:implement(PairPrinter) +function Point:new(x, y) + self.x = x or 0 + self.y = y or 0 +end +local p = Point() +p:printPairs() +``` + +### Usando variáveis estáticas +```lua +Point = Object:extend() +Point.scale = 2 +function Point:new(x, y) + self.x = x or 0 + self.y = y or 0 +end +function Point:getScaled() + return self.x * Point.scale, self.y * Point.scale +end +``` + +### Criando um meta-método +```lua +function Point:__tostring() + return self.x .. ", " .. self.y +end +``` + + +## Licença + +Este módulo é um software livre; você pode redistribuir e/ou modifica-lo sobre +os termos da licença MIT. Clique [aqui](LICENSE) para melhores detalhes.