vtable
Implement dynamic dispatch through vtable, should works for dynlib.
Summary
| Latest Version | Unknown |
|---|---|
| License | LGPL-3.0 |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:24 |
Tags
Installation
nimble install vtable
choosenim install vtable
git clone https://github.com/codehz/nim-vtable
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| vtable | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Source
| Repository | https://github.com/codehz/nim-vtable |
|---|---|
| Homepage | https://github.com/codehz/nim-vtable |
| Registry Source | nimble_official |
README
vtable for nim
Why choose vtable?
Nim's dynamic dispatch cannot work across dynamic link libraries.
Features
- Define vtable in few lines!
- Use it as normal ref object!
- Can survival across dynlib!
- Type safe!
- 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))