Mercurial > projects > dstep
annotate dstep/objc/bridge/Bridge.d @ 20:6255d355d752
Made it compile with dmd 1.056
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 03 Feb 2010 18:28:01 +0100 |
parents | ae08a08f44d3 |
children | b9de51448c6b |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Feb 4, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.objc.bridge.Bridge; | |
8 | |
9 version (Tango) | |
10 { | |
11 import tango.core.Memory; | |
12 import tango.core.Traits : ParameterTupleOf, ReturnTypeOf; | |
13 } | |
14 | |
15 else | |
16 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
17 import GC = std.gc : addRoot; |
1 | 18 import std.traits : ParameterTypeTuple, ReturnType; |
19 | |
20 alias ReturnType ReturnTypeOf; | |
21 alias ParameterTypeTuple ParameterTupleOf; | |
22 } | |
23 | |
24 import dstep.internal.String; | |
25 import dstep.internal.Version; | |
26 import dstep.objc.bridge.Capsule; | |
27 import dstep.objc.bridge.ClassInitializer; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
28 import dstep.objc.bridge.Type; |
1 | 29 import dstep.objc.bridge.TypeEncoding; |
30 import dstep.objc.bridge.Wrapper; | |
31 import dstep.objc.message; | |
32 import dstep.objc.objc; | |
33 import dstep.objc.runtime; | |
34 | |
35 /** | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
36 * Builds a string representing a selector out of the given method |
1 | 37 * |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
38 * It will build the string using the parameter names as a part of the selector, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
39 * like this: |
1 | 40 * |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
41 * Examples: |
1 | 42 * --- |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
43 * foo (int x, int y); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
44 * bar (); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
45 * fooBar (int x); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
46 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
47 * static assert(selectorAsString!(foo) == "foo:y:"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
48 * static assert(selectorAsString!(bar) == "bar"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
49 * static assert(selectorAsString!(fooBar) == "fooBar:"); |
1 | 50 * --- |
51 * | |
52 * Params: | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
53 * method = the method alias to build the selector of |
1 | 54 * |
55 * Returns: a string representing the selector | |
56 */ | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
57 template selectorAsString (alias method) |
1 | 58 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
59 const selectorAsString = buildSelector!(method); |
1 | 60 } |
61 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
62 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
63 * Registers a method with the Objective-C runtime system, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
64 * maps the method name to a selector, and returns the selector value. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
65 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
66 * You must register a method name with the Objective-C runtime system to obtain |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
67 * the method’s selector before you can add the method to a class definition. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
68 * If the method name has already been registered, this function simply returns |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
69 * the selector. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
70 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
71 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
72 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
73 * SEL sel = selector!("foo:"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
74 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
75 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
76 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
77 * str = the string to register |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
78 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
79 * Returns: a pointer of type SEL specifying the selector for the named method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
80 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
81 SEL selector (string str) () |
1 | 82 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
83 return sel.registerName!(str); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
84 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
85 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
86 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
87 * Registers a method with the Objective-C runtime system, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
88 * maps the method name to a selector, and returns the selector value. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
89 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
90 * Using selectorAsString to get the string representation of the selector. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
91 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
92 * You must register a method name with the Objective-C runtime system to obtain |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
93 * the method’s selector before you can add the method to a class definition. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
94 * If the method name has already been registered, this function simply returns |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
95 * the selector. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
96 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
97 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
98 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
99 * foo (int x); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
100 * SEL sel = selector!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
101 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
102 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
103 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
104 * method = the method to register |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
105 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
106 * Returns: a pointer of type SEL specifying the selector for the named method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
107 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
108 SEL selector (alias method) () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
109 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
110 return sel.registerName!(selectorAsString!(method)); |
1 | 111 } |
112 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
113 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
114 * All Objective-C wrappers should mix in this string. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
115 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
116 * Mixes in: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
117 * $(UL |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
118 * $(LI $(D_PSYMBOL __objcClass): a class variable representing the Objective-C class) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
119 * $(LI $(D_PSYMBOL __objcSuperClass): a class variable representing the Objective-C super class) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
120 * $(LI A constructor taking an Objective-C instance) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
121 * $(LI $(D_PSYMBOL dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
122 * ) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
123 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
124 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
125 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
126 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
127 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
128 * mixin(ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
129 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
130 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
131 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
132 const ObjcWrap = "static private dstep.objc.objc.Class __objcClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
133 static private dstep.objc.objc.Class __objcSuperClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
134 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
135 this (dstep.objc.objc.id object) |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
136 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
137 super(object); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
138 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
139 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
140 static typeof(this) alloc () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
141 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
142 return invokeObjcSelfClass!(typeof(this), \"alloc\"); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
143 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
144 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
145 mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; |
1 | 146 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
147 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
148 * All Objective-C wrappers should mix in this string. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
149 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
150 * Mixes in: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
151 * $(UL |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
152 * $(LI $(D_PSYMBOL __objcClass): a class variable representing the Objective-C class) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
153 * $(LI $(D_PSYMBOL __objcSuperClass): a class variable representing the Objective-C super class) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
154 * $(LI A constructor taking an Objective-C instance) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
155 * $(LI $(D_PSYMBOL dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
156 * ) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
157 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
158 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
159 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
160 * class NSString : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
161 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
162 * mixin(ObjcClusterWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
163 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
164 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
165 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
166 const ObjcClusterWrap = "static private dstep.objc.objc.Class __objcClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
167 static private dstep.objc.objc.Class __objcSuperClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
168 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
169 this (dstep.objc.objc.id object) |
1 | 170 { |
171 super(object); | |
172 } | |
173 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
174 static typeof(this) alloc () |
1 | 175 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
176 return invokeObjcSuperClass!(typeof(this), \"alloc\"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
177 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
178 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
179 mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; |
1 | 180 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
181 /** |
19 | 182 * Makes the given field available as an IBOutlet. |
183 * | |
184 * Mixes in a method that is called by the Objective-C side to set the value of the | |
185 * given field. | |
186 * | |
187 * Mixes in: $(D_PSYMBOL ObjcBindMethod) | |
188 * | |
189 * Examples: | |
190 * --- | |
191 * class AppController : NSObject | |
192 * { | |
193 * NSButton button; | |
194 * mixin IBOutlet!(button); | |
195 * } | |
196 * --- | |
197 * | |
198 * Params: | |
199 * field = the field make available as an IBOutlet | |
200 */ | |
201 template IBOutlet (alias field) | |
202 { | |
203 static assert (is(typeof(field) : Object), dstep.objc.bridge.Bridge.buildIBOutletErrorMessage!(field)); | |
204 | |
20 | 205 /// Sets the field |
19 | 206 void __setMethod (typeof(field) value) |
207 { | |
208 field = value; | |
209 } | |
210 | |
211 mixin dstep.objc.bridge.Bridge.ObjcBindMethod!(__setMethod, "set" ~ dstep.objc.bridge.Bridge.toUpper(field.stringof[0]) ~ field.stringof[1 .. $] ~ ":"); | |
212 } | |
213 | |
214 char toUpper (char c) | |
215 { | |
216 if (c >= 'a' && c <= 'z') | |
217 return c - 32; | |
218 | |
219 return c; | |
220 } | |
221 | |
222 template buildIBOutletErrorMessage (alias field) | |
223 { | |
224 const buildIBOutletErrorMessage = `The type "` ~ typeof(field).stringof ~ `" of the given field "` ~ field.stringof ~ `" in the class "` ~ typeof(this).stringof ~ `" is not a valid IBOutlet type. IBOutlets can only be of the type Object (or any of its subclasses)`; | |
225 } | |
226 | |
227 /** | |
18 | 228 * Binds a selector to an instance method. |
229 * | |
230 * This will create a receiver function which will forward the call to $(D_PARAM method), | |
231 * decapsulating arguments and encapsulating the return value as appropriate. | |
232 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build | |
233 * the selector. It will automatically infer the return type and the argument types | |
234 * of the method. An action method can only have one parameter and of the type Object | |
235 * (or any of its subclasses). | |
236 * | |
237 * Mixes in: ObjcBindMethod | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
238 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
239 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
240 * --- |
18 | 241 * class AppController : NSObject |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
242 * { |
18 | 243 * void foo (Object sender) {} |
244 * mixin IBAction!(foo); | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
245 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
246 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
247 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
248 * Params: |
18 | 249 * method = the method to bind |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
250 */ |
18 | 251 template IBAction (alias method) |
1 | 252 { |
19 | 253 static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "An action method is only allowed to have one parameter"); |
254 static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "An action method can only have a parameter of the type Object (or any of its subclasses)"); | |
18 | 255 |
256 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); | |
1 | 257 } |
258 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
259 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
260 * Binds a selector to an instance method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
261 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
262 * This will create a receiver function which will forward the call to $(D_PARAM method), |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
263 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
264 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
265 * the selector. It will automatically infer the return type and the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
266 * of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
267 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
268 * Mixes in: ObjcBindMethod |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
269 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
270 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
271 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
272 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
273 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
274 * void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
275 * mixin ObjcBindMethod!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
276 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
277 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
278 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
279 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
280 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
281 */ |
1 | 282 template ObjcBindMethod (alias method) |
283 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
284 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); |
1 | 285 } |
286 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
287 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
288 * Binds a selector to an instance method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
289 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
290 * This will create a receiver function which will forward the call to $(D_PARAM method), |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
291 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
292 * It will automatically infer the return type and the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
293 * of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
294 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
295 * Mixes in: ObjcBindMethod |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
296 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
297 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
298 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
299 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
300 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
301 * void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
302 * mixin ObjcBindMethod!(foo, "foo"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
303 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
304 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
305 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
306 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
307 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
308 * selector = the selector to bind the method to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
309 */ |
1 | 310 template ObjcBindMethod (alias method, string selector) |
311 { | |
19 | 312 mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); |
1 | 313 } |
314 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
315 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
316 * Binds a selector to an instance method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
317 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
318 * This will create a receiver method which will forward the call to $(D_PARAM method), |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
319 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
320 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
321 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
322 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
323 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
324 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
325 * int foo (int x) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
326 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
327 * return x; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
328 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
329 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
330 * mixin ObjcBindMethod!(foo, int, "foo:", int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
331 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
332 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
333 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
334 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
335 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
336 * R = the return type of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
337 * selector = the selector to bind the method to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
338 * ARGS = the argument types of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
339 */ |
1 | 340 template ObjcBindMethod (alias method, R, string selector, ARGS...) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
341 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
342 private |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
343 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
344 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
345 * Resolves the virtual call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
346 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
347 * Returns: a $(D_KEYWORD delegate) to the binded method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
348 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
349 R delegate (ARGS) __resolveVirtualCall () |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
350 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
351 return &method; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
352 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
353 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
354 /// A type tuple with all the encapsulated types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
355 alias dstep.objc.bridge.Type.ObjcTypes!(ARGS) __ObjcArgs; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
356 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
357 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
358 * The receiver method, this will be the method called from the Objective-C side |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
359 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
360 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
361 * self = the Objective-C instance to call the method on |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
362 * cmd = the Objective-C selector representing the method to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
363 * objcArgs = the encapsulated arguments to the binded method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
364 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
365 * Returns: whatever the binded method returns, encapsulated |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
366 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
367 extern (C) static dstep.objc.bridge.Type.ObjcType!(R) __forwardVirtualCall (dstep.objc.objc.id self, dstep.objc.objc.SEL cmd, __ObjcArgs objcArgs) |
1 | 368 in |
369 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
370 assert(dstep.objc.bridge.Capsule.isCapsule(self)); |
1 | 371 } |
372 body | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
373 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
374 R delegate (ARGS) delegate () dg; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
375 dg.ptr = cast(void*) dstep.objc.bridge.Capsule.decapsule!(typeof(this))(self); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
376 dg.funcptr = &__resolveVirtualCall; |
1 | 377 ARGS args; |
378 | |
379 foreach (i, a ; objcArgs) | |
380 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
381 alias typeof(args[i]) ArgType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
382 args[i] = dstep.objc.bridge.Capsule.decapsule!(ArgType)(a); |
1 | 383 } |
384 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
385 static if (is(R == void)) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
386 dg()(args); |
1 | 387 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
388 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
389 return dstep.objc.bridge.Capsule.encapsule!(R)(dg()(args)); |
1 | 390 } |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
391 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
392 /// The Objective-C method declaration for the binded method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
393 ObjcMethodDeclaration!(__forwardVirtualCall, R, selector, ARGS) __objcMethodDeclaration; |
1 | 394 } |
395 } | |
396 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
397 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
398 * Binds a selector to a class (static) method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
399 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
400 * This will create a receiver function which will forward the call to $(D_PARAM method), |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
401 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
402 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
403 * to build the selector. It will automatically infer the return type and the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
404 * argument types of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
405 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
406 * Mixes in: $(D_PSYMBOL ObjcBindClassMethod) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
407 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
408 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
409 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
410 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
411 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
412 * static void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
413 * mixin ObjcBindClassMethod!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
414 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
415 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
416 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
417 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
418 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
419 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
420 template ObjcBindClassMethod (alias method) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
421 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
422 mixin ObjcBindClassMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
423 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
424 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
425 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
426 * Binds a selector to a class (static) method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
427 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
428 * This will create a receiver function which will forward the call to $(D_PARAM method), |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
429 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
430 * It will automatically infer the return type and the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
431 * of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
432 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
433 * Mixes in: $(D_PSYMBOL ObjcBindClassMethod) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
434 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
435 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
436 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
437 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
438 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
439 * static void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
440 * mixin ObjcBindClassMethod!(foo, "foo"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
441 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
442 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
443 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
444 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
445 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
446 * selector = the selector to bind the method to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
447 */ |
1 | 448 template ObjcBindClassMethod (alias method, string selector) |
449 { | |
19 | 450 mixin ObjcBindClassMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); |
1 | 451 } |
452 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
453 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
454 * Binds a selector to a class (static) method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
455 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
456 * This will create a receiver method which will forward the call to $(D_PARAM method), |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
457 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
458 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
459 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
460 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
461 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
462 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
463 * static int foo (int x) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
464 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
465 * return x; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
466 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
467 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
468 * mixin ObjcBindClassMethod!(foo, int, "foo:", int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
469 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
470 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
471 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
472 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
473 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
474 * R = the return type of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
475 * selector = the selector to bind the method to |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
476 * ARGS = the argument types of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
477 */ |
1 | 478 template ObjcBindClassMethod (alias method, R, string selector, ARGS...) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
479 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
480 private |
1 | 481 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
482 /// A type tuple with all the encapsulated types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
483 alias dstep.objc.bridge.Type.ObjcTypes!(ARGS) __ObjcArgs; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
484 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
485 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
486 * The receiver method, this will be the method called from the Objective-C side |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
487 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
488 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
489 * objcArgs = the encapsulated arguments to the binded method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
490 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
491 * Returns: whatever the binded method returns, encapsulated |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
492 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
493 extern (C) static dstep.objc.bridge.Type.ObjcType!(R) __forwardStaticCall (dstep.objc.objc.Class self, dstep.objc.objc.SEL cmd, __ObjcArgs objcArgs) |
1 | 494 in |
495 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
496 assert(dstep.objc.bridge.Capsule.isCapsule(self)); |
1 | 497 } |
498 body | |
499 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
500 R function (ARGS) funcPtr = &method; |
1 | 501 ARGS args; |
502 | |
503 foreach (i, a ; objcArgs) | |
504 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
505 alias typeof(args[i]) ArgType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
506 args[i] = dstep.objc.bridge.Capsule.decapsule!(ArgType)(a); |
1 | 507 } |
508 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
509 static if (is(R == void)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
510 funcPtr()(args); |
1 | 511 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
512 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
513 return dstep.objc.bridge.Capsule.encapsule!(R)(funcPtr()(args)); |
1 | 514 } |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
515 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
516 /// The Objective-C method declaration for the binded method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
517 ObjcMethodDeclaration!(__forwardStaticCall, R, selector, ARGS) __objcClassMethodDeclaration; |
1 | 518 } |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
519 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
520 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
521 /** |
18 | 522 * This $(D_KEYWORD struct) represents an Objective-C method declaration. |
523 * | |
524 * Examples: | |
525 * --- | |
526 * class C : NSObject | |
527 * { | |
528 * void foo (int x) {} | |
529 * ObjcMethodDeclaration!(foo, void, "foo", int) objcMethodDecl; | |
530 * } | |
531 * --- | |
532 * | |
533 * Params: | |
534 * imp = the D method | |
535 * R = the return type of the method | |
536 * name = the name of the method | |
537 * ARGS = the argument types of the method | |
538 */ | |
539 struct ObjcMethodDeclaration (alias imp, R, string name, ARGS...) | |
540 { | |
541 dstep.objc.objc.IMP methodImp = cast(dstep.objc.objc.IMP) &imp; | |
542 alias R returnType; | |
543 const string methodName = name; | |
544 alias ARGS argsType; | |
545 } | |
546 | |
547 /** | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
548 * Binds a D free function to an Objective-C free function. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
549 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
550 * This will create a receiver function which will forward the call to the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
551 * binded function, decapsulating arguments and encapsulating the return value |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
552 * as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
553 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
554 * Mixes in: $(D_PSYMBOL ObjcBindFunction) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
555 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
556 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
557 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
558 * void foo (); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
559 * mixin ObjcBindFunction!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
560 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
561 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
562 template ObjcBindFunction (alias func) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
563 { |
19 | 564 mixin ObjcBindFunction!(func, dstep.objc.bridge.Bridge.ReturnTypeOf!(func), dstep.objc.bridge.Bridge.ParameterTupleOf!(func)); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
565 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
566 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
567 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
568 * Binds a D free function to an Objective-C free function. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
569 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
570 * This will create a receiver function which will forward the call to the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
571 * binded function, decapsulating arguments and encapsulating the return value |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
572 * as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
573 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
574 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
575 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
576 * char foo (int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
577 * mixin ObjcBindFunction!(foo, char, int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
578 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
579 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
580 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
581 * func = the function to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
582 * R = the return type of the function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
583 * ARGS = the argument types of the function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
584 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
585 template ObjcBindFunction (alias func, R, ARGS...) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
586 { |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
587 private |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
588 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
589 /// A type tuple with all the encapsulated types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
590 alias dstep.objc.bridge.Type.ObjcTypes!(ARGS) __ObjcArgs; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
591 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
592 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
593 * The receiver function, this will be the function called from the Objective-C side |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
594 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
595 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
596 * objcArgs = the encapsulated arguments to the binded function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
597 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
598 * Returns: whatever the binded function returns, encapsulated |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
599 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
600 extern (C) dstep.internal.Types.ObjcType!(R) __forwardFunctionCall (__ObjcArgs objcArgs) |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
601 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
602 R function (ARGS) funcPtr = &func; |
1 | 603 ARGS args; |
604 | |
605 foreach (i, a ; objcArgs) | |
606 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
607 alias typeof(args[i]) ArgType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
608 args[i] = dstep.objc.bridge.Capsule.decapsule!(ArgType)(a); |
1 | 609 } |
610 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
611 static if (is(R == void)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
612 funcPtr()(args); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
613 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
614 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
615 return dstep.objc.bridge.Capsule.encapsule!(R)(funcPtr()(args)); |
1 | 616 } |
617 } | |
618 } | |
619 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
620 /// This $(D_KEYWORD class) acts like a name space for various methods and functions |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
621 class Bridge |
1 | 622 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
623 private static Bridge bridgeInstance; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
624 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
625 /// The name of the method declaration variable mixed in in a $(D_KEYWORD class) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
626 const objcMethodDeclarationVar = "__objcMethodDeclaration"; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
627 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
628 /// The name of the class method declaration variable mixed in in a $(D_KEYWORD class) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
629 const objcClassMethodDeclarationVar = "__objcClassMethodDeclaration"; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
630 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
631 /// The name of the variable used on the Objective-C side to store the D object |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
632 const dObjectVar = "dObject"; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
633 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
634 /// This alias is used as an internal representation of a D object |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
635 //alias Object DObjectType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
636 alias void* DObjectType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
637 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
638 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
639 * Gets the only instance of this class |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
640 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
641 * Returns: the instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
642 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
643 static Bridge instance () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
644 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
645 if (bridgeInstance) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
646 return bridgeInstance; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
647 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
648 return bridgeInstance = new Bridge; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
649 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
650 |
1 | 651 static: |
652 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
653 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
654 * Gets the value of an Objective-C instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
655 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
656 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
657 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
658 * id self; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
659 * int x = getObjcIvar!(int, "x")(self); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
660 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
661 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
662 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
663 * T = the type of the instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
664 * name = the name of the instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
665 * self = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
666 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
667 * Returns: the value of the Objective-C variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
668 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
669 T getObjcIvar (T, string name) (id self) |
1 | 670 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
671 T value; |
1 | 672 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
673 self.getInstanceVariable!(T, name)(value); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
674 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
675 return value; |
1 | 676 } |
677 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
678 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
679 * Sets the value of an Objective-C instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
680 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
681 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
682 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
683 * id self; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
684 * Bridge.setObjcIvar!(int, "x")(self, 3); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
685 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
686 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
687 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
688 * T = the type of the instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
689 * name = the name of the instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
690 * objcObject = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
691 * value = the value to set |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
692 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
693 void setObjcIvar (T, string name) (id self, T value) |
1 | 694 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
695 GC.addRoot(value); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
696 self.setInstanceVariable!(T, dObjectVar)(value); |
1 | 697 } |
698 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
699 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
700 * Gets the D object stored in the given Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
701 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
702 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
703 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
704 * NSObject object = new NSObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
705 * id self = object.objcObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
706 * assert(object == Bridge.getDObject(self)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
707 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
708 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
709 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
710 * self = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
711 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
712 * Returns: the D object or null |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
713 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
714 package DObjectType getDObject (id self) |
1 | 715 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
716 return getObjcIvar!(DObjectType, dObjectVar)(self); |
1 | 717 } |
718 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
719 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
720 * Stores the given D object in the given Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
721 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
722 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
723 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
724 * NSObject object = new NSObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
725 * id self = object.objcObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
726 * Bridge.setDObject(object, self); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
727 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
728 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
729 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
730 * dObject = the D object to store |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
731 * objcObject = the Objective-C instance to store the D object in |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
732 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
733 * Returns: the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
734 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
735 package id setDObject (Object dObject, id objcObject) |
1 | 736 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
737 auto o = cast(DObjectType) dObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
738 setObjcIvar!(DObjectType, dObjectVar)(objcObject, o); |
1 | 739 |
740 return objcObject; | |
741 } | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
742 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
743 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
744 * Deregisters the given Objective-C instance from the bridge |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
745 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
746 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
747 * objcInstance = the Objective-C instance to deregister |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
748 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
749 package static void deregisterObjcInstance (id objcInstance) |
1 | 750 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
751 GC.removeRoot(getObjcIvar!(DObjectType, dObjectVar)(objcInstance)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
752 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
753 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
754 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
755 * This method wraps the family of $(D_PSYMBOL objc_msgSend) methods which is used to send a message |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
756 * to an instance of a class. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
757 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
758 * This method chooses the appropriate $(D_PSYMBOL objc_msgSend) method depending on the return value, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
759 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
760 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
761 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
762 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
763 * selector = the selector to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
764 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
765 * self = the reciver of the call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
766 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
767 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
768 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
769 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
770 R invokeObjcMethod (R, string selector, ARGS...) (id self, ARGS args) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
771 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
772 static assert (checkSelector!(selector, ARGS), "The selector \"" ~ selector ~ "\" and the arguments " ~ ARGS.stringof ~ " do not match"); |
1 | 773 |
774 SEL sel = sel.registerName!(selector); | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
775 ObjcTypes!(ARGS) objcArgs; |
1 | 776 |
777 foreach (i, a ; args) | |
778 { | |
779 alias typeof(a) ArgType; | |
780 | |
781 objcArgs[i] = encapsule!(ArgType)(a); | |
782 } | |
783 | |
784 static if (is(R == struct)) | |
785 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
786 R result; |
1 | 787 self.msgSend_stret(result, sel, objcArgs); |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
788 |
1 | 789 return result; |
790 } | |
791 | |
792 else static if (is(R == float) || is(R == double) || is(R == real)) | |
793 { | |
794 version (X86) | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
795 return self.msgSend_fpret!(R, ObjcTypes!(ARGS))(sel, objcArgs); |
1 | 796 |
797 else version (X86_64) | |
798 { | |
799 static if (is(R == real)) | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
800 return self.msgSend_fpret!(R)(sel, objcArgs); |
1 | 801 |
802 else | |
803 return self.msgSend!(R)(sel, objcArgs); | |
804 } | |
805 | |
806 else | |
807 return self.msgSend!(R)(sel, objcArgs); | |
808 } | |
809 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
810 else static if (needsEncapsulation!(R)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
811 return decapsule!(R)(self.msgSend(sel, objcArgs)); |
1 | 812 |
813 else | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
814 return self.msgSend!(R, ObjcTypes!(ARGS))(sel, objcArgs); |
1 | 815 } |
816 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
817 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
818 * This method wraps the family of $(D_PSYMBOL objc_msgSend) methods which is used to send a message |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
819 * to a class. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
820 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
821 * This method chooses the appropriate $(D_PSYMBOL objc_msgSend) method depending on the return value, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
822 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
823 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
824 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
825 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
826 * selector = the selector to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
827 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
828 * cls = the reciver of the call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
829 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
830 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
831 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
832 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
833 R invokeObjcClassMethod (R, string selector, ARGS...) (Class cls, ARGS args) |
1 | 834 { |
835 return invokeObjcMethod!(R, selector, ARGS)(cast(id) cls, args); | |
836 } | |
837 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
838 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
839 * This method wraps the family of $(D_PSYMBOL objc_msgSendSuper) methods which is used to send a message |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
840 * to an instance of a superclass. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
841 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
842 * This method chooses the appropriate $(D_PSYMBOL objc_msgSendSuper) method depending on the return value, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
843 * decapsulating arguments and encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
844 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
845 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
846 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
847 * selector = the selector to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
848 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
849 * self = the reciver of the call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
850 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
851 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
852 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
853 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
854 R invokeObjcSuperMethod (R, string selector, ARGS...) (objc_super* self, ARGS args) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
855 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
856 static assert (checkSelector!(selector, ARGS), "The selector \"" ~ selector ~ "\" and the arguments " ~ ARGS.stringof ~ " do not match"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
857 |
1 | 858 SEL sel = sel.registerName!(selector); |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
859 ObjcTypes!(ARGS) objcArgs; |
1 | 860 |
861 foreach (i, a ; args) | |
862 { | |
863 alias typeof(a) ArgType; | |
864 | |
865 objcArgs[i] = encapsule!(ArgType)(a); | |
866 } | |
867 | |
868 static if (is(R == struct)) | |
869 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
870 R result; |
1 | 871 self.msgSendSuper_stret(result, sel, objcArgs); |
872 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
873 return result; |
1 | 874 } |
875 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
876 else static if (needsEncapsulation!(R)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
877 return decapsule!(R)(self.msgSendSuper(sel, objcArgs)); |
1 | 878 |
879 else | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
880 return self.msgSendSuper!(R, ObjcTypes!(ARGS))(sel, objcArgs); |
1 | 881 } |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
882 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
883 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
884 * This method wraps a call to a regular C free function, decapsulating arguments and |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
885 * encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
886 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
887 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
888 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
889 * func = the function to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
890 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
891 * args = the arguments to the function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
892 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
893 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
894 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
895 R invokeObjcFunction (R, alias func, ARGS...) (ARGS args) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
896 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
897 auto funcPtr = &func; // use a function pointer instead of the alias because the function may not be public. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
898 ObjcTypes!(ARGS) objcArgs; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
899 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
900 foreach (i, a ; args) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
901 { |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
902 alias typeof(a) ArgType; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
903 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
904 objcArgs[i] = encapsule!(ArgType)(a); |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
905 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
906 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
907 static if (is(R == void)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
908 funcPtr(objcArgs); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
909 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
910 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
911 return decapsule!(R)(funcPtr(objcArgs)); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
912 } |
1 | 913 } |