-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Implementation of godots GDExtensionScriptInstance
#492
Implementation of godots GDExtensionScriptInstance
#492
Conversation
d3bf31a
to
5b24d33
Compare
This is very cool, thanks a lot! 🙂 Regarding the CI, you already found some issues. The classes Did you have a project that uses them? I'm thinking about ways to test this (maybe in an automated way)...? 🤔 |
5b24d33
to
8ca5b52
Compare
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-492 |
@Bromeon I'm using them in https://github.com/titannano/godot-rust-script. CI tests are also something I have been thinking about. To create a 💭 Perhaps we could implement the minimally stubbed out interfaces in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! im glad someone did this since i remember it being kinda tedious to do last time.
You leak values a lot without much justification, it'd be nice to know why it's fine to leak memory when you do. Whether it is because you're actually passing ownership to godot, or the memory will later be freed by another callback.
Maybe it'd be nice if we made create_script_instance
return a smart pointer? one which stores the instance pointer, and is able to check if it has been freed yet. And have that object implement ScriptInstance
?
Also you haven't documented any of the public methods/structs, you should do that.
And some tests as @Bromeon mentioned would be good. It should be possible to create a very barebones script "language", maybe one that just checks if a script contains one of a few hardcoded strings to represent the different things we wanna check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding tests:
💭 Perhaps we could implement the minimally stubbed out interfaces in
itest
and attach some script to a Godot object… I haven't tried it yet.
That would be great, because it would likely reveal UB and memory leaks during CI. Currently there's no way to check the safety of this PR, since the functionality is never used.
Let us know if you need some support there 🙂
@lilizoey so
yes, I should do that. Thanks. |
@Bromeon I just noticed that Godot 4.2 will introduce a second API ( |
Yep, that's definitely fine! Let's tackle one thing at a time, this is already great work 🙂
In general, I think this is OK and the workflow intended by Godot. The surprise is probably there because this is not obvious from the code when just looking at one of the functions. As mentioned, I would probably write a few functions that convert Rust domain models to C pointer types and back (so all conversions go through those functions). Maybe they could be named something that highlights the change of ownership, e.g. |
61ec6c8
to
c5aabcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
I added lots of small formatting comments, but most of them come with suggestions that you can directly commit in the UI, and later squash locally.
Also, how do we want to proceed with tests? You said you're already using this in a project of yours?
25a66cd
to
9026b9d
Compare
146011c
to
30d9652
Compare
I have now implemented While implementing tests, I came into a situation where the engine would crash because the
EDIT: I was able to resolve the memory leaks. |
39de807
to
0f677b0
Compare
66d8a09
to
ebdab39
Compare
ebdab39
to
94ca2a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased onto master (after Godot 4.2 change). Most things look good to me now.
A general note about the public API. The test does this:
#[godot_api]
impl IScriptExtension for TestScript {
unsafe fn instance_create(&self, _for_object: Gd<Object>) -> *mut c_void {
create_script_instance(TestScriptInstance::new(self.to_gd().upcast())) as *mut c_void
}
fn can_instantiate(&self) -> bool {
true
}
}
It would be good if we could somehow abstract the raw FFI types for the user. Remember, sys::
(i.e. the godot-ffi
crate) is not part of the public API. I'm aware that not all the things have been properly mapped to public pendants yet, but let's avoid them where possible.
For example, instance_create
could directly return a *mut c_void
, no? Then your implementation could become simpler (and a bit more explicit with the let script
declaration):
#[godot_api]
impl IScriptExtension for TestScript {
unsafe fn instance_create(&self, _for_object: Gd<Object>) -> *mut c_void {
let script: Gd<Script> = self.to_gd().upcast();
create_script_instance(TestScriptInstance::new(script))
}
fn can_instantiate(&self) -> bool {
true
}
}
(Btw, I think we mark IScriptExtension::instance_create
incorrectly as unsafe
, but we can fix that later...)
158ca24
to
99da879
Compare
@Bromeon so the last |
99da879
to
dc8b552
Compare
I think that's OK for now, we still need to map some remaining ones. Maybe you can add a Thanks a lot for all the updates! 👍 |
dc8b552
to
e935213
Compare
@lilizoey any more comments on this one? Do you think we can merge a first version soon? |
I think it looks good yeah |
@TitanNano Thanks a lot for the great work and your patience during the lengthy review process! 👍 I can fix the remaining CI issues. |
e935213
to
91b6cc3
Compare
I have recently worked on an implementation of
GDExtensionScriptInstance
and would now like to contribute it to gdext. This is required to be able to properly implement a customScriptExtension
/ScriptLanguageExtension
.Please let me know your thoughts on the changes, and I welcome every feedback.