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

Expose enum related methods in ClassDB #52571

Merged
merged 1 commit into from
Sep 16, 2021

Conversation

timothyqiu
Copy link
Member

This PR exposes 4 enum related methods in ClassDB:

  • class_has_enum(class, name) to tell whether name is an enum in class
  • class_get_enum_list(class) to retrieve a list of enums in class
  • class_get_enum_constants(class, enum) to retrieve a list of all valid keys class.enum has.
  • class_get_integer_constant_enum(class, name) to get which enum the constant name belongs to.

Useful when writing plugins.

extends SceneTree

func _init():
        # HTTPClient has enum Method? True
	print("HTTPClient has enum Method? ", ClassDB.class_has_enum("HTTPClient", "Method"))

        # Enums in HTTPClient: [Status, Method, ResponseCode, ConnectFlags]
	print("Enums in HTTPClient: ", ClassDB.class_get_enum_list("HTTPClient"))

        # Values in HTTPClient.Method: [METHOD_GET, METHOD_HEAD, METHOD_POST, METHOD_PUT, METHOD_DELETE, METHOD_OPTIONS, METHOD_TRACE, METHOD_CONNECT, METHOD_PATCH, METHOD_MAX]
	print("Values in HTTPClient.Method: ", ClassDB.class_get_enum_constants("HTTPClient", "Method"))

        # METHOD_GET belongs to enum: Method
	print("METHOD_GET belongs to enum: ", ClassDB.class_get_integer_constant_enum("HTTPClient", "METHOD_GET"))

	quit()

Copy link
Member

@mhilbrunner mhilbrunner left a comment

Choose a reason for hiding this comment

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

I would have needed something like this in multiple cases I had to abandon in the past.

Implementation looks good and unsurprising.

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.

3 participants