Updated Playing with CPP VTABLE from Nim (markdown)
This commit is contained in:
parent
9dfc7bfe5c
commit
35bd8f293b
|
@ -142,6 +142,7 @@ proc nvGetCharRange*(dv: IDocument, buf: cstring, pos, len: int) =
|
|||
|
||||
Again, we can see how actually C++ compilers translate `->` operator when calling virtual functions, it will use the right index to the vtable and call the function via pointer, that what we also do in Nim, cast the typeless pointer to proc pointer and call it, don't forget that the first argument is also a pointer to the class instance.
|
||||
|
||||
### Conclusion
|
||||
That's it, not too difficult heh? It's not too difficult because we are not dealing with C++ name mangling here, only dealing with pointers and calling convention, Nim can handle that perfectly, although a bit verbose compared to C++ style.
|
||||
|
||||
What about C++ ordinary [member] functions?, well that's another story, C++ name mangling can be a nightmare if you try to solve that in Nim, because every C++ compiler have their own flavor/style of name mangling, but if you know the exact formula of C++ name mangling, please write another wiki!
|
Loading…
Reference in New Issue