{"id":"kiy4ku/classic","name":"classic","scope":"kiy4ku","platform":"roblox","description":"A tiny class module for Lua. Attempts to stay simple and provide decent performance by avoiding unnecessary over-abstraction.","version":"1.0.0","latest":"1.0.0","versions":["1.0.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"b8a12aea3472d1965939b6414ca70a621bf55d46b88ad65f044f4a7fa16f1e19","likes":0,"downloads":0,"install":"forest install kiy4ku/classic","url":"https://forest.dev/p/roblox/kiy4ku/classic","files":"https://api.forest.dev/ai/package/roblox/kiy4ku/classic/files","readme":"# Classic\r\n\r\nA tiny class module for Lua. Attempts to stay simple and provide decent\r\nperformance by avoiding unnecessary over-abstraction.\r\n\r\n\r\n## Usage\r\n\r\nThe [module](classic.lua) should be dropped in to an existing project and\r\nrequired by it:\r\n\r\n```lua\r\nObject = require \"classic\"\r\n```\r\n\r\nThe module returns the object base class which can be extended to create any\r\nadditional classes.\r\n\r\n\r\n### Creating a new class\r\n```lua\r\nPoint = Object:extend()\r\n\r\nfunction Point:new(x, y)\r\n  self.x = x or 0\r\n  self.y = y or 0\r\nend\r\n```\r\n\r\n### Creating a new object\r\n```lua\r\nlocal p = Point(10, 20)\r\n```\r\n\r\n### Extending an existing class\r\n```lua\r\nRect = Point:extend()\r\n\r\nfunction Rect:new(x, y, width, height)\r\n  Rect.super.new(self, x, y)\r\n  self.width = width or 0\r\n  self.height = height or 0\r\nend\r\n```\r\n\r\n### Checking an object's type\r\n```lua\r\nlocal p = Point(10, 20)\r\nprint(p:is(Object)) -- true\r\nprint(p:is(Point)) -- true\r\nprint(p:is(Rect)) -- false \r\n```\r\n\r\n### Using mixins\r\n```lua\r\nPairPrinter = Object:extend()\r\n\r\nfunction PairPrinter:printPairs()\r\n  for k, v in pairs(self) do\r\n    print(k, v)\r\n  end\r\nend\r\n\r\n\r\nPoint = Object:extend()\r\nPoint:implement(PairPrinter)\r\n\r\nfunction Point:new(x, y)\r\n  self.x = x or 0\r\n  self.y = y or 0\r\nend\r\n\r\n\r\nlocal p = Point()\r\np:printPairs()\r\n```\r\n\r\n### Using static variables\r\n```lua\r\nPoint = Object:extend()\r\nPoint.scale = 2\r\n\r\nfunction Point:new(x, y)\r\n  self.x = x or 0\r\n  self.y = y or 0\r\nend\r\n\r\nfunction Point:getScaled()\r\n  return self.x * Point.scale, self.y * Point.scale\r\nend\r\n```\r\n\r\n### Creating a metamethod\r\n```lua\r\nfunction Point:__tostring()\r\n  return self.x .. \", \" .. self.y\r\nend\r\n```\r\n\r\n\r\n## License\r\n\r\nThis module is free software; you can redistribute it and/or modify it under\r\nthe terms of the MIT license. See [LICENSE](LICENSE) for details.\r\n\r\n","readmeTruncated":false}