-
-
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 get_script_instance()
to GDExtension
#7199
Comments
get_script_instance()
to GDExtension
I'm not super familiar with how scripting languages are implemented in Godot (this is an area that I hope to spend some time learning soon!), but if you have a pointer to an Object, you should be able to call the Would that get you access to what you need? |
No, unfortunately |
Ah, ok, thanks! I've spent the weekend learning more about the scripting language APIs in Godot and GDExtension, and I do think it would be nice to have a function like you described added to the GDExtension interface. While it is possible to solve this problem without it (see below!), it is a bit of work to access a piece of information that is "right there" and should be easier to get. If you make a PR for this, I'd happily review it! But if you were interested in a way to solve this without changing the GDExtension interface: I looked at the Godot Luau bindings, and they've got a So, in their Hopefully, that makes sense! Trying to explain code in prose is always tricky :-) |
Yeup, that makes sense and I figured that would be the workaround. I'm working on updating |
Thanks, sounds good!
It'd be nice to bake the language check into the |
Potentially. I think the only way available to us right now is to pass in the GDExtensionScriptInstanceDataPtr object_get_script_instance(GDExtensionConstObjectPtr p_language, GDExtensionConstObjectPtr p_object); Not necessarily relevant for this conversation, but I'm wondering how / if ScriptLanguages can talk to each other in the future. Topic for another time. |
That signature seems good to me! |
Actually, the one thing I'd say about that signature is that the order of the arguments should probably be swapped. All the other |
Describe the project you are working on
I'm working on binding Dart as both an extension and scripting language in Godot:
https://github.com/fuzzybinary/godot_dart/
Describe the problem or limitation you are having in your project
I need to be able to call Godot functions from GDExtension which return Objects, then cast these objects to defined by scripts.
For example from 3D tutorial
Currently, cast is calling
gdextension_object_cast_to
which fails because the Mob type (defined only in scripts) does not have a class tag.Describe the feature / enhancement and how it helps to overcome the problem or limitation
Adding
gdextension_get_script_instance
would allow me to do the following in mycast
functtion:gdextension_object_cast_to
gdextension_get_script_instance
and check if the language is our languageDescribe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Add gdextension_get_script_instance to the next version of GDExtension
If this enhancement will not be used often, can it be worked around with a few lines of script?
The only workaround I can see is to have my ScriptLanguageExtension or ScriptExtension store pointers to all ScriptInstances that are created, and use that to do casting.
Is there a reason why this should be core and not an add-on in the asset library?
Because it involves the interface for creating add-ons.
The text was updated successfully, but these errors were encountered: