Mercurial > projects > dstep
annotate dstep/objc/bridge/Capsule.d @ 25:b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 06 Apr 2010 11:37:27 +0200 |
parents | ab33fc0c3fc1 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Feb 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.objc.bridge.Capsule; | |
8 | |
9 version (Tango) | |
10 { | |
11 import tango.core.Memory; | |
12 import tango.math.Math : log2; | |
13 | |
14 import tango.core.Traits; | |
15 } | |
16 | |
17 else | |
18 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
19 import GC = std.gc : addRoot; |
1 | 20 import std.math : log2; |
21 } | |
22 | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
23 import dstep.internal.Reflection; |
1 | 24 import dstep.internal.String; |
25 import dstep.objc.bridge.Bridge; | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
26 import dstep.objc.bridge.Type; |
1 | 27 import dstep.objc.bridge.TypeEncoding; |
28 import dstep.objc.bridge.Wrapper; | |
29 import dstep.objc.message; | |
30 import dstep.objc.objc; | |
31 import dstep.objc.runtime; | |
32 import bindings = dstep.objc.bindings; | |
33 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
34 /// Returns the capsule class |
1 | 35 Class capsuleClass () |
36 { | |
37 if (!Capsule.capsuleClass) | |
38 initCapsuleClass; | |
39 | |
40 return Capsule.capsuleClass; | |
41 } | |
42 | |
43 private struct Capsule | |
44 { | |
45 static Class capsuleClass; | |
46 | |
47 static id create (Object object, Class capsuleClass) | |
48 { | |
49 id capsule = objc.createInstance(capsuleClass, 0); | |
50 | |
51 Bridge.setDObject(object, capsule); | |
52 | |
53 return capsule; | |
54 } | |
55 | |
56 static id description (id self, SEL op) | |
57 in | |
58 { | |
59 assert(isCapsule(self)); | |
60 } | |
61 body | |
62 { | |
24
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
63 if (auto object = decapsule!(Object)(self)) |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
64 return encapsuleString(object.toString); |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
65 |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
66 objc_super superObject; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
67 superObject.cls = .capsuleClass.getSuperclass; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
68 superObject.receiver = self; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
69 |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
70 return Bridge.invokeObjcSuperMethod!(id, "description")(&superObject); |
1 | 71 } |
72 | |
73 static hash_t hash (id self, SEL op) | |
74 in | |
75 { | |
76 assert(isCapsule(self)); | |
77 } | |
78 body | |
79 { | |
24
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
80 if (auto object = decapsule!(Object)(self)) |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
81 return object.toHash; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
82 |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
83 objc_super superObject; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
84 superObject.cls = .capsuleClass.getSuperclass; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
85 superObject.receiver = self; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
86 |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
87 return Bridge.invokeObjcSuperMethod!(hash_t, "hash")(&superObject); |
1 | 88 } |
89 | |
24
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
90 static bool isEqual (id self, SEL op, Object other) |
1 | 91 in |
92 { | |
93 assert(isCapsule(self)); | |
94 } | |
95 body | |
96 { | |
24
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
97 if (auto object = decapsule!(Object)(self)) |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
98 return cast(bool) (object == other); |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
99 |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
100 objc_super superObject; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
101 superObject.cls = .capsuleClass.getSuperclass; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
102 superObject.receiver = self; |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
103 |
ab33fc0c3fc1
Fixed the implementation for the methods in Capsule. Changed a method name in objc_class
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
104 return Bridge.invokeObjcSuperMethod!(bool, "isEqual:", Object)(&superObject, other); |
1 | 105 } |
106 } | |
107 | |
108 private void initCapsuleClass () | |
109 { | |
110 Class superClass = cast(Class) objc.getClass!("NSObject"); | |
111 Capsule.capsuleClass = objc.allocateClassPair!("D_Object")(superClass, 0); | |
112 | |
113 ubyte alignment = cast(ubyte) log2(Bridge.DObjectType.sizeof); | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
114 |
1 | 115 Capsule.capsuleClass.addIvar!(Bridge.dObjectVar, encode!(Bridge.DObjectType))(Bridge.DObjectType.sizeof, alignment); |
116 | |
117 Capsule.capsuleClass.addMethod!(encodeCallable!(Capsule.description))(sel.registerName!("description"), cast(IMP) &Capsule.description); | |
118 Capsule.capsuleClass.addMethod!(encodeCallable!(Capsule.hash))(sel.registerName!("hash"), cast(IMP) &Capsule.hash); | |
119 Capsule.capsuleClass.addMethod!(encodeCallable!(Capsule.isEqual))(sel.registerName!("isEqual"), cast (IMP) &Capsule.isEqual); | |
120 | |
121 objc.registerClassPair(capsuleClass); | |
122 } | |
123 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
124 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
125 * Returns $(D_KEYWORD true) if the given Objective-C instance is a capsule |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
126 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
127 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
128 * instance = the Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
129 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
130 * Returns: $(D_KEYWORD true) if the given Objective-C instance is a capsule |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
131 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
132 bool isCapsule (id instance) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
133 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
134 //if (capsule && capsule.isa) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
135 //return capsule.isa.getInstanceVariable!(Bridge.dObjectVar) !is null; |
1 | 136 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
137 if (instance) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
138 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
139 Class cls = instance.isa; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
140 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
141 while (cls && cls !is capsuleClass) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
142 cls = cls.super_class; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
143 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
144 return cls is capsuleClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
145 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
146 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
147 return false; |
1 | 148 } |
149 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
150 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
151 * Returns $(D_KEYWORD true) if the given Objective-C class is a capsule |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
152 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
153 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
154 * cls = the Objective-C class |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
155 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
156 * Returns: true if the given Objective-C class is a capsule |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
157 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
158 bool isCapsule (Class cls) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
159 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
160 while (cls && cls !is capsuleClass) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
161 cls = cls.super_class; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
162 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
163 return cls is capsuleClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
164 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
165 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
166 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
167 * Encapsulate the value of type $(D_PARAM T) to corresponding Objective-C type $(D_PSYMBOL ObjcType!(T)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
168 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
169 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
170 * T = the type of the value |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
171 * value = the value to encapsulate |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
172 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
173 * Returns: the encapsulated value |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
174 */ |
1 | 175 ObjcType!(T) encapsule (T) (T value) |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
176 { |
1 | 177 static if (needsEncapsulation!(T)) |
178 { | |
179 if (!value) | |
180 return null; | |
181 | |
182 if (auto wrapper = cast(ObjcWrapper) value) | |
183 return wrapper.objcObject; | |
184 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
185 static if (is(T == interface)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
186 return Capsule.create(cast(Object) value, capsuleClass); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
187 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
188 return Capsule.create(cast(Object) value, capsuleClass); |
1 | 189 } |
190 | |
191 else | |
192 return value; | |
193 } | |
194 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
195 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
196 * Decapsulate the given Objective-C value of type $(D_PSYMBOL ObjcType!(T)) to corresponding D type $(D_PARAM T). |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
197 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
198 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
199 * T = the type of the decapsulated value |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
200 * value = the value to decapsulate |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
201 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
202 * Returns: the decapsulated value |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
203 */ |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
204 T decapsule (T) (ObjcType!(T) value) |
1 | 205 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
206 static if (needsEncapsulation!(T)) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
207 { |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
208 static if (is(T : ObjcWrapper)) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
209 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
210 T instance = cast(T) Bridge.getDObject(value); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
211 |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
212 return instance ? instance : newWrapper!(T)(value); |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
213 } |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
214 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
215 else |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
216 return cast(T) Bridge.getDObject(value); |
1 | 217 } |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
218 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
219 else |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
220 return value; |
1 | 221 } |
222 | |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
223 private T newWrapper (T) (ObjcType!(T) value) |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
224 { |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
225 auto wrapper = cast(ObjcWrapper) newInstance(T.classinfo); |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
226 setValueOfField!("objcObject_")(wrapper, value); |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
227 Bridge.setDObject(wrapper, value); |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
228 |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
229 return cast(T) wrapper; |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
230 } |
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
231 |
1 | 232 private id encapsuleString (string str) |
233 { | |
234 enum { NSUTF8StringEncoding = 4 } | |
235 | |
236 return objc.getClass!("NSString").msgSend(sel.registerName!("alloc")).msgSend(sel.registerName!("initWithBytes:length:encoding:"), str.ptr, str.length, NSUTF8StringEncoding); | |
237 } |