Skip to content

Commit

Permalink
Updated for _.m examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Malakoff committed Aug 1, 2012
1 parent 3bb81b2 commit 250c7fe
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Lib/JavaScript/NSObject+JavaScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
- (B(^)(id key))hasOwnProperty;
- (B(^)(NSO* obj))in;

// string
- (NSS*(^)(NSS* string))add;
- (S*(^)(NSS* string))append;

@end
32 changes: 28 additions & 4 deletions Lib/JavaScript/NSObject+JavaScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ - (UI)length
- (S*(^)(NSS* separator))join
{
#ifdef DEBUG
NSAssert(nil, @"join not implemented for this type");
NSAssert(nil, @"join not implemented for this type");
#endif

return nil;
}
- (A*(^)(id value))push
{
return ^(NSO* obj) {
#ifdef DEBUG
NSAssert(nil, @"push not implemented for this type");
#endif
#ifdef DEBUG
NSAssert(nil, @"push not implemented for this type");
#endif
return A.new;
};
}
Expand All @@ -76,6 +76,9 @@ - (UI)length
- (B(^)(id key))hasOwnProperty
{
return ^B(id key) {
#ifdef DEBUG
NSAssert(nil, @"hasOwnProperty not implemented for this type");
#endif
return false;
};
}
Expand All @@ -87,4 +90,25 @@ - (UI)length
};
}

// string
- (NSS*(^)(NSS* string))add
{
return ^(NSS* string) {
#ifdef DEBUG
NSAssert(nil, @"add not implemented for this type");
#endif
return string;
};
}

- (S*(^)(NSS* string))append
{
return ^(NSS* string) {
#ifdef DEBUG
NSAssert(nil, @"append not implemented for this type");
#endif
return string.mutableCopy;
};
}

@end
1 change: 1 addition & 0 deletions Lib/JavaScript/SS+JavaScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
// global functions
+ (N*(^)(NSS* string))parseInt;
+ (const NSS*(^)(id obj))typeof_;
+ (void(^)(NSO* message))alert;

// timeouts
+ (SSTimeout*(^)(SSTaskIdBlock block, I waitNS))setTimeout;
Expand Down
12 changes: 12 additions & 0 deletions Lib/JavaScript/SS+JavaScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#import "SS+Types.h"
#import "SSArguments.h"

//#import <UIKit/UIKit.h> // TODO: make mac compliant and test-safe version

const NSS* SSJSTypeOfObject = @"object";
const NSS* SSJSTypeOfString = @"string";
const NSS* SSJSTypeOfNumber = @"number";
Expand Down Expand Up @@ -125,6 +127,16 @@ @implementation SS (JavaScript)
};
}

+ (void(^)(NSO* message))alert
{
return ^(NSO* message) {
// TODO: make mac compliant and test-safe version
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"alert" message:message.toString() delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
// [alertView show];
NSLog(@"%@", message.toString());
};
}

// timeouts
+ (SSTimeout*(^)(SSTaskIdBlock block, I waitNS))setTimeout
{
Expand Down
2 changes: 1 addition & 1 deletion Lib/Types/NSArray+SS.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ - (NSS*)mutableClassName { return NSStringFromClass([S class]); }
return ^(I start, I count) {
if (start<0)
start = self.count + start;
if (count<0)
if (count<=0)
count = (self.count - start) + count;
if ((start + count)>self.count-1)
count = self.count - start;
Expand Down
6 changes: 3 additions & 3 deletions Lib/Types/NSObject+SS.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ - (D)D
// helper
- (NSComparisonResult)compare:(NSO*)other
{
if (SS.isString(self)) return [(NSS*)self compare:(NSS*)other];
if (SS.isNumber(self)) return [(N*)self compare:(N*)other];
if (SS.isDate(self)) return [(Date*)self compare:(Date*)other];
if (SS.isString(self)) return [(NSS*)self compare:(NSS*)other];
if (SS.isNumber(self)) return [(N*)self compare:(N*)other];
if (SS.isDate(self)) return [(Date*)self compare:(Date*)other];

#ifdef DEBUG
NSAssert(nil, @"cannot compare the provided objects");
Expand Down
8 changes: 0 additions & 8 deletions SubjectiveScript.m.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@
0A2A8B8115C7D572002A71DE /* JavaScript */,
0A2A8B9815C7D572002A71DE /* NSDictionary+NamedProperties.h */,
0A2A8B9915C7D572002A71DE /* NSDictionary+NamedProperties.m */,
0A2A8B9A15C7D572002A71DE /* Ruby */,
0A2A8B9B15C7D573002A71DE /* SS.h */,
0A2A8B9C15C7D573002A71DE /* SS.m */,
0A2A8B9D15C7D573002A71DE /* SubjectiveScript.h */,
Expand Down Expand Up @@ -305,13 +304,6 @@
path = JavaScript;
sourceTree = "<group>";
};
0A2A8B9A15C7D572002A71DE /* Ruby */ = {
isa = PBXGroup;
children = (
);
path = Ruby;
sourceTree = "<group>";
};
0A2A8B9F15C7D573002A71DE /* Types */ = {
isa = PBXGroup;
children = (
Expand Down

0 comments on commit 250c7fe

Please sign in to comment.