Merge pull request #1128 from Mathis-Z/master

Fixing #1127 by making return types of auto-generated functions dynamic
pull/936/head
Rémi Verschelde 2023-06-08 22:31:51 +02:00 committed by GitHub
commit d12cf071bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 1 deletions

View File

@ -1798,6 +1798,9 @@ def generate_utility_functions(api, output_dir):
source += encode source += encode
arguments.append(arg_name) arguments.append(arg_name)
function_call += ", ".join(arguments) function_call += ", ".join(arguments)
else:
if has_return:
source.append(f'\t{get_gdextension_type(correct_type(function["return_type"]))} ret;')
else: else:
source.append("\tVariant ret;") source.append("\tVariant ret;")
function_call += "___function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(args), arg_count" function_call += "___function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(args), arg_count"

View File

@ -79,6 +79,9 @@ func _ready():
# String += operator # String += operator
assert_equal(example.test_string_ops(), "ABCĎE") assert_equal(example.test_string_ops(), "ABCĎE")
# UtilityFunctions::str()
assert_equal(example.test_str_utility(), "Hello, World! The answer is 42")
# PackedArray iterators # PackedArray iterators
assert_equal(example.test_vector_ops(), 105) assert_equal(example.test_vector_ops(), 105)

View File

@ -127,6 +127,7 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary); ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary);
ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument); ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument);
ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops); ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops);
ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility);
ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops); ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops);
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield); ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
@ -280,6 +281,10 @@ String Example::test_string_ops() const {
return s; return s;
} }
String Example::test_str_utility() const {
return UtilityFunctions::str("Hello, ", "World", "! The answer is ", 42);
}
int Example::test_vector_ops() const { int Example::test_vector_ops() const {
PackedInt32Array arr; PackedInt32Array arr;
arr.push_back(10); arr.push_back(10);

View File

@ -115,6 +115,7 @@ public:
Dictionary test_dictionary() const; Dictionary test_dictionary() const;
Example *test_node_argument(Example *p_node) const; Example *test_node_argument(Example *p_node) const;
String test_string_ops() const; String test_string_ops() const;
String test_str_utility() const;
int test_vector_ops() const; int test_vector_ops() const;
BitField<Flags> test_bitfield(BitField<Flags> flags); BitField<Flags> test_bitfield(BitField<Flags> flags);