No description
Find a file
2020-12-31 16:01:06 +08:00
src fix for allow recursive interface 2020-12-31 16:00:11 +08:00
tests fix generic impl 2020-12-26 18:06:50 +08:00
.gitignore add vscode to gitignore 2020-12-26 11:13:52 +08:00
README.md add features 2020-12-26 18:14:11 +08:00
vtable.nimble bump version to v0.3.3 2020-12-31 16:01:06 +08:00

vtable for nim

Why choose vtable?

Nim's dynamic dispatch cannot work across dynamic link libraries.

Features

  1. Define vtable in few lines!
  2. Use it as normal ref object!
  3. Can survival across dynlib!
  4. Type safe!
  5. Support nim's generic!

DOCS

Working in progress.

Example usage:

trait MyInterface:
  method sayName*(self: ref MyInterface)
  method add*(self: ref MyInterface, lhs, rhs: int): int

type MyClass = object of RootObj
  name: string

proc newMyClass(name: string): ref MyClass =
  new result
  result[].name = name

impl MyClass, MyInterface:
  method sayName(self: ref MyClass) =
    echo "I'm ", self.name

  method add(self: ref MyClass, lhs, rhs: int): int =
    lhs + rhs

proc testmethod(x: ref MyInterface, a: int): int =
  x.sayName()
  x.add(a, 2)

check 3 == testmethod(newMyClass(1))