Skip to content

Variable manual reflection

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

For the example, we will manually reflect the following variable:

//ThirdPartyVar.h
extern int const thirdPartyVariable;

Create a function to build the variable metadata

In any source file, create a function to create our variable metadata:

#include "ThirdPartyVar.h"
#include <string_view>
#include <Refureku/TypeInfo/Variables/Variable.h>

static rfk::Variable const& getVariable_thirdPartyVariable() noexcept
{
	static rfk::Variable var("thirdPartyVariable",
							 std::hash<std::string_view>()("thirdPartyVariable"),
							 rfk::getType<decltype(thirdPartyVariable)>(),
							 &thirdPartyVariable,
							 rfk::EVarFlags::Default);

	return var;
}

Register to the database

In any cpp file, write the following:

#include <Refureku/TypeInfo/Entity/DefaultEntityRegisterer.h>

rfk::DefaultEntityRegisterer registerer_thirdPartyVariable = getVariable_thirdPartyVariable();