mirror of
https://github.com/godotengine/godot-cpp.git
synced 2026-01-01 05:48:37 +03:00
Add CallableCustom that devs can use in their GDExtensions
This commit is contained in:
@@ -15,6 +15,46 @@
|
||||
|
||||
using namespace godot;
|
||||
|
||||
class MyCallableCustom : public CallableCustom {
|
||||
public:
|
||||
virtual uint32_t hash() const {
|
||||
return 27;
|
||||
}
|
||||
|
||||
virtual String get_as_text() const {
|
||||
return "<MyCallableCustom>";
|
||||
}
|
||||
|
||||
static bool compare_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) {
|
||||
return p_a == p_b;
|
||||
}
|
||||
|
||||
virtual CompareEqualFunc get_compare_equal_func() const {
|
||||
return &MyCallableCustom::compare_equal_func;
|
||||
}
|
||||
|
||||
static bool compare_less_func(const CallableCustom *p_a, const CallableCustom *p_b) {
|
||||
return (void *)p_a < (void *)p_b;
|
||||
}
|
||||
|
||||
virtual CompareLessFunc get_compare_less_func() const {
|
||||
return &MyCallableCustom::compare_less_func;
|
||||
}
|
||||
|
||||
bool is_valid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual ObjectID get_object() const {
|
||||
return ObjectID();
|
||||
}
|
||||
|
||||
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, GDExtensionCallError &r_call_error) const {
|
||||
r_return_value = "Hi";
|
||||
r_call_error.error = GDEXTENSION_CALL_OK;
|
||||
}
|
||||
};
|
||||
|
||||
void ExampleRef::set_id(int p_id) {
|
||||
id = p_id;
|
||||
}
|
||||
@@ -168,6 +208,7 @@ void Example::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("test_callable_mp_retc"), &Example::test_callable_mp_retc);
|
||||
ClassDB::bind_method(D_METHOD("test_callable_mp_static"), &Example::test_callable_mp_static);
|
||||
ClassDB::bind_method(D_METHOD("test_callable_mp_static_ret"), &Example::test_callable_mp_static_ret);
|
||||
ClassDB::bind_method(D_METHOD("test_custom_callable"), &Example::test_custom_callable);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
|
||||
|
||||
@@ -378,6 +419,10 @@ Callable Example::test_callable_mp_static_ret() const {
|
||||
return callable_mp_static(&Example::unbound_static_method2);
|
||||
}
|
||||
|
||||
Callable Example::test_custom_callable() const {
|
||||
return Callable(memnew(MyCallableCustom));
|
||||
}
|
||||
|
||||
void Example::unbound_method1(Object *p_object, String p_string, int p_int) {
|
||||
String test = "unbound_method1: ";
|
||||
test += p_object->get_class();
|
||||
|
||||
Reference in New Issue
Block a user