Mercurial > projects > dstep
annotate dstep/objc/bridge/Bridge.d @ 18:b2693af5a569
Added IBAction
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 15 Jan 2010 12:41:07 +0100 |
parents | 19885b43130e |
children | ae08a08f44d3 |
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 /** |
18 | 182 * Binds a selector to an instance method. |
183 * | |
184 * This will create a receiver function which will forward the call to $(D_PARAM method), | |
185 * decapsulating arguments and encapsulating the return value as appropriate. | |
186 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build | |
187 * the selector. It will automatically infer the return type and the argument types | |
188 * of the method. An action method can only have one parameter and of the type Object | |
189 * (or any of its subclasses). | |
190 * | |
191 * Mixes in: ObjcBindMethod | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
192 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
193 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
194 * --- |
18 | 195 * class AppController : NSObject |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
196 * { |
18 | 197 * void foo (Object sender) {} |
198 * mixin IBAction!(foo); | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
199 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
200 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
201 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
202 * Params: |
18 | 203 * method = the method to bind |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
204 */ |
18 | 205 template IBAction (alias method) |
1 | 206 { |
18 | 207 static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "dstep.objc.bridge.Bridge.IBAction: an action method is only allowed to have one parameter"); |
208 static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "dstep.objc.bridge.Bridge.IBAction: an action method can only have a parameter of the type Object (or any of its subclasses)"); | |
209 | |
210 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); | |
1 | 211 } |
212 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
213 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
214 * Binds a selector to an instance method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
215 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
216 * 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
|
217 * 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
|
218 * 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
|
219 * 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
|
220 * of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
221 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
222 * Mixes in: ObjcBindMethod |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
223 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
224 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
225 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
226 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
227 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
228 * void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
229 * mixin ObjcBindMethod!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
230 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
231 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
232 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
233 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
234 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
235 */ |
1 | 236 template ObjcBindMethod (alias method) |
237 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
238 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); |
1 | 239 } |
240 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
241 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
242 * Binds a selector to an instance method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
243 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
244 * 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
|
245 * 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
|
246 * 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
|
247 * of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
248 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
249 * Mixes in: ObjcBindMethod |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
250 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
251 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
252 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
253 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
254 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
255 * void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
256 * mixin ObjcBindMethod!(foo, "foo"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
257 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
258 * --- |
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 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
261 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
262 * 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
|
263 */ |
1 | 264 template ObjcBindMethod (alias method, string selector) |
265 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
266 version (Tango) |
18 | 267 mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
268 |
18 | 269 /*else |
270 mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method));*/ | |
1 | 271 } |
272 | |
16
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 * Binds a selector to an instance method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
275 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
276 * 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
|
277 * 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
|
278 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
279 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
280 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
281 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
282 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
283 * int foo (int x) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
284 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
285 * return x; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
286 * } |
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 * mixin ObjcBindMethod!(foo, int, "foo:", int); |
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 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
291 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
292 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
293 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
294 * R = the return type of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
295 * 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
|
296 * ARGS = the argument types of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
297 */ |
1 | 298 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
|
299 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
300 private |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
301 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
302 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
303 * Resolves the virtual call |
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 * 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
|
306 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
307 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
|
308 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
309 return &method; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
310 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
311 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
312 /// 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
|
313 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
|
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 * 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
|
317 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
318 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
319 * 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
|
320 * 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
|
321 * 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
|
322 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
323 * Returns: whatever the binded method returns, encapsulated |
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 extern (C) static dstep.objc.bridge.Type.ObjcType!(R) __forwardVirtualCall (dstep.objc.objc.id self, dstep.objc.objc.SEL cmd, __ObjcArgs objcArgs) |
1 | 326 in |
327 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
328 assert(dstep.objc.bridge.Capsule.isCapsule(self)); |
1 | 329 } |
330 body | |
16
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 R delegate (ARGS) delegate () dg; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
333 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
|
334 dg.funcptr = &__resolveVirtualCall; |
1 | 335 ARGS args; |
336 | |
337 foreach (i, a ; objcArgs) | |
338 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
339 alias typeof(args[i]) ArgType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
340 args[i] = dstep.objc.bridge.Capsule.decapsule!(ArgType)(a); |
1 | 341 } |
342 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
343 static if (is(R == void)) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
344 dg()(args); |
1 | 345 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
346 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
347 return dstep.objc.bridge.Capsule.encapsule!(R)(dg()(args)); |
1 | 348 } |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
349 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
350 /// 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
|
351 ObjcMethodDeclaration!(__forwardVirtualCall, R, selector, ARGS) __objcMethodDeclaration; |
1 | 352 } |
353 } | |
354 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
355 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
356 * 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
|
357 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
358 * 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
|
359 * 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
|
360 * 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
|
361 * 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
|
362 * argument types of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
363 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
364 * Mixes in: $(D_PSYMBOL ObjcBindClassMethod) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
365 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
366 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
367 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
368 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
369 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
370 * static void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
371 * mixin ObjcBindClassMethod!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
372 * } |
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 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
375 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
376 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
377 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
378 template ObjcBindClassMethod (alias method) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
379 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
380 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
|
381 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
382 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
383 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
384 * 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
|
385 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
386 * 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
|
387 * 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
|
388 * 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
|
389 * of the method. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
390 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
391 * Mixes in: $(D_PSYMBOL ObjcBindClassMethod) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
392 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
393 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
394 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
395 * class AppController : NSObject |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
396 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
397 * static void foo () {} |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
398 * mixin ObjcBindClassMethod!(foo, "foo"); |
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 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
401 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
402 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
403 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
404 * 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
|
405 */ |
1 | 406 template ObjcBindClassMethod (alias method, string selector) |
407 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
408 version (Tango) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
409 mixin ObjcBindClassMethod!(method, tango.core.Traits.ReturnTypeOf!(method), selector, tango.core.Traits.ParameterTupleOf!(method)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
410 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
411 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
412 mixin ObjcBindClassMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method)); |
1 | 413 } |
414 | |
16
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 * 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
|
417 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
418 * 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
|
419 * 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
|
420 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
421 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
422 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
423 * class AppController : NSObject |
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 * static int foo (int x) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
426 * { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
427 * return x; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
428 * } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
429 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
430 * mixin ObjcBindClassMethod!(foo, int, "foo:", int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
431 * } |
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 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
434 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
435 * method = the method to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
436 * R = the return type of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
437 * 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
|
438 * ARGS = the argument types of the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
439 */ |
1 | 440 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
|
441 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
442 private |
1 | 443 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
444 /// 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
|
445 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
|
446 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
447 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
448 * 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
|
449 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
450 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
451 * 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
|
452 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
453 * Returns: whatever the binded method returns, encapsulated |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
454 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
455 extern (C) static dstep.objc.bridge.Type.ObjcType!(R) __forwardStaticCall (dstep.objc.objc.Class self, dstep.objc.objc.SEL cmd, __ObjcArgs objcArgs) |
1 | 456 in |
457 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
458 assert(dstep.objc.bridge.Capsule.isCapsule(self)); |
1 | 459 } |
460 body | |
461 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
462 R function (ARGS) funcPtr = &method; |
1 | 463 ARGS args; |
464 | |
465 foreach (i, a ; objcArgs) | |
466 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
467 alias typeof(args[i]) ArgType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
468 args[i] = dstep.objc.bridge.Capsule.decapsule!(ArgType)(a); |
1 | 469 } |
470 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
471 static if (is(R == void)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
472 funcPtr()(args); |
1 | 473 |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
474 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
475 return dstep.objc.bridge.Capsule.encapsule!(R)(funcPtr()(args)); |
1 | 476 } |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
477 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
478 /// 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
|
479 ObjcMethodDeclaration!(__forwardStaticCall, R, selector, ARGS) __objcClassMethodDeclaration; |
1 | 480 } |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
481 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
482 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
483 /** |
18 | 484 * This $(D_KEYWORD struct) represents an Objective-C method declaration. |
485 * | |
486 * Examples: | |
487 * --- | |
488 * class C : NSObject | |
489 * { | |
490 * void foo (int x) {} | |
491 * ObjcMethodDeclaration!(foo, void, "foo", int) objcMethodDecl; | |
492 * } | |
493 * --- | |
494 * | |
495 * Params: | |
496 * imp = the D method | |
497 * R = the return type of the method | |
498 * name = the name of the method | |
499 * ARGS = the argument types of the method | |
500 */ | |
501 struct ObjcMethodDeclaration (alias imp, R, string name, ARGS...) | |
502 { | |
503 dstep.objc.objc.IMP methodImp = cast(dstep.objc.objc.IMP) &imp; | |
504 alias R returnType; | |
505 const string methodName = name; | |
506 alias ARGS argsType; | |
507 } | |
508 | |
509 /** | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
510 * 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
|
511 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
512 * 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
|
513 * 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
|
514 * as appropriate. |
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 * Mixes in: $(D_PSYMBOL ObjcBindFunction) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
517 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
518 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
519 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
520 * void foo (); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
521 * mixin ObjcBindFunction!(foo); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
522 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
523 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
524 template ObjcBindFunction (alias func) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
525 { |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
526 mixin ObjcBindFunction!(func, ReturnTypeOf!(func), ParameterTupleOf!(func)); |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
527 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
528 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
529 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
530 * 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
|
531 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
532 * 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
|
533 * 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
|
534 * as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
535 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
536 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
537 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
538 * char foo (int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
539 * mixin ObjcBindFunction!(foo, char, int); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
540 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
541 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
542 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
543 * func = the function to bind |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
544 * R = the return type of the function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
545 * ARGS = the argument types of the function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
546 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
547 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
|
548 { |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
549 private |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
550 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
551 /// 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
|
552 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
|
553 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
554 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
555 * 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
|
556 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
557 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
558 * 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
|
559 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
560 * Returns: whatever the binded function returns, encapsulated |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
561 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
562 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
|
563 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
564 R function (ARGS) funcPtr = &func; |
1 | 565 ARGS args; |
566 | |
567 foreach (i, a ; objcArgs) | |
568 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
569 alias typeof(args[i]) ArgType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
570 args[i] = dstep.objc.bridge.Capsule.decapsule!(ArgType)(a); |
1 | 571 } |
572 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
573 static if (is(R == void)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
574 funcPtr()(args); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
575 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
576 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
577 return dstep.objc.bridge.Capsule.encapsule!(R)(funcPtr()(args)); |
1 | 578 } |
579 } | |
580 } | |
581 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
582 /// 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
|
583 class Bridge |
1 | 584 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
585 private static Bridge bridgeInstance; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
586 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
587 /// 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
|
588 const objcMethodDeclarationVar = "__objcMethodDeclaration"; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
589 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
590 /// 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
|
591 const objcClassMethodDeclarationVar = "__objcClassMethodDeclaration"; |
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 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
|
594 const dObjectVar = "dObject"; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
595 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
596 /// 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
|
597 //alias Object DObjectType; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
598 alias void* DObjectType; |
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 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
601 * Gets the only instance of this class |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
602 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
603 * Returns: the instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
604 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
605 static Bridge instance () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
606 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
607 if (bridgeInstance) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
608 return bridgeInstance; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
609 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
610 return bridgeInstance = new Bridge; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
611 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
612 |
1 | 613 static: |
614 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
615 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
616 * 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
|
617 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
618 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
619 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
620 * id self; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
621 * int x = getObjcIvar!(int, "x")(self); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
622 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
623 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
624 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
625 * T = the type of the instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
626 * name = the name of the instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
627 * self = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
628 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
629 * 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
|
630 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
631 T getObjcIvar (T, string name) (id self) |
1 | 632 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
633 T value; |
1 | 634 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
635 self.getInstanceVariable!(T, name)(value); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
636 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
637 return value; |
1 | 638 } |
639 | |
16
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 * 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
|
642 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
643 * Examples: |
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 * id self; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
646 * Bridge.setObjcIvar!(int, "x")(self, 3); |
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 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
649 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
650 * T = the type of the instance variable |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
651 * name = the name of the instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
652 * objcObject = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
653 * value = the value to set |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
654 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
655 void setObjcIvar (T, string name) (id self, T value) |
1 | 656 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
657 GC.addRoot(value); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
658 self.setInstanceVariable!(T, dObjectVar)(value); |
1 | 659 } |
660 | |
16
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 * 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
|
663 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
664 * Examples: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
665 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
666 * NSObject object = new NSObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
667 * id self = object.objcObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
668 * assert(object == Bridge.getDObject(self)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
669 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
670 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
671 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
672 * self = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
673 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
674 * Returns: the D object or null |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
675 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
676 package DObjectType getDObject (id self) |
1 | 677 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
678 return getObjcIvar!(DObjectType, dObjectVar)(self); |
1 | 679 } |
680 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
681 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
682 * 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
|
683 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
684 * Examples: |
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 * NSObject object = new NSObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
687 * id self = object.objcObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
688 * Bridge.setDObject(object, self); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
689 * --- |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
690 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
691 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
692 * dObject = the D object to store |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
693 * 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
|
694 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
695 * Returns: the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
696 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
697 package id setDObject (Object dObject, id objcObject) |
1 | 698 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
699 auto o = cast(DObjectType) dObject; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
700 setObjcIvar!(DObjectType, dObjectVar)(objcObject, o); |
1 | 701 |
702 return objcObject; | |
703 } | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
704 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
705 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
706 * 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
|
707 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
708 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
709 * objcInstance = the Objective-C instance to deregister |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
710 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
711 package static void deregisterObjcInstance (id objcInstance) |
1 | 712 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
713 GC.removeRoot(getObjcIvar!(DObjectType, dObjectVar)(objcInstance)); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
714 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
715 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
716 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
717 * 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
|
718 * to an instance of a class. |
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 * 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
|
721 * 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
|
722 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
723 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
724 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
725 * selector = the selector to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
726 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
727 * self = the reciver of the call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
728 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
729 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
730 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
731 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
732 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
|
733 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
734 static assert (checkSelector!(selector, ARGS), "The selector \"" ~ selector ~ "\" and the arguments " ~ ARGS.stringof ~ " do not match"); |
1 | 735 |
736 SEL sel = sel.registerName!(selector); | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
737 ObjcTypes!(ARGS) objcArgs; |
1 | 738 |
739 foreach (i, a ; args) | |
740 { | |
741 alias typeof(a) ArgType; | |
742 | |
743 objcArgs[i] = encapsule!(ArgType)(a); | |
744 } | |
745 | |
746 static if (is(R == struct)) | |
747 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
748 R result; |
1 | 749 self.msgSend_stret(result, sel, objcArgs); |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
750 |
1 | 751 return result; |
752 } | |
753 | |
754 else static if (is(R == float) || is(R == double) || is(R == real)) | |
755 { | |
756 version (X86) | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
757 return self.msgSend_fpret!(R, ObjcTypes!(ARGS))(sel, objcArgs); |
1 | 758 |
759 else version (X86_64) | |
760 { | |
761 static if (is(R == real)) | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
762 return self.msgSend_fpret!(R)(sel, objcArgs); |
1 | 763 |
764 else | |
765 return self.msgSend!(R)(sel, objcArgs); | |
766 } | |
767 | |
768 else | |
769 return self.msgSend!(R)(sel, objcArgs); | |
770 } | |
771 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
772 else static if (needsEncapsulation!(R)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
773 return decapsule!(R)(self.msgSend(sel, objcArgs)); |
1 | 774 |
775 else | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
776 return self.msgSend!(R, ObjcTypes!(ARGS))(sel, objcArgs); |
1 | 777 } |
778 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
779 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
780 * 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
|
781 * to a class. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
782 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
783 * 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
|
784 * 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
|
785 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
786 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
787 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
788 * selector = the selector to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
789 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
790 * cls = the reciver of the call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
791 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
792 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
793 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
794 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
795 R invokeObjcClassMethod (R, string selector, ARGS...) (Class cls, ARGS args) |
1 | 796 { |
797 return invokeObjcMethod!(R, selector, ARGS)(cast(id) cls, args); | |
798 } | |
799 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
800 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
801 * 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
|
802 * to an instance of a superclass. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
803 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
804 * 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
|
805 * 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
|
806 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
807 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
808 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
809 * selector = the selector to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
810 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
811 * self = the reciver of the call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
812 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
813 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
814 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
815 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
816 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
|
817 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
818 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
|
819 |
1 | 820 SEL sel = sel.registerName!(selector); |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
821 ObjcTypes!(ARGS) objcArgs; |
1 | 822 |
823 foreach (i, a ; args) | |
824 { | |
825 alias typeof(a) ArgType; | |
826 | |
827 objcArgs[i] = encapsule!(ArgType)(a); | |
828 } | |
829 | |
830 static if (is(R == struct)) | |
831 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
832 R result; |
1 | 833 self.msgSendSuper_stret(result, sel, objcArgs); |
834 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
835 return result; |
1 | 836 } |
837 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
838 else static if (needsEncapsulation!(R)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
839 return decapsule!(R)(self.msgSendSuper(sel, objcArgs)); |
1 | 840 |
841 else | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
842 return self.msgSendSuper!(R, ObjcTypes!(ARGS))(sel, objcArgs); |
1 | 843 } |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
844 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
845 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
846 * 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
|
847 * encapsulating the return value as appropriate. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
848 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
849 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
850 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
851 * func = the function to call |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
852 * ARGS = the argument types |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
853 * args = the arguments to the function |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
854 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
855 * Returns: whatever the method returns, encapsulaed |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
856 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
857 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
|
858 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
859 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
|
860 ObjcTypes!(ARGS) objcArgs; |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
861 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
862 foreach (i, a ; args) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
863 { |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
864 alias typeof(a) ArgType; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
865 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
866 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
|
867 } |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
868 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
869 static if (is(R == void)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
870 funcPtr(objcArgs); |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
871 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
872 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
873 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
|
874 } |
1 | 875 } |