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 ClassDB.class_get_api_type() method #90703

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

ZerxZ
Copy link
Contributor

@ZerxZ ZerxZ commented Apr 15, 2024

Expose ClassDB::class_get_api_type() for editor-plugins and other languages wrapper generator.

@ZerxZ ZerxZ changed the title Add get_api_type method to ClassDB Expose ClassDB.get_api_type() Apr 15, 2024
@ZerxZ ZerxZ marked this pull request as ready for review April 15, 2024 21:41
@ZerxZ ZerxZ requested review from a team as code owners April 15, 2024 21:41
@ZerxZ
Copy link
Contributor Author

ZerxZ commented Apr 17, 2024

CI Tests Godot Cpp test fails cause.
It is because godot-cpp repository binding_generator.py script replaces extension_api.json, ClassDB with ClassDBSingleton.
But it does not change return_type or arguments_type the enumeration ClassDB::APIType to ClassDBSingleton::APIType.
@dsnopek @AThousandShips

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

Thanks!

I think this change makes sense, and the code looks good.

However, this will need to be squashed into a single commit, per Godot's pull request workflow. See the docs for a way to do that using git rebase: https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html#the-interactive-rebase

I'll take a look at fixing the godot-cpp issue.

core/core_bind.h Outdated Show resolved Hide resolved
doc/classes/ClassDB.xml Outdated Show resolved Hide resolved
doc/classes/ClassDB.xml Outdated Show resolved Hide resolved
@dsnopek
Copy link
Contributor

dsnopek commented Apr 23, 2024

I just posted PR godotengine/godot-cpp#1445 which will fix godot-cpp with these changes

@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch from 9e88b5c to ac8ecfe Compare April 24, 2024 15:28
@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch from 81e5f13 to 0a093d9 Compare April 24, 2024 22:30
@ZerxZ ZerxZ changed the title Expose ClassDB.get_api_type() Expose ClassDB::get_api_type() ClassDB::get_property_getter() ClassDB::get_property_setter() Apr 24, 2024
@ZerxZ ZerxZ changed the title Expose ClassDB::get_api_type() ClassDB::get_property_getter() ClassDB::get_property_setter() Expose ClassDB::get_api_type() ClassDB::get_property_getter() ClassDB::get_property_setter() method Apr 25, 2024
@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch from 218d286 to 57a6b03 Compare April 25, 2024 08:14
@ZerxZ
Copy link
Contributor Author

ZerxZ commented Apr 25, 2024

I just posted PR godotengine/godot-cpp#1445 which will fix godot-cpp with these changes

Thanks @dsnopek @AThousandShips !
I've already rebase the branch in single comment and run in local you PR success build and work.

@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch from 57a6b03 to a823d50 Compare April 25, 2024 15:02
core/core_bind.h Outdated Show resolved Hide resolved
@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch from a823d50 to 048d9d3 Compare April 25, 2024 22:34
@ZerxZ ZerxZ requested a review from dsnopek April 25, 2024 22:38
@ZerxZ
Copy link
Contributor Author

ZerxZ commented Apr 25, 2024

https://github.com/godotengine/godot/blob/048d9d328cc748d4f8c67a13345d22ac24dd13f0/core/core_bind.cpp#L1565-L1586

The first_argument_is_class variable in this code is becoming increasingly lengthy and less maintainable. Would it be more suitable to change it to a HashSet<String> field to store these names, and then use the HashSet<String> field to check for existence?

 void ClassDB::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { 
   const String pf = p_function; 
- 	bool first_argument_is_class = false; 
- 	if (p_idx == 0) { 
- 		first_argument_is_class = (pf == "get_inheriters_from_class" || pf == "get_parent_class" || 
- 				pf == "class_exists" || pf == "can_instantiate" || pf == "instantiate" || 
- 				pf == "class_has_signal" || pf == "class_get_signal" || pf == "class_get_signal_list" || 
- 				pf == "class_get_property_list" || pf == "class_get_property" || pf == "class_set_property" || 
- 				pf == "class_has_method" || pf == "class_get_method_list" || 
- 				pf == "class_get_integer_constant_list" || pf == "class_has_integer_constant" || pf == "class_get_integer_constant" || 
- 				pf == "class_has_enum" || pf == "class_get_enum_list" || pf == "class_get_enum_constants" || pf == "class_get_integer_constant_enum" || 
- 				pf == "is_class_enabled" || pf == "is_class_enum_bitfield" || pf == "class_get_api_type" || 
-				pf == "class_get_property_getter" || pf == "class_get_property_setter"); 
- 	} 
+ 	bool first_argument_is_class = p_idx == 0 && has_first_argument_class_methods(pf);
 	if (first_argument_is_class || pf == "is_parent_class") { 
 		for (const String &E : get_class_list()) { 
 			r_options->push_back(E.quote()); 
 		} 
 	} 
  
 	Object::get_argument_options(p_function, p_idx, r_options); 
 } 

+ HashSet<String> first_argument_class_methods;
+ bool has_first_argument_class_methods(const String p_function) const { 
+	if (!first_argument_class_methods.is_empty()) {
+		return first_argument_class_methods.has(p_function);
+	}
+	auto class_methods = {
+		"get_inheriters_from_class",
+		"get_parent_class",
+		"class_exists",
+		"is_parent_class",
+		"can_instantiate",
+		"instantiate",
+		"class_has_signal",
+		"class_get_signal",
+		"class_get_signal_list",
+		"class_get_property_list",
+		"class_get_property",
+		"class_set_property",
+		"class_has_method",
+		"class_get_method_list",
+		"class_get_integer_constant_list",
+		"class_has_integer_constant",
+		"class_get_integer_constant",
+		"class_has_enum",
+		"class_get_enum_list",
+		"class_get_enum_constants",
+		"class_get_integer_constant_enum",
+		"is_class_enabled",
+		"is_class_enum_bitfield",
+		"class_get_api_type",
+		"class_get_property_getter",
+		"class_get_property_setter"
+	};
+	bool result = false;
+	for (const String &E : class_methods) {
+		first_argument_class_methods.insert(E);
+		if (E == p_function) {
+			result = true;
+		}
+	}
+	return result;
+}

@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch 2 times, most recently from e2dafe1 to c48676e Compare April 26, 2024 14:21
@dsnopek
Copy link
Contributor

dsnopek commented Apr 26, 2024

The first_argument_is_class variable in this code is becoming increasingly lengthy and less maintainable. Would it be more suitable to change it to a HashSet<String> field to store these names, and then use the HashSet<String> field to check for existence?

I would just leave this as it is for now.

Overall, this PR is looking good to me!

CI is complaining about an extra line in the docs XML:

diff --git a/doc/classes/ClassDB.xml b/doc/classes/ClassDB.xml
index ed670fa..6a58536 100644
--- a/doc/classes/ClassDB.xml
+++ b/doc/classes/ClassDB.xml
@@ -106,7 +106,6 @@
 				Returns the default value of [param property] of [param class] or its ancestor classes.
 			</description>
 		</method>
-
 		<method name="class_get_property_getter" qualifiers="const">
 			<return type="StringName" />
 			<param index="0" name="class" type="StringName" />

However, aside from that, the main thing blocking this is that we need to get godot-cpp PR godotengine/godot-cpp#1445 merged and cherry-picked so that the rest of the tests can pass here.

@ZerxZ
Copy link
Contributor Author

ZerxZ commented May 28, 2024

cc @AThousandShips @dsnopek

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

The tests are now passing - yay!

This looks good to me, however, it would probably be good to update the PR title and commit message with the right method names.

core/core_bind.cpp Outdated Show resolved Hide resolved
core/core_bind.h Show resolved Hide resolved
@ZerxZ ZerxZ changed the title Expose ClassDB::get_api_type() ClassDB::get_property_getter() ClassDB::get_property_setter() method Expose ClassDB::class_get_api_type() ClassDB::class_get_property_getter() ClassDB::class_get_property_setter() method May 28, 2024
@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch from 76ce74c to d8fbe47 Compare May 28, 2024 20:42
@Delsin-Yu
Copy link
Contributor

Any chance we can have this in 4.3? As the PR has approved.

@AThousandShips
Copy link
Member

We're in feature freeze so I don't expect so, but we'll see what the production team says, I suspect 4.4

@AThousandShips AThousandShips changed the title Expose ClassDB::class_get_api_type() ClassDB::class_get_property_getter() ClassDB::class_get_property_setter() method Expose ClassDB class_get_api_type() class_get_property_getter() class_get_property_setter() methods May 29, 2024
@dalexeev
Copy link
Member

dalexeev commented Sep 3, 2024

I'm not sure about class_get_api_type().

@ZerxZ
Copy link
Contributor Author

ZerxZ commented Sep 3, 2024

I'm not sure about class_get_api_type().

I think the class_get_api_type part is still necessary. It is mainly used to distinguish between Native Class Type and GDExtension Class Type.
Seeing that others PR have merged get_property_getter and set_property_getter. so I just need to keep the class_get_api_type one?
@AThousandShips @dalexeev @dsnopek @Naros

@dalexeev
Copy link
Member

dalexeev commented Sep 3, 2024

so I just need to keep the class_get_api_type one?

I think yes, since the other two methods are already exposed.

@dalexeev dalexeev changed the title Expose ClassDB class_get_api_type() class_get_property_getter() class_get_property_setter() methods Expose ClassDB.class_get_api_type() method Sep 3, 2024
@ZerxZ ZerxZ force-pushed the core/classdb_get_api_type branch 3 times, most recently from bf1a9ba to 4eb805b Compare September 3, 2024 14:31
core/core_bind.cpp Outdated Show resolved Hide resolved
@ZerxZ
Copy link
Contributor Author

ZerxZ commented Sep 3, 2024

so I just need to keep the class_get_api_type one?

I think yes, since the other two methods are already exposed.

I've removed that part and just kept the class_get_api_type part. Can you see if it's working? @dalexeev @akien-mga

doc/classes/ClassDB.xml Outdated Show resolved Hide resolved
@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 18, 2024
@akien-mga akien-mga merged commit 57c8684 into godotengine:master Sep 18, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@ZerxZ
Copy link
Contributor Author

ZerxZ commented Sep 18, 2024

Thanks!

Thanks!

@ZerxZ ZerxZ deleted the core/classdb_get_api_type branch September 18, 2024 16:58
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.

Expose ClassDB.get_api_type() for better GDExtension interoperability with non-GDScript languages
6 participants