Changed from lib to framework

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@17436 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Stefan Urbanek 2003-08-06 17:21:45 +00:00
parent bdd10541e9
commit 5c5c430b4a
73 changed files with 6391 additions and 349 deletions

View file

@ -1,3 +1,8 @@
2003 Aug 6
* Frameworks: new directory
* Changed StepTalk from library to framework
2003 Aug 5 Stefan Urbanek <urbanek@host.sk>
* Added STScriptObject and STMethod.

View file

@ -65,6 +65,30 @@
language engine.
</desc>
</method>
<method type="id">
<sel>executeMethod:</sel>
<arg type="id&lt;STMethod&gt;">aMethod</arg>
<sel>forReceiver:</sel>
<arg type="id">anObject</arg>
<sel>withArguments:</sel>
<arg type="NSArray*">args</arg>
<sel>inEnvironment:</sel>
<arg type="STEnvironment*">env</arg>
<desc>
<em>Description forthcoming.</em>
</desc>
</method>
<method type="STMethod*">
<sel>methodFromSource:</sel>
<arg type="NSString*">sourceString</arg>
<sel>forReceiver:</sel>
<arg type="id">receiver</arg>
<sel>inEnvironment:</sel>
<arg type="STEnvironment*">env</arg>
<desc>
<em>Description forthcoming.</em>
</desc>
</method>
<method type="void">
<sel>setDefaultEnvironment:</sel>
<arg type="STEnvironment*">anEnvironment</arg>

View file

@ -9,9 +9,7 @@
<h1><a name="title$STEngine">STEngine class documentation</a></h1>
<h3>Authors</h3>
<dl>
<dt>Stefan Urbanek(<a href="mailto:urbanek@host.sk"><code>
urbanek@host.sk
</code></a>)</dt>
<dt>Stefan Urbanek (<a href="mailto:urbanek@host.sk"><code>urbanek@host.sk</code></a>)</dt>
<dd>
</dd>
</dl>
@ -43,6 +41,10 @@
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-defaultEnvironment">-defaultEnvironment</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-executeCode:">-executeCode:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-executeCode:inEnvironment:">-executeCode:inEnvironment:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-executeMethod:forReceiver:withArguments:inEnvironment:">-executeMethod:forReceiver:withArguments:inEnvironment:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-executeMethod:forScriptObject:">-executeMethod:forScriptObject:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-methodFromSource:forReceiver:inEnvironment:">-methodFromSource:forReceiver:inEnvironment:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-methodFromSource:forScriptObject:">-methodFromSource:forScriptObject:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-setDefaultEnvironment:">-setDefaultEnvironment:</a></li>
<li><a rel="gsdoc" href="STEngine.html#method$STEngine-understandsCode:">-understandsCode:</a></li>
</ul>
@ -93,6 +95,22 @@ Subclasses <strong>should</strong> override this method.<br />
has to be implemented by those who are writing a
language engine.
</p>
<hr width="25%" align="left" />
<h3><a name="method$STEngine-executeMethod:forReceiver:withArguments:inEnvironment:">executeMethod:forReceiver:withArguments:inEnvironment:</a></h3>
- (id) <b>executeMethod:</b> (id&#60;<a rel="gsdoc" href="STMethod.html#protocol$(STMethod)">STMethod</a>>)aMethod<b> forReceiver:</b> (id)anObject<b> withArguments:</b> (NSArray*)args<b> inEnvironment:</b> (<a rel="gsdoc" href="STEnvironment.html#class$STEnvironment">STEnvironment</a>*)env;<br />
<p>
<em>Description forthcoming.</em>
</p>
<hr width="25%" align="left" />
<h3><a name="method$STEngine-methodFromSource:forReceiver:inEnvironment:">methodFromSource:forReceiver:inEnvironment:</a></h3>
- (<a rel="gsdoc" href="STMethod.html#class$STMethod">STMethod</a>*) <b>methodFromSource:</b> (NSString*)sourceString<b> forReceiver:</b> (id)receiver<b> inEnvironment:</b> (<a rel="gsdoc" href="STEnvironment.html#class$STEnvironment">STEnvironment</a>*)env;<br />
<p>
<em>Description forthcoming.</em>
</p>
<hr width="25%" align="left" />
<h3><a name="method$STEngine-setDefaultEnvironment:">setDefaultEnvironment:</a></h3>

View file

@ -22,8 +22,10 @@
STEngine = STEngine;
STEnvironment = STEnvironment;
STLanguage = STLanguage;
STMethod = STMethod;
STObjectReference = STObjectReference;
STScript = STScript;
STScriptObject = STScriptObject;
STScriptsManager = STScriptsManager;
STSelector = STSelector;
STUndefinedObject = STUndefinedObject;
@ -119,6 +121,9 @@
"-addClassesWithNames:" = {
STEnvironment = STEnvironment;
};
"-addMethod:" = {
STScriptObject = STScriptObject;
};
"-addNamedObjectsFromDictionary:" = {
STEnvironment = STEnvironment;
};
@ -152,6 +157,12 @@
"-executeCode:inEnvironment:" = {
STEngine = STEngine;
};
"-executeMethod:forReceiver:withArguments:inEnvironment:" = {
STEngine = STEngine;
};
"-executeMethod:forScriptObject:" = {
STEngine = STEngine;
};
"-fileName" = {
STScript = STScript;
};
@ -185,12 +196,18 @@
"-initWithFile:" = {
STScript = STScript;
};
"-initWithInstanceVariableNames:" = {
STScriptObject = STScriptObject;
};
"-initWithObjectName:pool:" = {
STObjectReference = STObjectReference;
};
"-initWithSelector:" = {
STSelector = STSelector;
};
"-instanceVariableNames" = {
STScriptObject = STScriptObject;
};
"-isClass" = {
"(STScripting)" = STScripting;
};
@ -207,7 +224,9 @@
STScript = STScript;
};
"-languageName" = {
"(STMethod)" = STMethod;
STLanguage = STLanguage;
STMethod = STMethod;
};
"-loadModule:" = {
STEnvironment = STEnvironment;
@ -215,6 +234,25 @@
"-localizedName" = {
STScript = STScript;
};
"-methodDictionary" = {
STScriptObject = STScriptObject;
};
"-methodFromSource:forReceiver:inEnvironment:" = {
STEngine = STEngine;
};
"-methodFromSource:forScriptObject:" = {
STEngine = STEngine;
};
"-methodName" = {
"(STMethod)" = STMethod;
STMethod = STMethod;
};
"-methodNames" = {
STScriptObject = STScriptObject;
};
"-methodWithName:" = {
STScriptObject = STScriptObject;
};
"-namedObjects" = {
STBundleInfo = STBundleInfo;
};
@ -227,6 +265,9 @@
"-objectDictionary" = {
STEnvironment = STEnvironment;
};
"-objectForVariable:" = {
STScriptObject = STScriptObject;
};
"-objectName" = {
STObjectReference = STObjectReference;
};
@ -251,6 +292,12 @@
"-registerObjectFinderNamed:" = {
STEnvironment = STEnvironment;
};
"-removeMethod:" = {
STScriptObject = STScriptObject;
};
"-removeMethodWithName:" = {
STScriptObject = STScriptObject;
};
"-removeObjectFinderWithName:" = {
STEnvironment = STEnvironment;
};
@ -299,6 +346,9 @@
"-setObject:forName:" = {
STEnvironment = STEnvironment;
};
"-setObject:forVariable:" = {
STScriptObject = STScriptObject;
};
"-setObjectName:" = {
STObjectReference = STObjectReference;
};
@ -312,6 +362,8 @@
STScriptsManager = STScriptsManager;
};
"-source" = {
"(STMethod)" = STMethod;
STMethod = STMethod;
STScript = STScript;
};
"-stringValue" = {
@ -352,6 +404,9 @@
Headers/StepTalk/STLanguage.h = (
../Documentation/Reference/STLanguage.gsdoc
);
Headers/StepTalk/STMethod.h = (
../Documentation/Reference/STMethod.gsdoc
);
Headers/StepTalk/STObjCRuntime.h = (
../Documentation/Reference/STObjCRuntime.gsdoc
);
@ -361,6 +416,9 @@
Headers/StepTalk/STScript.h = (
../Documentation/Reference/STScript.gsdoc
);
Headers/StepTalk/STScriptObject.h = (
../Documentation/Reference/STScriptObject.gsdoc
);
Headers/StepTalk/STScripting.h = (
../Documentation/Reference/STScripting.gsdoc
);
@ -375,6 +433,7 @@
);
};
protocol = {
"(STMethod)" = STMethod;
"(STScripting)" = STScripting;
};
source = {
@ -402,6 +461,9 @@
Headers/StepTalk/STLanguage.h = (
STLanguage.m
);
Headers/StepTalk/STMethod.h = (
STMethod.m
);
Headers/StepTalk/STObjCRuntime.h = (
STObjCRuntime.m
);
@ -411,6 +473,9 @@
Headers/StepTalk/STScript.h = (
STScript.m
);
Headers/StepTalk/STScriptObject.h = (
STScriptObject.m
);
Headers/StepTalk/STScripting.h = (
STScripting.m
);
@ -429,8 +494,10 @@
STEngine = NSObject;
STEnvironment = NSObject;
STLanguage = NSBundle;
STMethod = NSObject;
STObjectReference = NSObject;
STScript = NSObject;
STScriptObject = NSObject;
STScriptsManager = NSObject;
STSelector = NSObject;
STUndefinedObject = NSObject;
@ -444,9 +511,11 @@
STExterns = "STExterns autogsdoc generated documentation";
STFunctions = "STFunctions autogsdoc generated documentation";
STLanguage = "STLanguage class documentation";
STMethod = "STMethod autogsdoc generated documentation";
STObjCRuntime = "STObjCRuntime autogsdoc generated documentation";
STObjectReference = "STObjectReference class documentation";
STScript = "STScript class documentation";
STScriptObject = "STScriptObject class documentation";
STScripting = "STScripting protocol documentation";
STScriptsManager = "STScriptsManager class documentation";
STSelector = "STSelector class documentation";
@ -454,6 +523,11 @@
StepTalk = "StepTalk Documentation";
};
unitmethods = {
"(STMethod)" = {
"-languageName" = STMethod;
"-methodName" = STMethod;
"-source" = STMethod;
};
"(STScripting)" = {
"+classForScripting" = STScripting;
"+className" = STScripting;
@ -495,6 +569,10 @@
"-defaultEnvironment" = STEngine;
"-executeCode:" = STEngine;
"-executeCode:inEnvironment:" = STEngine;
"-executeMethod:forReceiver:withArguments:inEnvironment:" = STEngine;
"-executeMethod:forScriptObject:" = STEngine;
"-methodFromSource:forReceiver:inEnvironment:" = STEngine;
"-methodFromSource:forScriptObject:" = STEngine;
"-setDefaultEnvironment:" = STEngine;
"-understandsCode:" = STEngine;
};
@ -536,6 +614,11 @@
"-engine" = STLanguage;
"-languageName" = STLanguage;
};
STMethod = {
"-languageName" = STMethod;
"-methodName" = STMethod;
"-source" = STMethod;
};
STObjectReference = {
"-initWithObjectName:pool:" = STObjectReference;
"-object" = STObjectReference;
@ -556,6 +639,18 @@
"-scriptName" = STScript;
"-source" = STScript;
};
STScriptObject = {
"-addMethod:" = STScriptObject;
"-initWithInstanceVariableNames:" = STScriptObject;
"-instanceVariableNames" = STScriptObject;
"-methodDictionary" = STScriptObject;
"-methodNames" = STScriptObject;
"-methodWithName:" = STScriptObject;
"-objectForVariable:" = STScriptObject;
"-removeMethod:" = STScriptObject;
"-removeMethodWithName:" = STScriptObject;
"-setObject:forVariable:" = STScriptObject;
};
STScriptsManager = {
"+defaultManager" = STScriptsManager;
"-allScripts" = STScriptsManager;

33
Frameworks/GNUmakefile Normal file
View file

@ -0,0 +1,33 @@
#
# Main Makefile for the StepTalk
#
# Copyright (C) 2000 Stefan Urbanek
#
# Written by: Stefan Urbanek <urbane@decef.elf.stuba.sk>
#
# This file is part of the StepTalk
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
#
include $(GNUSTEP_MAKEFILES)/common.make
SUBPROJECTS = \
StepTalk
-include GNUMakefile.preamble
include $(GNUSTEP_MAKEFILES)/aggregate.make
-include GNUMakefile.postamble

View file

@ -0,0 +1,17 @@
/** Common.stenv
* Common scripting environment description
*/
{
Name = "Common";
Bundles = (CommonEnvironment);
Import = ( "SymbolicSelectors",
"Foundation",
"AppKit",
"StepTalk"
);
Applications = ( All );
}

View file

@ -0,0 +1,106 @@
#
# GNUmakefile
#
# Copyright (C) 2000 Stefan Urbanek
#
# This file is part of the StepTalk.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
include $(GNUSTEP_MAKEFILES)/common.make
include ../Version
LIBRARY_NAME = libStepTalk
libStepTalk_OBJC_FILES = \
NSInvocation+additions.m \
STBehaviourInfo.m \
STBundleInfo.m \
STClassInfo.m \
STEngine.m \
STEnvironment.m \
STEnvironmentDescription.m \
STExterns.m \
STFunctions.m \
STLanguage.m \
STObjCRuntime.m \
STObjectReference.m \
STScript.m \
STScriptsManager.m \
STScripting.m \
STMethod.m \
STScriptObject.m \
STSelector.m \
STStructure.m \
STUndefinedObject.m \
NSNumber+additions.m \
NSObject+additions.m
STEPTALK_HEADER_FILES = \
STBundleInfo.h \
STEngine.h \
STEnvironment.h \
STExterns.h \
STFunctions.h \
STLanguage.h \
STObjCRuntime.h \
STObjectReference.h \
STMethod.h \
STScriptObject.h \
STScript.h \
STScriptsManager.h \
STScripting.h \
STSelector.h \
STUndefinedObject.h \
NSInvocation+additions.h \
NSObject+additions.h
libStepTalk_HEADER_FILES = $(STEPTALK_HEADER_FILES) \
StepTalk.h
libStepTalk_HEADER_FILES_DIR = Headers/StepTalk
libStepTalk_HEADER_FILES_INSTALL_DIR = StepTalk
STEPTALK_LIBRARY_DIR = $(GNUSTEP_INSTALLATION_DIR)/Library/StepTalk
STEPTALK_ENVDEFS_DIR = $(STEPTALK_LIBRARY_DIR)/Environments
ADDITIONAL_INCLUDE_DIRS += -I./Headers
ADDITIONAL_CPPFLAGS += -pipe
ADDITIONAL_OBJCFLAGS = -Wno-import -DSTEPTALK_VERSION=$(STEPTALK_VERSION)
DOCUMENT_NAME = StepTalk
StepTalk_DOC_INSTALL_DIR = Developer
StepTalk_HEADER_FILES_DIR = $(HEADER_DIR)
StepTalk_AGSDOC_FILES = StepTalk.gsdoc $(STEPTALK_HEADER_FILES)
StepTalk_AGSDOC_FLAGS = \
-HeaderDirectory Headers/StepTalk \
-Up StepTalk \
-Declared StepTalk \
-DocumentationDirectory ../Documentation/Reference
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
libStepTalk_LIBRARIES_DEPEND_UPON += -lgnustep-base -lobjc
endif
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/library.make
include $(GNUSTEP_MAKEFILES)/documentation.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,74 @@
#
# GNUmakefile.postamble
#
# Copyright (C) 2000 Stefan Urbanek
#
# This file is part of the StepTalk
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; see the file COPYING.LIB.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Project specific makefile rules
#
# Uncomment the targets you want.
# The double colons (::) are important, do not make them single colons
# otherwise the normal makefile rules will not be performed.
#
# Things to do before compiling
# before-all::
# Things to do after compiling
# after-all::
# Things to do before installing
before-install::
$(MKDIRS) $(STEPTALK_LIBRARY_DIR)
$(MKDIRS) $(STEPTALK_ENVDEFS_DIR)
# Things to do after installing
after-install::
@(echo Copying scripting environments...; \
cd Environments;\
for file in *.stenv; do \
$(INSTALL_DATA) $$file $(STEPTALK_ENVDEFS_DIR)/$$file ; \
done;\
)
# Things to do before uninstalling
# before-uninstall::
# Things to do after uninstalling
after-uninstall::
rm -rf $(STEPTALK_ENVDEFS_DIR)
# Things to do before cleaning
# before-clean::
# Things to do after cleaning
# after-clean::
# Things to do before distcleaning
# before-distclean::
# Things to do after distcleaning
# after-distclean::
# Things to do before checking
# before-check::
# Things to do after checking
# after-check::

View file

@ -0,0 +1,40 @@
/**
NSInvocation+additions.h
Various NSInvocation additions
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <Foundation/NSInvocation.h>
void STGetValueOfTypeFromObject(void *value, const char *type, id anObject);
id STObjectFromValueOfType(void *value, const char *type);
@interface NSInvocation(STAdditions)
+ invocationWithTarget:(id)target selectorName:(NSString *)selectorName;
- (void)setArgumentAsObject:(id)anObject atIndex:(int)anIndex;
- (id)getArgumentAsObjectAtIndex:(int)anIndex;
- (id)returnValueAsObject;
@end

View file

@ -0,0 +1,325 @@
/**
NSInvocation+additions
Various NSInvocation additions
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
<title>NSInvocation class additions</title>
*/
#import <StepTalk/NSInvocation+additions.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSException.h>
#import <Foundation/NSValue.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STObjCRuntime.h>
#import <StepTalk/STScripting.h>
#import <StepTalk/STSelector.h>
#import <StepTalk/STStructure.h>
#if 0
static Class NSNumber_class = nil;
static Class NSString_class = nil;
static Class NSValue_class = nil;
#endif
#define CASE_NUMBER_TYPE(otype,type,msgtype)\
case otype: object = [NSNumber numberWith##msgtype:*((type *)value)];\
NSDebugLLog(@"STStructure",\
@" is number value '%@'", object);\
break
id STObjectFromValueOfType(void *value, const char *type)
{
id object;
NSDebugLLog(@"STStructure",
@"object from value %p of of type '%c'",value,*type);
switch(*type)
{
case _C_ID:
case _C_CLASS:
object = *((id *)value);
NSDebugLLog(@"STStructure",
@" is object value %p", object);
break;
CASE_NUMBER_TYPE(_C_CHR,char,Char);
CASE_NUMBER_TYPE(_C_UCHR,unsigned char, UnsignedChar);
CASE_NUMBER_TYPE(_C_SHT,short,Short);
CASE_NUMBER_TYPE(_C_USHT,unsigned short,UnsignedShort);
CASE_NUMBER_TYPE(_C_INT,int,Int);
CASE_NUMBER_TYPE(_C_UINT,unsigned int,UnsignedInt);
CASE_NUMBER_TYPE(_C_LNG,long,Long);
CASE_NUMBER_TYPE(_C_ULNG,unsigned long,UnsignedLong);
CASE_NUMBER_TYPE(_C_LNG_LNG,long long,LongLong);
CASE_NUMBER_TYPE(_C_ULNG_LNG,unsigned long long,UnsignedLongLong);
CASE_NUMBER_TYPE(_C_FLT,float,Float);
CASE_NUMBER_TYPE(_C_DBL,double,Double);
case _C_PTR:
object = [NSValue valueWithPointer:*((void **)value)];
NSDebugLLog(@"STStructure",
@" is pointer value %p", *((void **)value));
break;
case _C_CHARPTR:
object = [NSString stringWithCString:*((char **)value)];
NSDebugLLog(@"STStructure",
@" is string value '%s'", *((char **)value));
break;
case _C_VOID:
object = nil;
break;
case _C_STRUCT_B:
object = [[STStructure alloc] initWithValue:value
type:type];
AUTORELEASE(object);
break;
case _C_SEL:
object = [[STSelector alloc] initWithSelector:*((SEL *)value)];
AUTORELEASE(object);
break;
case _C_BFLD:
case _C_UNDEF:
case _C_ATOM:
case _C_ARY_B:
case _C_ARY_E:
case _C_UNION_B:
case _C_UNION_E:
case _C_STRUCT_E:
default:
[NSException raise:STInvalidArgumentException
format:@"unhandled ObjC type '%s'",
type];
}
return object;
}
#define CASE_TYPE(otype,type,msgtype)\
case otype:(*((type *)value)) = [anObject msgtype##Value];\
NSDebugLLog(@"STStructure",\
@" is number value '%@'", anObject);\
break
void STGetValueOfTypeFromObject(void *value, const char *type, id anObject)
{
NSDebugLLog(@"STStructure",
@"value at %p from object '%@' of type '%c'",
value,anObject,*type);
switch(*type)
{
case _C_ID:
case _C_CLASS:
NSDebugLLog(@"STStructure",
@" is object value");
(*(id *)value) = anObject;
break;
CASE_TYPE(_C_CHR,char,char);
CASE_TYPE(_C_UCHR,unsigned char,unsignedChar);
CASE_TYPE(_C_SHT,short,short);
CASE_TYPE(_C_USHT,unsigned short,unsignedShort);
CASE_TYPE(_C_INT,int,int);
CASE_TYPE(_C_UINT,unsigned int,unsignedInt);
CASE_TYPE(_C_LNG,long,long);
CASE_TYPE(_C_ULNG,unsigned long,unsignedLong);
CASE_TYPE(_C_LNG_LNG,long long,longLong);
CASE_TYPE(_C_ULNG_LNG,unsigned long long,unsignedLongLong);
CASE_TYPE(_C_FLT,float,float);
CASE_TYPE(_C_DBL,double,double);
CASE_TYPE(_C_PTR,void *,pointer);
case _C_CHARPTR: /* FIXME: check if this is good (copy/no copy)*/
(*((const char **)value)) = [[anObject stringValue] cString];
NSDebugLLog(@"STStructure",
@" is cstring '%@'", [anObject stringValue]);
break;
case _C_STRUCT_B:
/* FIXME: chech for struct compatibility */
NSDebugLLog(@"STStructure",
@" is structure");
[(STStructure*)anObject getValue:value];
break;
case _C_SEL:
(*((SEL *)value)) = [anObject selectorValue];
break;
case _C_BFLD:
case _C_VOID:
case _C_UNDEF:
case _C_ATOM:
case _C_ARY_B:
case _C_ARY_E:
case _C_UNION_B:
case _C_UNION_E:
case _C_STRUCT_E:
default:
[NSException raise:STInvalidArgumentException
format:@"unhandled ObjC type '%s'",
type];
}
}
@implementation NSInvocation(STAdditions)
#if 0
/* with this method it does not work, it is not posiible to create an
invocation*/
+ (void)initialize
{
NSNumber_class = [NSNumber class];
NSString_class = [NSString class];
NSValue_class = [NSValue class];
}
#endif
+ invocationWithTarget:(id)target selectorName:(NSString *)selectorName
{
NSMethodSignature *signature;
NSInvocation *invocation;
SEL sel;
BOOL requiresRegistration = NO;
// NSLog(@"GETTING SELECTOR %@", selectorName);
sel = NSSelectorFromString(selectorName);
if(!sel)
{
// NSLog(@"REGISTERING SELECTOR");
char *name = [selectorName cString];
sel = sel_register_name(name);
if(!sel)
{
[NSException raise:STInternalInconsistencyException
format:@"Unable to register selector '%@'",
selectorName];
return nil;
}
requiresRegistration = YES;
}
signature = [target methodSignatureForSelector:sel];
/* FIXME: this is workaround for gnustep DO bug (hight priority) */
if(requiresRegistration)
{
// NSLog(@"REGISTERING SELECTOR TYPES");
sel = sel_register_typed_name([selectorName cString], [signature methodReturnType]);
// NSLog(@"REGISTERED %@", NSStringFromSelector(sel));
}
if(!signature)
{
[NSException raise:STInternalInconsistencyException
format:@"No method signature for selector '%@' for "
@"receiver of type %@",
selectorName,[target className]];
return nil;
}
invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:sel];
[invocation setTarget:target];
return invocation;
}
- (void)setArgumentAsObject:(id)anObject atIndex:(int)anIndex
{
const char *type;
void *value;
type = [[self methodSignature] getArgumentTypeAtIndex:anIndex];
value = NSZoneMalloc(STMallocZone,objc_sizeof_type(type));
STGetValueOfTypeFromObject(value, type, anObject);
[self setArgument:(void *)value atIndex:anIndex];
NSZoneFree(STMallocZone,value);
}
- (id)getArgumentAsObjectAtIndex:(int)anIndex
{
const char *type;
void *value;
id object;
type = [[self methodSignature] getArgumentTypeAtIndex:anIndex];
value = NSZoneMalloc(STMallocZone,objc_sizeof_type(type));
[self getArgument:value atIndex:anIndex];
object = STObjectFromValueOfType(value,type);
NSZoneFree(STMallocZone,value);
return object;
}
- (id)returnValueAsObject
{
const char *type;
int returnLength;
void *value;
id returnObject = nil;
NSMethodSignature *signature = [self methodSignature];
type = [signature methodReturnType];
returnLength = [signature methodReturnLength];
NSDebugLLog(@"STSending",
@" return type '%s', buffer length %i",type,returnLength);
if(returnLength!=0)
{
value = NSZoneMalloc(STMallocZone,returnLength);
[self getReturnValue:value];
if( *type == _C_VOID )
{
returnObject = [self target];
}
else
{
returnObject = STObjectFromValueOfType(value, type);
}
NSZoneFree(STMallocZone,value);
NSDebugLLog(@"STSending",
@" returned object %@",returnObject);
}
else
{
returnObject = [self target];
}
return returnObject;
}
@end

View file

@ -0,0 +1,52 @@
/**
NSNumber-additions.h
Various methods for NSNumber
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <Foundation/NSValue.h>
@interface NSNumber (STAdditions)
- add:(NSNumber *)number;
- subtract:(NSNumber *)number;
- multiply:(NSNumber *)number;
- divide:(NSNumber *)number;
- (unsigned int)isLessThan:(NSNumber *)number;
- (BOOL)isGreatherThan:(NSNumber *)number;
- (BOOL)isLessOrEqualThan:(NSNumber *)number;
- (BOOL)isGreatherOrEqualThan:(NSNumber *)number;
@end
@interface NSNumber (STLogicOperations)
- (unsigned int)or:(NSNumber *)number;
- (unsigned int)and:(NSNumber *)number;
- (unsigned int)not;
@end
@interface NSNumber (STStructure)
- rangeWith:(int)length;
- pointWith:(float)y;
- sizeWith:(float)h;
@end

View file

@ -0,0 +1,133 @@
/**
NSNumber-additions.h
Various methods for NSNumber
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <StepTalk/NSNumber+additions.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STStructure.h>
#import <Foundation/NSException.h>
#include <math.h>
@implementation NSNumber (STAdditions)
- add:(NSNumber *)number
{
return [NSNumber numberWithDouble:([self doubleValue]
+ [number doubleValue])];
}
- subtract:(NSNumber *)number
{
return [NSNumber numberWithDouble:([self doubleValue]
- [number doubleValue])];
}
- multiply:(NSNumber *)number
{
return [NSNumber numberWithDouble:([self doubleValue]
* [number doubleValue])];
}
- divide:(NSNumber *)number
{
if([number doubleValue] == 0.0)
{
[NSException raise:STGenericException
format:@"Division by zero"];
return self;
}
return [NSNumber numberWithDouble:([self doubleValue]
/ [number doubleValue])];
}
- modulo:(NSNumber *)number
{
if([number doubleValue] == 0.0)
{
[NSException raise:STGenericException
format:@"Division by zero"];
return self;
}
return [NSNumber numberWithDouble:(fmod([self doubleValue],
[number doubleValue]))];
}
- (unsigned int)isLessThan:(NSNumber *)number
{
return ([self doubleValue] < [number doubleValue]);
}
- (BOOL)isGreatherThan:(NSNumber *)number
{
return ([self doubleValue] > [number doubleValue]);
}
- (BOOL)isLessOrEqualThan:(NSNumber *)number
{
return ([self doubleValue] <= [number doubleValue]);
}
- (BOOL)isGreatherOrEqualThan:(NSNumber *)number
{
return ([self doubleValue] >= [number doubleValue]);
}
@end
@implementation NSNumber (STLogicOperations)
- (unsigned int)or:(NSNumber *)number
{
return ([self intValue] | [number intValue]);
}
- (unsigned int)and:(NSNumber *)number
{
return ([self intValue] & [number intValue]);
}
- (unsigned int)not
{
/* FIXME */
return ![self intValue];
}
@end
@implementation NSNumber (STStructure)
- rangeWith:(int)length
{
return [STStructure structureWithRange:NSMakeRange([self intValue], length)];
}
- pointWith:(float)y
{
return [STStructure structureWithPoint:NSMakePoint([self floatValue], y)];
}
- sizeWith:(float)h
{
return [STStructure structureWithSize:NSMakeSize([self floatValue], h)];
}
@end

View file

@ -0,0 +1,31 @@
/**
NSObject-additions.h
Various methods for NSObject
Copyright (c) 2002 Free Software Foundation
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
*/
#import <Foundation/NSObject.h>
@interface NSObject (STAdditions)
- (BOOL)isSame:(id)anObject;
- (BOOL)isNil;
- (BOOL)notNil;
@end

View file

@ -0,0 +1,27 @@
/**
NSObject-additions.m
Various methods for NSObject
Copyright (c) 2002 Free Software Foundation
This file is part of the StepTalk project.
*/
#import <StepTalk/NSObject+additions.h>
@implementation NSObject (STAdditions)
- (BOOL)isSame:(id)anObject
{
return self == anObject;
}
- (BOOL)isNil
{
return NO;
}
- (BOOL)notNil
{
return YES;
}
@end

View file

@ -0,0 +1,66 @@
/**
STBehaviourInfo.h
Scripting definition: behaviour information
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#include <Foundation/NSObject.h>
@class NSString;
@class NSDictionary;
@class NSMutableDictionary;
@class NSMutableSet;
@class NSSet;
@interface STBehaviourInfo:NSObject
{
NSString *name;
NSMutableDictionary *selectorMap;
NSMutableSet *allowMethods;
NSMutableSet *denyMethods;
}
- initWithName:(NSString *)aString;
- (NSString*)behaviourName;
- (void)setTranslation:(NSString *)aSelector
forSelector:(NSString *)aString;
- (void)removeTranslationForSelector:(NSString *)aString;
- (NSDictionary *)selectorMap;
- (void)addTranslationsFromDictionary:(NSDictionary *)map;
- (void)allowMethods:(NSSet *)set;
- (void)denyMethods:(NSSet *)set;
- (void)allowMethod:(NSString *)methodName;
- (void)denyMethod:(NSString *)methodName;
- (NSSet *)allowedMethods;
- (NSSet *)deniedMethods;
- (void)adopt:(STBehaviourInfo *)info;
@end

View file

@ -0,0 +1,137 @@
/**
STBehaviourInfo.m
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <StepTalk/STBehaviourInfo.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
@implementation STBehaviourInfo
- initWithName:(NSString *)aString
{
self = [super init];
selectorMap = [[NSMutableDictionary alloc] init];
allowMethods = [[NSMutableSet alloc] init];
denyMethods = [[NSMutableSet alloc] init];
name = RETAIN(aString);
return self;
}
- (void)dealloc
{
RELEASE(selectorMap);
RELEASE(allowMethods);
RELEASE(denyMethods);
RELEASE(name);
[super dealloc];
}
- (NSString*)behaviourName
{
return name;
}
- (void)adopt:(STBehaviourInfo *)info
{
[self addTranslationsFromDictionary:[info selectorMap]];
[self allowMethods:[info allowedMethods]];
[self denyMethods:[info deniedMethods]];
}
- (NSDictionary *)selectorMap
{
return selectorMap;
}
- (void)removeTranslationForSelector:(NSString *)aString
{
[selectorMap removeObjectForKey:aString];
}
- (void)setTranslation:(NSString *)translation
forSelector:(NSString *)selector
{
[selectorMap setObject:translation forKey:selector];
}
- (void)addMethodsFromArray:(NSArray *)methods
{
NSEnumerator *enumerator;
NSString *sel;
enumerator = [methods objectEnumerator];
while( (sel = [enumerator nextObject]) )
{
[self setTranslation:sel forSelector:sel];
}
}
- (void)addTranslationsFromDictionary:(NSDictionary *)map
{
[selectorMap addEntriesFromDictionary:map];
}
- (void)allowMethods:(NSSet *)set
{
[allowMethods unionSet:set];
[denyMethods minusSet:allowMethods];
}
- (void)denyMethods:(NSSet *)set;
{
[denyMethods unionSet:set];
[allowMethods minusSet:denyMethods];
}
- (void)allowMethod:(NSString *)methodName;
{
[allowMethods addObject:methodName];
[denyMethods removeObject:methodName];
}
- (void)denyMethod:(NSString *)methodName;
{
[denyMethods addObject:methodName];
[allowMethods removeObject:methodName];
}
- (NSSet *)allowedMethods
{
return AUTORELEASE([allowMethods copy]);
}
- (NSSet *)deniedMethods
{
return AUTORELEASE([denyMethods copy]);
}
@end

View file

@ -0,0 +1,61 @@
/**
STBundleInfo.h
Bundle scripting information
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2003 Jan 22
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
*/
#import <Foundation/NSBundle.h>
@class NSArray;
@interface STBundleInfo:NSObject
{
NSBundle *bundle;
BOOL useAllClasses;
NSArray *publicClasses;
NSArray *allClasses;
NSDictionary *objectReferenceDictionary;
NSString *scriptingInfoClassName;
Class scriptingInfoClass;
}
+ infoForBundle:(NSBundle *)aBundle;
- initWithBundle:(NSBundle *)aBundle;
- (NSDictionary *)objectReferenceDictionary;
- (NSDictionary *)namedObjects;
- (NSArray *)publicClassNames;
- (NSArray *)allClassNames;
@end
@interface NSBundle(STAdditions)
+ (NSArray *)stepTalkBundleNames;
+ stepTalkBundleWithName:(NSString *)moduleName;
- (NSDictionary *)scriptingInfoDictionary;
+ (NSArray *)allFrameworkNames;
+ (NSString *)pathForFrameworkWithName:(NSString *)aName;
+ (NSBundle *)bundleForFrameworkWithName:(NSString *)aName;
@end

View file

@ -0,0 +1,387 @@
/**
STBundleInfo.h
Bundle scripting information
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2003 Jan 22
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
*/
#import <StepTalk/STBundleInfo.h>
#import <StepTalk/STFunctions.h>
#import <StepTalk/STExterns.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSString.h>
static NSMutableDictionary *bundleInfoDict;
@protocol STScriptingInfoClass
+ (NSDictionary *)namedObjectsForScripting;
@end
@interface STBundleInfo(STPrivateMethods)
- (void) _bundleDidLoad:(NSNotification *)notif;
- (void)_initializeScriptingInfoClass;
@end
@implementation NSBundle(STAdditions)
/** Get list of all StepTalk bundles from Library/StepTalk/Bundles */
+ (NSArray *)stepTalkBundleNames
{
NSArray *bundles;
NSEnumerator *enumerator;
NSString *path;
NSMutableArray *names = [NSMutableArray array];
NSString *name;
bundles = STFindAllResources(@"Bundles", STModuleExtension);
enumerator = [bundles objectEnumerator];
while( (path = [enumerator nextObject]) )
{
name = [path lastPathComponent];
name = [name stringByDeletingPathExtension];
[names addObject:name];
}
bundles = STFindAllResources(@"Modules", STModuleExtension);
enumerator = [bundles objectEnumerator];
while( (path = [enumerator nextObject]) )
{
name = [path lastPathComponent];
name = [name stringByDeletingPathExtension];
[names addObject:name];
}
return AUTORELEASE([NSArray arrayWithArray:names]);
}
+ stepTalkBundleWithName:(NSString *)moduleName
{
NSString *file = STFindResource(moduleName, @"Bundles",
@"bundle");
if(!file)
{
file = STFindResource(moduleName, STModulesDirectory,
STModuleExtension);
if(!file)
{
NSLog(@"Could not find bundle with name '%@'", moduleName);
return nil;
}
}
return AUTORELEASE([[self alloc] initWithPath:file]);
}
- (NSDictionary *)scriptingInfoDictionary
{
NSFileManager *manager = [NSFileManager defaultManager];
NSString *file;
file = [self pathForResource:@"ScriptingInfo" ofType:@"plist"];
if([manager fileExistsAtPath:file])
{
return [NSDictionary dictionaryWithContentsOfFile:file];
}
else
{
return nil;
}
}
/** Return names of all available frameworks in the system. */
+ (NSArray *)allFrameworkNames
{
NSMutableArray *names = [NSMutableArray array];
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *paths;
NSEnumerator *fenum;
NSEnumerator *penum;
NSString *path;
NSString *file;
NSString *name;
paths = NSStandardLibraryPaths();
penum = [paths objectEnumerator];
while( (path = [penum nextObject]) )
{
path = [path stringByAppendingPathComponent:@"Frameworks"];
fenum = [[manager directoryContentsAtPath:path] objectEnumerator];
if( ![manager fileExistsAtPath:path isDirectory:NO] )
{
continue;
}
while( (file = [fenum nextObject]) )
{
if( [[file pathExtension] isEqualToString:@"framework"] )
{
name = [[file lastPathComponent] stringByDeletingPathExtension];
[names addObject:name];
}
}
}
return names;
}
/** Return path for framework with name <var>aName</var>. */
+ (NSString *)pathForFrameworkWithName:(NSString *)aName
{
NSMutableArray *names = [NSMutableArray array];
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *paths;
NSEnumerator *fenum;
NSEnumerator *penum;
NSString *path;
NSString *file;
NSString *name;
paths = NSStandardLibraryPaths();
penum = [paths objectEnumerator];
while( (path = [penum nextObject]) )
{
path = [path stringByAppendingPathComponent:@"Frameworks"];
fenum = [[manager directoryContentsAtPath:path] objectEnumerator];
if( ![manager fileExistsAtPath:path isDirectory:NO] )
{
continue;
}
while( (file = [fenum nextObject]) )
{
if( [[file pathExtension] isEqualToString:@"framework"] )
{
name = [[file lastPathComponent] stringByDeletingPathExtension];
if([name isEqualToString:aName])
{
return [path stringByAppendingPathComponent:file];
}
}
}
}
return nil;
}
/** Return bundle for framework with name <var>aName</var>. */
+ (NSBundle *)bundleForFrameworkWithName:(NSString *)aName
{
return [self bundleWithPath:[self pathForFrameworkWithName:aName]];;
}
@end
@implementation STBundleInfo
+ infoForBundle:(NSBundle *)aBundle
{
return AUTORELEASE([[self alloc] initWithBundle:aBundle]);
}
/** Initialize info with bundle <var>aBundle</var>.
<init />
*/
- initWithBundle:(NSBundle *)aBundle
{
STBundleInfo *info;
NSString *flagString;
NSDictionary *dict;
if(!aBundle)
{
[NSException raise:@"STBundleException"
format:@"Nil bundle specified"];
[self dealloc];
return nil;
}
info = [bundleInfoDict objectForKey:[aBundle bundlePath]];
if(info)
{
[self dealloc];
return RETAIN(info);
}
dict = [aBundle scriptingInfoDictionary];
if(!dict)
{
NSLog(@"Warning: Bundle '%@' does not provide scripting capabilities.",
[aBundle bundlePath]);
[self dealloc];
return nil;
}
ASSIGN(bundle, aBundle);
#if 0
/* FIXME: remove observer somewhere */
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(_bundleDidLoad:)
name:NSBundleDidLoadNotification
object:self];
#endif
flagString = [dict objectForKey:@"UseAllClasses"];
flagString = [flagString lowercaseString];
useAllClasses = [flagString isEqualToString:@"yes"];
if([dict objectForKey: @"STClasses"])
{
NSLog(@"WARNING: Use 'Classes' instead of 'STClasses' in "
@"ScriptingInfo.plist for bundle '%@'", [aBundle bundlePath]);
publicClasses = [dict objectForKey:@"STClasses"];
}
else
{
publicClasses = [dict objectForKey:@"Classes"];
}
RETAIN(publicClasses);
if([dict objectForKey: @"STScriptingInfoClass"])
{
NSLog(@"WARNING: Use 'ScriptingInfoClass' instead of 'STScriptingInfoClass' in "
@"ScriptingInfo.plist for bundle '%@'", [aBundle bundlePath]);
scriptingInfoClassName = [dict objectForKey:@"STScriptingInfoClass"];
}
else
{
scriptingInfoClassName = [dict objectForKey:@"ScriptingInfoClass"];
}
RETAIN(scriptingInfoClassName);
objectReferenceDictionary = [dict objectForKey:@"Objects"];
if(!bundleInfoDict)
{
bundleInfoDict = [[NSMutableDictionary alloc] init];
}
[bundleInfoDict setObject:self forKey:[bundle bundlePath]];
return self;
}
- (void) _bundleDidLoad:(NSNotification *)notif
{
NSLog(@"Module '%@' loaded", [bundle bundlePath]);
if([notif object] != self)
{
NSLog(@"STBundle: That's not me!");
return;
}
allClasses = [[notif userInfo] objectForKey:NSLoadedClasses];
RETAIN(allClasses);
NSLog(@"All classes are %@");
}
- (NSArray *)publicClassNames
{
if(useAllClasses)
{
if(!allClasses)
{
[self _initializeScriptingInfoClass];
}
return allClasses;
}
else
{
return publicClasses;
}
}
/** Return an array of all class names. */
- (NSArray *)allClassNames
{
/* FIXME: not implemented; */
NSLog(@"Warning: All bundle classes requested, using public classes only.");
return publicClasses;
}
/** Return a dictionary of named objects. Named objects are get from scripting
info class specified in ScriptingInfo.plist.*/
- (NSDictionary *)namedObjects
{
if(!scriptingInfoClass)
{
[self _initializeScriptingInfoClass];
}
return [(id)scriptingInfoClass namedObjectsForScripting];
}
- (void)_initializeScriptingInfoClass
{
scriptingInfoClass = [bundle classNamed:scriptingInfoClassName];
if(!scriptingInfoClass)
{
NSDebugLog(@"No scripting info class for bundle '%@'",[bundle bundlePath]);
#if 0
[NSException raise:@"STBundleException"
format:@"Unable to get scripting info class '%@' for "
@"bundle '%@'",
scriptingInfoClassName, [bundle bundlePath]];
#endif
}
}
/** This method is for application scripting support. Return dictionary
containing object references where a key is name of an object and
value is a path to the object relative to application delegate.
*/
- (NSDictionary *)objectReferenceDictionary
{
return objectReferenceDictionary;
}
@end

View file

@ -0,0 +1,51 @@
/**
STClassInfo.h
Objective-C class wrapper
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <StepTalk/STBehaviourInfo.h>
@class NSString;
@class NSMutableDictionary;
@interface STClassInfo:STBehaviourInfo
{
STClassInfo *superclass;
NSString *superclassName;
BOOL allowAll;
NSMutableDictionary *selectorCache;
}
- (NSString *)translationForSelector:(NSString *)aString;
- (void)setSuperclassInfo:(STClassInfo *)classInfo;
- (STClassInfo *)superclassInfo;
- (void)setSuperclassName:(NSString *)aString;
- (NSString *)superclassName;
- (void)setAllowAllMethods:(BOOL)flag;
- (BOOL)allowAllMethods;
@end

View file

@ -0,0 +1,140 @@
/**
STClassInfo.m
Objective-C class wrapper
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <StepTalk/STClassInfo.h>
#import <StepTalk/STFunctions.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
@implementation STClassInfo
- initWithName:(NSString *)aString
{
[super initWithName:aString];
selectorCache = [[NSMutableDictionary alloc] init];
return self;
}
- (void)dealloc
{
RELEASE(selectorCache);
[super dealloc];
}
- (void)setSuperclassInfo:(STClassInfo *)classInfo
{
ASSIGN(superclass,classInfo);
}
- (STClassInfo *)superclassInfo
{
return superclass;
}
- (void) setSuperclassName:(NSString *)aString
{
ASSIGN(superclassName,aString);
}
- (NSString *)superclassName
{
return superclassName;
}
- (NSString *)translationForSelector:(NSString *)aString
{
NSString *sel;
NSDebugLLog(@"STSending",@"Translate '%@' in %@:%@. (%i)",
aString, [self behaviourName],superclassName, allowAll);
sel = [selectorCache objectForKey:aString];
if(sel)
{
return sel;
}
sel = [selectorMap objectForKey:aString];
if(!sel)
{
/* Lookup for super selector maping */
if(superclass)
{
sel = [superclass translationForSelector:aString];
if(sel &&
([denyMethods containsObject:sel] ||
(!allowAll && ![allowMethods containsObject:sel])))
{
sel = nil;
}
else if([allowMethods containsObject:aString])
{
sel = aString;
}
}
else if(allowAll || [allowMethods containsObject:aString])
{
sel = aString;
}
NSDebugLLog(@"STSending",@" translated '%@' deny %i allow %i all %i",
sel, [denyMethods containsObject:sel],
[allowMethods containsObject:sel],
allowAll);
}
NSDebugLLog(@"STSending",@" Return '%@' (%@)",
sel, [self behaviourName]);
if(sel)
{
[selectorCache setObject:sel forKey:aString];
}
return sel;
}
- (void)setAllowAllMethods:(BOOL)flag
{
allowAll = flag;
}
- (BOOL)allowAllMethods
{
return allowAll;
}
@end

View file

@ -0,0 +1,64 @@
/**
STEngine.h
Scripting engine
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <Foundation/NSObject.h>
#import <StepTalk/STMethod.h>
@class STEnvironment;
@class STLanguageEngine;
@class STMethod;
/** STEngine is abstract class for language engines used to intepret scripts.*/
@interface STEngine:NSObject
{
STEnvironment *defaultEnvironment;
}
/** Instance creation */
+ (STEngine *) engineForLanguageWithName:(NSString *)name;
+ (STEngine *) engineForFileType:(NSString *)fileType;
/** Scripting Environment */
- (STEnvironment *)defaultEnvironment;
- (void) setDefaultEnvironment:(STEnvironment *)anEnvironment;
- (id) executeCode:(NSString *)code;
- (id) executeCode:(NSString *)code
inEnvironment:(STEnvironment *)env;
- (BOOL)understandsCode:(NSString *)code;
/* Methods */
- (STMethod *)methodFromSource:(NSString *)sourceString
forReceiver:(id)receiver
inEnvironment:(STEnvironment *)env;
- (id) executeMethod:(id <STMethod>)aMethod
forReceiver:(id)anObject
withArguments:(NSArray *)args
inEnvironment:(STEnvironment *)env;
@end

View file

@ -0,0 +1,149 @@
/**
STEngine.m
Scripting engine
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <StepTalk/STEngine.h>
#import <StepTalk/STEnvironment.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STFunctions.h>
#import <StepTalk/STLanguage.h>
#import <StepTalk/STUndefinedObject.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
NSZone *STMallocZone = NULL;
void _STInitMallocZone(void)
{
if(!STMallocZone)
{
STMallocZone = NSCreateZone(NSPageSize(),NSPageSize(),NO);
}
}
@implementation STEngine
+ (void)initialize
{
_STInitMallocZone();
if(!STNil)
{
STNil = (STUndefinedObject *)NSAllocateObject([STUndefinedObject class],
0, STMallocZone);
}
}
/**
Return a scripting engine for the language used in files of type
<var>fileType</var>
*/
+ (STEngine *) engineForFileType:(NSString *)fileType
{
STLanguage *language = [STLanguage languageForFileType:fileType];
return [language engine];
}
/**
Return a scripting engine for language with specified name.
*/
+ (STEngine *) engineForLanguageWithName:(NSString *)name
{
if(!name)
{
NSLog(@"No language name given");
return NULL;
}
return [[STLanguage languageWithName:name] engine];
}
- (void)dealloc
{
RELEASE(defaultEnvironment);
[super dealloc];
}
/** Return the default scripting environment for the engine. */
- (STEnvironment *)defaultEnvironment
{
return defaultEnvironment;
}
/** Set the default scripting environment for the engine. */
- (void) setDefaultEnvironment:(STEnvironment *)anEnvironment
{
ASSIGN(defaultEnvironment,anEnvironment);
}
/** Execude source code <var>code</var> in default scripting environment. */
- (id) executeCode:(NSString *)code
{
return [self executeCode:code
inEnvironment:defaultEnvironment];
}
/** Execude source code <var>code</var> in an environment <var>env</var>.
This is the method, that has to be implemented by those who are writing
a language engine.
<override-subclass />
*/
- (id) executeCode:(NSString *)code
inEnvironment:(STEnvironment *)env
{
[self subclassResponsibility:_cmd];
return nil;
}
- (BOOL)understandsCode:(NSString *)code
{
[self subclassResponsibility:_cmd];
return NO;
}
- (STMethod *)methodFromSource:(NSString *)sourceString
forReceiver:(id)receiver
inEnvironment:(STEnvironment *)env
{
[self subclassResponsibility:_cmd];
return nil;
}
- (id) executeMethod:(id <STMethod>)aMethod
forReceiver:(id)anObject
withArguments:(NSArray *)args
inEnvironment:(STEnvironment *)env;
{
[self subclassResponsibility:_cmd];
return nil;
}
@end

View file

@ -0,0 +1,104 @@
/**
STEnvironment
Scripting environment
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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 <Foundation/NSObject.h>
@class NSBundle;
@class NSDictionary;
@class NSMutableDictionary;
@class NSMutableArray;
@class NSMutableSet;
@class STObjectReference;
@class STEnvironmentDescription;
@interface STEnvironment:NSObject
{
NSMutableDictionary *defaultPool;
STEnvironmentDescription *description;
NSMutableDictionary *classes; /* from description */
BOOL fullScripting;
BOOL createsUnknownObjects;
NSMutableDictionary *infoCache;
NSMutableDictionary *objectFinders;
NSMutableArray *loadedBundles;
}
/** Creating environment */
+ (STEnvironment *)defaultScriptingEnvironment;
+ environmentWithDescriptionName:(NSString *)descName;
+ environmentWithDescription:(STEnvironmentDescription *)aDescription;
- initDefault;
- initWithDescriptionName:(NSString *)descName;
- initWithDescription:(STEnvironmentDescription *)aDescription;
/** Full scripting */
- (void)setFullScriptingEnabled:(BOOL)flag;
- (BOOL)fullScriptingEnabled;
-(void)setCreatesUnknownObjects:(BOOL)flag;
-(BOOL)createsUnknownObjects;
/** Modules */
- (void)loadModule:(NSString *)moduleName;
- (void)includeFramework:(NSString *)frameworkName;
- (BOOL)includeBundle:(NSBundle *)aBundle;
- (void)addClassesWithNames:(NSArray *)names;
/** Named objects and object references */
- (NSMutableDictionary *)objectDictionary;
- (void)setObject:(id)anObject
forName:(NSString *)objName;
- (void)removeObjectWithName:(NSString *)objName;
- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict;
- (id)objectWithName:(NSString *)objName;
- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name;
/** Distributed objects */
- (void)registerObjectFinder:(id)finder name:(NSString*)name;
- (void)registerObjectFinderNamed:(NSString *)name;
- (void)removeObjectFinderWithName:(NSString *)name;
- (NSArray *)knownObjectNames;
/** Selector translation */
- (NSString *)translateSelector:(NSString *)aString forReceiver:(id)anObject;
@end

View file

@ -0,0 +1,617 @@
/**
STEnvironment
Scripting environment
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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 <StepTalk/STEnvironment.h>
#import <StepTalk/STClassInfo.h>
#import <StepTalk/STEnvironmentDescription.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STFunctions.h>
#import <StepTalk/STBundleInfo.h>
#import <StepTalk/STObjCRuntime.h>
#import <StepTalk/STObjectReference.h>
#import <StepTalk/STUndefinedObject.h>
#import <StepTalk/STScripting.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>
@interface STEnvironment(STPrivateMethods)
- (STClassInfo *)findClassInfoForObject:(id)anObject;
@end
@implementation STEnvironment
/**
Creates and initialises scripting environment using standard description.
*/
+ (STEnvironment *)defaultScriptingEnvironment
{
NSString *name;
name = [STEnvironmentDescription defaultEnvironmentDescriptionName];
return [self environmentWithDescriptionName:name];
}
/**
Creates and initialises scripting environment using description with name
<var>descName</var>.
*/
+ environmentWithDescriptionName:(NSString *)descName
{
return AUTORELEASE([[self alloc] initWithDescriptionName:descName]);
}
/**
Creates and initialises scripting environment using environment description
<var>description</var>.
*/
+ environmentWithDescription:(STEnvironmentDescription *)aDescription
{
return AUTORELEASE([[self alloc] initWithDescription:aDescription]);
}
/**
Initialises scripting environment using default description.
<init />
*/
- initDefault
{
NSString *name;
name = [STEnvironmentDescription defaultEnvironmentDescriptionName];
return [self initWithDescriptionName:name];
}
/**
Initialises scripting environment using description with name
<var>descName</var>.
<init />
*/
- initWithDescriptionName:(NSString *)descName
{
return [self initWithDescription:
[STEnvironmentDescription descriptionWithName:descName]];
}
/**
Initialises scripting environment using scripting description
<var>aDescription</var>.
*/
- initWithDescription:(STEnvironmentDescription *)aDescription
{
NSEnumerator *enumerator;
NSString *name;
self = [super init];
defaultPool = [[NSMutableDictionary alloc] init];
infoCache = [[NSMutableDictionary alloc] init];
description = RETAIN(aDescription);
classes = [description classes];
/* Load modules */
enumerator = [[description modules] objectEnumerator];
while( (name = [enumerator nextObject]) )
{
[self loadModule:name];
}
/* Register finders */
enumerator = [[description objectFinders] objectEnumerator];
while( (name = [enumerator nextObject]) )
{
[self registerObjectFinderNamed:name];
}
RETAIN(description);
return self;
}
- (void)dealloc
{
RELEASE(defaultPool);
RELEASE(description);
RELEASE(infoCache);
RELEASE(objectFinders);
RELEASE(loadedBundles);
[super dealloc];
}
/**
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;
}
/**
Add classes specified by the names in the <var>names</var> array.
This method is used internally to add classes provided by modules.
*/
- (void)addClassesWithNames:(NSArray *)names
{
[self addNamedObjectsFromDictionary:STClassDictionaryWithNames(names)];
}
/**
Load StepTalk module with the name <var>moduleName</var>. Modules are stored
in the Library/StepTalk/Modules directory.
*/
- (void) loadModule:(NSString *)moduleName
{
NSBundle *bundle;
bundle = [NSBundle stepTalkBundleWithName:moduleName];
[self includeBundle:bundle];
}
/**
Include scripting capabilities advertised by the framework with name
<ivar>frameworkName</ivar>. If the framework is already loaded, nothing
happens.
*/
- (BOOL)includeFramework:(NSString *)frameworkName
{
NSBundle *bundle;
bundle = [NSBundle bundleForFrameworkWithName:frameworkName];
if(!bundle)
{
return NO;
}
return [self includeBundle:bundle];
}
/**
Include scripting capabilities advertised by the bundle
<ivar>aBundle</ivar>. If the bundle is already loaded, nothing
happens.
*/
- (BOOL)includeBundle:(NSBundle *)aBundle
{
STBundleInfo *info;
/* Ignore already included bundles. */
if([loadedBundles containsObject:[aBundle bundlePath]])
{
NSDebugLog(@"Bundle '%@' already included.", [aBundle bundlePath]);
return;
}
info = [STBundleInfo infoForBundle:aBundle];
if(!info)
{
return NO;
}
[self addNamedObjectsFromDictionary:[info namedObjects]];
[self addClassesWithNames:[info publicClassNames]];
if(!loadedBundles)
{
loadedBundles = [[NSMutableArray alloc] init];
}
/* FIXME: is this sufficient? */
[loadedBundles addObject:[aBundle bundlePath]];
return YES;
}
/**
Returns a dictionary of all named objects in the environment.
*/
- (NSMutableDictionary *)objectDictionary
{
return defaultPool;
}
/* -----------------------------------------------------------------------
Objects
----------------------------------------------------------------------- */
/**
Register object <var>anObject</var> with name <var>objName</var>.
*/
- (void)setObject:(id)anObject
forName:(NSString *)objName
{
if(anObject)
{
[defaultPool setObject:anObject forKey:objName];
}
else
{
[defaultPool setObject:STNil forKey:objName];
}
}
/**
Remove object named <var>objName</var>.
*/
- (void)removeObjectWithName:(NSString *)objName
{
[defaultPool removeObjectForKey:objName];
}
/**
*/
- (void)addNamedObjectsFromDictionary:(NSDictionary *)dict
{
[defaultPool addEntriesFromDictionary:dict];
}
/**
Return object with name <var>objName</var>. If object is not found int 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
{
NSEnumerator *enumerator;
id obj;
id finder;
obj = [defaultPool objectForKey:objName];
if(!obj)
{
enumerator = [objectFinders objectEnumerator];
while( (finder = [enumerator nextObject]) )
{
obj = [finder objectWithName:objName];
if(obj)
{
[defaultPool setObject:obj forKey:objName];
break;
}
}
}
return obj;
}
- (STObjectReference *)objectReferenceForObjectWithName:(NSString *)name
{
STObjectReference *ref;
id pool = defaultPool;
if( ![self objectWithName:name] )
{
if([[self knownObjectNames] containsObject:name])
{
pool = nil;
}
else if(createsUnknownObjects)
{
[defaultPool setObject:STNil forKey:name];
}
}
ref = [STObjectReference alloc];
[ref initWithObjectName:name
pool:defaultPool];
return AUTORELEASE(ref);
}
/* FIXME: rewrite, it is too sloooooow */
- (STClassInfo *)findClassInfoForObject:(id)anObject
{
STClassInfo *info = nil;
NSString *className;
NSString *origName;
Class class;
if(!anObject)
{
anObject = STNil;
}
/* FIXME: temporary solution */
if( [anObject isProxy] )
{
NSDebugLog(@"FIXME: receiver is a distant object");
info = [classes objectForKey:@"NSProxy"];
if(!info)
{
return [classes objectForKey:@"All"];
}
return info;
}
if([anObject respondsToSelector:@selector(classForScripting)])
{
class = [anObject classForScripting];
}
else
{
class = [anObject class];
}
className = [anObject className];
if([anObject isClass])
{
origName = className = [className stringByAppendingString:@" class"];
NSDebugLLog(@"STSending",
@"Looking for class info '%@'...",
className);
info = [infoCache objectForKey:className];
if(info)
{
return info;
}
while( !(info = [classes objectForKey:className]) )
{
class = [class superclass];
if(!class)
{
break;
}
className = [[class className] stringByAppendingString:@" class"];
NSDebugLLog(@"STSending",
@" ... %@?",className);
}
}
else
{
origName = className;
NSDebugLLog(@"STSending",
@"Looking for class info '%@' (instance)...",
className);
info = [infoCache objectForKey:className];
if(info)
{
return info;
}
while( !(info = [classes objectForKey:className]) )
{
class = [class superclass];
if(!class)
{
break;
}
className = [class className];
NSDebugLLog(@"STSending",
@" ... %@?",className);
}
}
if(!info)
{
NSDebugLLog(@"STSending",
@"No class info '%@'",
className);
return nil;
}
NSDebugLLog(@"STSending",
@"Found class info '%@'",
className);
[infoCache setObject:info forKey:origName];
return info;
}
- (NSString *)translateSelector:(NSString *)aString forReceiver:(id)anObject
{
STClassInfo *class;
NSString *selector;
class = [self findClassInfoForObject:anObject];
NSDebugLLog(@"STSending",
@"Lookup selector '%@' class %@", aString, [class behaviourName]);
selector = [class translationForSelector:aString];
NSDebugLLog(@"STSending",
@"Found selector '%@'",selector);
#ifdef DEBUG
if(! [selector isEqualToString:aString])
{
NSDebugLLog(@"STSending",
@"using selector '%@' instead of '%@'",
selector,aString);
}
#endif
if(!selector && fullScripting )
{
NSDebugLLog(@"STSending",
@"using selector '%@' (full scriptig)",
aString);
selector = AUTORELEASE([aString copy]);
}
if(!selector)
{
[NSException raise:STScriptingException
format:@"Receiver of type %@ denies selector '%@'",
[anObject className],aString];
/* if exception is ignored, then try to use original selector */
selector = AUTORELEASE([aString copy]);
}
return selector;
}
- (NSArray *)knownObjectNames
{
NSMutableArray *array = [NSMutableArray array];
NSEnumerator *enumerator;
id finder;
[array addObjectsFromArray:[defaultPool allKeys]];
enumerator = [objectFinders objectEnumerator];
while( (finder = [enumerator nextObject]) )
{
[array addObjectsFromArray:[finder knownObjectNames]];
}
return [NSArray arrayWithArray:array];
}
/** Register object finder <var>finder</var> under the name <var>name</var> */
- (void)registerObjectFinder:(id)finder name:(NSString*)name
{
if(!objectFinders)
{
objectFinders = [[NSMutableDictionary alloc] init];
}
[objectFinders setObject:finder forKey:name];
}
/** Register object finder named <var>name</var>. This method will try to find
an object finder bundle in Library/StepTalk/Finders directories.
*/
- (void)registerObjectFinderNamed:(NSString *)name
{
NSBundle *bundle;
NSString *path;
id finder;
if([objectFinders objectForKey:name])
{
return;
}
path = STFindResource(name, @"Finders", @"bundle");
if(!path)
{
NSLog(@"Unknown object finder with name '%@'", name);
return;
}
NSDebugLog(@"Finder '%@'", path);
bundle = [NSBundle bundleWithPath:path];
if(!bundle)
{
NSLog(@"Unable to load object finder bundle '%@'", path);
return;
}
finder = [[[bundle principalClass] alloc] init];
if(!finder)
{
NSLog(@"Unable to create object finder from '%@'", path);
return;
}
[self registerObjectFinder:finder name:name];
}
/** Remove object finder with name <var>name</var> */
- (void)removeObjectFinderWithName:(NSString *)name
{
[objectFinders removeObjectForKey:name];
}
@end

View file

@ -0,0 +1,66 @@
/**
STEnvironmentDescription.h
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000 Jun 16
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
*/
#import <Foundation/NSObject.h>
enum
{
STUndefinedRestriction,
STAllowAllRestriction,
STDenyAllRestriction
};
@class NSDictionary;
@class NSMutableArray;
@class NSMutableDictionary;
@interface STEnvironmentDescription:NSObject
{
NSMutableArray *usedDefs;
NSMutableDictionary *classes;
NSMutableDictionary *behaviours;
NSMutableDictionary *aliases;
NSMutableArray *modules;
NSMutableArray *finders;
int restriction;
}
+ (NSString *)defaultEnvironmentDescriptionName;
+ descriptionWithName:(NSString *)descriptionName;
+ descriptionFromDictionary:(NSDictionary *)dictionary;
- initWithName:(NSString *)defName;
- initFromDictionary:(NSDictionary *)def;
- (void)updateFromDictionary:(NSDictionary *)def;
- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def;
- (NSMutableDictionary *)classes;
- (NSArray *)modules;
- (NSArray *)objectFinders;
@end

View file

@ -0,0 +1,495 @@
/**
STEnvironmentDescription.m
Compiled scripting environment description
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000 Jun 16
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
*/
#import <StepTalk/STEnvironmentDescription.h>
#import <StepTalk/STClassInfo.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STFunctions.h>
#import <StepTalk/STBehaviourInfo.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSUserDefaults.h>
static NSDictionary *dictForDescriptionWithName(NSString *defName)
{
NSString *file;
NSDictionary *dict;
file = STFindResource(defName,
STScriptingEnvironmentsDirectory,
STScriptingEnvironmentExtension);
if(!file)
{
[NSException raise:STGenericException
format: @"Could not find "
@"environment description with name '%@'.",
defName];
return nil;
}
dict = [NSDictionary dictionaryWithContentsOfFile:file];
if(!dict)
{
[NSException raise:STGenericException
format:@"Error while opening "
@"environment description with name '%@'.",
defName];
return nil;
}
return dict;
}
@interface STEnvironmentDescription(PrivateMethods)
- (void)updateFromDictionary:(NSDictionary *)def;
- (void)updateUseListFromDictionary:(NSDictionary *)def;
- (void)updateBehavioursFromDictionary:(NSDictionary *)aDict;
- (void)updateBehaviour:(STBehaviourInfo *)behInfo
description:(NSDictionary *)def;
- (void)updateClassesFromDictionary:(NSDictionary *)def;
- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def;
- (void)updateAliasesFromDictionary:(NSDictionary *)def;
- (void)fixupScriptingDescription;
- (void)resolveSuperclasses;
- (void)updateUseList:(NSArray *)array;
- (void)updateModuleList:(NSArray *)array;
- (void)updateFinderList:(NSArray *)array;
@end
@implementation STEnvironmentDescription
+ (NSString *)defaultEnvironmentDescriptionName
{
NSUserDefaults *defs;
NSString *name;
defs = [NSUserDefaults standardUserDefaults];
name = [defs objectForKey:@"STDefaultEnvironmentDescriptionName"];
if(!name || [name isEqualToString:@""])
{
name = [NSString stringWithString:@"Standard"];
}
return name;
}
+ descriptionWithName:(NSString *)descriptionName
{
return AUTORELEASE([[self alloc] initWithName:descriptionName]);
}
+ descriptionFromDictionary:(NSDictionary *)dictionary
{
return AUTORELEASE([[self alloc] initFromDictionary:dictionary]);
}
- (void)dealloc
{
RELEASE(usedDefs);
RELEASE(classes);
RELEASE(behaviours);
RELEASE(aliases);
RELEASE(modules);
RELEASE(finders);
[super dealloc];
}
- initWithName:(NSString *)defName;
{
return [self initFromDictionary:dictForDescriptionWithName(defName)];
}
- initFromDictionary:(NSDictionary *)def
{
if(!def)
{
[self dealloc];
return nil;
}
[self updateFromDictionary:def];
[self fixupScriptingDescription];
return self;
}
- (void)updateFromDictionary:(NSDictionary *)def
{
NSString *str;
BOOL saveFlag = restriction;
if(!def)
{
NSLog(@"Warning: nil dictionary for environmet description update");
return;
};
str = [def objectForKey:@"DefaultRestriction"];
if(str)
{
str = [str lowercaseString];
if([str isEqualToString:@"allowall"])
{
restriction = STAllowAllRestriction;
}
else if([str isEqualToString:@"denyall"])
{
restriction = STDenyAllRestriction;
}
else
{
[NSException raise:STGenericException
format:@"Invalid default restriction rule '%@'.",
str];
return;
}
}
[self updateUseList:[def objectForKey:@"Use"]];
[self updateModuleList:[def objectForKey:@"Modules"]];
[self updateFinderList:[def objectForKey:@"Finders"]];
[self updateBehavioursFromDictionary:[def objectForKey:@"Behaviours"]];
[self updateClassesFromDictionary:[def objectForKey:@"Classes"]];
[self updateAliasesFromDictionary:[def objectForKey:@"Aliases"]];
restriction = saveFlag;
}
- (void)updateUseList:(NSArray *)array
{
NSEnumerator *enumerator;
NSString *str;
enumerator = [array objectEnumerator];
while( (str = [enumerator nextObject]) )
{
if(!usedDefs)
{
usedDefs = [[NSMutableArray alloc] init];
}
if( ![usedDefs containsObject:str] )
{
[usedDefs addObject:str];
[self updateFromDictionary:dictForDescriptionWithName(str)];
}
}
}
- (void)updateModuleList:(NSArray *)array
{
NSEnumerator *enumerator;
NSString *str;
enumerator = [array objectEnumerator];
while( (str = [enumerator nextObject]) )
{
if(!modules)
{
modules = [[NSMutableArray alloc] init];
}
if( ![modules containsObject:str] )
{
[modules addObject:str];
}
}
}
- (void)updateFinderList:(NSArray *)array
{
NSEnumerator *enumerator;
NSString *str;
enumerator = [array objectEnumerator];
while( (str = [enumerator nextObject]) )
{
if(!finders)
{
finders = [[NSMutableArray alloc] init];
}
if( ![finders containsObject:str] )
{
[finders addObject:str];
}
}
}
- (void)updateBehavioursFromDictionary:(NSDictionary *)dict
{
NSEnumerator *enumerator;
NSString *name;
STBehaviourInfo *behInfo;
enumerator = [dict keyEnumerator];
while( (name = [enumerator nextObject]) )
{
if([behaviours objectForKey:name])
{
[NSException raise:STGenericException
format:@"Behaviour '%@' defined more than once.",
name];
return;
}
if(!behaviours)
{
behaviours = [[NSMutableDictionary alloc] init];
}
behInfo = [[STBehaviourInfo alloc] initWithName:name];
[behaviours setObject:behInfo forKey:name];
[self updateBehaviour:behInfo description:[dict objectForKey:name]];
}
}
- (void)updateBehaviour:(STBehaviourInfo *)behInfo
description:(NSDictionary *)def
{
NSString *str;
NSEnumerator *enumerator;
STBehaviourInfo *useInfo;
enumerator = [[def objectForKey:@"Use"] objectEnumerator];
while( (str = [enumerator nextObject]) )
{
useInfo = [behaviours objectForKey:str];
if(!useInfo)
{
[NSException raise:STGenericException
format:@"Undefined behaviour '%@'.",
str];
return;
}
[behInfo adopt:useInfo];
}
[behInfo allowMethods:[NSSet setWithArray:[def objectForKey:@"AllowMethods"]]];
[behInfo denyMethods:[NSSet setWithArray:[def objectForKey:@"DenyMethods"]]];
[behInfo addTranslationsFromDictionary:[def objectForKey:@"SymbolicSelectors"]];
[behInfo addTranslationsFromDictionary:[def objectForKey:@"Aliases"]];
}
- (void)updateClassesFromDictionary:(NSDictionary *)dict
{
NSEnumerator *enumerator;
NSString *str;
enumerator = [dict keyEnumerator];
while( (str = [enumerator nextObject]) )
{
[self updateClassWithName:str
description:[dict objectForKey:str]];
}
}
- (void)updateClassWithName:(NSString *)className description:(NSDictionary *)def
{
STClassInfo *class;
NSString *superName;
NSString *flag;
NSString *str;
BOOL newClass = NO;
if(!classes)
{
classes = [[NSMutableDictionary alloc] init];
}
class = [classes objectForKey:className];
if( !class )
{
class = [[STClassInfo alloc] initWithName:className];
[classes setObject:class forKey:className];
newClass = YES;
}
str = [def objectForKey:@"Super"];
superName = [class superclassName];
if(str && (![str isEqualToString:superName]))
{
if(newClass | (superName == nil))
{
[class setSuperclassName:str];
}
else
{
[NSException raise:STGenericException
format:@"Trying to change superclass of '%@' "
@"from '%@' to '%@'",
className,[class superclassName],str];
return;
}
}
[self updateBehaviour:class description:def];
flag = [def objectForKey:@"Restriction"];
NSDebugLLog(@"STEnvironment", @"Class %@ restriction %@ (default %i)",
className, flag, restriction);
if(flag)
{
flag = [flag lowercaseString];
if([flag isEqualToString:@"allowall"])
{
[class setAllowAllMethods:YES];
}
else if([flag isEqualToString:@"denyall"])
{
[class setAllowAllMethods:NO];
}
else
{
[NSException raise:STGenericException
format:@"Invalid method restriction rule '%@'.",
flag];
return;
}
}
else
{
if(restriction == STAllowAllRestriction)
{
[class setAllowAllMethods:YES];
}
else if (restriction == STDenyAllRestriction)
{
[class setAllowAllMethods:NO];
}
}
}
- (void)updateAliasesFromDictionary:(NSDictionary *)dict
{
NSEnumerator *enumerator;
NSString *str;
enumerator = [dict keyEnumerator];
while( (str = [enumerator nextObject]) )
{
[aliases setObject:str forKey:[dict objectForKey:str]];
}
}
- (NSMutableDictionary *)classes
{
return classes;
}
- (NSArray *)modules
{
return [NSArray arrayWithArray:modules];
}
- (NSArray *)objectFinders
{
return [NSArray arrayWithArray:finders];
}
- (void)fixupScriptingDescription
{
[self resolveSuperclasses];
}
- (void)resolveSuperclasses
{
NSEnumerator *enumerator;
STClassInfo *superclass;
STClassInfo *class;
NSString *className;
enumerator = [classes objectEnumerator];
while( (class = [enumerator nextObject]) )
{
if([[class behaviourName] isEqualToString:@"All"])
{
continue;
}
className = [class superclassName];
if( (className == nil) || [className isEqualToString:@"nil"] )
{
superclass = [classes objectForKey:@"All"];
if(!superclass)
{
continue;
}
}
else
{
superclass = [classes objectForKey:className];
}
if(!superclass)
{
[NSException raise:STGenericException
format:@"Resolving superclasses: "
@"Could not find class '%@'.", className];
return;
}
[class setSuperclassInfo:superclass];
}
}
@end

View file

@ -0,0 +1,57 @@
/**
STExterns.h
Misc. variables
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
@class NSString;
@class STUndefinedObject;
extern STUndefinedObject *STNil;
/* exceptions */
extern NSString *STGenericException; /* can be ignored */
extern NSString *STInvalidArgumentException;
extern NSString *STInternalInconsistencyException; /* not recoverable */
extern NSString *STScriptingException;
extern NSString *STLibraryDirectory;
extern NSString *STScriptExtension;
extern NSString *STScriptsDirectory;
extern NSString *STScriptingEnvironmentsDirectory;
extern NSString *STScriptingEnvironmentExtension;
extern NSString *STModulesDirectory;
extern NSString *STModuleExtension;
extern NSString *STLanguageBundlesDirectory;
extern NSString *STLanguageBundleExtension;
extern NSString *STLanguagesConfigFile;
/* malloc zone */
extern NSZone *STMallocZone;

View file

@ -0,0 +1,55 @@
/**
STExterns.m
Misc. variables
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <Foundation/NSString.h>
NSString *STGenericException = @"STGenericException";
NSString *STInvalidArgumentException = @"STInvalidArgumentException";
NSString *STInternalInconsistencyException = @"STInternalInconsistencyException";
NSString *STRangeException = @"STRangeException";
NSString *STScriptingException = @"STScriptingException";
NSString *STCompilerSyntaxException = @"STCompilerSyntaxException";
NSString *STCompilerGenericException = @"STCompilerGenericException";
NSString *STCompilerInconsistencyException = @"STCompilerInconsistencyException";
NSString *STInterpreterGenericException = @"STInterpreterGenericException";
NSString *STInvalidBytecodeException = @"STInterpreterInvalidBytecodeException";
NSString *STInterpreterInconsistencyException = @"STInterpreterInconsistencyException";
NSString *STLibraryDirectory = @"StepTalk";
NSString *STScriptsDirectory = @"Scripts";
NSString *STModulesDirectory = @"Modules";
NSString *STModuleExtension = @"bundle";
NSString *STScriptingEnvironmentsDirectory = @"Environments";
NSString *STScriptingEnvironmentExtension = @"stenv";
NSString *STLanguageBundlesDirectory = @"Languages";
NSString *STLanguageBundleExtension = @"stlanguage";
NSString *STLanguagesConfigFile = @"Languages.plist";

View file

@ -0,0 +1,38 @@
/**
STFunctions.h
Misc. functions
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <Foundation/NSObject.h>
@class NSString;
NSArray *STFindAllResources(NSString *resourceDir, NSString *extension);
NSString *STFindResource(NSString *name,
NSString *resourceDir,
NSString *extension);
NSString *STUserConfigPath(void);

View file

@ -0,0 +1,130 @@
/**
STFunctions.m
Misc. functions
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <StepTalk/STFunctions.h>
#import <StepTalk/STExterns.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSString.h>
NSString *STFindResource(NSString *name,
NSString *resourceDir,
NSString *extension)
{
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *paths;
NSEnumerator *enumerator;
NSString *path;
NSString *file;
paths = NSStandardLibraryPaths();
enumerator = [paths objectEnumerator];
while( (path = [enumerator nextObject]) )
{
file = [path stringByAppendingPathComponent:STLibraryDirectory];
file = [file stringByAppendingPathComponent:resourceDir];
file = [file stringByAppendingPathComponent:name];
if( [manager fileExistsAtPath:file isDirectory:NO] )
{
return file;
}
file = [file stringByAppendingPathExtension:extension];
if( [manager fileExistsAtPath:file isDirectory:NO] )
{
return file;
}
}
return nil;
}
NSArray *STFindAllResources(NSString *resourceDir, NSString *extension)
{
NSFileManager *manager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirs;
NSArray *paths;
NSEnumerator *enumerator;
NSString *path;
NSString *file;
NSMutableArray *resources = [NSMutableArray array];
paths = NSStandardLibraryPaths();
enumerator = [paths objectEnumerator];
while( (path = [enumerator nextObject]) )
{
path = [path stringByAppendingPathComponent:STLibraryDirectory];
path = [path stringByAppendingPathComponent:resourceDir];
if( ![manager fileExistsAtPath:path] )
{
continue;
}
dirs = [manager enumeratorAtPath:path];
while( (file = [dirs nextObject]) )
{
if( [[[dirs directoryAttributes] fileType]
isEqualToString:NSFileTypeDirectory]
&& [[file pathExtension] isEqualToString:extension])
{
file = [path stringByAppendingPathComponent:file];
[resources addObject:file];
}
}
}
return [NSArray arrayWithArray:resources];
}
NSString *STUserConfigPath(void)
{
NSString *path = nil;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
path = [paths objectAtIndex: 0];
path = [path stringByAppendingPathComponent:STLibraryDirectory];
path = [path stringByAppendingPathComponent:@"Configuration"];
return path;
}

View file

@ -0,0 +1,46 @@
/**
STLanguage.h
StepTalk language bundle
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2001 Oct 24
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
*/
#import <Foundation/NSBundle.h>
@class STEngine;
@interface STLanguage:NSBundle
+ (NSArray *)allLanguageNames;
+ (NSString *)defaultLanguageName;
+ (NSArray *)allKnownFileTypes;
+ languageWithName:(NSString *)languageName;
+ languageWithPath:(NSString *)path;
+ (NSString *)languageNameForFileType:(NSString *)fileType;
+ (STLanguage *)languageForFileType:(NSString *)fileType;
- (NSString *)languageName;
- (STEngine *)engine;
@end

View file

@ -0,0 +1,224 @@
/**
STLanguage.m
StepTalk language bundle
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2001 Oct 24
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
*/
#import <StepTalk/STLanguage.h>
#import <StepTalk/STEngine.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STFunctions.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSTask.h>
#import <Foundation/NSUserDefaults.h>
static NSDictionary *fileTypeDictionary = nil;
@implementation STLanguage
/** Returns an array containing the names of all available languages*/
+ (NSArray *)allLanguageNames
{
NSArray *bundles;
NSEnumerator *enumerator;
NSString *path;
NSMutableArray *languages = [NSMutableArray array];
STLanguage *lang;
bundles = STFindAllResources(STLanguageBundlesDirectory,
STLanguageBundleExtension);
enumerator = [bundles objectEnumerator];
while( (path = [enumerator nextObject]) )
{
lang = [STLanguage languageWithPath:path];
[languages addObject:[lang languageName]];
}
return AUTORELEASE([languages copy]);
}
/** Returns the name of default scripting language specified by the
STDefaultLanguageName default. If there is no such default in user's
defaults database, then Smalltalk is used. */
+ (NSString *)defaultLanguageName
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSString *name= [defs objectForKey:@"STDefaultLanguageName"];
if(!name)
{
return @"Smalltalk";
}
else
{
return name;
}
}
/** Returns language bundle for a language with name <var>languageName</var> */
+ languageWithName:(NSString *)languageName
{
NSString *file = STFindResource(languageName, STLanguageBundlesDirectory,
STLanguageBundleExtension);
if(!file)
{
NSLog(@"Could not find language with name '%@'", languageName);
return nil;
}
return [self languageWithPath:file];
}
/** Returns language bundle for language with name <var>languageName</var>. */
+ languageWithPath:(NSString *)path
{
if(!path)
{
return nil;
}
return AUTORELEASE([[STLanguage alloc] initWithPath:path]);
}
/** Update information about handling various files with StepTalk. */
+ (NSDictionary *)updateFileTypeDictionary
{
NSString *path = STUserConfigPath();
NSFileManager *fm = [NSFileManager defaultManager];
NSTask *task;
NSDictionary *dict;
RELEASE(fileTypeDictionary);
path = [path stringByAppendingPathComponent:STLanguagesConfigFile];
if( ![fm fileExistsAtPath:path])
{
NSLog(@"Creating lanugages configuration file...");
task = [NSTask launchedTaskWithLaunchPath:@"stupdate_languages"
arguments:nil];
[task waitUntilExit];
}
if( ![fm fileExistsAtPath:path])
{
[NSException raise:STGenericException
format:@"Unable to get languages configuration file"];
return nil;
}
dict = [NSDictionary dictionaryWithContentsOfFile:path];
fileTypeDictionary = [dict objectForKey:@"STFileTypes"];
RETAIN(fileTypeDictionary);
}
/** Returns name of a language used by files of type <var>fileType</var>. */
+ (NSString *)languageNameForFileType:(NSString *)fileType
{
if(!fileTypeDictionary)
{
[self updateFileTypeDictionary];
}
return [fileTypeDictionary objectForKey:fileType];
}
/** Return all known types (extensions) of StepTalk script files */
+ (NSArray *)allKnownFileTypes
{
if(!fileTypeDictionary)
{
[self updateFileTypeDictionary];
}
return [fileTypeDictionary allKeys];
}
/** Returns the language bundle for a language used by files of type
<var>fileType</var>. */
+ (STLanguage *)languageForFileType:(NSString *)fileType
{
NSString *langName = [STLanguage languageNameForFileType:fileType];
if(langName)
{
return [STLanguage languageWithName:langName];
}
[NSException raise:STGenericException
format:@"Unknown language for file type '%@'", fileType];
return nil;
}
/** Returns the name of the language */
- (NSString *)languageName
{
NSString *name;
name = [[self infoDictionary] objectForKey:@"STLanguageName"];
if(!name)
{
name = [[self bundlePath] lastPathComponent];
name = [name stringByDeletingPathExtension];
}
return name;
}
/** Returns a scripting engine provided by the language. */
- (STEngine *)engine
{
NSString *className =[[self infoDictionary] objectForKey:@"STEngine"];
Class engineClass = nil;
STEngine *engine;
if(className)
{
engineClass = [self classNamed:className];
}
if(!engineClass)
{
engineClass = [self principalClass];
}
engine = [[engineClass alloc] init];
return AUTORELEASE(engine);
}
@end

View file

@ -0,0 +1,33 @@
/**
STMethod
Copyright (c) 2003 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2003 Aug 6
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <Foundation/NSObject.h>
@protocol STMethod
- (NSString *)source;
- (NSString *)methodName;
- (NSString *)languageName;
@end

View file

@ -0,0 +1,29 @@
/**
STMethod
Copyright (c) 2003 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2003 Aug 6
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <StepTalk/STMethod.h>
/* Nothig here */

View file

@ -0,0 +1,44 @@
/**
STObjCRuntime.m
Objective C runtime additions
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <Foundation/NSObject.h>
@class NSMutableDictionary;
@class NSString;
@class NSValue;
@class NSMethodSignature;
extern NSMutableDictionary *STAllObjectiveCClasses(void);
extern NSMutableDictionary *STGetFoundationConstants(void);
extern NSDictionary *STClassDictionaryWithNames(NSArray *classNames);
extern NSArray *STAllObjectiveCSelectors(void);
extern NSValue *STValueFromSelector(SEL sel);
extern SEL STSelectorFromValue(NSValue *val);
extern SEL STSelectorFromString(NSString *aString);
extern NSMethodSignature *STMethodSignatureForSelector(SEL sel);

View file

@ -0,0 +1,262 @@
/**
STObjCRuntime.m
Objective C runtime additions
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <StepTalk/STObjCRuntime.h>
#import <StepTalk/STExterns.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#define SELECTOR_TYPES_COUNT 6
static const char *selector_types[] =
{
"@8@0:4",
"@12@0:4@8",
"@16@0:4@8@12",
"@20@0:4@8@12@16",
"@24@0:4@8@12@16@20",
"@28@0:4@8@12@16@20@24"
};
NSMutableDictionary *STAllObjectiveCClasses(void)
{
NSString *name;
NSMutableDictionary *dict;
void *state = NULL;
Class class;
dict = [NSMutableDictionary dictionary];
while( (class = objc_next_class(&state)) )
{
name = [NSString stringWithCString:class_get_class_name(class)];
[dict setObject:class forKey:name];
}
// NSLog(@"%i Objective-C classes found",[dict count]);
return dict;
}
NSDictionary *STClassDictionaryWithNames(NSArray *classNames)
{
NSEnumerator *enumerator = [classNames objectEnumerator];
NSString *className;
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
Class class;
while( (className = [enumerator nextObject]) )
{
class = NSClassFromString(className);
if(class)
{
[dict setObject:NSClassFromString(className) forKey:className];
}
else
{
NSLog(@"Warning: Class with name '%@' not found", className);
}
}
return [NSDictionary dictionaryWithDictionary:dict];
}
NSValue *STValueFromSelector(SEL sel)
{
return [NSValue value:&sel withObjCType:@encode(SEL)];
}
SEL STSelectorFromValue(NSValue *val)
{
SEL sel;
[val getValue:&sel];
return sel;
}
SEL STSelectorFromString(NSString *aString)
{
const char *name = [aString cString];
const char *ptr;
int argc = 0;
SEL sel;
sel = NSSelectorFromString(aString);
if(!sel)
{
ptr = name;
while(*ptr)
{
if(*ptr == ':')
{
argc ++;
}
ptr++;
}
if( argc < SELECTOR_TYPES_COUNT )
{
NSDebugLLog(@"STSending",
@"registering selector '%s' "
@"with %i arguments, types:'%s'",
name,argc,selector_types[argc]);
sel = sel_register_typed_name(name, selector_types[argc]);
}
if(!sel)
{
[NSException raise:STInternalInconsistencyException
format:@"Unable to register selector '%@'",
aString];
return NULL;
}
}
else
{
/* FIXME: temporary hack */
}
return sel;
}
SEL STCreateTypedSelector(SEL sel)
{
const char *name = sel_get_name(sel);
const char *ptr;
int argc = 0;
SEL newSel;
ptr = name;
while(*ptr)
{
if(*ptr == ':')
{
argc ++;
}
ptr++;
}
if( argc < SELECTOR_TYPES_COUNT )
{
NSDebugLLog(@"STSending",
@"registering selector '%s' "
@"with %i arguments, types:'%s'",
name,argc,selector_types[argc]);
newSel = sel_register_typed_name(name, selector_types[argc]);
}
if(!newSel)
{
[NSException raise:STInternalInconsistencyException
format:@"Unable to register typed selector '%s'",
name];
return NULL;
}
return newSel;
}
NSMethodSignature *STMethodSignatureForSelector(SEL sel)
{
char *types;
types = sel_get_type(sel);
if(!types)
{
sel = STCreateTypedSelector(sel);
types = sel_get_type(sel);
}
return [NSMethodSignature signatureWithObjCTypes:types];
}
static NSArray *selectors_from_list(struct objc_method_list *methods)
{
NSMutableArray *array = [NSMutableArray array];
int count = methods->method_count;
int i;
for(i=0;i<count;i++)
{
[array addObject:NSStringFromSelector(methods->method_list[i].method_name)];
}
if(methods->method_next)
{
[array addObjectsFromArray:selectors_from_list(methods->method_next)];
}
return array;
}
NSArray *STAllObjectiveCSelectors(void)
{
NSMutableArray *array;
NSArray *methods;
Class class;
void *state = NULL;
array = [[NSMutableArray alloc] init];
while( (class = objc_next_class(&state)) )
{
if(class->methods)
{
methods = selectors_from_list(class->methods);
[array addObjectsFromArray:methods];
}
class = class->class_pointer;
if(class->methods)
{
methods = selectors_from_list(class->methods);
[array addObjectsFromArray:methods];
}
}
/* get rid of duplicates */
array = (NSMutableArray *)[[NSSet setWithArray:(NSArray *)array] allObjects];
array = (NSMutableArray *)[array sortedArrayUsingSelector:@selector(compare:)];
return array;
}

View file

@ -0,0 +1,50 @@
/**
STObjectReference.h
Reference to object in NSDictionary.
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of StepTalk.
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
*/
#import <Foundation/NSObject.h>
@class NSString;
@class NSMutableDictionary;
@interface STObjectReference:NSObject
{
NSString *key;
NSMutableDictionary *pool;
}
- initWithObjectName:(NSString *)name
pool:(NSMutableDictionary *)aPool;
- (void)setObject:anObject;
- object;
- (NSString *)objectName;
- (void)setObjectName:(NSString *)newName;
- (NSMutableDictionary *) pool;
- (void)setPool:(NSMutableDictionary *) aDict;
@end

View file

@ -0,0 +1,90 @@
/**
STObjectReference.m
Reference to object in NSDictionary.
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of StepTalk.
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
*/
#import <StepTalk/STObjectReference.h>
#import <StepTalk/STExterns.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
@implementation STObjectReference
- initWithObjectName:(NSString *)name pool:(NSMutableDictionary *)aPool
{
self = [super init];
key = RETAIN(name);
pool = RETAIN(aPool);
return self;
}
- (void)dealloc
{
RELEASE(key);
RELEASE(pool);
[super dealloc];
}
- (void)setObject:anObject
{
if(anObject)
{
[pool setObject:anObject forKey:key];
}
else
{
[pool setObject:STNil forKey:key];
}
}
- object
{
return [pool objectForKey:key];
}
- (NSString *)objectName
{
return key;
}
- (void)setObjectName:(NSString *)newName
{
ASSIGN(key,newName);
}
- (NSMutableDictionary *) pool
{
return pool;
}
- (void)setPool:(NSMutableDictionary *) aDict
{
ASSIGN(pool,aDict);
}
@end

View file

@ -0,0 +1,47 @@
/**
STScript
Copyright (c) 2002 Stefan Urbanek
Written by: Stefan Urbanek <stefanurbanek@yahoo.fr>
Date: 2002 Mar 10
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
*/
#import <Foundation/NSObject.h>
@interface STScript:NSObject
{
NSString *fileName;
NSString *localizedName;
NSString *menuKey;
NSString *description;
NSString *language;
}
+ scriptWithFile:(NSString *)file;
- initWithFile:(NSString *)aFile;
- (NSString *)fileName;
- (NSString *)source;
- (NSString *)scriptName;
- (NSString *)localizedName;
- (NSString *)scriptDescription;
- (NSString *)language;
- (NSComparisonResult)compareByLocalizedName:(STScript *)aScript;
@end

View file

@ -0,0 +1,186 @@
/**
STScript
Copyright (c) 2002 Stefan Urbanek
Written by: Stefan Urbanek <stefanurbanek@yahoo.fr>
Date: 2002 Mar 10
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
*/
#import <StepTalk/STScript.h>
#import <StepTalk/STLanguage.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSUserDefaults.h>
@interface NSDictionary(LocalizedKey)
- (id)localizedObjectForKey:(NSString *)key;
@end
@implementation NSDictionary(LocalizedKey)
- (id)localizedObjectForKey:(NSString *)key
{
NSEnumerator *enumerator;
NSDictionary *dict;;
NSString *language;
NSArray *languages;
id obj = nil;
languages = [NSUserDefaults userLanguages];
enumerator = [languages objectEnumerator];
while( (language = [enumerator nextObject]) )
{
dict = [self objectForKey:language];
obj = [dict objectForKey:key];
if(obj)
{
return obj;
}
}
return [[self objectForKey:@"Default"] objectForKey:key];
}
@end
@implementation STScript
+ scriptWithFile:(NSString *)file
{
STScript *script;
script = [[STScript alloc] initWithFile:file];
return AUTORELEASE(script);
}
/**
Create a new script from file <var>aFile></var>. Script information will
be read from 'aFile.stinfo' file containing a dictionary property list.
*/
- initWithFile:(NSString *)aFile
{
NSFileManager *manager = [NSFileManager defaultManager];
NSDictionary *info = nil;
NSString *infoFile;
BOOL isDir;
// infoFile = [aFile stringByDeletingPathExtension];
infoFile = [aFile stringByAppendingPathExtension: @"stinfo"];
if([manager fileExistsAtPath:infoFile isDirectory:&isDir] && !isDir )
{
info = [NSDictionary dictionaryWithContentsOfFile:infoFile];
}
self = [super init];
fileName = RETAIN(aFile);
localizedName = [info localizedObjectForKey:@"Name"];
if(!localizedName)
{
localizedName = [[fileName lastPathComponent]
stringByDeletingPathExtension];
}
RETAIN(localizedName);
menuKey = RETAIN([info localizedObjectForKey:@"MenuKey"]);
description = RETAIN([info localizedObjectForKey:@"Description"]);
language = [info localizedObjectForKey:@"Language"];
if(!language)
{
language = [STLanguage languageNameForFileType:[fileName pathExtension]];
}
if(!language)
{
language = @"Unknown";
}
RETAIN(language);
return self;
}
- (void)dealloc
{
RELEASE(fileName);
RELEASE(localizedName);
RELEASE(menuKey);
RELEASE(description);
RELEASE(language);
[super dealloc];
}
/** Return file name of the receiver. */
- (NSString *)fileName
{
return fileName;
}
/** Return menu item key equivalent for receiver. */
- (NSString *)menuKey
{
return menuKey;
}
/** Returns source string of the receiver script.*/
- (NSString *)source
{
return [NSString stringWithContentsOfFile:fileName];
}
/** Returns a script name by which the script is identified */
- (NSString *)scriptName
{
return fileName;
}
/** Returns localized name of the receiver script. */
- (NSString *)localizedName
{
return localizedName;
}
/** Returns localized description of the script. */
- (NSString *)scriptDescription
{
return description;
}
/** Returns language of the script. */
- (NSString *)language
{
return language;
}
/** Compare scripts by localized name. */
- (NSComparisonResult)compareByLocalizedName:(STScript *)aScript
{
return [localizedName caseInsensitiveCompare:[aScript localizedName]];
}
@end

View file

@ -0,0 +1,28 @@
/* 2003 Aug 5 */
#import <Foundation/NSObject.h>
@class NSMutableDictionary;
@class NSDictionary;
@class NSArray;
@class STMethod;
@interface STScriptObject:NSObject
{
NSMutableDictionary *ivars;
NSMutableDictionary *methods;
}
- initWithInstanceVariableNames:(NSString *)names;
- (void)setObject:(id)anObject forVariable:(NSString *)aName;
- (id)objectForVariable:(NSString *)aName;
- (NSArray *)instanceVariableNames;
- (void)addMethod:(STMethod *)aMethod;
- (STMethod *)methodWithName:(NSString *)aName;
- (void)removeMethod:(STMethod *)aMethod;
- (void)removeMethodWithName:(NSString *)aName;
- (NSArray *)methodNames;
- (NSDictionary *)methodDictionary;
@end

View file

@ -0,0 +1,59 @@
/* 2003 Aug 5 */
#import "StepTalk/STScriptObject.h"
@implementation STScriptObject
- initWithInstanceVariableNames:(NSString *)names
{
self = [super init];
methods = [[NSMutableDictionary alloc] init];
return self;
}
- (void)dealloc
{
RELEASE(methods);
RELEASE(ivars);
[super dealloc];
}
- (void)setObject:(id)anObject forVariable:(NSString *)aName
{
[self _notImplemented:_cmd];
}
- (id)objectForVariable:(NSString *)aName
{
[self _notImplemented:_cmd];
}
- (NSArray *)instanceVariableNames
{
[self _notImplemented:_cmd];
}
- (void)addMethod:(STMethod *)aMethod
{
[methods setObject:aMethod forKey:[aMethod methodName]];
}
- (STMethod *)methodWithName:(NSString *)aName
{
return [methods objectForKey:aName];
}
- (void)removeMethod:(STMethod *)aMethod
{
[self _notImplemented:_cmd];
}
- (void)removeMethodWithName:(NSString *)aName
{
[methods removeObjectForKey:aName];
}
- (NSArray *)methodNames
{
return [methods allKeys];
}
- (NSDictionary *)methodDictionary
{
return [NSDictionary dictionaryWithDictionary:methods];
}
@end

View file

@ -0,0 +1,43 @@
/**
STScripting.h
Scripting protocol
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <Foundation/NSObject.h>
@class STEnvironment;
@protocol STScripting
- (BOOL)isClass;
+ (BOOL)isClass;
- (NSString *)className;
+ (NSString *)className;
- (Class) classForScripting;
+ (Class) classForScripting;
@end
@interface NSObject (STScripting) <STScripting>
@end

View file

@ -0,0 +1,66 @@
/**
STScripting.m
Scripting protocol
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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>STScripting protocol documentation</title>
*/
#import <StepTalk/STScripting.h>
@implementation NSObject (STScripting)
/*
- (id)replacementForScriptingInEnvironment:(STEnvironment *)env
{
return self;
}
*/
- (BOOL)isClass
{
return NO;
}
+ (BOOL)isClass
{
return YES;
}
+ (NSString *)className
{
return NSStringFromClass(self);
}
- (NSString *)className
{
return [[self class] className];
}
/*Subclasses should override this method to force use of another class */
- (Class) classForScripting
{
return [self class];
}
+ (Class) classForScripting
{
return [self class];
}
@end

View file

@ -0,0 +1,51 @@
/**
STScriptsManager
Copyright (c)2002 Stefan Urbanek
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2002 Mar 10
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
*/
#import <Foundation/NSObject.h>
@class NSArray;
@class STScript;
@interface STScriptsManager:NSObject
{
NSString *scriptsDomainName;
NSArray *scriptSearchPaths;
}
+ defaultManager;
- initWithDomainName:(NSString *)name;
- (NSString *)scriptsDomainName;
- (void)setScriptSearchPathsToDefaults;
- (NSArray *)scriptSearchPaths;
- (void)setScriptSearchPaths:(NSArray *)anArray;
- (NSArray *)validScriptSearchPaths;
- (STScript *)scriptWithName:(NSString*)aString;
- (NSArray *)allScripts;
@end

View file

@ -0,0 +1,294 @@
/**
STScriptsManager
Copyright (c)2002 Stefan Urbanek
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2002 Mar 10
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
*/
#import <StepTalk/STScriptsManager.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STLanguage.h>
#import <StepTalk/STScript.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
static STScriptsManager *sharedScriptsManager = nil;
@interface STScriptsManager (STPriavteMethods)
- (NSArray *)_scriptsAtPath:(NSString *)path;
@end
@implementation STScriptsManager
/** Return default domain name for scripts. Usually this is application or
process name.*/
+ (NSString *)defaultScriptsDomainName
{
return [[NSProcessInfo processInfo] processName];
}
/** Returns default scripts manager for current process (application or tool). */
+ defaultManager
{
if(!sharedScriptsManager)
{
sharedScriptsManager = [[STScriptsManager alloc] init];
}
return sharedScriptsManager;
}
- init
{
return [self initWithDomainName:nil];
}
/**
Initializes the receiver to be used with domain named <var>name</var>.
If <var>name</var> is nil, default scripts domain name will be used.
<init />
*/
- initWithDomainName:(NSString *)name
{
self = [super init];
if(!name)
{
name = [STScriptsManager defaultScriptsDomainName];
}
scriptsDomainName = RETAIN(name);
return self;
}
- (void)dealloc
{
RELEASE(scriptsDomainName);
[super dealloc];
}
/** Return name of script manager domain. */
- (NSString *)scriptsDomainName
{
return scriptsDomainName;
}
/* Sets script search paths to defaults. Default paths are (in this order):
<gnustep library paths>/StepTalk/Scripts/<domain name>.
<gnustep library paths>/StepTalk/Scripts/Shared and
paths to Resource/Scripts in all loaded bundles including the main bundle.*/
- (void)setScriptSearchPathsToDefaults
{
NSMutableArray *scriptPaths = [NSMutableArray array];
NSEnumerator *enumerator;
NSString *path;
NSString *str;
NSArray *paths;
NSBundle *bundle;
paths = NSStandardLibraryPaths();
enumerator = [paths objectEnumerator];
while( (path = [enumerator nextObject]) )
{
path = [path stringByAppendingPathComponent:STLibraryDirectory];
path = [path stringByAppendingPathComponent:@"Scripts"];
str = [path stringByAppendingPathComponent: scriptsDomainName];
[scriptPaths addObject:str];
str = [path stringByAppendingPathComponent:@"Shared"];
[scriptPaths addObject:str];
}
enumerator = [[NSBundle allBundles] objectEnumerator];
while( (bundle = [enumerator nextObject]) )
{
path = [bundle resourcePath];
path = [path stringByAppendingPathComponent:@"Scripts"];
[scriptPaths addObject:path];
}
RELEASE(scriptSearchPaths);
scriptSearchPaths = [[NSArray alloc] initWithArray:scriptPaths];
}
/**
Retrun an array of script search paths. Scripts are searched
in Library/StepTalk/Scripts/<var>scriptsDomainName</var>,
Library/StepTalk/Scripts/Shared and in all loaded bundles in
<var>bundlePath</var>/Resources/Scripts.
*/
- (NSArray *)scriptSearchPaths
{
if(!scriptSearchPaths)
{
[self setScriptSearchPathsToDefaults];
}
return scriptSearchPaths;
}
/** Set script search paths to <var>anArray</var>. */
- (void)setScriptSearchPaths:(NSArray *)anArray
{
ASSIGN(scriptSearchPaths, anArray);
}
/** Return script search paths that are valid. That means that path exists and
is a directory. */
- (NSArray *)validScriptSearchPaths
{
NSMutableArray *scriptPaths = [NSMutableArray array];
NSFileManager *manager = [NSFileManager defaultManager];
NSEnumerator *enumerator;
NSString *path;
NSArray *paths;
BOOL isDir;
paths = [self scriptSearchPaths];
enumerator = [paths objectEnumerator];
while( (path = [enumerator nextObject]) )
{
if( [manager fileExistsAtPath:path isDirectory:&isDir] && isDir )
{
[scriptPaths addObject:path];
}
}
return [NSArray arrayWithArray:scriptPaths];
}
/**
Get a script with name <var>aString</var> for current scripting domain.
*/
- (STScript *)scriptWithName:(NSString*)aString
{
NSFileManager *manager = [NSFileManager defaultManager];
NSEnumerator *pEnumerator;
NSEnumerator *sEnumerator;
NSString *path;
NSString *file;
NSString *str;
NSArray *paths;
paths = [self validScriptSearchPaths];
pEnumerator = [paths objectEnumerator];
while( (path = [pEnumerator nextObject]) )
{
sEnumerator = [[manager directoryContentsAtPath:path] objectEnumerator];
while( (file = [sEnumerator nextObject]) )
{
if( ! [[file pathExtension] isEqualToString:@"stinfo"] )
{
NSDebugLLog(@"STScriptManager", @"Script %@", file);
str = [file lastPathComponent];
str = [str stringByDeletingPathExtension];
if([str isEqualToString:aString])
{
return [STScript scriptWithFile:
[path stringByAppendingPathComponent:file]];
}
}
}
}
return nil;
}
- (NSArray *)_scriptsAtPath:(NSString *)path
{
NSMutableArray *scripts = [NSMutableArray array];
NSFileManager *manager = [NSFileManager defaultManager];
NSEnumerator *enumerator;
NSString *file;
NSString *str;
NSString *ext;
NSArray *paths;
NSSet *types;
types = [NSSet setWithArray:[STLanguage allKnownFileTypes]];
enumerator = [[manager directoryContentsAtPath:path] objectEnumerator];
while( (file = [enumerator nextObject]) )
{
ext = [file pathExtension];
if( [types containsObject:ext] )
{
STScript *script;
NSLog(@"Found script %@", file);
script = [STScript scriptWithFile:
[path stringByAppendingPathComponent:file]];
[scripts addObject:script];
}
}
return [NSArray arrayWithArray:scripts];
}
/** Return list of all scripts for managed domain. */
- (NSArray *)allScripts
{
NSMutableArray *scripts = [NSMutableArray array];
NSEnumerator *enumerator;
NSString *path;
enumerator = [[self validScriptSearchPaths] objectEnumerator];
while( (path = [enumerator nextObject]) )
{
[scripts addObjectsFromArray:[self _scriptsAtPath:path]];
}
return [NSArray arrayWithArray:scripts];
}
@end

View file

@ -0,0 +1,38 @@
/*
STSelector
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2002 Feb 4
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
*/
#import <Foundation/NSObject.h>
@interface STSelector:NSObject
{
SEL sel;
}
- initWithSelector:(SEL)aSel;
- (SEL)selectorValue;
- (NSString *)stringValue;
@end

View file

@ -0,0 +1,51 @@
/*
STSelector
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2002 Feb 4
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
*/
#import <StepTalk/STSelector.h>
@implementation STSelector
- initWithSelector:(SEL)aSel
{
[super init];
sel = aSel;
return self;
}
- (SEL)selectorValue
{
return sel;
}
- (NSString *)description
{
return NSStringFromSelector(sel);
}
- (NSString *)stringValue
{
return NSStringFromSelector(sel);
}
@end

View file

@ -0,0 +1,90 @@
/**
STStructure.h
C structure wrapper
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of StepTalk.
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
*/
#import <Foundation/NSObject.h>
#import <Foundation/NSGeometry.h>
#import <Foundation/NSRange.h>
// @class STRange;
// @class STPoint;
// @class STRect;
@class NSString;
@class NSMutableArray;
@interface STStructure:NSObject
{
NSString *structType;
NSString *name;
NSMutableArray *fields;
}
+ structureWithValue:(void *)value type:(const char*)type;
+ structureWithRange:(NSRange)range;
+ structureWithPoint:(NSPoint)point;
+ structureWithRect:(NSRect)rect;
+ structureWithSize:(NSSize)size;
- initWithValue:(void *)value type:(const char*)type;
- (const char *)type;
- (NSString *)structureName;
- (void)getValue:(void *)value;
- (NSRange)rangeValue;
- (NSPoint)pointValue;
- (NSRect)rectValue;
- (NSSize)sizeValue;
- valueAtIndex:(unsigned)index;
- (void)setValue:anObject atIndex:(unsigned)index;
- (int)intValueAtIndex:(unsigned)index;
- (float)floatValueAtIndex:(unsigned)index;
@end
/*
@interface STRange:STStructure
- rangeWithLocation:(int)loc length:(int)length;
- (int)location;
- (int)length;
@end
@interface STPoint:STStructure
- pointWithX:(float)x y:(float)y;
- (float)x;
- (float)y;
@end
@interface STRect:STStructure
- rectWithX:(float)x y:(float)y width:(float)w heigth:(float)h;
- rectWithOrigin:(NSPoint)origin size:(NSPoint)size;
- (float)x;
- (float)y;
- (float)width;
- (float)height;
- (NSPoint)origin;
- (NSPoint)size;
@end
*/

View file

@ -0,0 +1,309 @@
/**
STStructure.m
C structure wrapper
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of StepTalk.
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
*/
#import <StepTalk/STStructure.h>
#import <StepTalk/STExterns.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSDebug.h>
#import <StepTalk/NSInvocation+additions.h>
@implementation STStructure
+ structureWithValue:(void *)value type:(const char*)type
{
STStructure *str;
str = [[self alloc] initWithValue:value type:type];
return AUTORELEASE(str);
}
+ structureWithRange:(NSRange)range
{
STStructure *str;
str = [[self alloc] initWithValue:&range type:@encode(NSRange)];
return AUTORELEASE(str);
}
+ structureWithPoint:(NSPoint)point
{
STStructure *str;
str = [[self alloc] initWithValue:&point type:@encode(NSPoint)];
return AUTORELEASE(str);
}
+ structureWithSize:(NSSize)size
{
STStructure *str;
str = [[self alloc] initWithValue:&size type:@encode(NSSize)];
return AUTORELEASE(str);
}
+ structureWithRect:(NSRect)rect
{
STStructure *str;
str = [[self alloc] initWithValue:&rect type:@encode(NSRect)];
return AUTORELEASE(str);
}
- initWithValue:(void *)value type:(const char*)type
{
const char *nameBeg;
int offset = 0;
int align;
int rem;
self = [super init];
NSDebugLLog(@"STStructure",
@"creating structure of type '%s' value ptr %p",type,value);
structType = [[NSString alloc] initWithCString:type];
fields = [[NSMutableArray alloc] init];
type++;
nameBeg = type;
while (*type != _C_STRUCT_E && *type++ != '=');
name = [[NSString alloc] initWithCString:nameBeg length:type-nameBeg];
while(*type != _C_STRUCT_E)
{
[fields addObject:STObjectFromValueOfType(((char *)value)+offset,type)];
offset += objc_sizeof_type(type);
type = objc_skip_typespec(type);
if(*type == _C_STRUCT_E)
{
break;
}
align = objc_alignof_type(type);
rem = offset % align;
if(rem != 0)
{
offset += align - rem;
}
}
return self;
}
- (void)dealloc
{
RELEASE(fields);
RELEASE(structType);
RELEASE(name);
[super dealloc];
}
- (void)getValue:(void *)value
{
const char *type = [structType cString];
int offset=0;
int align;
int rem;
int i = 0;
type++;
while (*type != _C_STRUCT_E && *type++ != '=');
while(*type != _C_STRUCT_E)
{
STGetValueOfTypeFromObject((void *)((char*)value+offset),
type,
[fields objectAtIndex:i++]);
offset += objc_sizeof_type(type);
type = objc_skip_typespec(type);
if(*type == _C_STRUCT_E)
{
break;
}
align = objc_alignof_type(type);
rem = offset % align;
if(rem != 0)
{
offset += align - rem;
}
}
}
- (const char *)type
{
return [structType cString];
}
- (NSString *)structureName
{
return name;
}
- (const char *)typeOfFieldAtIndex:(unsigned)index
{
const char *type = [structType cString];
for(type += 1; *type != _C_STRUCT_E && index>0; index--)
{
type = objc_skip_argspec(type);
}
if(*type == _C_STRUCT_E)
{
[NSException raise:STInternalInconsistencyException
format:@"invalid structure field index"];
return 0;
}
return type;
}
- (NSRange)rangeValue
{
/* FIXME: do some checking */
return NSMakeRange([self intValueAtIndex:0],[self intValueAtIndex:1]);
}
- (NSPoint)pointValue
{
/* FIXME: do some checking */
return NSMakePoint([self floatValueAtIndex:0],[self floatValueAtIndex:1]);
}
- (NSSize)sizeValue
{
/* FIXME: do some checking */
return NSMakeSize([self floatValueAtIndex:0],[self floatValueAtIndex:1]);
}
- (NSRect)rectValue
{
NSPoint origin = [[fields objectAtIndex:0] pointValue];
NSSize size = [[fields objectAtIndex:1] sizeValue];
NSRect rect;
/* FIXME: do some checking */
rect.origin = origin;
rect.size = size;
return rect;
}
- valueAtIndex:(unsigned)index
{
return [fields objectAtIndex:index];
}
- (void)setValue:anObject atIndex:(unsigned)index
{
[fields replaceObjectAtIndex:index withObject:anObject];
}
- (int)intValueAtIndex:(unsigned)index
{
return (int)[[fields objectAtIndex:index] intValue];
}
- (float)floatValueAtIndex:(unsigned)index
{
return (float)[[fields objectAtIndex:index] floatValue];
}
/* NSRange */
- (int)location
{
return [[fields objectAtIndex:0] intValue];
}
- (int)length
{
return [[fields objectAtIndex:1] intValue];
}
- (void)setLocation:(int)location
{
[fields replaceObjectAtIndex:0 withObject: [NSNumber numberWithInt:location]];
}
- (void)setLength:(int)length
{
[fields replaceObjectAtIndex:1 withObject: [NSNumber numberWithInt:length]];
}
/* NSPoint */
- (float)x
{
return [[fields objectAtIndex:0] floatValue];
}
- (void)setX:(float)x
{
[fields replaceObjectAtIndex:0 withObject: [NSNumber numberWithFloat:x]];
}
- (float)y
{
return [[fields objectAtIndex:1] floatValue];
}
- (void)setY:(float)y
{
[fields replaceObjectAtIndex:1 withObject: [NSNumber numberWithFloat:y]];
}
/* NSSize */
- (float)width
{
return [[fields objectAtIndex:0] floatValue];
}
- (float)height
{
return [[fields objectAtIndex:1] floatValue];
}
- (void)setWidth:(float)width
{
[fields replaceObjectAtIndex:0 withObject: [NSNumber numberWithFloat:width]];
}
- (void)setHeight:(float)height
{
[fields replaceObjectAtIndex:1 withObject: [NSNumber numberWithFloat:height]];
}
/* NSRect */
- (id)origin
{
NSLog(@"Origin %@", [fields objectAtIndex:0]);
return [fields objectAtIndex:0];
}
- (id)size
{
NSLog(@"Size %@", [fields objectAtIndex:1]);
return [fields objectAtIndex:1] ;
}
@end

View file

@ -0,0 +1,31 @@
/**
STUndefinedObject.h
Wrapper for nil object
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
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
*/
#import <Foundation/NSObject.h>
#import <StepTalk/STScripting.h>
@interface STUndefinedObject:NSObject
@end

View file

@ -0,0 +1,101 @@
/**
STUndefinedObject.m
Wrapper for nil object
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <StepTalk/STUndefinedObject.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STObjCRuntime.h>
#import <Foundation/NSString.h>
STUndefinedObject *STNil = nil;
@implementation STUndefinedObject
+ (id) alloc
{
return STNil;
}
+ (id) allocWithZone: (NSZone*)z
{
return STNil;
}
+ (id) autorelease
{
return self;
}
- (void) dealloc
{
NSLog(@"Warning: Trying to dealloc STNil object");
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
NSMethodSignature *signature = nil;
signature = [super methodSignatureForSelector:sel];
if(!signature)
{
signature = STMethodSignatureForSelector(sel);
}
return signature;
}
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
/* this object is deaf */
}
- (BOOL) isEqual: (id)anObject
{
return ( (self == anObject) || (anObject == nil) );
}
- (void) release
{
/* do nothing */
}
- (id) retain
{
return self;
}
- (BOOL)isNil
{
return YES;
}
- (BOOL)notNil
{
return NO;
}
@end

View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 0.6.7//EN" "http://www.gnustep.org/gsdoc-0_6_7.xml">
<gsdoc base="StepTalk">
<head>
<title>StepTalk Documentation</title>
<author name="Stefan Urbanek">
<email address="urbanek@host.sk"/>
<url url="http://urbanek.host.sk"/>
</author>
<version>0.7.1</version>
<date>2003 Apr 22</date>
</head>
<body>
<chapter>
<heading>Introduction</heading>
<p>
StepTalk is a scripting framework for creating scriptable servers or
applications. StepTalk, when combined with the dynamism that the
Objective-C language provides, goes way beyond mere scripting. intro
</p>
</chapter>
<back>
<index scope="project" type="class" />
<index scope="project" type="protocol" />
</back>
</body>
</gsdoc>

View file

@ -0,0 +1,39 @@
/**
StepTalk.h
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2001 Nov 1
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
*/
#import <StepTalk/STEngine.h>
#import <StepTalk/STEnvironment.h>
#import <StepTalk/STExterns.h>
#import <StepTalk/STFunctions.h>
#import <StepTalk/STLanguage.h>
#import <StepTalk/STObjCRuntime.h>
#import <StepTalk/STObjectReference.h>
#import <StepTalk/STScript.h>
#import <StepTalk/STScripting.h>
#import <StepTalk/STScriptsManager.h>
#import <StepTalk/STUndefinedObject.h>
#import <StepTalk/NSInvocation+additions.h>

View file

@ -35,7 +35,7 @@ ifeq ($(appkit),no)
endif
SUBPROJECTS = \
Source \
Frameworks \
Languages \
Finders \
Modules \

View file

@ -65,8 +65,6 @@
- (void)returnValue:(id)value;
@end
static STBytecodeInterpreter *sharedInterpreter = nil;
static SEL sendSelectorAtIndexSel;
static IMP sendSelectorAtIndexImp;
static SEL pushSel;
@ -89,16 +87,17 @@ static Class NSInvocation_class = nil;
NSInvocation_class = [NSInvocation class];
}
+ (STBytecodeInterpreter *)sharedInterpreter
+ interpreterWithEnvrionment:(STEnvironment *)env
{
if(!sharedInterpreter)
{
sharedInterpreter = [[self alloc] init];
}
return sharedInterpreter;
return AUTORELEASE([[self alloc] initWithEnvironment:env]);
}
- initWithEnvironment:(STEnvironment *)env
{
self = [super init];
environment = RETAIN(env);
return self;
}
- (void)setEnvironment:(STEnvironment *)env
{
ASSIGN(environment,env);

View file

@ -22,9 +22,11 @@
#import "STCompiledCode.h"
#import <StepTalk/STMethod.h>
@class STMessage;
@interface STCompiledMethod:STCompiledCode
@interface STCompiledMethod:STCompiledCode<STMethod>
{
NSString *selector;
short argCount;

View file

@ -57,10 +57,6 @@ typedef struct _STParserContext
/*" Get source reader from parser context "*/
#define STParserContextGetReader(context)\
(((STParserContext *)context)->reader)
#define STParserContextGetResult(context)\
(((STParserContext *)context)->result)
#define STParserContextSetResult(context, c)\
( ASSIGN(((STParserContext *)(context))->result, (c)) )
/*" Initialize parser context "*/
#define STParserContextInit(context,aCompiler,aReader) \
@ -76,13 +72,16 @@ typedef struct _STParserContext
STSourceReader *reader;
STParserContext context;
STCompiledScript *resultScript;
STCompiledMethod *resultMethod;
NSMutableData *byteCodes;
NSMutableArray *tempVars;
NSMutableArray *externVars;
NSMutableArray *receiverVars;
NSMutableArray *literals;
STCompiledScript *script;
BOOL isSingleMethod;
unsigned stackSize; /* Required stack size */
unsigned stackPos; /* Current stack pointer */
@ -97,6 +96,8 @@ typedef struct _STParserContext
Class realNumberLiteralClass; /* default: NSNumber */
Class symbolLiteralClass; /* default: NSString */
}
+ compilerWithEnvironment:(STEnvironment *)env;
- initWithEnvironment:(STEnvironment *)env;
/*" Environment "*/
- (void)setEnvironment:(STEnvironment *)env;
- (STSourceReader *)sourceReader;

View file

@ -47,6 +47,31 @@
extern int STCparse(void *context);
/* FIXME: rewrite parser
We need three kinds of grammars:
1. <source> = <statements> | <temp_variables> <statements>
2. <source> = '[|' <method_list> ']'
<method_list> = <method> | <method> '!' <method_list>
<method> = <statements> | <temp_variables> <statements>
3. <source> = <method>
<method> = <statements> | <temp_variables> <statements>
Parser 1. are 2. are for scripts. Parser 3. is for script object
methods. Because majority of the grammar is reused in all three
parsers we use only one grammar definition. There is no problem
in haveng 1. and 2. in one file. To be able to have 3. in the same
file we do a hack: we add a prefix '!!' for method source. Then
we diferentiate it in grammar file by changin the rule:
3. <source> = '!' '!' <method>
See STGrammar.y
*/
@interface STCompiler(STCompilerPrivate)
- (void)compile;
- (void)initializeContext;
@ -94,6 +119,17 @@ extern int STCparse(void *context);
#define MAX(a,b) (((a)>(b))?(a):(b))
@implementation STCompiler
+ compilerWithEnvironment:(STEnvironment *)env
{
return AUTORELEASE([[self alloc] initWithEnvironment:env]);
}
- initWithEnvironment:(STEnvironment *)env
{
self = [self init];
[self setEnvironment:env];
return self;
}
- init
{
[super init];
@ -113,7 +149,20 @@ extern int STCparse(void *context);
[super dealloc];
}
- (BOOL)beginScript
{
if(isSingleMethod)
{
[NSException raise:@"STCompilerException"
format:@"Script source given for single method"];
return NO;
}
else
{
return YES;
}
}
/* ---------------------------------------------------------------------------
* Compilation
* ---------------------------------------------------------------------------
@ -124,6 +173,74 @@ extern int STCparse(void *context);
ASSIGN(environment,env);
}
- (STCompiledMethod *)compileMethodFromSource:(NSString *)aString
forReceiver:(id)receiver
{
STCompiledMethod *result;
NSString *hackedSource;
NSString *exceptionFmt = @"Syntax error at line %i near '%@', "
@"reason: %@.";
int parsRetval = 0;
// NSDebugLLog(@"STCompiler", @"Compile method", aString);
NSLog(@"Compile method");
if(!environment)
{
[NSException raise:STCompilerGenericException
format:@"Compilation environment is not initialized"];
return nil;
}
hackedSource = [@"!!" stringByAppendingString:aString];
reader = [[STSourceReader alloc] initWithString:hackedSource];
receiverVars = [[NSArray alloc]
initWithArray:[receiver instanceVariableNames]];
isSingleMethod = YES;
STParserContextInit(&context,self,reader);
NS_DURING
{
// extern int STCdebug;
// STCdebug = 1;
parsRetval = STCparse(&context);
}
NS_HANDLER
{
if ([[localException name] isEqualToString: STCompilerSyntaxException])
{
NSString *tokenString;
int line;
tokenString = [reader tokenString];
line = [reader currentLine];
RELEASE(reader);
RELEASE(receiverVars);
receiverVars = nil;
reader = nil;
[NSException raise:STCompilerSyntaxException
format:exceptionFmt,
line,
tokenString,
[localException reason]];
}
[localException raise];
}
NS_ENDHANDLER
RELEASE(receiverVars);
RELEASE(reader);
result = AUTORELEASE(resultMethod);
resultMethod = nil;
return result;
}
- (STCompiledScript *)compileString:(NSString *)aString
{
@ -135,6 +252,8 @@ extern int STCparse(void *context);
NSDebugLLog(@"STCompiler", @"Compile string", aString);
isSingleMethod = NO;
if(!environment)
{
[NSException raise:STCompilerGenericException
@ -182,10 +301,10 @@ extern int STCparse(void *context);
RELEASE(receiverVars);
RELEASE(reader);
result = script;
script = nil;
result = AUTORELEASE(resultScript);
resultScript = nil;
return AUTORELEASE(result);
return result;
}
- (void)compileMethod:(STCMethod *)method
@ -194,15 +313,6 @@ extern int STCparse(void *context);
STCompiledCode *code;
STMessage *messagePattern;
if(!script)
{
NSDebugLLog(@"STCompiler",
@"Creating script with %i variables",[receiverVars count]);
script = [[STCompiledScript alloc] initWithVariableCount:
[receiverVars count]];
}
/* FIXME: unite STCMessage and STMessage */
messagePattern = (STMessage *)[method messagePattern];
@ -221,7 +331,41 @@ extern int STCparse(void *context);
compiledMethod = [STCompiledMethod methodWithCode:AUTORELEASE(code)
messagePattern:messagePattern];
[script addMethod:compiledMethod];
if(!isSingleMethod)
{
if(resultMethod)
{
[NSException raise:@"STCompilerException"
format:@"Method is present when compiling a script"];
return;
}
if(!resultScript)
{
NSDebugLLog(@"STCompiler",
@"Creating script with %i variables",[receiverVars count]);
resultScript = [[STCompiledScript alloc] initWithVariableCount:
[receiverVars count]];
}
[resultScript addMethod:compiledMethod];
}
else
{
if(resultMethod)
{
[NSException raise:@"STCompilerException"
format:@"More than one method compiled for single method request"];
return;
}
if(resultScript)
{
[NSException raise:@"STCompilerException"
format:@"Compiled script is present when compiling single method"];
return;
}
resultMethod = RETAIN(compiledMethod);
}
}
- (STCompiledCode *)compileStatements:(STCStatements *)statements

File diff suppressed because it is too large Load diff

View file

@ -71,17 +71,26 @@ source: /* empty string */ {
}
| single_method {
| plain_code {
[COMPILER compileMethod:$1];
}
/* FIXME: this is a hack */
| TK_SEPARATOR TK_SEPARATOR method
{
[COMPILER compileMethod:$1];
}
|
TK_BLOCK_OPEN TK_BAR
{
[COMPILER beginScript];
}
methods
TK_BLOCK_CLOSE
;
single_method: statements
plain_code: statements
{
$$ = [STCMethod methodWithPattern:nil
/**/ statements:$1];

View file

@ -128,8 +128,7 @@
NSDebugLLog(@"STEngine",
@"creating new interpreter for script '%@'",
name);
interpreter = [[STBytecodeInterpreter alloc] init];
[interpreter setEnvironment:environment];
interpreter = [[STBytecodeInterpreter alloc] initWithEnvironment:environment];
}

View file

@ -29,8 +29,10 @@
#import "STCompiler.h"
#import "STCompiledCode.h"
#import "STCompiledScript.h"
#import "STBytecodeInterpreter.h"
#import <StepTalk/STEnvironment.h>
#import <StepTalk/STMethod.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSException.h>
@ -77,4 +79,33 @@
return retval;
}
- (id <STMethod>)methodFromSource:(NSString *)sourceString
forReceiver:(id)receiver
inEnvironment:(STEnvironment *)env
{
STCompiler *compiler;
STCompiledMethod *method;
compiler = [STCompiler compilerWithEnvironment:env];
method = [compiler compileMethodFromSource:sourceString
forReceiver:receiver];
return method;
}
- (id) executeMethod:(id <STMethod>)aMethod
forReceiver:(id)anObject
withArguments:(NSArray *)args
inEnvironment:(STEnvironment *)env
{
STBytecodeInterpreter *interpreter;
id result;
interpreter = [STBytecodeInterpreter interpreterWithEnvrionment:env];
result = [interpreter interpretMethod:aMethod
forReceiver:anObject
arguments:args];
return result;
}
@end

View file

@ -1,7 +0,0 @@
*.app
*.debug
*.profile
shared_*obj
*.bundle
*.stmodule
*.stlanguage

2
TODO
View file

@ -13,3 +13,5 @@ TODO list
14 Add framework list into environment description
15 Change Modules to Framework
16 Remove StepTalk modules
17 Fill implementation of STScriptObject, STMethod and related STEngine methods
18 Rewrite Smalltalk compiler (grammar)