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

GDScript -> Rust calls: parameter and return type conversions #125

Open
Bromeon opened this issue Feb 13, 2023 · 2 comments
Open

GDScript -> Rust calls: parameter and return type conversions #125

Bromeon opened this issue Feb 13, 2023 · 2 comments
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library

Comments

@Bromeon
Copy link
Member

Bromeon commented Feb 13, 2023

We need to work out rules regarding how values from and to Rust #[func] methods are passed, when invoked from GDScript. Most notably, we should decide which implicit conversions (if at all) we provide. Then, we should test those, and make sure unwanted conversions don't happen (and panic instead).

Generally I'd like an approach where we start quite restrictive, and then can loosen restrictions on a demand basis. This not only avoids bugs and makes things more explicit, but it also prevents performance traps where someone passes Array to a Vec, needing reallocation and copying each frame.

Or we keep type-safety, but provide tooling to avoid excessive user-side converting.

Examples:

GDScript Rust allowed
int f32
float i32
float u32
String std::string::String
StringName std::string::String
Array Array<i32>
Array Array<Variant>
Array Vec<Variant>
Array[int] Array<i32>
Array[int] Array<Variant>
... Variant
... Option<T>
... Result<T, E>
@Bromeon Bromeon added feature Adds functionality to the library c: register Register classes, functions and other symbols to GDScript labels Feb 13, 2023
@Bromeon Bromeon mentioned this issue Feb 13, 2023
@ttencate
Copy link
Contributor

There is prior art in GDNative as well. It lets you receive usize and u8 at least, which are fallible conversions from the engine's i64 type. Especially usize is very practical to have for e.g. indices. I haven't checked, but I assume the conversion will panic if the value is out of range.

@Bromeon
Copy link
Member Author

Bromeon commented Dec 28, 2023

See also #263.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library
Projects
None yet
Development

No branches or pull requests

2 participants