variadic_functions.gd 831 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. class A:
  2. func f(x: int) -> void:
  3. print(x)
  4. class B extends A:
  5. func f(x: int, ...args: Array) -> void:
  6. prints(x, args)
  7. class C extends B:
  8. func f(x: int, y: int = 0, ...args: Array) -> void:
  9. prints(x, y, args)
  10. class D extends C:
  11. func f(...args: Array) -> void:
  12. print(args)
  13. func test_func(x: int, y: int = 0, ...args: Array) -> void:
  14. prints(x, y, args)
  15. var test_lambda := func (x: int, y: int = 0, ...args: Array) -> void:
  16. prints(x, y, args)
  17. func test():
  18. for method in get_method_list():
  19. if str(method.name).begins_with("test_"):
  20. print(Utils.get_method_signature(method))
  21. test_func(1)
  22. test_func(1, 2)
  23. test_func(1, 2, 3)
  24. test_func(1, 2, 3, 4)
  25. test_func(1, 2, 3, 4, 5)
  26. test_lambda.call(1)
  27. test_lambda.call(1, 2)
  28. test_lambda.call(1, 2, 3)
  29. test_lambda.call(1, 2, 3, 4)
  30. test_lambda.call(1, 2, 3, 4, 5)