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

Allow implementing get_class_category in GDExtension #78995

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ static GDExtensionScriptInstancePtr gdextension_script_instance_create(const GDE
info_2->get_func = p_info->get_func;
info_2->get_property_list_func = p_info->get_property_list_func;
info_2->free_property_list_func = p_info->free_property_list_func;
info_2->get_class_category_func = nullptr;
info_2->property_can_revert_func = p_info->property_can_revert_func;
info_2->property_get_revert_func = p_info->property_get_revert_func;
info_2->get_owner_func = p_info->get_owner_func;
Expand Down
3 changes: 3 additions & 0 deletions core/extension/gdextension_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ typedef GDExtensionBool (*GDExtensionScriptInstanceSet)(GDExtensionScriptInstanc
typedef GDExtensionBool (*GDExtensionScriptInstanceGet)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret);
typedef const GDExtensionPropertyInfo *(*GDExtensionScriptInstanceGetPropertyList)(GDExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count);
typedef void (*GDExtensionScriptInstanceFreePropertyList)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionPropertyInfo *p_list);
typedef GDExtensionBool (*GDExtensionScriptInstanceGetClassCategory)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_class_category);

typedef GDExtensionVariantType (*GDExtensionScriptInstanceGetPropertyType)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionBool *r_is_valid);
typedef GDExtensionBool (*GDExtensionScriptInstanceValidateProperty)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_property);

Expand Down Expand Up @@ -508,6 +510,7 @@ typedef struct {
GDExtensionScriptInstanceGet get_func;
GDExtensionScriptInstanceGetPropertyList get_property_list_func;
GDExtensionScriptInstanceFreePropertyList free_property_list_func;
GDExtensionScriptInstanceGetClassCategory get_class_category_func;

GDExtensionScriptInstancePropertyCanRevert property_can_revert_func;
GDExtensionScriptInstancePropertyGetRevert property_get_revert_func;
Expand Down
17 changes: 14 additions & 3 deletions core/object/script_language_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,20 @@ class ScriptInstanceExtension : public ScriptInstance {
const GDExtensionPropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount);

#ifdef TOOLS_ENABLED
Ref<Script> script = get_script();
if (script.is_valid() && pcount > 0) {
p_list->push_back(script->get_class_category());
if (pcount > 0) {
if (native_info->get_class_category_func) {
GDExtensionPropertyInfo gdext_class_category;
if (native_info->get_class_category_func(instance, &gdext_class_category)) {
p_list->push_back(PropertyInfo(gdext_class_category));
}
#ifndef DISABLE_DEPRECATED
} else {
Ref<Script> script = get_script();
if (script.is_valid()) {
p_list->push_back(script->get_class_category());
}
#endif // DISABLE_DEPRECATED
}
}
#endif // TOOLS_ENABLED

Expand Down