Created
June 18, 2011 16:41
-
-
Save itfrombit/1033259 to your computer and use it in GitHub Desktop.
Handler generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IMP handler_returning_void(void* userdata) | |
{ | |
return imp_implementationWithBlock(^(id receiver, ...) { | |
struct handler_description description; | |
description.handler = NULL; | |
description.description = userdata; | |
va_list ap; | |
va_start(ap, receiver); | |
nu_handler(0, &description, receiver, ap); | |
}); | |
} | |
#define MAKE_HANDLER_WITH_TYPE(type) \ | |
static IMP handler_returning_ ## type (void* userdata) \ | |
{ \ | |
return imp_implementationWithBlock(^(id receiver, ...) { \ | |
struct handler_description description; \ | |
description.handler = NULL; \ | |
description.description = userdata; \ | |
va_list ap; \ | |
va_start(ap, receiver); \ | |
type result; \ | |
nu_handler(&result, &description, receiver, ap); \ | |
return result; \ | |
}); \ | |
} | |
MAKE_HANDLER_WITH_TYPE(id) | |
MAKE_HANDLER_WITH_TYPE(int) | |
MAKE_HANDLER_WITH_TYPE(bool) | |
MAKE_HANDLER_WITH_TYPE(float) | |
MAKE_HANDLER_WITH_TYPE(double) | |
MAKE_HANDLER_WITH_TYPE(CGRect) | |
MAKE_HANDLER_WITH_TYPE(CGPoint) | |
MAKE_HANDLER_WITH_TYPE(CGSize) | |
MAKE_HANDLER_WITH_TYPE(NSRange) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment