oop_utils

Macro for building OOP class hierarchies based on closure methods.

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install oop_utils
choosenim install oop_utils
git clone https://github.com/bluenote10/oop_utils

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
oop_utils - - - - - - -

Source

Repository https://github.com/bluenote10/oop_utils
Homepage https://github.com/bluenote10/closure_methods
Registry Source nimble_official

README

oop_utils Build Status license

oop_utils provides macros that allow to easily create OOP class hierarchies.

It comes in two different flavors: - Standard classes: Allows to define type hierarchies based on Nim's standard method dispatch. - Closure classes: Allows to define type hierarchies based on closure method dispatch.

The two approaches have minor syntactical differences, but share the same general scheme. For comparison:

import oop_utils/standard_class

# A standard class:
# - The object instance is attached to a `self` symbol.
# - Initialization + field definitions go into the ctor proc.
class(Counter):
  ctor(newCounter) proc(init: int) =
    self:
      counter = init

  method inc*() {.base.} = self.counter.inc
  method dec*() {.base.} = self.counter.dec
  method get*(): int {.base.} = self.counter

vs.

import oop_utils/closure_class

# A closure class:
# - No `self` symbol required.
# - Initialization + field definitions go into main scopre to emphasize closure nature.
class(Counter):
  ctor(newCounter) proc(init: int)

  var counter = init

  proc inc*() = counter.inc
  proc dec*() = counter.dec
  proc get*(): int = counter