class_callable.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Callable.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Callable:
  6. Callable
  7. ========
  8. An object representing a method in a certain object that can be called.
  9. Description
  10. -----------
  11. ``Callable`` is a first class object which can be held in variables and passed to functions. It represents a given method in an :ref:`Object<class_Object>`, and is typically used for signal callbacks.
  12. **Example:**
  13. ::
  14. var callable = Callable(self, "print_args")
  15. func print_args(arg1, arg2, arg3 = ""):
  16. prints(arg1, arg2, arg3)
  17. func test():
  18. callable.call("hello", "world") # Prints "hello world".
  19. callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(Node.gd)::print_args".
  20. callable.call("invalid") # Invalid call, should have at least 2 arguments.
  21. Methods
  22. -------
  23. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_method_Callable>` **(** :ref:`Object<class_Object>` object, :ref:`StringName<class_StringName>` method_name **)** |
  25. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Variant<class_Variant>` | :ref:`call<class_Callable_method_call>` **(** ... **)** vararg |
  27. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`call_deferred<class_Callable_method_call_deferred>` **(** ... **)** vararg |
  29. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`StringName<class_StringName>` | :ref:`get_method<class_Callable_method_get_method>` **(** **)** |
  31. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Object<class_Object>` | :ref:`get_object<class_Callable_method_get_object>` **(** **)** |
  33. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_object_id<class_Callable_method_get_object_id>` **(** **)** |
  35. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`hash<class_Callable_method_hash>` **(** **)** |
  37. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`is_custom<class_Callable_method_is_custom>` **(** **)** |
  39. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`bool<class_bool>` | :ref:`is_null<class_Callable_method_is_null>` **(** **)** |
  41. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`is_standard<class_Callable_method_is_standard>` **(** **)** |
  43. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  44. Method Descriptions
  45. -------------------
  46. .. _class_Callable_method_Callable:
  47. - :ref:`Callable<class_Callable>` **Callable** **(** :ref:`Object<class_Object>` object, :ref:`StringName<class_StringName>` method_name **)**
  48. Creates a new ``Callable`` for the method called ``method_name`` in the specified ``object``.
  49. ----
  50. .. _class_Callable_method_call:
  51. - :ref:`Variant<class_Variant>` **call** **(** ... **)** vararg
  52. Calls the method represented by this ``Callable``. Arguments can be passed and should match the method's signature.
  53. ----
  54. .. _class_Callable_method_call_deferred:
  55. - void **call_deferred** **(** ... **)** vararg
  56. Calls the method represented by this ``Callable`` in deferred mode, i.e. during the idle frame. Arguments can be passed and should match the method's signature.
  57. ----
  58. .. _class_Callable_method_get_method:
  59. - :ref:`StringName<class_StringName>` **get_method** **(** **)**
  60. Returns the name of the method represented by this ``Callable``.
  61. ----
  62. .. _class_Callable_method_get_object:
  63. - :ref:`Object<class_Object>` **get_object** **(** **)**
  64. Returns the object on which this ``Callable`` is called.
  65. ----
  66. .. _class_Callable_method_get_object_id:
  67. - :ref:`int<class_int>` **get_object_id** **(** **)**
  68. Returns the ID of this ``Callable``'s object (see :ref:`Object.get_instance_id<class_Object_method_get_instance_id>`).
  69. ----
  70. .. _class_Callable_method_hash:
  71. - :ref:`int<class_int>` **hash** **(** **)**
  72. ----
  73. .. _class_Callable_method_is_custom:
  74. - :ref:`bool<class_bool>` **is_custom** **(** **)**
  75. ----
  76. .. _class_Callable_method_is_null:
  77. - :ref:`bool<class_bool>` **is_null** **(** **)**
  78. ----
  79. .. _class_Callable_method_is_standard:
  80. - :ref:`bool<class_bool>` **is_standard** **(** **)**