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

[DRAFT] Add ScriptInstanceExtension class which mimicks the API of Godot's internal ScriptInstance class #1544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dsnopek
Copy link
Collaborator

@dsnopek dsnopek commented Aug 7, 2024

Background

Godot's internal ScriptInstance class (which is used in implementing scripting languages, like GDScript) isn't exposed the normal way, because we don't want scripts (ex a user script written in GDScript) to be able to directly interact with it.

Instead, GDExtensions get a special API from gdextension_interface.h to create script instances, allowing GDExtensions to provide new scripting languages for Godot.

However, working directly with that C API from C++ isn't ideal. And it also means big differences between GDExtensions and modules.

A number of extension projects have made their own C++ wrapper classes over this API to make life easier:

Given that this is something frequently done, I personally think it makes sense to have a wrapper in godot-cpp, so each project doesn't need to recreate it.

Implementation

This PR has the implementation I used in 'godot-gravity-lang', updated for the latest gdextension_interface.h, but I haven't re-tested it.

The main thing I don't like about it, is that it doesn't exactly mimick the API of ScriptInstance because it uses some types from gdextension_interface.h, rather than the equivalent Godot types (most of which also exist in godot-cpp).

The reason for this is that we'd need to copy data back and forth between the Godot types and gdextension_interface.h types, but script instances need to aim to be fairly performant. However, complete API compatibility may be worth it? It's something we'll need to discuss.

Making a DRAFT for now so that we can discuss whether or not we want this in godot-cpp, and if this implementation makes sense.

@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label Aug 7, 2024
@dsnopek dsnopek added this to the 4.x milestone Aug 7, 2024
@dsnopek dsnopek requested a review from a team as a code owner August 7, 2024 19:55
@dsnopek
Copy link
Collaborator Author

dsnopek commented Aug 12, 2024

We discussed this PR at the last GDExtension meetup, and decided that it'd be best for ScriptInstanceExtension to exactly match the method signatures from Godot, even if that means allocating and copying a bunch of extra memory.

I've updated this PR with everything that I think we need to do in order to do that, however, I still haven't had a chance to actually test it. So, leaving as a draft until I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement on the current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant