One of the cooler features of Nim that many doesnt know about is static introspection. Imagine you want to know the parent of type at compile time. There is no built in function for it, but no worries, it can be implemented like so:
1/2
#nimlang #gamedev #indiegamedev
1/2
#nimlang #gamedev #indiegamedev
Oct 10, 2023 · 2:44 PM UTC
1
3
11
929

![proc parent*(T:typedesc): string =
let child = bindSym typeof(T).name
let parent = child.getImpl()[^1][1]
case parent.kind:
of nnkOfInherit:parent[0].strVal()
else: ""
#example:
type
Foo = object of RootObj
Boo = object of Foo
static:
assert parent(Boo) == "Foo"](/pic/media%2FF8FflcsWwAAJQzR.png)