Objective-Everything Release 5.  Copyright ©1994-1998 by TipTop Software, Inc.  All Rights Reserved.

  Objective-WebScript

See the WebScript documentation in /NextLibrary/Documentation/NextDev/WebObjects/WOPages/LocalDoc/DevGuide/WebScript for description of the WebScript language. In this section we describe some extensions to the vanilla WebScript language facilitated by Objective-WebScript.

ObjWebScript Interpreter

ObjWebScript introduces the concept of an interpreter to WebScript. The interpreter class is TTObjWebScriptInterp. There is only one, default interpreter instance. Inside WebScript code, this interpreter is accessible as the interp global variable. You can also obtain a reference to the interpreter by invoking [TTObjWebScriptInterp getDefaultInterp].

Class Autoloading

The ObjWebScript interpreter maintains a library path. If you reference a class classname which is not loaded, the system will search the library path for the file name classname.wos. If the file is found, the file will be executed. The file must define class with classname.

Example

Create file ~/Library/WebScript/AutoloadedClass.wos with the following content:

@interface AutoloadedClass:NSObject
{
  id foo;
}
@end

@implementation AutoloadedClass
- foo { return "autoloaded!"; }
@end

Run ObjShell.app. Open a WebScript interactor. Type:

wos% id x=[AutoloadedClass instantiate];
// NB: Method -instantiate is short for [[[class alloc] init] autorelease]
// Referencing the class, loaded the WebScript implementation!

// Now we can use it, e.g.:
wos% [x foo];
"autoloaded!"

[previous][contents][next]