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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/**
STContext
Scripting context
Copyright (c) 2004 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2004
This file is part of the StepTalk project.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<title>STEnvironment class reference</title>
*/
#import "STContext.h"
#import "STScripting.h"
#import "STClassInfo.h"
#import "STEnvironmentDescription.h"
#import "STExterns.h"
#import "STFunctions.h"
#import "STBundleInfo.h"
#import "STObjCRuntime.h"
#import "STObjectReference.h"
#import "STUndefinedObject.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSInvocation.h>
@implementation STContext
-init
{
if ((self = [super init]) != nil)
{
objectDictionary = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc
{
RELEASE(objectDictionary);
RELEASE(parentContext);
[super dealloc];
}
- (void)setParentContext:(STContext *)context
{
ASSIGN(parentContext, context);
}
- (STContext *)parentContext
{
return parentContext;
}
/**
Enable or disable full scripting. When full scripting is enabled,
you may send any message to any object.
*/
- (void)setFullScriptingEnabled:(BOOL)flag
{
fullScripting = flag;
}
/**
Returns YES if full scripting is enabled.
*/
- (BOOL)fullScriptingEnabled
{
return fullScripting;
}
/**
<p>
Enable or disable creation of unknown objects. Normally you get nil if you
request for non-existant object. If <var>flag</var> is YES
then by requesting non-existant object, name for that object is created
and it is set no STNil.
</p>
<p>
Note: This method will be probably removed (moved to Smalltalk language bundle).
</p>
*/
-(void)setCreatesUnknownObjects:(BOOL)flag
{
createsUnknownObjects = flag;
}
/**
Returns YES if unknown objects are being created.
*/
-(BOOL)createsUnknownObjects
{
return createsUnknownObjects;
}
/**
Returns a dictionary of all named objects in the environment.
*/
- (NSMutableDictionary *)objectDictionary
{
return objectDictionary;
}
/* -----------------------------------------------------------------------
Objects
----------------------------------------------------------------------- */
/**
Register object <var>anObject</var> with name <var>objName</var>.
*/
- (void)setObject:(id)anObject
forName:(NSString *)objName
{
if(anObject)
{
[objectDictionary setObject:anObject forKey:objName];
}
else
{
[objectDictionary setObject:STNil forKey:objName];
}
}
/**
Remove object named <var>objName</var>.
*/
- (void)removeObjectWithName:(NSString *)objName
{
[objectDictionary removeObjectForKey:objName];
}
/**
*/
- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict
{
[objectDictionary addEntriesFromDictionary:dict];
}
/**
Return object with name <var>objName</var>. If object is not found in the
object dictionary, then object finders are used to try to find the object.
If object is found by an object finder, then it is put into the object
dicitonary. If there is no object with given name, <var>nil</var> is
returned.
*/
- (id)objectWithName:(NSString *)objName
{
id obj;
obj = [objectDictionary objectForKey:objName];
if(!obj)
{
return [parentContext objectWithName:objName];
}
return obj;
}
- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name
{
STObjectReference *ref;
id target = objectDictionary;
if( ![self objectWithName:name] )
{
if([[self knownObjectNames] containsObject:name])
{
/* FIXME: What I meant by this? */
target = nil;
}
else if(createsUnknownObjects)
{
[objectDictionary setObject:STNil forKey:name];
}
}
ref = [[STObjectReference alloc] initWithIdentifier:name
target:target];
return AUTORELEASE(ref);
}
- (NSArray *)knownObjectNames
{
NSMutableArray *array = [NSMutableArray array];
[array addObjectsFromArray:[objectDictionary allKeys]];
return [NSArray arrayWithArray:array];
}
@end
|