-
-
Notifications
You must be signed in to change notification settings - Fork 20.8k
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 CallableCustom objects to be created from GDExtensions #79005
Merged
+233
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,6 +364,47 @@ typedef struct { | |
GDExtensionVariantPtr *default_arguments; | ||
} GDExtensionClassMethodInfo; | ||
|
||
typedef void (*GDExtensionCallableCustomCall)(void *callable_userdata, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error); | ||
typedef GDExtensionBool (*GDExtensionCallableCustomIsValid)(void *callable_userdata); | ||
typedef void (*GDExtensionCallableCustomFree)(void *callable_userdata); | ||
|
||
typedef uint32_t (*GDExtensionCallableCustomHash)(void *callable_userdata); | ||
typedef GDExtensionBool (*GDExtensionCallableCustomEqual)(void *callable_userdata_a, void *callable_userdata_b); | ||
typedef GDExtensionBool (*GDExtensionCallableCustomLessThan)(void *callable_userdata_a, void *callable_userdata_b); | ||
|
||
typedef void (*GDExtensionCallableCustomToString)(void *callable_userdata, GDExtensionBool *r_is_valid, GDExtensionStringPtr r_out); | ||
|
||
typedef struct { | ||
/* Only `call_func` and `token` are strictly required, however, `object` should be passed if its not a static method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: it's |
||
* | ||
* `token` should point to an address that uniquely identifies the GDExtension (for example, the | ||
* `GDExtensionClassLibraryPtr` passed to the entry symbol function. | ||
* | ||
* `hash_func`, `equal_func`, and `less_than_func` are optional. If not provided both `call_func` and | ||
* `callable_userdata` together are used as the identity of the callable for hashing and comparison purposes. | ||
* | ||
* The hash returned by `hash_func` is cached, `hash_func` will not be called more than once per callable. | ||
* | ||
* `is_valid_func` is necessary if the validity of the callable can change before destruction. | ||
* | ||
* `free_func` is necessary if `callable_userdata` needs to be cleaned up when the callable is freed. | ||
*/ | ||
void *callable_userdata; | ||
void *token; | ||
|
||
GDExtensionObjectPtr object; | ||
|
||
GDExtensionCallableCustomCall call_func; | ||
GDExtensionCallableCustomIsValid is_valid_func; | ||
GDExtensionCallableCustomFree free_func; | ||
|
||
GDExtensionCallableCustomHash hash_func; | ||
dsnopek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
GDExtensionCallableCustomEqual equal_func; | ||
GDExtensionCallableCustomLessThan less_than_func; | ||
|
||
GDExtensionCallableCustomToString to_string_func; | ||
} GDExtensionCallableCustomInfo; | ||
|
||
/* SCRIPT INSTANCE EXTENSION */ | ||
|
||
typedef void *GDExtensionScriptInstanceDataPtr; // Pointer to custom ScriptInstance native implementation. | ||
|
@@ -2245,6 +2286,34 @@ typedef void (*GDExtensionInterfacePlaceHolderScriptInstanceUpdate)(GDExtensionS | |
*/ | ||
typedef GDExtensionScriptInstanceDataPtr (*GDExtensionInterfaceObjectGetScriptInstance)(GDExtensionConstObjectPtr p_object, GDExtensionObjectPtr p_language); | ||
|
||
/* INTERFACE: Callable */ | ||
|
||
/** | ||
* @name callable_custom_create | ||
* @since 4.2 | ||
* | ||
* Creates a custom Callable object from a function pointer. | ||
* | ||
* Provided struct can be safely freed once the function returns. | ||
* | ||
* @param r_callable A pointer that will receive the new Callable. | ||
* @param p_callable_custom_info The info required to construct a Callable. | ||
*/ | ||
typedef void (*GDExtensionInterfaceCallableCustomCreate)(GDExtensionUninitializedTypePtr r_callable, GDExtensionCallableCustomInfo *p_callable_custom_info); | ||
|
||
/** | ||
* @name callable_custom_get_userdata | ||
* @since 4.2 | ||
* | ||
* Retrieves the userdata pointer from a custom Callable. | ||
* | ||
* If the Callable is not a custom Callable or the token does not match the one provided to callable_custom_create() via GDExtensionCallableCustomInfo then NULL will be returned. | ||
* | ||
* @param p_callable A pointer to a Callable. | ||
* @param p_token A pointer to an address that uniquely identifies the GDExtension. | ||
*/ | ||
typedef void *(*GDExtensionInterfaceCallableCustomGetUserData)(GDExtensionConstTypePtr p_callable, void *p_token); | ||
|
||
/* INTERFACE: ClassDB */ | ||
|
||
/** | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it makes sense to have this say
<CallableCustomExtension>
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the distinction between
CallableCustomExtension
used for GDExtension andCallableCustom
used by Godot makes much difference here, if more clarity is needed it would be better to provide ato_string_func
with any needed details about the callable.