-
Notifications
You must be signed in to change notification settings - Fork 22
Function manual reflection
Julien SOYSOUVANH edited this page Oct 26, 2021
·
2 revisions
For the example, we will manually reflect the following function:
//ThirdPartyFunc.h
inline int thirdPartyFunction(int i, float j) { return i + (int)j; }
In any source file, create a function to create our function metadata:
#include "ThirdPartyFunc.h"
#include <string_view>
#include <Refureku/TypeInfo/Functions/Function.h>
static rfk::Function const& getFunction_thirdPartyFunction() noexcept
{
static bool initialized = false;
static rfk::Function func("thirdPartyFunction",
std::hash<std::string_view>()("thirdPartyFunction"),
rfk::getType<int>(),
new rfk::NonMemberFunction<int(int, float)>(&thirdPartyFunction),
rfk::EFunctionFlags::Inline);
if (!initialized)
{
initialized = true;
func.setParametersCapacity(2);
func.addParameter("i", std::hash<std::string_view>()("thirdPartyFunction i"), rfk::getType<int>());
func.addParameter("j", std::hash<std::string_view>()("thirdPartyFunction j"), rfk::getType<float>());
}
return func;
}
In any cpp file, write the following:
#include <Refureku/TypeInfo/Entity/DefaultEntityRegisterer.h>
rfk::DefaultEntityRegisterer registerer_thirdPartyFunction = getFunction_thirdPartyFunction();