1 module godot.callable;
2 
3 import godot.abi;
4 import godot.variant;
5 import godot.object;
6 import godot.array;
7 import godot.stringname;
8 import godot.builtins;
9 
10 /// Untyped Callable that binds directly to Godot's Callable
11 struct GodotCallable {
12     package(godot) union callable {
13         godot_callable _godot_callable;
14         GodotCallable_Bind _bind;
15     }
16 
17     package(godot) callable _callable;
18     alias _callable this;
19 
20     package(godot) this(godot_callable opaque) {
21         _godot_callable = opaque;
22     }
23 
24     this(ref scope const GodotCallable other) {
25         _callable = other._callable;
26     }
27 
28 
29     this(in GodotObject object, in StringName method) {
30         this = _bind.new2(object, method);
31     }
32 
33     this(in GodotObject object, in string method) {
34         StringName snMethod = method;
35         this = _bind.new2(object, snMethod);
36     }
37 
38     void _defaultCtor() {
39         _bind.new0();
40     }
41 
42     ~this() {
43         _bind._destructor();
44     }
45 
46     Variant callv(in Array arguments) const {
47         return _bind.callv(arguments);
48     }
49 
50     Variant call(Args...)(Args args) const {
51         return _bind.call(args);
52     }
53 
54     Variant callDeferred(Args...)(Args args) const {
55         return _bind.callDeferred(args);
56     }
57 
58     void rpc(Args...)(Args args) const {
59         return _bind.rpc(args);
60     }
61 
62     void rpcId(Args...)(long peerId, Args args) const {
63         return _bind.rpcId(peerId, args);
64     }
65 
66     bool isNull() const {
67         return _bind.isNull();
68     }
69 
70     bool isCustom() const {
71         return _bind.isCustom();
72     }
73 
74     bool isStandard() const {
75         return _bind.isStandard();
76     }
77 
78     bool isValid() const {
79         return _bind.isValid();
80     }
81 
82     GodotObject getObject() const {
83         return _bind.getObject();
84     }
85 
86     ObjectID getObjectId() const {
87         return ObjectID(_bind.getObjectId());
88     }
89 
90     StringName getMethod() const {
91         return _bind.getMethod();
92     }
93 
94     long getBoundArgumentsCount() const {
95         return _bind.getBoundArgumentsCount();
96     }
97 
98     Array getBoundArguments() const {
99         return _bind.getBoundArguments();
100     }
101 
102     long hash() const {
103         return _bind.hash();
104     }
105 
106     GodotCallable bindv(in Array arguments) {
107         return _bind.bindv(arguments);
108     }
109 
110     GodotCallable unbind(in long argcount) const {
111         return _bind.unbind(argcount);
112     }
113 
114     GodotCallable bind(Args...)(Args args) const {
115         return _bind.bind(args);
116     }
117 }
118 
119 
120 /// Type-safe Callable wrapper around Godot's Callable
121 version(none) struct GodotCallableT(Return, Args...) {
122     GodotCallable _impl;
123 
124     this(GodotCallable callable) {
125         _impl = callable;
126     }
127 
128     ref typeof(this) opAssign(GodotCallable value)
129     {
130         _impl = value;
131         return this;
132     }
133 
134     Return call(Args args) {
135         static if (is(Return == void))
136             _impl.call(args);
137         else
138             return _impl.call(args);
139     }
140 }