Skip to content
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

Fixing #1127 by making return types of auto-generated functions dynamic #1128

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,10 @@ def generate_utility_functions(api, output_dir):
arguments.append(arg_name)
function_call += ", ".join(arguments)
else:
source.append("\tVariant ret;")
if has_return:
source.append(f'\t{get_gdextension_type(correct_type(function["return_type"]))} ret;')
else:
source.append("\tVariant ret;")
function_call += "___function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(args), arg_count"

function_call += ");"
Expand Down
3 changes: 3 additions & 0 deletions test/project/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func _ready():
# String += operator
assert_equal($Example.test_string_ops(), "ABCĎE")

# UtilityFunctions::str()
assert_equal(example.test_str_utility(), "Hello, World! The answer is 42")

# PackedArray iterators
assert_equal($Example.test_vector_ops(), 105)

Expand Down
5 changes: 5 additions & 0 deletions test/src/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void Example::_bind_methods() {
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_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_bitfield", "flags"), &Example::test_bitfield);
Expand Down Expand Up @@ -280,6 +281,10 @@ String Example::test_string_ops() const {
return s;
}

String Example::test_str_utility() const {
return UtilityFunctions::str("Hello, ", "World", "! The answer is ", 42);
}

int Example::test_vector_ops() const {
PackedInt32Array arr;
arr.push_back(10);
Expand Down
1 change: 1 addition & 0 deletions test/src/example.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Example : public Control {
Dictionary test_dictionary() const;
Example *test_node_argument(Example *p_node) const;
String test_string_ops() const;
String test_str_utility() const;
int test_vector_ops() const;

BitField<Flags> test_bitfield(BitField<Flags> flags);
Expand Down