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 type_string() utility #69624

Merged

Conversation

Kubulambula
Copy link
Contributor

@Kubulambula Kubulambula commented Dec 5, 2022

Closes #1860

Adds typeof_string() method, using Variant::get_type_name() effectively just exposing this method to GDScript.

This method goes hand in hand with the already implemented error_string() utility. Both of these methods are extremely useful for plugin development where user interaction is expected.

The proposal describes a method that prints the name of the variable directly without the typeof() step between. But I believe that this makes this function more versatile and a method like that can be simply made like this:

func typeofname(x):
    return type_string(typeof(x))

@Kubulambula Kubulambula requested review from a team as code owners December 5, 2022 21:03
@MewPurPur
Copy link
Contributor

Regarding the PR itself: I love this feature and I'll be using it a ton in debugging. But since 4.0 is in feature freeze and this doesn't fix any bugs, it will likely not make the cut for now.

@MewPurPur
Copy link
Contributor

MewPurPur commented Dec 5, 2022

Since this is a small feature, the commits need to be squashed into one. Here's a link to our tutorial on this: https://docs.godotengine.org/en/stable/community/contributing/pr_workflow.html#the-interactive-rebase

@Kubulambula
Copy link
Contributor Author

Since this is a small feature, the commits need to be squashed into one. Here's a link to our tutorial on this: https://docs.godotengine.org/en/stable/community/contributing/pr_workflow.html#the-interactive-rebase

Thanks! I always find a way to mess my branch up

@Chaosus Chaosus added this to the 4.x milestone Dec 6, 2022
@20milliliter
Copy link

@Kubulambula Is this PR ready? I would love this feature, and it could make 4.1.

@Kubulambula
Copy link
Contributor Author

@Kubulambula Is this PR ready? I would love this feature, and it could make 4.1.

Yes it should be ready as it does not change anything and just exposes an already present function and is just waiting for approval.

@Kubulambula
Copy link
Contributor Author

After looking at it though, maybe type_string() would be more fitting?

Because you get the name of type that you get from typeof() and typeof_string() implies that is gets the string type of something.

Any thoughts?

@20milliliter
Copy link

20milliliter commented May 27, 2023

I think it would, yes. type_string() would make it consistent with the error_string() method.

@MewPurPur
Copy link
Contributor

MewPurPur commented May 27, 2023

This is clearly the correct implementation, I think it's a matter of whether we approve of the feature and if so, when we get to merging this. And I also prefer type_string() personally.

@Kubulambula Kubulambula force-pushed the add-`typeof_string()`-utility branch from b861210 to e9388b7 Compare May 28, 2023 13:14
@Kubulambula Kubulambula changed the title Add typeof_string() utility Add type_string() utility May 28, 2023
@Kubulambula Kubulambula force-pushed the add-`typeof_string()`-utility branch from c3c975d to f61cfc3 Compare May 31, 2023 18:29
@dalexeev
Copy link
Member

Need to rebase the branch and resolve conflicts.

@Kubulambula
Copy link
Contributor Author

Need to rebase the branch and resolve conflicts.

Should be good now.

@Kubulambula Kubulambula requested review from a team as code owners September 25, 2023 17:17
@Kubulambula
Copy link
Contributor Author

@AThousandShips I think that I somehow fixed it. Thank you for your help and patience with me ❤️

core/variant/variant_utility.cpp Outdated Show resolved Hide resolved
core/variant/variant_utility.cpp Outdated Show resolved Hide resolved
core/variant/variant_utility.cpp Outdated Show resolved Hide resolved
core/variant/variant_utility.h Outdated Show resolved Hide resolved
Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove the variant_get_type_name() function in GDScript tests by the way:

static func variant_get_type_name(type: Variant.Type) -> String:
match type:
TYPE_NIL:
return "Nil" # `Nil` in core, `null` in GDScript.
TYPE_BOOL:
return "bool"
TYPE_INT:
return "int"

And replace it here:

return variant_get_type_name(property.type)

-	return variant_get_type_name(property.type)
+	return type_string(property.type)

Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@YuriSizov YuriSizov modified the milestones: 4.x, 4.2 Sep 28, 2023
Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the note, it looks good!

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems useful to me.

@akien-mga akien-mga merged commit e64fce3 into godotengine:master Oct 3, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add typeofname() to get a name of a type rather than its enumerated value
9 participants