Overriding C++ clases on the nim side (current best implementation idea) #2
Labels
C++
Issues related specifically to C++ processing
open for design discussion
question
Further information is requested
Base C++ class
cppbase.cpp
Automatically derived generated file - generated for every class definition during wrapping process.
Generated derived class definition
cppderived.hpp
Generated implementation for method implementations
cppderived.cpp
Wrappers
callbacks.nim
To override behavior of the class, you can set implementation callback to a new function:
main.nim
But I still can provide override for the behavior of the object without actually overriding anything, which might be quite useful for various 'DelegatePainter' OOP patterns, where you actually only want to override implementation of a single method and nothing else. With support for passing user data, and setting closures as implementation (and not just
{.cdecl.}
callbacks) it won't be necessary to derive from C++ classes in most cases anyway.-—
standalone classes
In rarer cases where you'd actually need to provide a full-fledged derived class, it is possible to implement some codegen facilities.
I couldn't find a way to generate standalone files that can be injected in nim object hierarchy (at least without some ugly hacks). In order to derive from C++ class, I would generate actual C++ class via nim macros, similarly to nim by example macros.
Will generate following C++ code:
Actually generating C++ code also helps with Qt - I no longer need to reimplement MOC, and instead can just use it as-is.
The text was updated successfully, but these errors were encountered: