Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DevonPalma/LowerClass
https://github.com/DevonPalma/LowerClass
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/DevonPalma/LowerClass
- Owner: DevonPalma
- License: mit
- Created: 2024-11-04T00:26:21.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-11-11T05:13:53.000Z (about 1 month ago)
- Last Synced: 2024-11-11T06:22:06.443Z (about 1 month ago)
- Language: Lua
- Size: 57.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-love2d - LowerClass - A MiddleClass Inspired library with extended features. (OO)
- trackawesomelist - LowerClass (⭐2) - A MiddleClass Inspired library with extended features. (Recently Updated / [Nov 29, 2024](/content/2024/11/29/README.md))
README
## LowerClass
A simple OOP library for Lua. It has complex inheritance, metamethod support, and weak mixin support.> [!NOTE]
> This is heavily inspired by [middleclass](https://github.com/kikito/middleclass) by kikito. Many parts of the code are directly copied, and the core functionallity is modeled after it. I love MiddleClass but found a few features limiting, hence why LowerClass was developed. All changes can be found [here](https://github.com/DevonPalma/LowerClass/wiki/MiddleClass-vs-LowerClass)## Quick Look
```lua
local class = require 'lowerclass'local Fruit = class('fruit')
function Fruit:__init(sweetness)
self.sweetness = sweetness
endlocal Colorful = class('colorful')
function Colorful:__init(color)
self.color = color
endlocal Lemon = class('Lemon', Fruit, Colorful)
function Lemon:__init(color, sweetness)
Fruit.__init(self, sweetness)
Colorful.__init(self, color)
endlocal lemon = Lemon:new('blue', 10)
```## Quick Docs
LowerClass
- `LowerClass(name: str, ...: mixin|class) => Class` - Generates a new class.
- `LowerClass.type(obj: any) => string` - Returns the type of a passed object (Defaults to lua's type() if a non-class/instance type is passed)Class
- `Class.name` - name of the class
- `Class:new(...) => Instance` - Generates a new instance of a class, passing all args __init(...)
- `Class:is(otherClass) => Boolean` - Checks if the calling class inherits (is a sub-child) of otherClass.
- `Class:include(...: mixin|class)` - Either mixes in a table or adds the passed class as a parent of the calling class.Instance
- `Instance.class` Pointer to the instance's class
- `Instance:is(otherClass) => Boolean` Checks if instance inherits (is a sub-child) of otherClass.
- `Instance:include(...: mixin)` - Copies all functions from a mixin directyly to the calling instance.