Skip to content

glassesneo/OOlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👑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

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

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

✨Features

  • class macro
    • Automatic generation of constructor
    • self inserted in procedures
    • all routines (e.g., method, converter, template) with the only exception of macro
  • protocol macro
    • Provide an Kotlin-like interface
    • defining setter/getter

Changelog

See CHANGELOG

🥷Author

Twitter

License

Copyright © 2021 Neo meganeo.programmer@gmail.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.