forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFSNSDistantObject.m
194 lines (154 loc) · 5.74 KB
/
FSNSDistantObject.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* FSNSDistantObject.m Copyright (c) 2001-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "FSNSDistantObject.h"
#import "FSVoid.h"
#import "build_config.h"
#import "FSNSStringPrivate.h"
#import "FSBoolean.h"
#import "FSNSString.h"
#import "FScriptFunctions.h"
#import "FSNSNumber.h"
#import "FSNumber.h"
#import "NumberPrivate.h"
#import "ArrayPrivate.h"
#import "FSBooleanPrivate.h"
#import "FSNSObject.h"
#import "FSNSProxy.h"
#import "FSBlock.h"
#import <objc/objc.h>
#import <AppKit/AppKit.h>
#import "FSAssociation.h"
@interface NSObject(FSNSObjectPrivate)
- (id) _operator_equal_remote:(id)operand;
- (id) _operator_tilde_equal_remote:(id)operand;
- (NSString *) _printString_remote;
- (void) _throw_remote;
@end
@interface NSMethodSignature(UndocumentedNSMethodSignature)
+ (NSMethodSignature*) signatureWithObjCTypes:(char *)types;
@end
@implementation NSDistantObject(FSNSDistantObject)
+ (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
// Partial fix for broken Mac OS X implementation of NSProxy meta-class level.
// Limitation: this is all hard wired here, and thus will not work for methods added in new categories or new subclasses.
// Note: signatureWithObjCTypes method is a private and undocumented Cocoa method (Mac OS X 10.1.2)
if (selector == @selector(proxyWithLocal:connection:)) return [NSMethodSignature signatureWithObjCTypes:"@@:@@"];
else if (selector == @selector(proxyWithTarget:connection:)) return [NSMethodSignature signatureWithObjCTypes:"@@:@@"];
else return [[NSProxy class] methodSignatureForSelector:selector];
// A strange bug in GCC3 (beta) makes using "super" seemingly impossible here.
// We can't use [self superclass] instead because it's buggy too (it returns NSProxy meta class)!
// So we hard-wire the use of NSProxy.
}
- (NSString *)descriptionLimited:(NSUInteger)nbElem
{
// fallback to the standard printString method. No implementation yet of string's length limitation for remote objects.
return [self printString];
}
///////////////////////// USER METHODS /////////////////////
- (id) applyBlock:(FSBlock *)block
{
return [block value:self];
}
- (id) classOrMetaclass
{
return [super classOrMetaclass];
}
- (FSArray *) enlist
{
return [FSArray arrayWithObject:self];
}
- (FSArray *)enlist:(NSNumber *)operand
{
FSArray *r;
VERIF_OP_NSNUMBER(@"enlist:")
if ([operand doubleValue] < 0)
FSExecError([NSString stringWithFormat:@"argument of method \"enlist:\" must be non-negative"]);
if ([operand doubleValue] > NSUIntegerMax)
FSExecError([NSString stringWithFormat:@"argument of method \"enlist:\" must be less or equal to %lu",(unsigned long)NSUIntegerMax]);
if (r = [[[FSArray alloc] initFilledWith:self count:[operand doubleValue]] autorelease])
return r;
else
FSExecError(@"not enough memory");
}
- (FSBoolean *)operator_equal_equal:(id)operand
{
/*if ([self respondsToSelector:@selector(_operator_equal_equal_remote:)])
return [(id)self _operator_equal_equal_remote:operand];
else */
return (self == operand ? (id)[FSBoolean fsTrue] : (id)[FSBoolean fsFalse]);
}
- (FSAssociation *)operator_hyphen_greater:(id)operand
{
return [FSAssociation associationWithKey:self value:operand];
}
- (FSBoolean *)operator_tilde_tilde:(id)operand;
{
/* if ([self respondsToSelector:@selector(_operator_tilde_tilde_remote:)])
return [(id)self _operator_tilde_tilde_remote:operand];
else */
return (self == operand ? (id)[FSBoolean fsFalse] : (id)[FSBoolean fsTrue]);
}
- (NSString *)printString
{
NSString *remoteObjectPrintString;
if ([self respondsToSelector:@selector(_printString_remote)])
remoteObjectPrintString = [(id)self _printString_remote];
else
remoteObjectPrintString = [self description];
if ([self isKindOfClass:[FSVoid class]]) return remoteObjectPrintString;
return [@"a proxy for " stringByAppendingString:remoteObjectPrintString];
}
- (void)throw
{
//******************************************************************************************
// We should do the folowing but a bug (Mac OS X 10.4.4) prevents us to do so (when an
// non-NSException object is thrown in a remote method call, the client waits indefinitely).
//******************************************************************************************
// if ([self respondsToSelector:@selector(_throw_remote)]) [(id)self _throw_remote];
// else @throw self;
@throw self;
}
- (NSConnection *)vend:(NSString *)operand
{
NSConnection *theConnection;
VERIF_OP_NSSTRING(@"vend:")
theConnection = [[NSConnection alloc] init];
[theConnection setRootObject:self];
if ([theConnection registerName:operand] == NO) return nil;
else return theConnection;
}
/* FSNSString, FSNSArray, FSNSNumber support */
/*
- (Block *) asBlock
{
return [self asBlockOnError:nil];
}
- (Block *) asBlockOnError:(Block *)errorBlock // untested
{
if ([self isKindOfClass:[NSString class]])
return [[NSString stringWithString:(NSString *)self] asBlockOnError:errorBlock]; // get a local copy then send the message
else
FSExecError(@"F-Script distributed object support report: the message \"asBlock\" or \"asBlockOnError:\" must be sent to an NSString");
}
- (NSString *)descriptionLimited:(unsigned)nbElem
{
return [self printString];
}
*/
- (NSUInteger) _ul_count
{
return [self isKindOfClass:[NSArray class]] ? [(id)self count] : 1;
}
- (id)_ul_objectAtIndex:(NSUInteger)index
{
return [self isKindOfClass:[NSArray class]] ? [(id)self objectAtIndex:index] : [self self];
}
/*+ (id)superclass
{
return ((struct objc_class {
struct objc_class *isa;
struct objc_class *super_class;
} *)self)->super_class;
}*/
@end