No description
Find a file
2024-11-02 21:06:14 +09:00
.github/workflows chore: fix Nim version for CI 2024-11-02 21:06:14 +09:00
docs 📚 Add docs for protocol 2024-06-30 18:47:20 +09:00
src Add pick macro for handling runtime polymorphism 2024-07-01 23:04:48 +09:00
tests Add pick macro for handling runtime polymorphism 2024-07-01 23:04:48 +09:00
.gitignore 🍰 Change the nimble package installation process from devbox to nimble 2024-07-01 21:25:41 +09:00
CHANGELOG.md 📚 Update CHANGELOG 2024-07-02 13:01:10 +09:00
COPYING first commit 2021-07-27 23:49:01 +09:00
devbox.json 🍰 Change the nimble package installation process from devbox to nimble 2024-07-01 21:25:41 +09:00
devbox.lock 🍰 Change the nimble package installation process from devbox to nimble 2024-07-01 21:25:41 +09:00
nim.cfg Fix nimble path 2024-07-08 20:10:59 +09:00
oolib.nimble 🍰 Update nimble dependencies 2024-07-02 12:15:22 +09:00
README.md 📚 Update README 2024-06-29 11:06:08 +09:00

👑OOlib

license test contributors stars

OOlib is currently work in progress🔥

🗺Overview

OOlib is a nimble package for object oriented programming.

📜Usage

class

import oolib

class Person:
  var
    name: string
    age = 0

  proc greet =
    echo "hello, I'm ", self.name

let steve = Person.new(name = "Steve")
let tony = Person.new(name = "Tony", age = 30)

steve.greet()
tony.greet()

protocol

import oolib

protocol Readable:
  var text: string

protocol Writable:
  var text: string
  proc `text=`(value: string)

protocol Product:
  var price: int

protocol pub Writer:
  proc write(text: string)

class Book impl (Readable, Product):
  var
    text: string = ""
    price: int

class Diary impl (Readable, Writable, Product):
  var text {.initial.}: string = ""
  var price: int
  proc `text=`(value: string) =
    self.text = value

class HTMLWriter impl Writer:
  var writable: Writable
  proc write(text: string) =
    self.writable.text = text

See 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

License

Copyright © 2024 Neo glassesneo@protonmail.com 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.