Skip to content

Support every class-registration option that Godot offers #563

Open
@lilizoey

Description

@lilizoey

Edit bromeon: updated list according to latest developments.

To register a class with godot we use the GDExtensionClassCreationInfo struct, which has two versions depending on the godot version:

pub struct GDExtensionClassCreationInfo2 {
    pub is_virtual: GDExtensionBool,
    pub is_abstract: GDExtensionBool,
    pub is_exposed: GDExtensionBool, // only in 2
    pub set_func: GDExtensionClassSet,
    pub get_func: GDExtensionClassGet,
    pub get_property_list_func: GDExtensionClassGetPropertyList,
    pub free_property_list_func: GDExtensionClassFreePropertyList,
    pub property_can_revert_func: GDExtensionClassPropertyCanRevert,
    pub property_get_revert_func: GDExtensionClassPropertyGetRevert,
    pub validate_property_func: GDExtensionClassValidateProperty, // only in 2
    pub notification_func: GDExtensionClassNotification2, // different type in 2
    pub to_string_func: GDExtensionClassToString,
    pub reference_func: GDExtensionClassReference,
    pub unreference_func: GDExtensionClassUnreference,
    pub create_instance_func: GDExtensionClassCreateInstance,
    pub free_instance_func: GDExtensionClassFreeInstance,
    pub recreate_instance_func: GDExtensionClassRecreateInstance,
    pub get_virtual_func: GDExtensionClassGetVirtual,
    pub get_virtual_call_data_func: GDExtensionClassGetVirtualCallData, // only in 2
    pub call_virtual_with_data_func: GDExtensionClassCallVirtualWithData, // only in 2
    pub get_rid_func: GDExtensionClassGetRID,
    pub class_userdata: *mut ::std::os::raw::c_void,
}

Each corresponding to something configurable about class registration.

Current state of user-available registration options:

  • is_virtual 1
  • is_abstract we might need to set this to true for classes that cant be instantiated 1
  • is_exposed
  • set_func
  • get_func
  • get_property_list_func (Add get_property_list #707)
  • free_property_list_func
  • property_can_revert_func
  • property_get_revert_func
  • validate_property_func
  • notification_func through on_notification in interface
  • to_string_func through to_string in interface
  • create_instance_func based on init function in interface
  • recreate_instance_func based on init function in interface
  • get_virtual_func generated from virtual method implementations

Not necessary

  • get_rid_func -- already available in regular class APIs
  • get_virtual_call_data_func -- mutually exclusive with get_virtual_func, will not implement without a use-case
  • call_virtual_with_data_func -- must be implemented along with above

Not planned for now

  • class_userdata
  • reference_func -- is used to update the refcount, but the user cannot add custom logic to this
  • unreference_func -- is used to update the refcount, but the user cannot add custom logic to this

The planned builder-api would likely want the ability to set/override these options as desired.

Footnotes

  1. See this pr for information about what virtual vs abstract classes mean in godot 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions