annotate dstep/objc/bridge/Bridge.d @ 27:57371c29ef73 default tip

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