#pragma once #include #include #include #include namespace vl::mod { // ---- platform section helpers (ELF) ---- #if defined(__ELF__) #define VL_MOD_SECTION __attribute__((section("vlmods"), used)) #else // Fallback: keep the variable, but discovery code will need a different path on non-ELF. #define VL_MOD_SECTION __attribute__((used)) #endif // CRTP base: derive as `class MyMod : public Mod { ... };` // Requires: `MyMod::MyMod(const Context&)` constructor. template class Mod : public Base { private: // Factory thunk that Core will call via the registration record. static std::unique_ptr _vl_factory(const Context& ctx) { return std::make_unique(ctx); } // One registration record per T in a well-known section. // This creates *no* runtime cost for mods beyond a single static object. static inline const Registration _vl_reg VL_MOD_SECTION = { kModRegMagic, &_vl_factory, typeid(T).name() }; public: // The rest (onStart/onStop/name/version/ctor) is implemented by T. }; } // namespace vl::log