summaryrefslogtreecommitdiff
path: root/doc/classes/Callable.xml
blob: ad5c549fee9fe7d7776dbf1ad515043e0686ca6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Callable" version="4.0">
	<brief_description>
		An object representing a method in a certain object that can be called.
	</brief_description>
	<description>
		[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.
		[b]Example:[/b]
		[codeblocks]
		[gdscript]
		var callable = Callable(self, "print_args")
		func print_args(arg1, arg2, arg3 = ""):
		    prints(arg1, arg2, arg3)

		func test():
		    callable.call("hello", "world")  # Prints "hello world".
		    callable.call(Vector2.UP, 42, callable)  # Prints "(0, -1) 42 Node(Node.gd)::print_args".
		    callable.call("invalid")  # Invalid call, should have at least 2 arguments.
		[/gdscript]
		[csharp]
		Callable callable = new Callable(this, "print_args");
		public void PrintArgs(object arg1, object arg2, object arg3 = "")
		{
		    GD.PrintS(arg1, arg2, arg3);
		}

		public void Test()
		{
		    callable.Call("hello", "world"); // Prints "hello world".
		    callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.gd)::print_args".
		    callable.Call("invalid"); // Invalid call, should have at least 2 arguments.
		}
		[/csharp]
		[/codeblocks]
	</description>
	<tutorials>
	</tutorials>
	<methods>
		<method name="Callable">
			<return type="Callable">
			</return>
			<argument index="0" name="object" type="Object">
			</argument>
			<argument index="1" name="method_name" type="StringName">
			</argument>
			<description>
				Creates a new [Callable] for the method called [code]method_name[/code] in the specified [code]object[/code].
			</description>
		</method>
		<method name="bind" qualifiers="vararg">
			<return type="void">
			</return>
			<description>
			</description>
		</method>
		<method name="call" qualifiers="vararg">
			<return type="Variant">
			</return>
			<description>
				Calls the method represented by this [Callable]. Arguments can be passed and should match the method's signature.
			</description>
		</method>
		<method name="call_deferred" qualifiers="vararg">
			<return type="void">
			</return>
			<description>
				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.
			</description>
		</method>
		<method name="get_method">
			<return type="StringName">
			</return>
			<description>
				Returns the name of the method represented by this [Callable].
			</description>
		</method>
		<method name="get_object">
			<return type="Object">
			</return>
			<description>
				Returns the object on which this [Callable] is called.
			</description>
		</method>
		<method name="get_object_id">
			<return type="int">
			</return>
			<description>
				Returns the ID of this [Callable]'s object (see [method Object.get_instance_id]).
			</description>
		</method>
		<method name="hash">
			<return type="int">
			</return>
			<description>
			</description>
		</method>
		<method name="is_custom">
			<return type="bool">
			</return>
			<description>
			</description>
		</method>
		<method name="is_null">
			<return type="bool">
			</return>
			<description>
			</description>
		</method>
		<method name="is_standard">
			<return type="bool">
			</return>
			<description>
			</description>
		</method>
		<method name="unbind">
			<return type="Callable">
			</return>
			<argument index="0" name="argcount" type="int">
			</argument>
			<description>
			</description>
		</method>
	</methods>
	<constants>
	</constants>
</class>