Permalink
Browse files

Added support for some sort of JSTalk envirnoment vars, which you can…

… stuff runtime info in.
  • Loading branch information...
1 parent 4843fe1 commit 1a4ff63a1f26bbf07241b3ec68ebe03f5e8ee552 August Mueller committed Oct 19, 2009
Showing with 71 additions and 11 deletions.
  1. +13 −0 jstalk.xcodeproj/project.pbxproj
  2. +4 −1 src/JSTDocument.m
  3. +9 −0 src/JSTExtras.m
  4. +4 −2 src/JSTalk.h
  5. +12 −8 src/JSTalk.m
  6. +29 −0 src/jstalkmain.m
@@ -239,6 +239,13 @@
remoteGlobalIDString = CC4143190F25254200E46669;
remoteInfo = "JSTalk Framework";
};
+ CC77FDCE10879C8D00323EE7 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 2A37F4A9FDCFA73011CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = CC5FB7C10F1FDCCC00F4ECC2;
+ remoteInfo = "jstalk command line";
+ };
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -823,6 +830,7 @@
dependencies = (
CC5064E60F4A164D00F4A952 /* PBXTargetDependency */,
CC43C12A0F4BBE750044BA41 /* PBXTargetDependency */,
+ CC77FDCF10879C8D00323EE7 /* PBXTargetDependency */,
);
name = "JSTalk Editor";
productInstallPath = "$(HOME)/Applications";
@@ -1105,6 +1113,11 @@
target = CC4143190F25254200E46669 /* JSTalk Framework */;
targetProxy = CC5064E50F4A164D00F4A952 /* PBXContainerItemProxy */;
};
+ CC77FDCF10879C8D00323EE7 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = CC5FB7C10F1FDCCC00F4ECC2 /* jstalk command line */;
+ targetProxy = CC77FDCE10879C8D00323EE7 /* PBXContainerItemProxy */;
+ };
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
View
@@ -173,7 +173,6 @@ - (void) runScript:(NSString*)s {
@try {
-
JSTalk *jstalk = [[JSTalk alloc] init];
JSCocoaController *jsController = [jstalk jsController];
@@ -183,6 +182,10 @@ - (void) runScript:(NSString*)s {
[errorLabel setStringValue:@""];
+ if ([self fileURL]) {
+ [jstalk.env setObject:[self fileURL] forKey:@"scriptURL"];
+ }
+
if ([JSTPrefs boolForKey:@"clearConsoleOnRun"]) {
[self clearConsole:nil];
}
View
@@ -7,8 +7,17 @@
//
#import "JSTExtras.h"
+#import "JSTalk.h"
#import <ScriptingBridge/ScriptingBridge.h>
+@implementation JSTalk (JSTExtras)
+
+- (void) exit:(int)termCode {
+ exit(termCode);
+}
+
+@end
+
@implementation NSApplication (JSTExtras)
- (id)open:(NSString*)pathToFile {
View
@@ -13,15 +13,17 @@
id _printController;
id _errorController;
JSCocoaController *_jsController;
+ NSMutableDictionary *_env;
}
@property (assign) id printController;
@property (assign) id errorController;
@property (retain) JSCocoaController *jsController;
+@property (retain) NSMutableDictionary *env;
- (id) executeString:(NSString*) str;
-- (void) pushObject:(id)obj withName:(NSString*)name inController:(JSCocoaController*)jsController;
-- (void) deleteObjectWithName:(NSString*)name inController:(JSCocoaController*)jsController;
+- (void) pushObject:(id)obj withName:(NSString*)name;
+- (void) deleteObjectWithName:(NSString*)name;
- (JSCocoaController*) jsController;
- (id) callFunctionNamed:(NSString*)name withArguments:(NSArray*)args;
View
@@ -23,6 +23,7 @@ @implementation JSTalk
@synthesize printController=_printController;
@synthesize errorController=_errorController;
@synthesize jsController=_jsController;
+@synthesize env=_env;
+ (void) load {
//debug(@"%s:%d", __FUNCTION__, __LINE__);
@@ -44,14 +45,14 @@ - (id) init {
self = [super init];
if (self != nil) {
self.jsController = [[[JSCocoaController alloc] init] autorelease];
+ self.env = [NSMutableDictionary dictionary];
}
return self;
}
- (void)dealloc {
- debug(@"%s:%d", __FUNCTION__, __LINE__);
[[NSNotificationCenter defaultCenter] removeObserver:self];
@@ -62,6 +63,9 @@ - (void)dealloc {
[_jsController release];
_jsController = 0x00;
+ [_env release];
+ _env = 0x00;
+
[super dealloc];
}
@@ -140,9 +144,9 @@ - (void) loadPlugins {
}
}
-- (void) pushObject:(id)obj withName:(NSString*)name inController:(JSCocoaController*)jsController {
+- (void) pushObject:(id)obj withName:(NSString*)name {
- JSContextRef ctx = [jsController ctx];
+ JSContextRef ctx = [_jsController ctx];
JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
JSObjectRef jsObject = [JSCocoaController jsCocoaPrivateObjectInContext:ctx];
JSCocoaPrivateObject *private = JSObjectGetPrivate(jsObject);
@@ -153,9 +157,9 @@ - (void) pushObject:(id)obj withName:(NSString*)name inController:(JSCocoaContro
JSStringRelease(jsName);
}
-- (void) deleteObjectWithName:(NSString*)name inController:(JSCocoaController*)jsController {
+- (void) deleteObjectWithName:(NSString*)name {
- JSContextRef ctx = [jsController ctx];
+ JSContextRef ctx = [_jsController ctx];
JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
JSObjectDeleteProperty(ctx, JSContextGetGlobalObject(ctx), jsName, NULL);
@@ -171,8 +175,8 @@ - (id) executeString:(NSString*) str {
}
str = [JSTPreprocessor preprocessCode:str];
-
- [self pushObject:self withName:@"jstalk" inController:_jsController];
+
+ [self pushObject:self withName:@"jstalk"];
JSValueRef resultRef = 0x00;
id resultObj = 0x00;
@@ -193,7 +197,7 @@ - (id) executeString:(NSString*) str {
[JSCocoaFFIArgument unboxJSValueRef:resultRef toObject:&resultObj inContext:[[self jsController] ctx]];
}
- [self deleteObjectWithName:@"jstalk" inController:_jsController];
+ [self deleteObjectWithName:@"jstalk"];
// this will free up the reference to ourself
if ([_jsController ctx]) {
View
@@ -2,6 +2,26 @@
#import "JSTListener.h"
#import "JSTalk.h"
+
+@interface JSCErrorHandler : NSObject {
+
+}
+@end
+
+@implementation JSCErrorHandler
+
+- (void) JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
+
+ NSLog(@"Error line %d, %@", lineNumber, error);
+
+ exit(1);
+}
+
+
+@end
+
+
+
int main(int argc, char *argv[]) {
if (argc < 2) {
@@ -15,8 +35,15 @@ int main(int argc, char *argv[]) {
encoding:NSUTF8StringEncoding
error:nil];
+ JSCErrorHandler *eh = [[[JSCErrorHandler alloc] init] autorelease];
+
JSTalk *t = [[[JSTalk alloc] init] autorelease];
+ JSCocoaController *jsController = [t jsController];
+ jsController.delegate = eh;
+
+ [t.env setObject:[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]] forKey:@"scriptURL"];
+
if ([s hasPrefix:@"#!"]) {
NSRange r = [s rangeOfString:@"\n"];
@@ -29,4 +56,6 @@ int main(int argc, char *argv[]) {
[t executeString:s];
[pool release];
+
+ return 0;
}

0 comments on commit 1a4ff63

Please sign in to comment.