Skip to content

Inject reflection code

Julien SOYSOUVANH edited this page Oct 26, 2021 · 3 revisions

To add reflection to your program, Refureku generates reflection metadata in separate files, that must be injected in your own code. Whenever you add reflected entities to one of you header files, you must ensure that you follow the below rules:

  1. Include the generated header file as your last include in your header file.
  2. Add the file macro at the very end of your header file.
//Example.h
#pragma once

//Other includes...

#include "Generated/Example.rfkh.h"

//Your code containing reflected entities here

//File_[FileNameWithoutExtension]_GENERATED
File_Example_GENERATED

Note: By default, the generator generates file and macro names so that name collisions are rare. However you can see that if 2 reflected files have the same name (regardless of their respective path), both the generated files and the macro names will overlap, hence breaking the injected code. This is avoidable by adjusting a few settings in the generator's MacroCodeGenUnit.

  1. Include the generated source file as your last include in any cpp file of your project. The only requirement is that it is included in a single translation unit.
//Example.cpp
//Other includes...

#include "Generated/Example.rfks.h"

Note: It is not necessary to include Example.h manually since it is automatically included in the generated source file.

Clone this wiki locally