diff options
Diffstat (limited to 'test/src/example.cpp')
-rw-r--r-- | test/src/example.cpp | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp index ad82103..992f29c 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -46,6 +46,18 @@ ExampleRef::~ExampleRef() { UtilityFunctions::print("ExampleRef destroyed."); } +int Example::test_static(int p_a, int p_b) { + return p_a + p_b; +} + +void Example::test_static2() { + UtilityFunctions::print(" void static"); +} + +int Example::def_args(int p_a, int p_b) { + return p_a + p_b; +} + void Example::_bind_methods() { // Methods. ClassDB::bind_method(D_METHOD("simple_func"), &Example::simple_func); @@ -58,6 +70,11 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("test_array"), &Example::test_array); ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary); + ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200)); + + ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static); + ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2); + { MethodInfo mi; mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); @@ -65,11 +82,26 @@ void Example::_bind_methods() { ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func", &Example::varargs_func, mi); } + { + MethodInfo mi; + mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); + mi.name = "varargs_func_nv"; + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func_nv", &Example::varargs_func_nv, mi); + } + + { + MethodInfo mi; + mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); + mi.name = "varargs_func_void"; + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func_void", &Example::varargs_func_void, mi); + } + // Properties. ADD_GROUP("Test group", "group_"); ADD_SUBGROUP("Test subgroup", "group_subgroup_"); ClassDB::bind_method(D_METHOD("get_custom_position"), &Example::get_custom_position); + ClassDB::bind_method(D_METHOD("get_v4"), &Example::get_v4); ClassDB::bind_method(D_METHOD("set_custom_position", "position"), &Example::set_custom_position); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "group_subgroup_custom_position"), "set_custom_position", "get_custom_position"); @@ -94,20 +126,20 @@ Example::~Example() { // Methods. void Example::simple_func() { - UtilityFunctions::print("Simple func called."); + UtilityFunctions::print(" Simple func called."); } void Example::simple_const_func() const { - UtilityFunctions::print("Simple const func called."); + UtilityFunctions::print(" Simple const func called."); } String Example::return_something(const String &base) { - UtilityFunctions::print("Return something called."); + UtilityFunctions::print(" Return something called."); return base; } Viewport *Example::return_something_const() const { - UtilityFunctions::print("Return something const called."); + UtilityFunctions::print(" Return something const called."); if (is_inside_tree()) { Viewport *result = get_viewport(); return result; @@ -124,15 +156,24 @@ Ref<ExampleRef> Example::extended_ref_checks(Ref<ExampleRef> p_ref) const { ref.instantiate(); // TODO the returned value gets dereferenced too early and return a null object otherwise. ref->reference(); - UtilityFunctions::print("Example ref checks called with value: ", p_ref->get_instance_id(), ", returning value: ", ref->get_instance_id()); + UtilityFunctions::print(" Example ref checks called with value: ", p_ref->get_instance_id(), ", returning value: ", ref->get_instance_id()); return ref; } Variant Example::varargs_func(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error) { - UtilityFunctions::print("Varargs called with ", String::num((double)arg_count), " arguments"); + UtilityFunctions::print(" Varargs (Variant return) called with ", String::num((double)arg_count), " arguments"); return arg_count; } +int Example::varargs_func_nv(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error) { + UtilityFunctions::print(" Varargs (int return) called with ", String::num((double)arg_count), " arguments"); + return 42; +} + +void Example::varargs_func_void(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error) { + UtilityFunctions::print(" Varargs (no return) called with ", String::num((double)arg_count), " arguments"); +} + void Example::emit_custom_signal(const String &name, int value) { emit_signal("custom_signal", name, value); } @@ -165,6 +206,10 @@ Vector2 Example::get_custom_position() const { return custom_position; } +Vector4 Example::get_v4() const { + return Vector4(1.2, 3.4, 5.6, 7.8); +} + // Virtual function override. bool Example::_has_point(const Vector2 &point) const { Label *label = get_node<Label>("Label"); |