Skip to content

Commit

Permalink
Merge pull request #78995 from Gallilus/master
Browse files Browse the repository at this point in the history
Allow implementing `get_class_category` in GDExtension
  • Loading branch information
YuriSizov committed Sep 27, 2023
2 parents aa474c9 + 531f56e commit 5f53ec9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
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

0 comments on commit 5f53ec9

Please sign in to comment.