/
NuAppDelegate.m
79 lines (66 loc) · 2.71 KB
/
NuAppDelegate.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// NuAppDelegate.m
// NuApp
//
// Created by Tim Burks on 6/11/11.
// Copyright 2011 Radtastical Inc. All rights reserved.
//
#import "NuAppDelegate.h"
#import "Nu.h"
#import "NuBlock.h"
#import "NuBridgedBlock.h"
#import <UIKit/UIKit.h>
@class ViewController;
@implementation NuAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect frame = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:frame] autorelease];
[self.window makeKeyAndVisible];
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
UIView *view = [[UIView alloc] initWithFrame:frame];
viewController.view = view;
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.textAlignment = NSTextAlignmentCenter;
[view addSubview:label];
NuInit();
[[Nu sharedParser] parseEval:@"(load \"nu\")"];
[[Nu sharedParser] parseEval:@"(load \"test\")"];
NSString *resourceDirectory = [[NSBundle mainBundle] resourcePath];
NSArray *files = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:resourceDirectory
error:NULL];
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"^test_.*nu$" options:0 error:NULL];
for (NSString *filename in files) {
NSUInteger numberOfMatches = [regex numberOfMatchesInString:filename
options:0
range:NSMakeRange(0, [filename length])];
if (numberOfMatches) {
NSLog(@"loading %@", filename);
NSString *s = [NSString stringWithContentsOfFile:[resourceDirectory stringByAppendingPathComponent:filename]
encoding:NSUTF8StringEncoding
error:NULL];
[[Nu sharedParser] parseEval:s];
}
}
[regex release];
NSLog(@"running tests");
int failures = [[[Nu sharedParser] parseEval:@"(NuTestCase runAllTests)"] intValue];
NSString* script = @"(do () (puts \"cBlock Work!\"))";
id parsed = [[Nu sharedParser] parse:script];
NuBlock* block = [[Nu sharedParser] eval:parsed];
void (^cblock)() = [NuBridgedBlock cBlockWithNuBlock:block signature:@"v"];
cblock();
if (failures == 0) {
view.backgroundColor = [UIColor greenColor];
label.text = @"Everything Nu!";
} else {
view.backgroundColor = [UIColor redColor];
label.text = [NSString stringWithFormat:@"%d failures!",failures];
}
NSLog(@"ok");
return YES;
}
@end