godot-cpp
godot-cpp copied to clipboard
Templated and custom-named classes support and test
Support for template classes, and, as side effect, classes with custom name, different for actual name. To add template class:
- Replace
GDCLASS()macro withGDCLASS_TEMPLATE()
template <class T>
class ExampleTemplated : public Object {
GDCLASS_TEMPLATE(ExampleTemplated, Object);
};
- For each template instantiation, set name of this class, and optionally explicitly instantiate them
template <>
const char *ExampleTemplated<int>::_template_class_name = "ExampleTemplatedInt";
template class ExampleTemplated<int>;
template <>
const char *ExampleTemplated<float>::_template_class_name = "ExampleTemplatedFloat";
template class ExampleTemplated<float>;
As a side effect after changes, classes with custom name are now also easily created with GDCLASS_NAME(ExampleCustom, Object, "CustomExample"); macro
Thanks!
This is an interesting feature. However, one of the design goals of godot-cpp is to provide the same API as is available internally in Godot itself. So, for this to be added to godot-cpp, it'd need to be added first to Godot, so you'd need to propose it there first.