Skip to content

Classname Alias #332

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

Closed
hapenia opened this issue Jul 7, 2023 · 1 comment · Fixed by #419
Closed

Classname Alias #332

hapenia opened this issue Jul 7, 2023 · 1 comment · Fixed by #419
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library good first issue Good for newcomers

Comments

@hapenia
Copy link
Contributor

hapenia commented Jul 7, 2023

In godot engine, each class should have unique name, since their's no mod/package/namespace. But in rust, we can have multiple structs with a same name (in different mods). When you try to export two or more structs with the same name to Godot, a very subtle runtime error occurs. If you don't start the editor from the command line, you won't see the error message.

image

So we need a way to provide an alias to the registered class.

@Bromeon Bromeon added feature Adds functionality to the library c: register Register classes, functions and other symbols to GDScript good first issue Good for newcomers labels Jul 7, 2023
@Bromeon
Copy link
Member

Bromeon commented Jul 7, 2023

Suggested syntax:

#[derive(GodotClass)]
#[class(init, base=Node2D, rename=GodotName)]
struct RustName {
   ... 
}

Should also be documented in the GodotClass derive macro.

fpdotmonkey added a commit to fpdotmonkey/gdext that referenced this issue Sep 21, 2023
There's an issue that two structs with the same name in different
modules will conflict with each other when sent to Godot since only the
struct name is considered.  This resolves that by allowing the API user
to manually change the name of the class as Godot understands it.  This
also improves the error message that occurs when theres are aliased
classes.

Future work may seek to catch this issue at compile time rather than at
runtime.

Relevant to godot-rust#332
fpdotmonkey added a commit to fpdotmonkey/gdext that referenced this issue Sep 21, 2023
There's an issue that two structs with the same name in different
modules will conflict with each other when sent to Godot since only the
struct name is considered.  This resolves that by allowing the API user
to manually change the name of the class as Godot understands it.  This
also improves the error message that occurs when theres are aliased
classes.

Future work may seek to catch this issue at compile time rather than at
runtime.

Relevant to godot-rust#332
fpdotmonkey added a commit to fpdotmonkey/gdext that referenced this issue Sep 21, 2023
There's an issue that two structs with the same name in different
modules will conflict with each other when sent to Godot since only the
struct name is considered.  This resolves that by allowing the API user
to manually change the name of the class as Godot understands it.  This
also improves the error message that occurs when theres are aliased
classes.

Future work may seek to catch this issue at compile time rather than at
runtime.

Relevant to godot-rust#332
fpdotmonkey added a commit to fpdotmonkey/gdext that referenced this issue Sep 21, 2023
There's an issue that two structs with the same name in different
modules will conflict with each other when sent to Godot since only the
struct name is considered.  This resolves that by allowing the API user
to manually change the name of the class as Godot understands it.  This
also improves the error message that occurs when theres are aliased
classes.

Future work may seek to catch this issue at compile time rather than at
runtime.

Relevant to godot-rust#332
@Bromeon Bromeon linked a pull request Sep 21, 2023 that will close this issue
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 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants