Callable.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Callable" version="4.0">
  3. <brief_description>
  4. An object representing a method in a certain object that can be called.
  5. </brief_description>
  6. <description>
  7. [Callable] is a first class object which can be held in variables and passed to functions. It represents a given method in an [Object], and is typically used for signal callbacks.
  8. [b]Example:[/b]
  9. [codeblocks]
  10. [gdscript]
  11. func print_args(arg1, arg2, arg3 = ""):
  12. prints(arg1, arg2, arg3)
  13. func test():
  14. var callable = Callable(self, "print_args")
  15. callable.call("hello", "world") # Prints "hello world ".
  16. callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(Node.gd)::print_args".
  17. callable.call("invalid") # Invalid call, should have at least 2 arguments.
  18. [/gdscript]
  19. [csharp]
  20. public void PrintArgs(object arg1, object arg2, object arg3 = null)
  21. {
  22. GD.PrintS(arg1, arg2, arg3);
  23. }
  24. public void Test()
  25. {
  26. Callable callable = new Callable(this, nameof(PrintArgs));
  27. callable.Call("hello", "world"); // Prints "hello world null".
  28. callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.cs)::PrintArgs".
  29. callable.Call("invalid"); // Invalid call, should have at least 2 arguments.
  30. }
  31. [/csharp]
  32. [/codeblocks]
  33. </description>
  34. <tutorials>
  35. </tutorials>
  36. <constructors>
  37. <constructor name="Callable">
  38. <return type="Callable" />
  39. <description>
  40. Constructs a null [Callable] with no object nor method bound.
  41. </description>
  42. </constructor>
  43. <constructor name="Callable">
  44. <return type="Callable" />
  45. <argument index="0" name="from" type="Callable" />
  46. <description>
  47. Constructs a [Callable] as a copy of the given [Callable].
  48. </description>
  49. </constructor>
  50. <constructor name="Callable">
  51. <return type="Callable" />
  52. <argument index="0" name="object" type="Object" />
  53. <argument index="1" name="method" type="StringName" />
  54. <description>
  55. Creates a new [Callable] for the method called [code]method[/code] in the specified [code]object[/code].
  56. </description>
  57. </constructor>
  58. </constructors>
  59. <methods>
  60. <method name="bind" qualifiers="vararg const">
  61. <return type="Callable" />
  62. <description>
  63. Returns a copy of this [Callable] with the arguments bound. Bound arguments are passed after the arguments supplied by [method call].
  64. </description>
  65. </method>
  66. <method name="call" qualifiers="vararg const">
  67. <return type="Variant" />
  68. <description>
  69. Calls the method represented by this [Callable]. Arguments can be passed and should match the method's signature.
  70. </description>
  71. </method>
  72. <method name="call_deferred" qualifiers="vararg const">
  73. <return type="void" />
  74. <description>
  75. 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.
  76. </description>
  77. </method>
  78. <method name="get_method" qualifiers="const">
  79. <return type="StringName" />
  80. <description>
  81. Returns the name of the method represented by this [Callable].
  82. </description>
  83. </method>
  84. <method name="get_object" qualifiers="const">
  85. <return type="Object" />
  86. <description>
  87. Returns the object on which this [Callable] is called.
  88. </description>
  89. </method>
  90. <method name="get_object_id" qualifiers="const">
  91. <return type="int" />
  92. <description>
  93. Returns the ID of this [Callable]'s object (see [method Object.get_instance_id]).
  94. </description>
  95. </method>
  96. <method name="hash" qualifiers="const">
  97. <return type="int" />
  98. <description>
  99. Returns the hash value of this [Callable]'s object.
  100. </description>
  101. </method>
  102. <method name="is_custom" qualifiers="const">
  103. <return type="bool" />
  104. <description>
  105. Returns [code]true[/code] 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 [code]true[/code], you can't use [method get_method].
  106. </description>
  107. </method>
  108. <method name="is_null" qualifiers="const">
  109. <return type="bool" />
  110. <description>
  111. Returns [code]true[/code] if this [Callable] has no target to call the method on.
  112. </description>
  113. </method>
  114. <method name="is_standard" qualifiers="const">
  115. <return type="bool" />
  116. <description>
  117. Returns [code]true[/code] if this [Callable] is a standard callable, referencing an object and a method using a [StringName].
  118. </description>
  119. </method>
  120. <method name="is_valid" qualifiers="const">
  121. <return type="bool" />
  122. <description>
  123. Returns [code]true[/code] if the object exists and has a valid function assigned, or is a custom callable.
  124. </description>
  125. </method>
  126. <method name="rpc" qualifiers="vararg const">
  127. <return type="void" />
  128. <description>
  129. 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 [i]RPC[/i]. Calling it on unsupported functions will result in an error.
  130. </description>
  131. </method>
  132. <method name="rpc_id" qualifiers="vararg const">
  133. <return type="void" />
  134. <argument index="0" name="peer_id" type="int" />
  135. <description>
  136. 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 [i]RPC[/i]. Calling it on unsupported functions will result in an error.
  137. </description>
  138. </method>
  139. <method name="unbind" qualifiers="const">
  140. <return type="Callable" />
  141. <argument index="0" name="argcount" type="int" />
  142. <description>
  143. 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.
  144. </description>
  145. </method>
  146. </methods>
  147. <operators>
  148. <operator name="operator !=">
  149. <return type="bool" />
  150. <description>
  151. </description>
  152. </operator>
  153. <operator name="operator !=">
  154. <return type="bool" />
  155. <argument index="0" name="right" type="Callable" />
  156. <description>
  157. Returns [code]true[/code] if both [Callable]s invoke different targets.
  158. </description>
  159. </operator>
  160. <operator name="operator ==">
  161. <return type="bool" />
  162. <description>
  163. </description>
  164. </operator>
  165. <operator name="operator ==">
  166. <return type="bool" />
  167. <argument index="0" name="right" type="Callable" />
  168. <description>
  169. Returns [code]true[/code] if both [Callable]s invoke the same custom target.
  170. </description>
  171. </operator>
  172. </operators>
  173. </class>