# HG changeset patch # User Jacob Carlborg # Date 1263555667 -3600 # Node ID b2693af5a569e26739565dc52e03ee9294e412db # Parent c2fba45df857b7bdcad34d8dde1f16d3710bd61b Added IBAction diff -r c2fba45df857 -r b2693af5a569 dsss.conf --- a/dsss.conf Sun Jan 10 13:22:58 2010 +0100 +++ b/dsss.conf Fri Jan 15 12:41:07 2010 +0100 @@ -1,4 +1,4 @@ -[dstep] +[main.d] #target=cocoa-d-test version (GNU){ @@ -11,4 +11,6 @@ version (DigitalMars) { buildflags += -L-framework -LFoundation -L-framework -LApplicationServices -L-framework -LCoreFoundation -L-framework -LCoreServices -L-framework -LDiskArbitration -L-framework -LSecurity -L-framework -LQuartzCore -L-framework -LQTKit -L-framework -LAppKit -} \ No newline at end of file +} + +#-L-dead_strip -L-x -L-S \ No newline at end of file diff -r c2fba45df857 -r b2693af5a569 dstep/objc/bridge/Bridge.d --- a/dstep/objc/bridge/Bridge.d Sun Jan 10 13:22:58 2010 +0100 +++ b/dstep/objc/bridge/Bridge.d Fri Jan 15 12:41:07 2010 +0100 @@ -179,29 +179,35 @@ mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; /** - * This $(D_KEYWORD struct) represents an Objective-C method declaration. + * Binds a selector to an instance method. + * + * This will create a receiver function which will forward the call to $(D_PARAM method), + * decapsulating arguments and encapsulating the return value as appropriate. + * This $(D_KEYWORD template) will use the buildSelector $(D_KEYWORD template) to build + * the selector. It will automatically infer the return type and the argument types + * of the method. An action method can only have one parameter and of the type Object + * (or any of its subclasses). + * + * Mixes in: ObjcBindMethod * * Examples: * --- - * class C : NSObject + * class AppController : NSObject * { - * void foo (int x) {} - * ObjcMethodDeclaration!(foo, void, "foo", int) objcMethodDecl; + * void foo (Object sender) {} + * mixin IBAction!(foo); * } * --- * * Params: - * imp = the D method - * R = the return type of the method - * name = the name of the method - * ARGS = the argument types of the method + * method = the method to bind */ -struct ObjcMethodDeclaration (alias imp, R, string name, ARGS...) +template IBAction (alias method) { - dstep.objc.objc.IMP methodImp = cast(dstep.objc.objc.IMP) &imp; - alias R returnType; - const string methodName = name; - alias ARGS argsType; + 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"); + 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)"); + + mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); } /** @@ -258,10 +264,10 @@ template ObjcBindMethod (alias method, string selector) { version (Tango) - mixin ObjcBindMethod!(method, tango.core.Traits.ReturnTypeOf!(method), selector, tango.core.Traits.ParameterTupleOf!(method)); + mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); - else - mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method)); + /*else + mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method));*/ } /** @@ -475,6 +481,32 @@ } /** + * This $(D_KEYWORD struct) represents an Objective-C method declaration. + * + * Examples: + * --- + * class C : NSObject + * { + * void foo (int x) {} + * ObjcMethodDeclaration!(foo, void, "foo", int) objcMethodDecl; + * } + * --- + * + * Params: + * imp = the D method + * R = the return type of the method + * name = the name of the method + * ARGS = the argument types of the method + */ +struct ObjcMethodDeclaration (alias imp, R, string name, ARGS...) +{ + dstep.objc.objc.IMP methodImp = cast(dstep.objc.objc.IMP) &imp; + alias R returnType; + const string methodName = name; + alias ARGS argsType; +} + +/** * Binds a D free function to an Objective-C free function. * * This will create a receiver function which will forward the call to the