Script objects
Jump to navigation
Jump to search
Script object looks like ordinary object. However, it's behaviour is described by small scripts - methods written in some scripting language.
They can be used for:
- Custom application objects
- Event and notiication handlers
- Objects in servers with customisable behaviour
- ...
NOTE: See TODO list at the end of this page.
Using script objects
Just send it a message as to any other object:
[object sayHi];
Creating script objetcs
object = [STScriptObject scriptObject]; [object setEnvironment:someScriptingEnvironment];
Adding methods
Create a source:
source = @"sayHi Transcript showLine: 'Hi.'. ^self".
or
source = [NSString stringWithContentsOfFile:@"SomeFile"];
Get the the proper engine for a language used in the source:
engine = [STEngine engineForLanguageWithName:@"Smalltalk"];
create a method:
method = [engine methodFromSource:source forReceiver:object inEnvironment:Environment];
and finally add the method to the object:
[object addMethod:method];
Methods with arguments
Well, no difference to any other methods. If you have source:
source = @"sayHiTo:someone Transcript showLine: ('Hi ', someone). ^self";
you can do:
[object sayHiTo:@"World"];
Script object interface
Script object understands following:
- addMethod:aMethod
- removeMethod:aMethod
- removeMethodWithName:aString
- methodWithName:aString
- methodNames
- respondsToSelector:aSelector
TODO
Here are unimplemented features of the Script Objects. Feel free to add them, if you have a bit of time. Please consult with the author of StepTalk and on the gnustep lists.
- object variables (this is high priority)
- inheritance of variables and methods (traits like in Self?)
- object archiving
- object cloning (copying)
- integration with scripting contexts
- script object builder application (it should be something simple)