Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/glassesneo/OOlib
A nimble package for object-oriented programming
https://github.com/glassesneo/OOlib
metaprogramming nim nimble oop
Last synced: 6 days ago
JSON representation
A nimble package for object-oriented programming
- Host: GitHub
- URL: https://github.com/glassesneo/OOlib
- Owner: glassesneo
- License: wtfpl
- Created: 2021-07-27T14:48:20.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-02T12:06:41.000Z (11 days ago)
- Last Synced: 2024-11-02T13:17:41.722Z (11 days ago)
- Topics: metaprogramming, nim, nimble, oop
- Language: Nim
- Homepage:
- Size: 337 KB
- Stars: 66
- Watchers: 3
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# 👑OOlib
![license](https://img.shields.io/github/license/glassesneo/OOlib?color=blueviolet)
[![test](https://github.com/glassesneo/OOlib/actions/workflows/test.yml/badge.svg)](https://github.com/glassesneo/OOlib/actions/workflows/test.yml)
![contributors](https://img.shields.io/github/contributors/glassesneo/OOlib?color=important)
![stars](https://img.shields.io/github/stars/glassesneo/OOlib?style=social)**OOlib is currently work in progress**🔥
## 🗺Overview
OOlib is a nimble package for object oriented programming.## 📜Usage
### class
```nim
import oolibclass Person:
var
name: string
age = 0proc greet =
echo "hello, I'm ", self.namelet steve = Person.new(name = "Steve")
let tony = Person.new(name = "Tony", age = 30)steve.greet()
tony.greet()
```### protocol
```nim
import oolibprotocol Readable:
var text: stringprotocol Writable:
var text: string
proc `text=`(value: string)protocol Product:
var price: intprotocol pub Writer:
proc write(text: string)class Book impl (Readable, Product):
var
text: string = ""
price: intclass Diary impl (Readable, Writable, Product):
var text {.initial.}: string = ""
var price: int
proc `text=`(value: string) =
self.text = valueclass HTMLWriter impl Writer:
var writable: Writable
proc write(text: string) =
self.writable.text = text
```See [doc.md](https://github.com/glassesneo/OOlib/blob/develop/docs/doc.md) for more details
## ✨Features
- `class`
- Automatic generation of constructor
- `self` inserted in procedures
- All routines (e.g., method, converter, template) are supported, excluding macro
- `protocol`
- A Kotlin-like interface
- Defining setter/getter
- `construct`
- An easy way to declare a class without `class`, only supporting normal class
- `protocoled`
- The same as `construct`, but for interface
- `isInstanceOf` for checking if a variable is an instance of a class or can be converted into a protocol## ðŸ’Planning
- `struct` from Swift
- `dataclass` from Kotlin
- `sealed class` from Kotlin## Changelog
See [CHANGELOG](https://github.com/glassesneo/OOlib/blob/develop/CHANGELOG.md)## License
Copyright © 2024 Neo [email protected]
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.