Mercurial > projects > dstep
annotate dstep/objc/bridge/Wrapper.d @ 2:9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 05 Jul 2009 17:16:19 +0200 |
parents | 033d260cfc9b |
children | 19885b43130e |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Feb 1, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.objc.bridge.Wrapper; | |
8 | |
9 import dstep.internal.String; | |
10 import dstep.objc.bridge.Bridge; | |
11 import dstep.objc.bridge.Capsule; | |
12 import dstep.objc.message; | |
13 import dstep.objc.objc; | |
14 import dstep.objc.runtime; | |
15 | |
16 class ObjcWrapper | |
17 { | |
18 static private Class objcClass_; | |
19 static private Class objcSuperClass_; | |
20 | |
21 private id objcObject_; | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
22 private objc_super* objcSuper_; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
23 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
24 this () |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
25 { |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
26 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
27 id ret = Bridge.invokeObjcMethod!(id, "init")(objcObject); |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
28 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
29 if (ret) |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
30 objcObject = ret; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
31 |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
32 dObject = this; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
33 } |
1 | 34 |
35 /// Initialize object from an Objective-C object instance to wrap. | |
36 this (id object) | |
37 { | |
38 objcObject_ = object; | |
39 dObject = this; | |
40 } | |
41 | |
42 static Class objcClass () | |
43 { | |
44 return capsuleClass; | |
45 } | |
46 | |
47 static Class objcSuperClass () | |
48 { | |
49 if (!objcSuperClass_) | |
50 return objcSuperClass_ = objcClass.getSuperclass; | |
51 | |
52 return objcSuperClass_; | |
53 } | |
54 | |
55 id objcObject () | |
56 { | |
57 return objcObject_; | |
58 } | |
59 | |
60 protected id objcObject (id object) | |
61 { | |
62 return objcObject_ = object; | |
63 } | |
64 | |
65 protected void dObject (Object dObject) | |
66 { | |
67 Bridge.setDObject(dObject, objcObject); | |
68 } | |
69 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
70 objc_super* objcSuper () |
1 | 71 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
72 if (!objcSuper_) |
1 | 73 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
74 objcSuper_ = new objc_super; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
75 objcSuper_.receiver = objcObject; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
76 objcSuper_.cls = objcSuperClass; |
1 | 77 } |
78 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
79 return objcSuper_; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
80 } |
1 | 81 } |