Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a new method "include" which includes and evals the named file

Formatting cleanup.
  • Loading branch information...
commit c07386b58be160e91eb483c5fc6fa5651fa29a8d 1 parent aeb1a40
@ccgus authored
View
4 src/JSTListener.h
@@ -21,7 +21,7 @@
@property (assign) id rootObject;
-+ (void) listen;
-+ (void) listenWithRootObject:(id)rootObject;
++ (void)listen;
++ (void)listenWithRootObject:(id)rootObject;
@end
View
8 src/JSTListener.m
@@ -17,7 +17,7 @@ @implementation JSTListener
@synthesize rootObject=_rootObject;
-+ (id) sharedListener {
++ (id)sharedListener {
static JSTListener *me = 0x00;
if (!me) {
me = [[JSTListener alloc] init];
@@ -26,17 +26,17 @@ + (id) sharedListener {
return me;
}
-+ (void) listen {
++ (void)listen {
[[self sharedListener] setupListener];
}
-+ (void) listenWithRootObject:(id)rootObject; {
++ (void)listenWithRootObject:(id)rootObject; {
((JSTListener*)[self sharedListener]).rootObject = rootObject;
[self listen];
}
-- (void) setupListener {
+- (void)setupListener {
NSString *myBundleId = [[NSBundle mainBundle] bundleIdentifier];
NSString *port = [NSString stringWithFormat:@"%@.JSTalk", myBundleId];
View
5 src/JSTPreprocessor.h
@@ -13,7 +13,7 @@
}
-+ (NSString*) preprocessCode:(NSString*)sourceString;
++ (NSString*)preprocessCode:(NSString*)sourceString;
@end
@@ -24,13 +24,12 @@
unichar _openSymbol;
NSMutableArray *_args;
JSTPSymbolGroup *_parent;
-
}
@property (retain) NSMutableArray *args;
@property (retain) JSTPSymbolGroup *parent;
-- (void) addSymbol:(id)aSymbol;
+- (void)addSymbol:(id)aSymbol;
@end
View
16 src/JSTPreprocessor.m
@@ -14,7 +14,7 @@
@implementation JSTPreprocessor
-+ (NSString*) preprocessForObjCStrings:(NSString*)sourceString {
++ (NSString*)preprocessForObjCStrings:(NSString*)sourceString {
NSMutableString *buffer = [NSMutableString string];
TDTokenizer *tokenizer = [TDTokenizer tokenizerWithString:sourceString];
@@ -49,15 +49,15 @@ + (NSString*) preprocessForObjCStrings:(NSString*)sourceString {
return buffer;
}
-+ (BOOL) isOpenSymbol:(NSString*)tag {
++ (BOOL)isOpenSymbol:(NSString*)tag {
return [tag isEqualToString:@"["] || [tag isEqualToString:@"("];
}
-+ (BOOL) isCloseSymbol:(NSString*)tag {
++ (BOOL)isCloseSymbol:(NSString*)tag {
return [tag isEqualToString:@"]"] || [tag isEqualToString:@")"];
}
-+ (NSString*) preprocessForObjCMessagesToJS:(NSString*)sourceString {
++ (NSString*)preprocessForObjCMessagesToJS:(NSString*)sourceString {
NSMutableString *buffer = [NSMutableString string];
TDTokenizer *tokenizer = [TDTokenizer tokenizerWithString:sourceString];
@@ -107,7 +107,7 @@ + (NSString*) preprocessForObjCMessagesToJS:(NSString*)sourceString {
return buffer;
}
-+ (NSString*) preprocessCode:(NSString*)sourceString {
++ (NSString*)preprocessCode:(NSString*)sourceString {
sourceString = [self preprocessForObjCStrings:sourceString];
sourceString = [self preprocessForObjCMessagesToJS:sourceString];
@@ -123,7 +123,7 @@ @implementation JSTPSymbolGroup
@synthesize args=_args;
@synthesize parent=_parent;
-- (id) init {
+- (id)init {
self = [super init];
if (self != nil) {
_args = [[NSMutableArray array] retain];
@@ -139,7 +139,7 @@ - (void)dealloc {
[super dealloc];
}
-- (void) addSymbol:(id)aSymbol {
+- (void)addSymbol:(id)aSymbol {
if (!_openSymbol && [aSymbol isKindOfClass:[TDToken class]]) {
_openSymbol = [[aSymbol stringValue] characterAtIndex:0];
@@ -149,7 +149,7 @@ - (void) addSymbol:(id)aSymbol {
}
}
-- (NSString*) description {
+- (NSString*)description {
NSUInteger argsCount = [_args count];
View
16 src/JSTalk.h
@@ -21,15 +21,15 @@
@property (retain) JSCocoaController *jsController;
@property (retain) NSMutableDictionary *env;
-- (id) executeString:(NSString*) str;
-- (void) pushObject:(id)obj withName:(NSString*)name;
-- (void) deleteObjectWithName:(NSString*)name;
+- (id)executeString:(NSString*) str;
+- (void)pushObject:(id)obj withName:(NSString*)name;
+- (void)deleteObjectWithName:(NSString*)name;
-- (JSCocoaController*) jsController;
-- (id) callFunctionNamed:(NSString*)name withArguments:(NSArray*)args;
+- (JSCocoaController*)jsController;
+- (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args;
-+ (void) listen;
-+ (void) setShouldLoadJSTPlugins:(BOOL)b;
-+ (id) application:(NSString*)app;
++ (void)listen;
++ (void)setShouldLoadJSTPlugins:(BOOL)b;
++ (id)application:(NSString*)app;
@end
View
55 src/JSTalk.m
@@ -25,23 +25,23 @@ @implementation JSTalk
@synthesize jsController=_jsController;
@synthesize env=_env;
-+ (void) load {
++ (void)load {
//debug(@"%s:%d", __FUNCTION__, __LINE__);
}
-+ (void) listen {
++ (void)listen {
[JSTListener listen];
}
-+ (void) setShouldLoadExtras:(BOOL)b {
++ (void)setShouldLoadExtras:(BOOL)b {
JSTalkShouldLoadJSTPlugins = b;
}
-+ (void) setShouldLoadJSTPlugins:(BOOL)b {
++ (void)setShouldLoadJSTPlugins:(BOOL)b {
JSTalkShouldLoadJSTPlugins = b;
}
-- (id) init {
+- (id)init {
self = [super init];
if (self != nil) {
self.jsController = [[[JSCocoaController alloc] init] autorelease];
@@ -69,7 +69,7 @@ - (void)dealloc {
[super dealloc];
}
-- (void) loadExtraAtPath:(NSString*) fullPath {
+- (void)loadExtraAtPath:(NSString*)fullPath {
Class pluginClass;
@@ -118,7 +118,7 @@ - (void) loadExtraAtPath:(NSString*) fullPath {
}
-- (void) loadPlugins {
+- (void)loadPlugins {
JSTalkPluginList = [[NSMutableArray array] retain];
NSString *appSupport = @"Library/Application Support/JSTalk/Plug-ins";
@@ -144,7 +144,7 @@ - (void) loadPlugins {
}
}
-- (void) pushObject:(id)obj withName:(NSString*)name {
+- (void)pushObject:(id)obj withName:(NSString*)name {
JSContextRef ctx = [_jsController ctx];
JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
@@ -157,7 +157,7 @@ - (void) pushObject:(id)obj withName:(NSString*)name {
JSStringRelease(jsName);
}
-- (void) deleteObjectWithName:(NSString*)name {
+- (void)deleteObjectWithName:(NSString*)name {
JSContextRef ctx = [_jsController ctx];
JSStringRef jsName = JSStringCreateWithUTF8CString([name UTF8String]);
@@ -168,7 +168,7 @@ - (void) deleteObjectWithName:(NSString*)name {
}
-- (id) executeString:(NSString*) str {
+- (id)executeString:(NSString*) str {
if (!JSTalkPluginList && JSTalkShouldLoadJSTPlugins) {
[self loadPlugins];
@@ -208,7 +208,7 @@ - (id) executeString:(NSString*) str {
return resultObj;
}
-- (id) callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
+- (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
JSCocoaController *jsController = [self jsController];
JSContextRef ctx = [jsController ctx];
@@ -227,9 +227,32 @@ - (id) callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
return returnObject;
}
+- (void)include:(NSString*)fileName {
+
+ if (![fileName hasPrefix:@"/"] && [_env objectForKey:@"scriptURL"]) {
+ NSString *parentDir = [[[_env objectForKey:@"scriptURL"] path] stringByDeletingLastPathComponent];
+ fileName = [parentDir stringByAppendingPathComponent:fileName];
+ }
+
+ NSURL *scriptURL = [NSURL fileURLWithPath:fileName];
+ NSError *err = 0x00;
+ NSString *str = [NSString stringWithContentsOfURL:scriptURL encoding:NSUTF8StringEncoding error:&err];
+
+ if (!str) {
+ NSLog(@"Could not open file '%@'", scriptURL);
+ NSLog(@"Error: %@", err);
+ return;
+ }
+
+ str = [JSTPreprocessor preprocessCode:str];
+
+ #warning fixme: why does withScriptURL take a string path?
+ if (![[self jsController] evalJSString:str withScriptURL:[scriptURL path]]) {
+ NSLog(@"Could not include '%@'", fileName);
+ }
+}
-
-- (void) print:(NSString*)s {
+- (void)print:(NSString*)s {
if (_printController && [_printController respondsToSelector:@selector(print:)]) {
[_printController print:s];
@@ -243,7 +266,7 @@ - (void) print:(NSString*)s {
}
}
-+ (id) applicationOnPort:(NSString*)port {
++ (id)applicationOnPort:(NSString*)port {
NSConnection *conn = 0x00;
NSUInteger tries = 0;
@@ -266,7 +289,7 @@ + (id) applicationOnPort:(NSString*)port {
return [conn rootProxy];
}
-+ (id) application:(NSString*)app {
++ (id)application:(NSString*)app {
NSString *appPath = [[NSWorkspace sharedWorkspace] fullPathForApplication:app];
@@ -294,7 +317,7 @@ + (id) application:(NSString*)app {
}
-+ (id) proxyForApp:(NSString*)app {
++ (id)proxyForApp:(NSString*)app {
return [self application:app];
}
Please sign in to comment.
Something went wrong with that request. Please try again.