Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moved some common methods and symbols from nu.nu to Nu.m

  • Loading branch information...
commit 7e3a0935e2a47d45fc054c41d587ae2090017286 1 parent df78ec3
@timburks authored
Showing with 26 additions and 28 deletions.
  1. +1 −1  Xcode/NuApp/main.m
  2. +0 −21 nu/nu.nu
  3. +25 −6 objc/Nu.m
View
2  Xcode/NuApp/main.m
@@ -3,7 +3,7 @@
// NuApp
//
// Created by Tim Burks on 6/11/11.
-// Copyright 2011 Neon Design Technology, Inc. All rights reserved.
+// Copyright 2011 Radtastical Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
View
21 nu/nu.nu
@@ -15,9 +15,6 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
-(global NSUTF8StringEncoding 4)
-(global NSLog (NuBridgedFunction functionWithName:"NSLog" signature:"v@"))
-
(global rand
(do (maximum)
(let ((r (NuMath random)))
@@ -188,24 +185,6 @@
(results addObject:filename)))
((results allObjects) sortedArrayUsingSelector:"compare:"))))
-(class NSMutableArray
-
- ;; Concisely add objects to arrays using this method, which is equivalent to a call to addObject:.
- (- (void) << (id) object is (self addObject:object)))
-
-(class NSMutableSet
-
- ;; Concisely add objects to sets using this method, which is equivalent to a call to addObject:.
- (- (void) << (id) object is (self addObject:object)))
-
-(class NSMutableString
-
- ;; Concisely append to a string using this method, which is equivalent to a call to appendString:.
- (- (void) << (id) object is
- (if (not (string? object))
- (then (self appendString:(object stringValue)))
- (else (self appendString:object)))))
-
(if (eq (uname) "Darwin")
(class NuCell
;; Convert a list into an NSRect. The list must have at least four elements.
View
31 objc/Nu.m
@@ -373,15 +373,29 @@ void NuInit()
if (!initialized) {
initialized = 1;
+ // as a convenience, we set a file static variable to nil.
Nu__null = [NSNull null];
// add enumeration to collection classes
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSArray include: [NuClass classWithClass:[NuEnumerable class]]];
[NSSet include: [NuClass classWithClass:[NuEnumerable class]]];
[NSString include: [NuClass classWithClass:[NuEnumerable class]]];
- [pool drain];
+ // create "<<" messages that append their arguments to arrays, sets, and strings
+ id parser = [Nu sharedParser];
+ [[NuClass classWithClass:[NSMutableArray class]]
+ addInstanceMethod:@"<<"
+ signature:@"v*"
+ body:[parser eval:[parser parse:@"(do (value) (self addObject:value))"]]];
+ [[NuClass classWithClass:[NSMutableSet class]]
+ addInstanceMethod:@"<<"
+ signature:@"v*"
+ body:[parser eval:[parser parse:@"(do (value) (self addObject:value))"]]];
+ [[NuClass classWithClass:[NSMutableString class]]
+ addInstanceMethod:@"<<"
+ signature:@"v*"
+ body:[parser eval:[parser parse:@"(do (object) (self appendString:(object stringValue)))"]]];
+
// Copy some useful methods from NSObject to NSProxy.
// Their implementations are identical; this avoids code duplication.
transplant_nu_methods([NSProxy class], [NSObject class]);
@@ -391,14 +405,12 @@ void NuInit()
#if !defined(MININUSH) && !TARGET_OS_IPHONE
// Load some standard files
- // Warning: since these loads are performed without a context, the non-global symbols defined in them
- // will not be available to other Nu scripts or at the console. These loads should only be used
- // to set globals and to make changes to information stored in the ObjC runtime.
[Nu loadNuFile:@"nu" fromBundleWithIdentifier:@"nu.programming.framework" withContext:nil];
[Nu loadNuFile:@"bridgesupport" fromBundleWithIdentifier:@"nu.programming.framework" withContext:nil];
[Nu loadNuFile:@"cocoa" fromBundleWithIdentifier:@"nu.programming.framework" withContext:nil];
[Nu loadNuFile:@"help" fromBundleWithIdentifier:@"nu.programming.framework" withContext:nil];
#endif
+
}
}
@@ -509,7 +521,7 @@ + (BOOL) loadNuFile:(NSString *) fileName fromBundleWithIdentifier:(NSString *)
if (filePath) {
NSString *fileNu = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
if (fileNu) {
- NuParser *parser = [Nu parser];
+ NuParser *parser = [Nu sharedParser];
id script = [parser parse:fileNu asIfFromFilename:[filePath cStringUsingEncoding:NSUTF8StringEncoding]];
if (!context) context = [parser context];
[script evalWithContext:context];
@@ -8936,6 +8948,13 @@ void load_builtins(NuSymbolTable *symbolTable)
install(@"help", Nu_help_operator);
install(@"?", Nu_help_operator);
install(@"version", Nu_version_operator);
+
+ // set some commonly-used globals
+ [(NuSymbol *) [symbolTable symbolWithString:@"NSUTF8StringEncoding"]
+ setValue:[NSNumber numberWithInt:NSUTF8StringEncoding]];
+
+ [(NuSymbol *) [symbolTable symbolWithString:@"NSLog"] // let's make this an operator someday
+ setValue:[NuBridgedFunction functionWithName:@"NSLog" signature:@"v@"]];
}
// NuParser.m
Please sign in to comment.
Something went wrong with that request. Please try again.