-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for exposing C++ template classes in GDExtension #9721
Comments
Is it even possible? C++ templates are an element of generic programming. Each template describes a whole family of types/functions. When substituting specific template parameters, different code is generated. This proposal is probably impossible even for GDExtension, not to mention GDScript. This is why we have several hardcoded |
I wonder how the gdscript binding works. It seems to be a interpretive language, I guess. and for the template <typename T, typename measure_t = std::size_t>
class grid;
ClassDB::register_class<grid>(); there is a way to do this: template <template<typename> typename T>
ClassDB::register_class()
{
// do something, like "T<godot::Variant>"
} You should really explain some mechanics of binding between gdscript and the c++ core, it really helps (avoid seeking through the source code...) |
Templates don't exist at runtime, (they don't even really exist throughout most of the compile time either) GDScript only exists at runtime and can only have runtime provided information, Templates don't even exist in the compiler unless you instantiate them and the machine code can't know anything about them, so I'm don't see how this could ever be accomplished in C++. Like template<typename T>
struct Foo { T val };
template class Foo<int>; just becomes struct Foo_i { int val; }; // the name of Foo is likely to a bit more mangled by every compiler, but this is basically what compiler does when it sees a used template, unused templates literally don't exist before the compiler even really gets its hands on much of anything. |
Describe the project you are working on
A highly performance required game, with a c++ template class:
Describe the problem or limitation you are having in your project
I had searching through the source code godot, expecting to found export method for
godot::Array
class, but all in vain.Describe the feature / enhancement and how it helps to overcome the problem or limitation
I hope godot can provide a way to export template class in c++, and detailed description.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
It supposed to be used as:
or using variant:
so two possible implementation, one is to register the type without giving template arguments (I'm doubting myself when I worte this), and the other is to export a derived class which inherits to
godot::RefCounted
andgrid<godot::Variant>
(which means it's a godot class), and do some trick in gdscript to make it usage just like it is a template class.If this enhancement will not be used often, can it be worked around with a few lines of script?
no, it is about gdscript's language binding, which I supposed to be a complicated stuff.
Is there a reason why this should be core and not an add-on in the asset library?
It's about the engine itself, it's highly integrated within the engine, it's part of the engine.
The text was updated successfully, but these errors were encountered: