-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.m
53 lines (40 loc) · 1.53 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#import <Foundation/Foundation.h>
#import "MABlockClosure.h"
#if TARGET_OS_IPHONE
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>
#define NSStringFromRect(r) NSStringFromCGRect(r)
#endif
int main(int argc, char **argv)
{
[NSAutoreleasePool new];
id block = ^(int x) { return x + argc; };
MABlockClosure *closure = [[MABlockClosure alloc] initWithBlock: block];
int ret = ((int (*)(int))[closure fptr])(3);
NSLog(@"%d", ret);
[closure release];
block = ^{ return argv[0]; };
closure = [[MABlockClosure alloc] initWithBlock: block];
char *s = ((char *(*)(void))[closure fptr])();
NSLog(@"%s", s);
[closure release];
block = ^{ return CGRectMake(0, 0, 0, 0); };
closure = [[MABlockClosure alloc] initWithBlock: block];
CGRect r = ((CGRect (*)(void))[closure fptr])();
NSLog(@"%@", NSStringFromRect(r));
[closure release];
block = [^(NSString *s) { return [s stringByAppendingFormat: @" %s", argv[0]]; } copy];
NSString *strObj = ((id (*)(id))BlockFptr(block))(@"hello");
NSLog(@"%@", strObj);
[block release];
block = ^(int x, int y) { return x + y; };
closure = [[MABlockClosure alloc] initWithBlock: block];
ret = ((int (*)(int, int))[closure fptr])(5, 10);
NSLog(@"%d", ret);
block = ^{ NSLog(@"Hello"); };
closure = [[MABlockClosure alloc] initWithBlock: block];
((void (*)(void))[closure fptr])();
[closure release];
void (*fptr)(void) = BlockFptrAuto(^{ NSLog(@"Hello 2"); });
fptr();
}