Mercurial > projects > dstep
annotate dstep/objc/bridge/ClassInitializer.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 9fd439a28ce3 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Apr 7, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.objc.bridge.ClassInitializer; | |
8 | |
9 version (Tango) | |
10 import tango.math.Math; | |
11 | |
12 else | |
13 import std.math; | |
14 | |
15 import dstep.internal.String; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
16 import dstep.internal.Traits; |
1 | 17 import bindings = dstep.objc.bindings; |
18 import dstep.objc.bridge.Bridge; | |
19 import dstep.objc.bridge.TypeEncoding; | |
20 import dstep.objc.objc; | |
21 import dstep.objc.runtime; | |
22 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
23 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
24 * Objective-C subclass initializer template. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
25 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
26 * Param: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
27 * subclassName = the name of the subclass to create |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
28 * superClassName = the name of the Objective-C superclass |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
29 */ |
1 | 30 package template ObjcSubclassInitializer (string subclassName, string superclassName) |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
31 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
32 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
33 * Return a pointer to the created class data structure. If this class hasn't been added |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
34 * to the Objective-C runtime, it'll be added. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
35 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
36 * Returns: a pointer to the created class data structure |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
37 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
38 static dstep.objc.objc.Class objcClass () |
1 | 39 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
40 if (__objcClass) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
41 return __objcClass; |
1 | 42 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
43 dstep.objc.objc.Class superClass = objcSuperClass; |
1 | 44 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
45 auto methods = __collectObjcInstanceMethods(); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
46 auto classMethods = __collectObjcClassMethods(); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
47 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
48 static if (dstep.internal.Traits.hasClassMethod!(typeof(super), objcClass.stringof)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
49 typeof(super).objcClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
50 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
51 return __objcClass = dstep.objc.bridge.ClassInitializer.subclassInit!(subclassName)(superClass, methods, classMethods); |
1 | 52 } |
53 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
54 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
55 * Return a pointer to the superclass data structure. If the superclass hasn't been added |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
56 * to the Objective-C runtime, it'll be added. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
57 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
58 * Returns: a pointer to the superclass data structure |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
59 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
60 static dstep.objc.objc.Class objcSuperClass () |
1 | 61 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
62 if (__objcSuperClass) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
63 return __objcSuperClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
64 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
65 if (is(typeof(super) == dstep.objc.bridge.Wrapper.ObjcWrapper)) // root class |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
66 return __objcSuperClass = dstep.objc.bridge.Capsule.capsuleClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
67 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
68 __objcSuperClass = cast(dstep.objc.objc.Class) dstep.objc.objc.objc.getClass!(subclassName); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
69 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
70 while (!__objcSuperClass && !is(typeof(super) == dstep.objc.bridge.Wrapper.ObjcWrapper)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
71 __objcSuperClass = super.objcClass; |
1 | 72 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
73 if (!__objcSuperClass) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
74 __objcSuperClass = dstep.objc.bridge.Capsule.capsuleClass; |
1 | 75 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
76 return __objcSuperClass; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
77 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
78 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
79 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
80 * Collects all binded methods in the class this template is mixed into. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
81 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
82 * Returns: an array of methods |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
83 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
84 private static dstep.objc.runtime.Method[] __collectObjcInstanceMethods () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
85 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
86 dstep.objc.runtime.Method[] methods; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
87 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
88 mixin("alias " ~ subclassName ~ " Type;"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
89 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
90 static if (Type.tupleof.length > 0) |
1 | 91 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
92 foreach (i, f ; typeof(Type.tupleof)) |
1 | 93 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
94 const len = Type.stringof.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
95 const fieldName = Type.tupleof[i].stringof[1 + len + 2 .. $]; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
96 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
97 static if (fieldName == dstep.objc.bridge.Bridge.Bridge.objcMethodDeclarationVar) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
98 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
99 typeof(Type.tupleof[i]) field; |
1 | 100 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
101 dstep.objc.runtime.Method m = new dstep.objc.objc.objc_method; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
102 m.method_name = dstep.objc.objc.sel.registerName!(field.methodName); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
103 m.method_types = dstep.objc.bridge.TypeEncoding.encode!(field.returnType, dstep.objc.objc.id, dstep.objc.objc.SEL, field.argsType).ptr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
104 m.method_imp = cast(dstep.objc.objc.IMP) field.methodImp; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
105 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
106 methods ~= m; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
107 } |
1 | 108 } |
109 } | |
110 | |
111 return methods; | |
112 } | |
113 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
114 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
115 * Collects all binded class methods in the class this template is mixed into. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
116 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
117 * Returns: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
118 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
119 private static dstep.objc.runtime.Method[] __collectObjcClassMethods () |
1 | 120 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
121 dstep.objc.runtime.Method[] methods; |
1 | 122 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
123 mixin("alias " ~ subclassName ~ " Type;"); |
1 | 124 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
125 static if (Type.tupleof.length > 0) |
1 | 126 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
127 foreach (i, f ; typeof(Type.tupleof)) |
1 | 128 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
129 const len = Type.stringof.length; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
130 const fieldName = Type.tupleof[i].stringof[1 + len + 2 .. $]; |
1 | 131 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
132 static if (fieldName == dstep.objc.bridge.Bridge.Bridge.objcClassMethodDeclarationVar) |
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 typeof(Type.tupleof[i]) field; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
135 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
136 dstep.objc.runtime.Method m = new dstep.objc.objc.objc_method; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
137 m.method_name = dstep.objc.objc.sel.registerName!(field.methodName); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
138 m.method_types = dstep.objc.bridge.TypeEncoding.encode!(field.returnType, field.argsType).ptr; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
139 m.method_imp = cast(dstep.objc.objc.IMP) field.methodImp; |
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 methods ~= m; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
142 } |
1 | 143 } |
144 } | |
145 | |
146 return methods; | |
147 } | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
148 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
149 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
150 * Invoke on the receiver the instance method with the given name, return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
151 * and arguments. |
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 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
155 * name = the name (selector) of the method to invoke |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
156 * ARGS = the type of the arguments |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
157 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
158 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
159 * Returns: whatever the method returns |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
160 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
161 private R invokeObjcSelf (R, dstep.internal.String.string name, ARGS...) (ARGS args) |
1 | 162 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
163 return dstep.objc.bridge.Bridge.Bridge.invokeObjcMethod!(R, name, ARGS)(this.objcObject, args); |
1 | 164 } |
165 | |
16
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 * Invoke on the receiver's super part the instance method with the given name, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
168 * return type and arguments. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
169 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
170 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
171 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
172 * name = the name (selector) of the method to invoke |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
173 * ARGS = the type of the arguments |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
174 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
175 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
176 * Returns: whatever the method returns |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
177 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
178 private R invokeObjcSuper (R, dstep.internal.String.string name, ARGS...) (ARGS args) |
1 | 179 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
180 return dstep.objc.bridge.Bridge.Bridge.invokeObjcSuperMethod!(R, name, ARGS)(this.objcSuper, args); |
1 | 181 } |
182 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
183 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
184 * Invoke class method with given name, return type and arguments, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
185 * on the receiver's superclass. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
186 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
187 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
188 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
189 * name = the name (selector) of the method to invoke |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
190 * ARGS = the type of the arguments |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
191 * args = the arguments to the method |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
192 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
193 * Returns: whatever the method returns |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
194 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
195 private static R invokeObjcSelfClass (R, dstep.internal.String.string name, ARGS...) (ARGS args) |
1 | 196 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
197 return dstep.objc.bridge.Bridge.Bridge.invokeObjcClassMethod!(R, name, ARGS)(objcClass, args); |
1 | 198 } |
199 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
200 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
201 * Invoke class method with given name, return type and arguments, |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
202 * on the receiver's superclass. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
203 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
204 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
205 * R = the return type |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
206 * name = the name (selector) of the method to invoke |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
207 * ARGS = the type of the arguments |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
208 * args = the arguments to the method |
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 * Returns: whatever the method returns |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
211 */ |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
212 private static R invokeObjcSuperClass (R, dstep.internal.String.string name, ARGS...) (ARGS args) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
213 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
214 return dstep.objc.bridge.Bridge.Bridge.invokeObjcClassMethod!(R, name, ARGS)(objcSuperClass, args); |
1 | 215 } |
216 } | |
217 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
218 /** |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
219 * Creates a new Objective-C subclass, initializes its data and register it with the |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
220 * Objective-C runtime. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
221 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
222 * Params: |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
223 * className = the name of the subclass |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
224 * superClass = the subclass' superclass |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
225 * instanceMethods = the instance methods that should be added to the subclass |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
226 * classMethods = the class methods that should be added to the subclass |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
227 * |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
228 * Returns: the newly created subclass |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
229 */ |
1 | 230 Class subclassInit (string className) (Class superClass, Method[] instanceMethods = null, Method[] classMethods = null) |
231 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
232 Class cls; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
233 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
234 if (objc.getClass!(className)) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
235 cls = objc.allocateClassPair!("D_" ~ className)(superClass, 0); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
236 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
237 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
238 cls = objc.allocateClassPair!(className)(superClass, 0); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
239 |
1 | 240 Class metaClass = (cast(id) cls).getClass; |
241 | |
242 ubyte alignment = cast(ubyte) log2(Bridge.DObjectType.sizeof); | |
243 cls.addIvar!(Bridge.dObjectVar, encode!(Bridge.DObjectType))(Bridge.DObjectType.sizeof, alignment); | |
244 | |
245 foreach (method ; instanceMethods) | |
246 bindings.class_addMethod(cls, method.method_name, method.method_imp, method.method_types); | |
247 | |
248 foreach (method ; classMethods) | |
249 bindings.class_addMethod(metaClass, method.method_name, method.method_imp, method.method_types); | |
250 | |
251 objc.registerClassPair(cls); | |
252 | |
253 return cls; | |
254 } |