[DRAFT] Add ScriptInstanceExtension
class which mimicks the API of Godot's internal ScriptInstance
class
#1544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 fromgdextension_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.