comparison dstep/objc/bridge/Bridge.d @ 18:b2693af5a569

Added IBAction
author Jacob Carlborg <doob@me.com>
date Fri, 15 Jan 2010 12:41:07 +0100
parents 19885b43130e
children ae08a08f44d3
comparison
equal deleted inserted replaced
17:c2fba45df857 18:b2693af5a569
177 } 177 }
178 178
179 mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; 179 mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);";
180 180
181 /** 181 /**
182 * This $(D_KEYWORD struct) represents an Objective-C method declaration. 182 * Binds a selector to an instance method.
183 * 183 *
184 * Examples: 184 * This will create a receiver function which will forward the call to $(D_PARAM method),
185 * --- 185 * decapsulating arguments and encapsulating the return value as appropriate.
186 * class C : NSObject 186 * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build
187 * { 187 * the selector. It will automatically infer the return type and the argument types
188 * void foo (int x) {} 188 * of the method. An action method can only have one parameter and of the type Object
189 * ObjcMethodDeclaration!(foo, void, "foo", int) objcMethodDecl; 189 * (or any of its subclasses).
190 * } 190 *
191 * --- 191 * Mixes in: ObjcBindMethod
192 * 192 *
193 * Params: 193 * Examples:
194 * imp = the D method 194 * ---
195 * R = the return type of the method 195 * class AppController : NSObject
196 * name = the name of the method 196 * {
197 * ARGS = the argument types of the method 197 * void foo (Object sender) {}
198 */ 198 * mixin IBAction!(foo);
199 struct ObjcMethodDeclaration (alias imp, R, string name, ARGS...) 199 * }
200 { 200 * ---
201 dstep.objc.objc.IMP methodImp = cast(dstep.objc.objc.IMP) &imp; 201 *
202 alias R returnType; 202 * Params:
203 const string methodName = name; 203 * method = the method to bind
204 alias ARGS argsType; 204 */
205 template IBAction (alias method)
206 {
207 static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "dstep.objc.bridge.Bridge.IBAction: an action method is only allowed to have one parameter");
208 static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "dstep.objc.bridge.Bridge.IBAction: an action method can only have a parameter of the type Object (or any of its subclasses)");
209
210 mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method));
205 } 211 }
206 212
207 /** 213 /**
208 * Binds a selector to an instance method. 214 * Binds a selector to an instance method.
209 * 215 *
256 * selector = the selector to bind the method to 262 * selector = the selector to bind the method to
257 */ 263 */
258 template ObjcBindMethod (alias method, string selector) 264 template ObjcBindMethod (alias method, string selector)
259 { 265 {
260 version (Tango) 266 version (Tango)
261 mixin ObjcBindMethod!(method, tango.core.Traits.ReturnTypeOf!(method), selector, tango.core.Traits.ParameterTupleOf!(method)); 267 mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method));
262 268
263 else 269 /*else
264 mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method)); 270 mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method));*/
265 } 271 }
266 272
267 /** 273 /**
268 * Binds a selector to an instance method. 274 * Binds a selector to an instance method.
269 * 275 *
473 ObjcMethodDeclaration!(__forwardStaticCall, R, selector, ARGS) __objcClassMethodDeclaration; 479 ObjcMethodDeclaration!(__forwardStaticCall, R, selector, ARGS) __objcClassMethodDeclaration;
474 } 480 }
475 } 481 }
476 482
477 /** 483 /**
484 * This $(D_KEYWORD struct) represents an Objective-C method declaration.
485 *
486 * Examples:
487 * ---
488 * class C : NSObject
489 * {
490 * void foo (int x) {}
491 * ObjcMethodDeclaration!(foo, void, "foo", int) objcMethodDecl;
492 * }
493 * ---
494 *
495 * Params:
496 * imp = the D method
497 * R = the return type of the method
498 * name = the name of the method
499 * ARGS = the argument types of the method
500 */
501 struct ObjcMethodDeclaration (alias imp, R, string name, ARGS...)
502 {
503 dstep.objc.objc.IMP methodImp = cast(dstep.objc.objc.IMP) &imp;
504 alias R returnType;
505 const string methodName = name;
506 alias ARGS argsType;
507 }
508
509 /**
478 * Binds a D free function to an Objective-C free function. 510 * Binds a D free function to an Objective-C free function.
479 * 511 *
480 * This will create a receiver function which will forward the call to the 512 * This will create a receiver function which will forward the call to the
481 * binded function, decapsulating arguments and encapsulating the return value 513 * binded function, decapsulating arguments and encapsulating the return value
482 * as appropriate. 514 * as appropriate.