Skip to content

Commit

Permalink
[FIXORS] Little bit o' code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Apr 9, 2009
1 parent 36e08cd commit 019c2f2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 143 deletions.
3 changes: 1 addition & 2 deletions example_scripts/Sketch.jstalk
Expand Up @@ -4,8 +4,7 @@ var sketch = [JSTalk application:"Sketch"];
var doc = [sketch orderedDocuments][0]
var rectangle = [doc makeNewBox];

[rectangle setWidth:100];
[rectangle setHeight:100];
[rectangle setSize:NSMakeSize(100, 100)];
[rectangle setXPosition:100];
[rectangle setYPosition:100];

Expand Down
70 changes: 49 additions & 21 deletions res/English.lproj/JSTDocument.xib
Expand Up @@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="100059"/>
<integer value="100061"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -123,20 +123,14 @@
<string>WebURLsWithTitlesPboardType</string>
</object>
</object>
<string key="NSFrameSize">{584, 238}</string>
<string key="NSFrameSize">{584, 42}</string>
<reference key="NSSuperview" ref="579376345"/>
<object class="NSTextContainer" key="NSTextContainer" id="843780999">
<object class="NSLayoutManager" key="NSLayoutManager">
<object class="NSTextStorage" key="NSTextStorage">
<object class="NSMutableString" key="NSString">
<bytes key="NS.bytes">dmFyIHNrZXRjaCA9IFtKU1RhbGsgYXBwbGljYXRpb246IlNrZXRjaCJdOwp2YXIgZG9jID0gW3NrZXRj
aCBvcmRlcmVkRG9jdW1lbnRzXVswXQp2YXIgcmVjdGFuZ2xlID0gW2RvYyBtYWtlTmV3Qm94XTsKClty
ZWN0YW5nbGUgc2V0V2lkdGg6MTAwXTsKW3JlY3RhbmdsZSBzZXRIZWlnaHQ6MTAwXTsKW3JlY3Rhbmds
ZSBzZXRYUG9zaXRpb246MTAwXTsKW3JlY3RhbmdsZSBzZXRZUG9zaXRpb246MTAwXTsKcmVjdGFuZ2xl
LndpZHRoID0gMjAwCnByaW50KHJlY3RhbmdsZS53aWR0aCgpKQpyZWN0YW5nbGUuc2l6ZSA9IG5ldyBO
U1NpemUoMjUwLCAxNTApCnZhciB3ID0gc2tldGNoLndpbmRvd3MoKVswXQpwcmludCgndz0nICsgdy5m
cmFtZSgpKQp3LmZyYW1lT3JpZ2luID0gbmV3IE5TUG9pbnQoMTAwLCAxMDApCnByaW50KCd3PScgKyB3
LmZyYW1lKCkpCgo</bytes>
<bytes key="NS.bytes">dmFyIG1lc3NhZ2UgPSAiSGVsbG8gV29ybGQhIjsKCltbSlNUYWxrIGFwcGxpY2F0aW9uOiJKU1RhbGsg
RWRpdG9yIl0gZGlzcGxheURpYWxvZzptZXNzYWdlXTs</bytes>
</object>
<object class="NSDictionary" key="NSAttributes">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -147,14 +141,52 @@ LmZyYW1lKCkpCgo</bytes>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSFont">
<string key="NSName">Helvetica</string>
<double key="NSSize">1.200000e+01</double>
<object class="NSFont" id="155459336">
<string key="NSName">Monaco</string>
<double key="NSSize">1.000000e+01</double>
<int key="NSfFlags">16</int>
</object>
<object class="NSParagraphStyle">
<int key="NSAlignment">4</int>
<nil key="NSTabStops"/>
<object class="NSArray" key="NSTabStops">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSTextTab">
<double key="NSLocation">2.800000e+01</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">5.600000e+01</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">8.400000e+01</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">1.120000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">1.400000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">1.680000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">1.960000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">2.240000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">2.520000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">2.800000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">3.080000e+02</double>
</object>
<object class="NSTextTab">
<double key="NSLocation">3.360000e+02</double>
</object>
</object>
</object>
</object>
</object>
Expand Down Expand Up @@ -322,11 +354,7 @@ LmZyYW1lKCkpCgo</bytes>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSFont" id="155459336">
<string key="NSName">Monaco</string>
<double key="NSSize">1.000000e+01</double>
<int key="NSfFlags">16</int>
</object>
<reference ref="155459336"/>
<integer value="0" id="8"/>
<object class="NSParagraphStyle">
<int key="NSAlignment">4</int>
Expand Down Expand Up @@ -700,8 +728,8 @@ LmZyYW1lKCkpCgo</bytes>
<string>JSTTextView</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{391, 292}, {584, 452}}</string>
<string>{{391, 292}, {584, 452}}</string>
<string>{{485, 378}, {584, 452}}</string>
<string>{{485, 378}, {584, 452}}</string>
<reference ref="9"/>
<string>{{201, 387}, {507, 413}}</string>
<reference ref="9"/>
Expand Down
120 changes: 0 additions & 120 deletions src/JSTDocument.m
Expand Up @@ -195,126 +195,6 @@ - (void) JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLine
}


/*
//
// JSCocoa : handle setting with callMethod
// object.width = 100
// ->
// [object setWidth:100]
//
- (BOOL) JSCocoa:(JSCocoaController*)controller setProperty:(NSString*)propertyName ofObject:(id)object toValue:(JSValueRef)value inContext:(JSContextRef)ctx exception:(JSValueRef*)exception;
{
// FIXME: this doesn't actually work with objc properties, and we can't always rely that this method will exist either...
// it should probably be moved up into the JSCocoa layer.
NSString* setterName = [NSString stringWithFormat:@"set%@%@:",
[[propertyName substringWithRange:NSMakeRange(0,1)] capitalizedString],
[propertyName substringWithRange:NSMakeRange(1, [propertyName length]-1)]];
if ([self JSCocoa:controller callMethod:setterName ofObject:object argumentCount:1 arguments:&value inContext:ctx exception:exception]) {
return YES;
}
return NO;
}
//
// NSDistantObject call using NSInvocation
//
- (JSValueRef) JSCocoa:(JSCocoaController*)controller callMethod:(NSString*)methodName ofObject:(id)callee argumentCount:(int)argumentCount arguments:(JSValueRef*)arguments inContext:(JSContextRef)ctx exception:(JSValueRef*)exception
{
SEL selector = NSSelectorFromString(methodName);
if (class_getInstanceMethod([callee class], selector) || class_getClassMethod([callee class], selector)) {
return nil;
}
NSMethodSignature *signature = [callee methodSignatureForSelector:selector];
if (!signature) {
return nil;
}
// we need to do all this for NSDistantObject , since JSCocoa doesn't handle it natively.
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
NSUInteger argIndex = 0;
while (argIndex < argumentCount) {
id arg = 0x00;
[JSCocoaFFIArgument unboxJSValueRef:arguments[argIndex] toObject:&arg inContext:ctx];
if ([arg isKindOfClass:[NSNumber class]]) {
const char *type = [signature getArgumentTypeAtIndex:argIndex + 2];
if (strcmp(type, @encode(BOOL)) == 0) {
BOOL b = [arg boolValue];
[invocation setArgument:&b atIndex:argIndex + 2];
}
else if (strcmp(type, @encode(unsigned int)) == 0) {
unsigned int i = [arg unsignedIntValue];
[invocation setArgument:&i atIndex:argIndex + 2];
}
else if (strcmp(type, @encode(int)) == 0) {
int i = [arg intValue];
[invocation setArgument:&i atIndex:argIndex + 2];
}
else if (strcmp(type, @encode(unsigned long)) == 0) {
unsigned long l = [arg unsignedLongValue];
[invocation setArgument:&l atIndex:argIndex + 2];
}
else if (strcmp(type, @encode(long)) == 0) {
long l = [arg longValue];
[invocation setArgument:&l atIndex:argIndex + 2];
}
else if (strcmp(type, @encode(float)) == 0) {
float f = [arg floatValue];
[invocation setArgument:&f atIndex:argIndex + 2];
}
else if (strcmp(type, @encode(double)) == 0) {
double d = [arg doubleValue];
[invocation setArgument:&d atIndex:argIndex + 2];
}
else { // just do int for all else.
int i = [arg intValue];
[invocation setArgument:&i atIndex:argIndex + 2];
}
}
else {
[invocation setArgument:&arg atIndex:argIndex + 2];
}
argIndex++;
}
[invocation invokeWithTarget:callee];
id result = 0x00;
const char *type = [signature methodReturnType];
if (strcmp(type, @encode(id)) == 0) {
[invocation getReturnValue:&result];
}
if (!result) {
return JSValueMakeNull(ctx);
}
JSValueRef jsReturnValue = NULL;
[JSCocoaFFIArgument boxObject:result toJSValueRef:&jsReturnValue inContext:ctx];
return jsReturnValue;
}
*/


- (void) runScript:(NSString*)s {

JSTalk *jstalk = [[[JSTalk alloc] init] autorelease];
Expand Down

0 comments on commit 019c2f2

Please sign in to comment.