godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Templated and custom-named classes support and test

Open IvanInventor opened this issue 1 year ago • 1 comments

Support for template classes, and, as side effect, classes with custom name, different for actual name. To add template class:

  • Replace GDCLASS() macro with GDCLASS_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

IvanInventor avatar Jan 18 '24 00:01 IvanInventor

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.

dsnopek avatar Jan 19 '24 02:01 dsnopek