diff options
Diffstat (limited to 'entities')
| -rw-r--r-- | entities/JMXScriptEntity.h | 3 | ||||
| -rw-r--r-- | entities/JMXScriptEntity.mm | 24 | ||||
| -rw-r--r-- | entities/JMXScriptFile.mm | 2 | ||||
| -rw-r--r-- | entities/JMXScriptLive.h | 2 | ||||
| -rw-r--r-- | entities/JMXScriptLive.mm | 12 | ||||
| -rw-r--r-- | entities/video/JMXTextEntity.mm | 1 |
6 files changed, 29 insertions, 15 deletions
diff --git a/entities/JMXScriptEntity.h b/entities/JMXScriptEntity.h index 82e6388..0ee832d 100644 --- a/entities/JMXScriptEntity.h +++ b/entities/JMXScriptEntity.h @@ -20,13 +20,16 @@ JMXScript *jsContext; NSThread *executionThread; NSMutableSet *pinWrappers; + JMXOutputPin *codeOutputPin; } @property (copy) NSString *code; +@property (retain) NSArray *arguments; // XXX - arguments need to be set before code @property (readonly) JMXScript *jsContext; @property (readonly) NSThread *executionThread; - (BOOL)exec; +- (BOOL)exec:(NSString *)code; - (void)resetContext; - (void)hookEntity:(JMXEntity *)entity; diff --git a/entities/JMXScriptEntity.mm b/entities/JMXScriptEntity.mm index b039957..b05d691 100644 --- a/entities/JMXScriptEntity.mm +++ b/entities/JMXScriptEntity.mm @@ -23,7 +23,7 @@ using namespace v8; @implementation JMXScriptEntity -@synthesize code, jsContext, executionThread; +@synthesize code, arguments, jsContext, executionThread; + (void)initialize { @@ -40,6 +40,8 @@ using namespace v8; if (self) { self.label = @"ScriptEntity"; pinWrappers = [[NSMutableSet alloc] initWithCapacity:25]; + codeOutputPin = [self registerOutputPin:@"runningCode" withType:kJMXCodePin andSelector:@"code"]; + } return self; } @@ -99,15 +101,22 @@ using namespace v8; [pool drain]; } -- (BOOL)exec +- (BOOL)exec:(NSString *)someCode { + if (!someCode) + someCode = self.code; if (!jsContext) { jsContext = [[JMXScript alloc] init]; [jsContext startWithEntity:self]; } [executionThread release]; executionThread = [[NSThread currentThread] retain]; - return [jsContext runScript:self.code]; + return [jsContext runScript:someCode withArgs:self.arguments]; +} + +- (BOOL)exec +{ + return [self exec:nil]; } - (void)hookEntity:(JMXEntity *)entity @@ -142,6 +151,15 @@ using namespace v8; return pin; } +- (void)setCode:(NSString *)someCode +{ + if (code == someCode) + return; + [code release]; + code = [someCode retain]; + codeOutputPin.data = code; +} + #pragma mark - #pragma JMXPinOwner - (id)provideDataToPin:(JMXOutputPin *)aPin diff --git a/entities/JMXScriptFile.mm b/entities/JMXScriptFile.mm index c4d02da..d298dde 100644 --- a/entities/JMXScriptFile.mm +++ b/entities/JMXScriptFile.mm @@ -106,7 +106,7 @@ extern void JSExit(int code); [self exec]; } } - if (jsContext) + if (isRunning && jsContext) [jsContext nodejsRun]; [super tick:timeStamp]; } diff --git a/entities/JMXScriptLive.h b/entities/JMXScriptLive.h index 768a0e6..104ee9d 100644 --- a/entities/JMXScriptLive.h +++ b/entities/JMXScriptLive.h @@ -14,8 +14,6 @@ @interface JMXScriptLive : JMXScriptEntity { @private JMXInputPin *codeInputPin; - JMXOutputPin *codeOutputPin; - NSString *history; } - (void)execCode:(NSString *)code; diff --git a/entities/JMXScriptLive.mm b/entities/JMXScriptLive.mm index 3f2990b..5a81024 100644 --- a/entities/JMXScriptLive.mm +++ b/entities/JMXScriptLive.mm @@ -18,8 +18,6 @@ if (self) { self.label = @"JMXScriptLive"; codeInputPin = [self registerInputPin:@"code" withType:kJMXCodePin andSelector:@"execCode:"]; - codeOutputPin = [self registerOutputPin:@"runningCode" withType:kJMXCodePin andSelector:@"executedCode:"]; - history = [[NSString alloc] init]; JMXThreadedEntity *threadedEntity = [[JMXThreadedEntity threadedEntity:self] retain]; if (threadedEntity) return (JMXScriptLive *)threadedEntity; @@ -30,12 +28,9 @@ - (void)execCode:(NSString *)jsCode { @synchronized(self) { - self.code = jsCode; - if ([self exec]) { - NSString *newHistory = [NSString stringWithFormat:@"%@\n%@", history, jsCode]; - [history release]; - history = [newHistory retain]; - codeOutputPin.data = history; + if ([self exec:jsCode]) { + NSString *history = [NSString stringWithFormat:@"%@\n%@", self.code, jsCode]; + self.code = history; } else { // TODO - show an alert to the user } @@ -44,7 +39,6 @@ - (void)dealloc { - [history release]; [super dealloc]; } diff --git a/entities/video/JMXTextEntity.mm b/entities/video/JMXTextEntity.mm index d966e10..20af177 100644 --- a/entities/video/JMXTextEntity.mm +++ b/entities/video/JMXTextEntity.mm @@ -95,6 +95,7 @@ JMXV8_EXPORT_NODE_CLASS(JMXTextEntity); @synchronized(self) { [renderer setString:text withAttributes:stanStringAttrib]; [renderer drawOnBuffer:textFrame]; + if (renderedText) [renderedText release]; renderedText = [[CIImage imageWithCVImageBuffer:textFrame] retain]; |

