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

[GDScript] Fix get_argument_count for lambda Callables #93964

Merged
merged 1 commit into from
Jul 5, 2024
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
4 changes: 2 additions & 2 deletions modules/gdscript/gdscript_lambda_callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int GDScriptLambdaCallable::get_argument_count(bool &r_is_valid) const {
return 0;
}
r_is_valid = true;
return function->get_argument_count();
return function->get_argument_count() - captures.size();
}

void GDScriptLambdaCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
Expand Down Expand Up @@ -204,7 +204,7 @@ int GDScriptLambdaSelfCallable::get_argument_count(bool &r_is_valid) const {
return 0;
}
r_is_valid = true;
return function->get_argument_count();
return function->get_argument_count() - captures.size();
}

void GDScriptLambdaSelfCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://github.com/godotengine/godot/issues/93952

func foo():
pass

func test():
var a: int

var lambda_self := func (x: int) -> void:
foo()
print(a, x)

print(lambda_self.get_argument_count()) # Should print 1.

var lambda_non_self := func (x: int) -> void:
print(a, x)

print(lambda_non_self.get_argument_count()) # Should print 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GDTEST_OK
1
1
Loading