Hello.
In C I can use void pointer to store any pointer to some data. It can be helpful when type is unknown because it related to external source (something can use my library but replaces some functions to own and wants store own's object inside of my object). Does Nim have something for this? I know that I can still use void pointers but it lacks GC and pointer-less magic.
I know about generics but it creates objects subtypes (and returns to original problem if I places my objects in one array).
In some case I can use object variant as replacement for union. I saw sources for SDL and Nim's SDL wrapper. But why it use some pointer casting/template magic instead of simply wrapping C structures/unions to Nim's objects syntax? I not fully understand for now how Event object casts to KeyboardEvent for example.
Is it correct that if I use conditional fields Nim simply creating many object type copies?
Does Nim have something for this?
Yes, you can use a closure or a RootRef (which is a ref so you get automatic memory management).