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 abstraction for ScriptInstanceExtension #196

Closed
lilizoey opened this issue Mar 21, 2023 · 4 comments
Closed

Add abstraction for ScriptInstanceExtension #196

lilizoey opened this issue Mar 21, 2023 · 4 comments
Labels
c: engine Godot classes (nodes, resources, ...) feature Adds functionality to the library

Comments

@lilizoey
Copy link
Member

When creating a language extension for godot, you need to create instances of your scripts. These are the actual objects that will run the code that your scripts define. For performance reasons, these are not normal godot classes, but instead a pointer to the instance and a vtable (struct of function pointers).

This means that if you want to use/create these instances, you currently need to do a lot of manual pointer casting and ffi-stuff. Generally through the method script_instance_create and using the GDExtensionScriptInstanceInfo struct directly.

Ideally there would be some abstraction, probably a trait or something that will let you easily create the instance, and a trait for the GDExtensionScriptInstanceInfo struct, as it is effectively just an interface for what methods are supported.

Another issue is that this is almost entirely undocumented, as there is no godot documentation page (that i could find) that talks about this.

@Bromeon Bromeon added feature Adds functionality to the library c: engine Godot classes (nodes, resources, ...) labels Mar 21, 2023
@Gallilus
Copy link

Hi Sayaks,
Do you have a example of what needs to be done manualy?
I am currently working on a unrelated project and can not get GDExtensionScriptInstanceInfo to work without compilation errors.

@lilizoey
Copy link
Member Author

lilizoey commented Mar 31, 2023

Hi Sayaks, Do you have a example of what needs to be done manualy? I am currently working on a unrelated project and can not get GDExtensionScriptInstanceInfo to work without compilation errors.

firstly you're likely gonna need to include both #204 and #207, or manually work around them

then you can have a look at https://github.com/sayaks/godot-mun where i messed around with it a bit. i also actually documented some undocumented functions from godot. a lot of the code is messy especially because i did not have #204 or #207 implemented, you can see i used a hacky patch in the cargo.toml for gdext, and i also inlined some of the #[godot_api] macros to fix issues. but the project did compile and run. i didnt quite get far enough to actually begin writing functional code but i got all the way to where the next step was actually writing the runtime (or in my case, integrating the mun runtime)

most (hopefully all) of the really hacky issues i faced are fixed in the two issues i mentioned.

@Gallilus
Copy link

Gallilus commented Apr 4, 2023

Thanks, It seems that in C++ I needed to define the function (I wanted to point at in GDExtensionScriptInstanceInfo) outside any class definition.

@Bromeon
Copy link
Member

Bromeon commented Dec 28, 2023

Implemented in #492.

@Bromeon Bromeon closed this as completed Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: engine Godot classes (nodes, resources, ...) feature Adds functionality to the library
Projects
None yet
Development

No branches or pull requests

3 participants