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 static method support to ClassDB #59314

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

reduz
Copy link
Member

@reduz reduz commented Mar 19, 2022

  • Based on the work done for Variant in the past.
  • Added ClassDB::bind_static_method
  • Cleaned up ClassDB::bind_method to use variadic templates.

This adds support for having static methods in Object derived classes.
Note that this does not make it work yet in GDScript, Visual Script or Mono and, while it works for GDExtension, GodotCPP needs to be updated.

@reduz reduz requested a review from a team as a code owner March 19, 2022 12:22
@KoBeWi KoBeWi added this to the 4.0 milestone Mar 19, 2022
@reduz reduz force-pushed the add-static-methods-to-classdb branch from cbe529a to 69bfb21 Compare March 20, 2022 09:54
@reduz reduz requested a review from a team as a code owner March 20, 2022 09:54
@bruvzg
Copy link
Member

bruvzg commented Mar 22, 2022

diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp
index 31af28b783..9acc28f51e 100644
--- a/core/extension/extension_api_dump.cpp
+++ b/core/extension/extension_api_dump.cpp
@@ -666,6 +666,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
 						Dictionary d2;
 						d2["name"] = String(method_name);
 						d2["is_const"] = (F.flags & METHOD_FLAG_CONST) ? true : false;
+						d2["is_static"] = (F.flags & METHOD_FLAG_STATIC) ? true : false;
 						d2["is_vararg"] = false;
 						d2["is_virtual"] = true;
 						// virtual functions have no hash since no MethodBind is involved
@@ -708,6 +709,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
 
 						d2["is_const"] = method->is_const();
 						d2["is_vararg"] = method->is_vararg();
+						d2["is_static"] = method->is_static();
 						d2["is_virtual"] = false;
 						d2["hash"] = method->get_hash();
 

A few extra changes required for godot-cpp binding generator.

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.

Needs amending as suggested by @bruvzg, otherwise the code seems fine to me. Compiled locally and didn't notice any obvious issue (as mentioned the File.file_exists static method added in this PR doesn't work in GDScript yet, but it's still usable as non-static).

@reduz
Copy link
Member Author

reduz commented Mar 22, 2022

@bruvzg great catch, thanks!

* Based on the work done for Variant in the past.
* Added `ClassDB::bind_static_method`
* Cleaned up ClassDB::bind_method to use variadic templates.

This adds support for having static methods in Object derived classes.
Note that this does not make it work yet in GDScript or Mono and, while it works for GDExtension, GodotCPP needs to be updated.
@reduz reduz force-pushed the add-static-methods-to-classdb branch from 69bfb21 to 2f65127 Compare March 22, 2022 15:27
@akien-mga akien-mga merged commit 9162f27 into godotengine:master Mar 22, 2022
@akien-mga
Copy link
Member

Thanks!

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.

4 participants