I’ve been experimenting with static reflection in the gcc16 trunk. I’ve built a library that lets you annotate class/struct methods and inject behavior through attributes.
You mark methods as hookable with
[[=splice::hook::hookable{}]], then you can inject before/after/return hooks at runtime through a registry. You can cancel calls, override return values, rewrite arguments and control execution order by changing the priority of your hooks, all without touching the original class.It also has a wire system for signal/slot connections. Slots declare which signal they handle via reflection attributes, and you can connect specific, or all signals on a listener. Listeners can also be paused, resumed, and they automatically disconnect when destroyed via RAII. If you want to wire a listener to for example, an on_click method on a class, you just add an attribute:
[[SPLICE_WIRE_SLOT(.signal = ^^MyClass::on_click)]]This currently requires GCC 16 (built from a snapshot) and the
-freflection compiler flag. Still early, but all the tests pass and the API feels simple to use. Eventually, I want to use the same reflection machinery to generate FFI bindings for Lua, and maybe other scripting languages too.GitHub: https://github.com/FloofyPlasma/splice
Curious if anyone else is experimenting with the reflection coming in C++ 26.
https://redd.it/1rxj838
@r_cpp