Skip to content

Create custom properties

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

To define a new property, you just need to create a new reflected struct or class and inherit from rfk::Property. You can optionally use the PropertySettings property to further define how the new property should be used.

//Tooltip.h
#pragma once

#include <utility>  //std::move

//Don't forget this include to be able to use the PropertySettings property
#include <Refureku/TypeInfo/Properties/PropertySettings.h>

#include "Generated/Tooltip.rfk.h"

//Make the Tooltip property valid on methods and functions only.
//It can be attached only once per entity.
//If a virtual method has a tooltip, the overridden versions of the method (if reflected) will inherit the Tooltip property.
struct RFKStruct(PropertySettings(rfk::EEntityKind::Method | rfk::EEntityKind::Function, false, true))
    Tooltip : public rfk::Property
{
    std::string message;

    Tooltip(std::string _message) noexcept:
        message{std::move(_message)}
    {}

    Tooltip_GENERATED
};

File_GENERATED

You can then use the Tooltip property right away by including Tooltip.h:

//TestTooltip.h
#pragma once

#include "Tooltip.h"

#include "Generated/TestTooltip.rfk.h"

RFKFunction(Tooltip("It is working!"))
void testTooltipFunction(){}

File_GENERATED
//main.cpp
#include "TestTooltip.h"

#include <iostream>
#include <Refureku/Refureku.h>

//...

std::cout << rfk::Database::getFunction("testTooltipFunction")->getProperty<Tooltip>()->message << std::endl; //prints "It is working!"

Possible issues

On some systems (Linux), you might get a compilation error when creating a new property using the PropertySettings property:
(.rodata._ZTI16Tooltip[_ZTI16Tooltip]+0x10): undefined reference to `typeinfo for rfk::Property'.

This error appears because the program containing the new property definition has different RTTI settings than Refureku. By default, Refureku doesn't generate RTTI so you are likely to encounter this error if your program uses RTTI.
To fix the issue, you will need to recompile the library and provide the -DGEN_PROPERTY_RTTI=1 argument to cmake.

cmake -B Build/Debug -DCMAKE_BUILD_TYPE=Debug -DGEN_PROPERTY_RTTI=1 -G "Ninja"

RTTI will be generated for the Refureku file "Property.h", and the compilation error should be gone.