Skip to content
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 GDExtension function to get Object class name #73511

Merged
merged 1 commit into from
May 22, 2023

Conversation

dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Feb 17, 2023

This adds a function for GDExtension to get the class name of an Object, in order to support a fix to godot-cpp: godotengine/godot-cpp#1050

Please see that PR for the full details!

This is draft, because that PR is still a draft, and this PR may be updated before it's ready.

The other PR is out of draft, so taking this one out of draft too!

Back in draft, since I'm rebasing this on #76406

UPDATE: #76406 was merged, so I'm taking this out of draft!

@dsnopek
Copy link
Contributor Author

dsnopek commented Mar 20, 2023

Now that Godot 4.0 stable has happened, and merging this as-is would break the GDExtension ABI, I'd love some advice on how we plan on making those sort of changes in a "safe-ish" :-) way.

All we need to do here is add another function pointer to GDExtensionInterface. With GDNative in Godot 3.x, there was a "next" pointer at the end of some structures, so we could add more later. We don't appear to have something like that here?

If this hasn't been figured out yet, and there's a discussion about it, I'd love to be a part of that!

@dsnopek dsnopek marked this pull request as draft April 27, 2023 22:07
@dsnopek
Copy link
Contributor Author

dsnopek commented Apr 27, 2023

Converting this to a draft while PR #76406 is in progress. If that gets merged, then I'll update this PR to add the new function to GDExtension's interface using the new mechanism

@dsnopek
Copy link
Contributor Author

dsnopek commented May 10, 2023

I've updated this to be based on #76406

So, this'll need to wait until at least that one is merged before this can come out of draft again.

However, there is one more thing I'd like to add: this doesn't take into account classes that come from other GDExtensions. It should get the class name, and if that's a built in class or a class from the current extension, return it. But if the class is from another extension, it should return the class name of the built in class it descends from.

Update: This last bit is now in too!

@dsnopek
Copy link
Contributor Author

dsnopek commented May 10, 2023

Alright, I just got in the last thing I wanted to add here! So, now this one is just waiting on PR #76406 in order to come out of draft.

@dsnopek dsnopek marked this pull request as ready for review May 16, 2023 20:41
@dsnopek
Copy link
Contributor Author

dsnopek commented May 16, 2023

This is finally really ready for review! I've also put it on the agenda for the next GDExtension meeting :-)

core/object/object.cpp Outdated Show resolved Hide resolved
@BastiaanOlij
Copy link
Contributor

Isn't the class name already accessible through the macro functions added to the class?

cc @vnen

@dsnopek
Copy link
Contributor Author

dsnopek commented May 18, 2023

@BastiaanOlij:

Isn't the class name already accessible through the macro functions added to the class?

We can't use that in this case for two reasons:

  1. This is before the wrapper class is created (in fact, we need it to make sure the correct wrapper class is created - see the companion godot-cpp PR which discusses the bug this is needed to fix)
  2. We need the class name from the perspective of this particular GDExtension. If the class comes from this extension, we need the actual class name, but if it's from another extension we need the name of the built-in class it descends from

@BastiaanOlij
Copy link
Contributor

@dsnopek ah I get it, damn thats funky

@dsnopek
Copy link
Contributor Author

dsnopek commented May 19, 2023

Discussed at the GDExtension meeting, and we think this solution makes sense. It is a problem that has also come up in the Python and Rust bindings.

Copy link
Member

@touilleMan touilleMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@akien-mga akien-mga modified the milestones: 4.x, 4.1 May 22, 2023
core/object/object.h Outdated Show resolved Hide resolved
@akien-mga akien-mga merged commit 80bf8fd into godotengine:master May 22, 2023
@akien-mga
Copy link
Member

Thanks!

@dsnopek dsnopek deleted the gdextension-object-name branch July 22, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants