Skip to main content

Reflection

The Reflection plugin provides a runtime interface for inspecting and interacting with classes in Tellusim API. It supports querying metadata such as class names, inheritance, constructors, destructors, functions, callbacks, and enumerations. Using this plugin, applications can dynamically construct objects, invoke methods, and access argument information without requiring compile-time type knowledge. Reflection supports function lookup by name, argument count, or full signature, and allows invocation of both instance and static methods.

note

To enable dynamic function and method invocation through the Reflection system, define the global TS_REFLECTION_FUNC macro. Enabling this macro increases the binary size due to additional runtime dispatch logic.

note

All Tellusim classes implement the getClassName() method, which can be used with the Reflection system.

info

The Reflection plugin is used in the System Flow editor.

#include <system/reflection/include/TellusimReflection.h>

Example

// create app
const Reflection *app_refl = Reflection::get("App");
void *app = app_refl->constructor<void*>(Maxu32, argc, argv);

// create window
const Reflection *window_refl = Reflection::get("Window");
void *window = window_refl->constructor<void*>("Platform, uint32_t", app_refl->function<Platform>(app, "getPlatform"), app_refl->function<uint32_t>(app, "getDevice"));
if(!window_refl->function<bool>(window, "isValidPtr")) return false;
String title = String::format("%s Tellusim::Reflection", window_refl->function<const char*>(window, "getPlatformName"));
window_refl->function<void>(window, "setSize", "uint32_t, uint32_t, bool", app_refl->function<uint32_t>(app, "getWidth"), app_refl->function<uint32_t>(app, "getHeight"));
if(!window_refl->function<bool>(window, "create", "const String&, Window::Flags", title)) return false;
if(!window_refl->function<bool>(window, "setHidden")) return false;
window_refl->function<void>(window, "setKeyboardPressedCallback", Maxu32, Window::KeyboardPressedCallback([&](uint32_t key, uint32_t code) {
if(key == Window::KeyEsc) window_refl->function<void>(window, "stop");
}));
window_refl->function<void>(window, "setCloseClickedCallback", Maxu32, Window::CloseClickedCallback([&]() {
window_refl->function<void>(window, "stop");
}));

// create device
const Reflection *device_refl = Reflection::get("Device");
void *device = device_refl->constructor<void*>("Window&", window);
if(!device_refl->function<bool>(device, "isValidPtr")) return false;

Reflection