class_callable.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Callable.xml.
  6. .. _class_Callable:
  7. Callable
  8. ========
  9. An object representing a method in a certain object that can be called.
  10. Description
  11. -----------
  12. ``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.
  13. \ **Example:**\
  14. .. tabs::
  15. .. code-tab:: gdscript
  16. func print_args(arg1, arg2, arg3 = ""):
  17. prints(arg1, arg2, arg3)
  18. func test():
  19. var callable = Callable(self, "print_args")
  20. callable.call("hello", "world") # Prints "hello world ".
  21. callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(Node.gd)::print_args".
  22. callable.call("invalid") # Invalid call, should have at least 2 arguments.
  23. .. code-tab:: csharp
  24. public void PrintArgs(object arg1, object arg2, object arg3 = null)
  25. {
  26. GD.PrintS(arg1, arg2, arg3);
  27. }
  28. public void Test()
  29. {
  30. Callable callable = new Callable(this, nameof(PrintArgs));
  31. callable.Call("hello", "world"); // Prints "hello world null".
  32. callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.cs)::PrintArgs".
  33. callable.Call("invalid"); // Invalid call, should have at least 2 arguments.
  34. }
  35. Constructors
  36. ------------
  37. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_constructor_Callable>` **(** **)** |
  39. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_constructor_Callable>` **(** :ref:`Callable<class_Callable>` from **)** |
  41. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Callable<class_Callable>` | :ref:`Callable<class_Callable_constructor_Callable>` **(** :ref:`Object<class_Object>` object, :ref:`StringName<class_StringName>` method **)** |
  43. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  44. Methods
  45. -------
  46. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Callable<class_Callable>` | :ref:`bind<class_Callable_method_bind>` **(** ... **)** |vararg| |const| |
  48. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Variant<class_Variant>` | :ref:`call<class_Callable_method_call>` **(** ... **)** |vararg| |const| |
  50. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`call_deferred<class_Callable_method_call_deferred>` **(** ... **)** |vararg| |const| |
  52. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  53. | :ref:`StringName<class_StringName>` | :ref:`get_method<class_Callable_method_get_method>` **(** **)** |const| |
  54. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Object<class_Object>` | :ref:`get_object<class_Callable_method_get_object>` **(** **)** |const| |
  56. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_object_id<class_Callable_method_get_object_id>` **(** **)** |const| |
  58. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  59. | :ref:`int<class_int>` | :ref:`hash<class_Callable_method_hash>` **(** **)** |const| |
  60. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`is_custom<class_Callable_method_is_custom>` **(** **)** |const| |
  62. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  63. | :ref:`bool<class_bool>` | :ref:`is_null<class_Callable_method_is_null>` **(** **)** |const| |
  64. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`is_standard<class_Callable_method_is_standard>` **(** **)** |const| |
  66. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`is_valid<class_Callable_method_is_valid>` **(** **)** |const| |
  68. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`rpc<class_Callable_method_rpc>` **(** ... **)** |vararg| |const| |
  70. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`rpc_id<class_Callable_method_rpc_id>` **(** :ref:`int<class_int>` peer_id, ... **)** |vararg| |const| |
  72. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Callable<class_Callable>` | :ref:`unbind<class_Callable_method_unbind>` **(** :ref:`int<class_int>` argcount **)** |const| |
  74. +-------------------------------------+-------------------------------------------------------------------------------------------------------------+
  75. Operators
  76. ---------
  77. +-------------------------+--------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Callable_operator_neq_bool>` **(** :ref:`Callable<class_Callable>` right **)** |
  79. +-------------------------+--------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Callable_operator_eq_bool>` **(** :ref:`Callable<class_Callable>` right **)** |
  81. +-------------------------+--------------------------------------------------------------------------------------------------------+
  82. Constructor Descriptions
  83. ------------------------
  84. .. _class_Callable_constructor_Callable:
  85. - :ref:`Callable<class_Callable>` **Callable** **(** **)**
  86. Constructs a null ``Callable`` with no object nor method bound.
  87. ----
  88. - :ref:`Callable<class_Callable>` **Callable** **(** :ref:`Callable<class_Callable>` from **)**
  89. Constructs a ``Callable`` as a copy of the given ``Callable``.
  90. ----
  91. - :ref:`Callable<class_Callable>` **Callable** **(** :ref:`Object<class_Object>` object, :ref:`StringName<class_StringName>` method **)**
  92. Creates a new ``Callable`` for the method called ``method`` in the specified ``object``.
  93. Method Descriptions
  94. -------------------
  95. .. _class_Callable_method_bind:
  96. - :ref:`Callable<class_Callable>` **bind** **(** ... **)** |vararg| |const|
  97. Returns a copy of this ``Callable`` with the arguments bound. Bound arguments are passed after the arguments supplied by :ref:`call<class_Callable_method_call>`.
  98. ----
  99. .. _class_Callable_method_call:
  100. - :ref:`Variant<class_Variant>` **call** **(** ... **)** |vararg| |const|
  101. Calls the method represented by this ``Callable``. Arguments can be passed and should match the method's signature.
  102. ----
  103. .. _class_Callable_method_call_deferred:
  104. - void **call_deferred** **(** ... **)** |vararg| |const|
  105. 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.
  106. ----
  107. .. _class_Callable_method_get_method:
  108. - :ref:`StringName<class_StringName>` **get_method** **(** **)** |const|
  109. Returns the name of the method represented by this ``Callable``.
  110. ----
  111. .. _class_Callable_method_get_object:
  112. - :ref:`Object<class_Object>` **get_object** **(** **)** |const|
  113. Returns the object on which this ``Callable`` is called.
  114. ----
  115. .. _class_Callable_method_get_object_id:
  116. - :ref:`int<class_int>` **get_object_id** **(** **)** |const|
  117. Returns the ID of this ``Callable``'s object (see :ref:`Object.get_instance_id<class_Object_method_get_instance_id>`).
  118. ----
  119. .. _class_Callable_method_hash:
  120. - :ref:`int<class_int>` **hash** **(** **)** |const|
  121. Returns the 32-bit hash value of this ``Callable``'s object.
  122. \ **Note:** ``Callable``\ s with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does *not* imply the callables are equal, because different callables can have identical hash values due to hash collisions. The engine uses a 32-bit hash algorithm for :ref:`hash<class_Callable_method_hash>`.
  123. ----
  124. .. _class_Callable_method_is_custom:
  125. - :ref:`bool<class_bool>` **is_custom** **(** **)** |const|
  126. Returns ``true`` if this ``Callable`` is a custom callable whose behavior differs based on implementation details. Custom callables are used in the engine for various reasons. If ``true``, you can't use :ref:`get_method<class_Callable_method_get_method>`.
  127. ----
  128. .. _class_Callable_method_is_null:
  129. - :ref:`bool<class_bool>` **is_null** **(** **)** |const|
  130. Returns ``true`` if this ``Callable`` has no target to call the method on.
  131. ----
  132. .. _class_Callable_method_is_standard:
  133. - :ref:`bool<class_bool>` **is_standard** **(** **)** |const|
  134. Returns ``true`` if this ``Callable`` is a standard callable, referencing an object and a method using a :ref:`StringName<class_StringName>`.
  135. ----
  136. .. _class_Callable_method_is_valid:
  137. - :ref:`bool<class_bool>` **is_valid** **(** **)** |const|
  138. Returns ``true`` if the object exists and has a valid function assigned, or is a custom callable.
  139. ----
  140. .. _class_Callable_method_rpc:
  141. - void **rpc** **(** ... **)** |vararg| |const|
  142. Perform an RPC (Remote Procedure Call). This is used for multiplayer and is normally not available unless the function being called has been marked as *RPC*. Calling it on unsupported functions will result in an error.
  143. ----
  144. .. _class_Callable_method_rpc_id:
  145. - void **rpc_id** **(** :ref:`int<class_int>` peer_id, ... **)** |vararg| |const|
  146. Perform an RPC (Remote Procedure Call) on a specific peer ID (see multiplayer documentation for reference). This is used for multiplayer and is normally not available unless the function being called has been marked as *RPC*. Calling it on unsupported functions will result in an error.
  147. ----
  148. .. _class_Callable_method_unbind:
  149. - :ref:`Callable<class_Callable>` **unbind** **(** :ref:`int<class_int>` argcount **)** |const|
  150. Returns a copy of this ``Callable`` with the arguments unbound. Calling the returned ``Callable`` will call the method without the extra arguments that are supplied in the ``Callable`` on which you are calling this method.
  151. Operator Descriptions
  152. ---------------------
  153. .. _class_Callable_operator_neq_bool:
  154. - :ref:`bool<class_bool>` **operator !=** **(** :ref:`Callable<class_Callable>` right **)**
  155. Returns ``true`` if both ``Callable``\ s invoke different targets.
  156. ----
  157. .. _class_Callable_operator_eq_bool:
  158. - :ref:`bool<class_bool>` **operator ==** **(** :ref:`Callable<class_Callable>` right **)**
  159. Returns ``true`` if both ``Callable``\ s invoke the same custom target.
  160. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  161. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  162. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  163. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  164. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  165. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`