Core: Allow methods of built-in Variant types to be used as Callables

This commit is contained in:
Danil Alexeev 2023-09-24 23:33:28 +03:00
parent 06d5189167
commit b04263644c
No known key found for this signature in database
GPG key ID: 124453E157DA8DC7
9 changed files with 231 additions and 73 deletions

View file

@ -46,17 +46,6 @@
# Prints "Attack!", when the button_pressed signal is emitted.
button_pressed.connect(func(): print("Attack!"))
[/codeblock]
[b]Note:[/b] Methods of native types such as [Signal], [Array], or [Dictionary] are not of type [Callable] in order to avoid unnecessary overhead. If you need to pass those methods as [Callable], use a lambda function as a wrapper.
[codeblock]
func _init():
var my_dictionary = { "hello": "world" }
# This will not work, `clear` is not a callable.
create_tween().tween_callback(my_dictionary.clear)
# This will work, as lambdas are custom callables.
create_tween().tween_callback(func(): my_dictionary.clear())
[/codeblock]
</description>
<tutorials>
</tutorials>