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

 Quick Tour

1. Run ObjWebScript

In ObjShell: Double-click on ObjShell.app.  Click "Load WebScript", and then click "WebScript".

In a terminal window: Type objwebscript.

In InterfaceBuilder: Load ObjPalette.palette from /Local/Developer/Palettes/. Click Tools->Objective->Interactor->Interact and select WebScript to open an ObjWebScript interactor window.

All of the following examples are executed in InterfaceBuilder.

2. Invoke a C function

Type a function name followed by the arguments.  E.g., in an Interactor window, type:

wos% // Using the "classic syntax"
wos% [C NSRunAlertPanel:"Classic" _:"Hello World!" _:nil _:nil _:nil];

wos% // Using the "modern syntax":
wos% C.NSRunAlertPanel(_:="Modern", _:="Hello World!", _:=nil, _:=nil, _:=nil);

Note that string constants can be writen as either "string" or @"string", i.e., with or without the @ sign. In this documentation we omit @.

Note that due to the limitations of the WebScript parser, every argument has to be named. The argument name should be "_". If the function takes zero or one argument, you can invoke it by using the usual C syntax.

wos% [TTInterp cdefine:"double cos(double);" flags:0];
wos% C.cos(0);
1

Alternatively, if you turn the "TrustVaragFunctions" config ON, then you can use "vararg" messages to invoke functions. Note however that in this case ObjWebScript (due to WebScript limitations) cannot check whether the argument count passed matches the numer of arguments that the function expects. If you pass less arguments, you can crash the system. This is why this config value is OFF by default.

wos% [TTConfig takeValue:1 forKey:"TrustVarargFunctions"];
wos% [C NSRunAlertPanel:"Classic Vararg","Hello World!",nil,nil,nil];

3. Access a C global

To read a value, simply "call" it by name as a C function:

wos% C.NSApp();
<IB:0x...>
wos% [NSApplication sharedApplication]; // yields the same value
<IB:0x...>
wos% C.NSArgc()
1
wos% C.NSArgv()
<TTCDatum: ^[1*]@0...>
wos% C.NSArgv().fetch()
@(/NextDeveloper/Apps/InterfaceBuilder.app/InterfaceBuilder)

4. Send a message

Use WebScript syntax to send a message as described in the WebScript documentation. You can mix classic and modern message syntax.

wos% // Send message -printf: to interp
wos% interp.printString("Hello World!\n");
Hello World!
nil

wos% // Vararg messages can be only invoked using the classic syntax:
wos% [interp printf:"%@ and %@\n","Foo","Bar"];
Foo and Bar
nil

5. Extend a class

Use WebScript syntax to define a category as described in the WebScript documentation.

wos% @implementation NSObject(Foo)
%--> - foo { return "Bar"; }
%--> @end
wos% id x;
wos% x=[NSObject instantiate];
<NSObject:0x...>
wos% x.foo();
"Bar"

6. Define a class

Use WebScript syntax to define a class as described in the WebScript documentation.

wos% @interface Foo:NSObject
%--> {
%-->   id anIvar;
%--> }
%--> @end
%--> @implementation Foo
%--> - bar { return "Method -bar in class Foo"; }
%--> @end
Foo
wos% x=[Foo instantiate];
<Foo:0x...>
wos% [x bar];
"Method -bar in class Foo"

7. Extend an instance

Extending an instance is not supported directly via the WebScript syntax. .

8. Create a NIB file

Click Document->NewApplication.  Drag the ObjWebScript interpreter object from ObjPalette into the object suitcase. Drag a button into the window.  Ctrl-connect the button to the interpreter object, and select the newWInteractor: action.

Now, when you run the nib file by clicking Document->TestInterface, when you click the button, you will get an interactor window in which you can type commands to be executed by the interpreter.

9. Connect a global variable

Add another button into the window.  Ctrl-drag from the interpreter instance to this button.  Type "but" in the connections inspector.  Ctrl-drag from the interpreter instance to the "My Window" window title bar.  Type "win".

Run the interface (Cmd-r or click Document->TestInterface).  Hit the button which opens the interactor window. Type:

wos% but
<NSButton:0x...>
wos% [but setTitle:"Baz"]

Quit the TestInterface mode.  Close the nib file (save it if you like).

10. Use the Code object to implement simple actions

In this example we build a simple expression calculator which simply uses the -evalString: method to evaluate expressions.

Click Document->NewApplication.  Drag the TextField object into window "My Window".  Change it to look something like:

Drag the NibImplementation object from ObjPalette into the object suitcase.  Ctrl-Alt-drag from the code object to the result field.  Type "resultField".

In the implementation inspector, select WebScript.  The code object will then use the WebScript interpreter for evaluation.  Hit "+" and implement the action as follows:

- action:sender {
  id r;
  // Use the -evalString: method to evaluate any WebScript expression
  r=[[interp evalString:[sender stringValue]] objectValue];
  [[self valueForXVar:"resultField"] setStringValue:r];
}

Ctrl-drag from the "Expr:" field to the code object, and connect it to the "action:" action.
Test the interface:  Type "1+2" and hit Return.  Type "C.cos(.5)" and hit Return.

Close the nib file (save it if you like).

The Code object lets you implement interpreted action methods without having to implement a new class.  In general, the Code object is useful for implementing simple actions.

11. Define actions in interpreter startup code

Not supported in WebScript.

12. Extend an object to perform an action

Yet another way of implementing actions is to directly extend an instance with an action method.  In this example we implement the same calculator as in the previous example.

Create a window with the fields, like in the previous example.

Double-click on the "Expr:" field to select it.  Connect xvar "resultField" of the "Expr:" field to the "Result:" field: Ctrl-Alt-Drag from the "Expr:" filed to the "Result:" field, type "resultField", and hit Return.

Since we want to define an action for the "Expr:" field, double-click on the "Expr:" field to select it. In the Implementation inspector select "WOS", hit "+", and implement the action as follows:

- action:sender {
  id rfield, r;
  rfield=[self valueForXVar:"resultField"];
  r=[[interp evalString:[sender stringValue]] objectValue];
  [rfield setStringValue:r];
  [sender selectText:nil];
}

Note that there you should not use @interface and @implementation constructs. Just include your method definitions and optional instance variable declarations. This is similar to how you define WebObject components in WebScript.

Run and test the interface. It should behave exactly the same as the previous example.

13. Connect to a remote interpreter

In a terminal shell, type:

robjtclsh -i ObjWebScriptInterp 

This will give you access to the default ObjWebScript interpreter in InterfaceBuilder.  You can now issue any command to this interpreter; e.g., type: C.NSApp().showInfoPanel(nil)

To set a remote interpreter connection in InterfaceBuilder:  Drag an Interactor object from the ObjPalette into the object suitcase.  Drag a button into the window.  Connect a button to the interactor, so that it sends the "run:" message. In the attribute inspector for the interactor, click the Remote switch, so that it is ON, enter "IBInterp" into the connection field, enter "ObjWebScriptInterp" into the interpreter field, and hit return.   Now when you run the nib file, and hit the button, the interactor will connect to IB (itself)...

14. Run Objective-Browser

Click Objective->Browse->NSApp, and browse away!

15. Create a standalone application

Use ProjectBuilder to create an application project, and use InterfaceBuilder to create nib files.  Make sure that you link the application with ObjCore and ObjAppKit frameworks.  When you build and run the application, Objective-Everything will get initialized.

Note: Under Windows, you need to reference a symbol in each of the frameworks that you link with.  E.g., in YourApp_main.m, make sure you do:

 #import <ObjAppKit/ObjAppKit.h> 
 int main(int argc, const char *argv[]) { 
 { 
   [TTInterp class]; 
   [TTApplication class]; 
   return NSApplicationMain(argc, argv); 
 } 

See the "Using ProjectBuilder for how to include ObjTcl files in the project, how to manage and edit them using PB.

If you have a NIB file which you want to run as an application, you can simply run objtclsh, and type:

 appkit::run -nib /your/nib/file.nib 

16. Embed Objective-Everything into your application

Statically link your application with the ObjCore and ObjAppKit frameworks; or, dynamically load these frameworks:

 [[NSBundle bundleWithPath:@"/LocalLibrary/Frameworks/ObjAppKit.framework"] 
   principalClass]; 

To open an interactor window:

 [TTInterp newWInteractor:nil]; 

or, send the newWInteractor: message to the first responder, e.g., via a button, or a menu item.   This will give you a starting point for interactively issuing commands to your app...

17. Run an application with Objective-Everything preloaded

For example, to run Objective-Browser inside EOModeler:

objmeddle /System/Developer/Applications/EOModeller.app/EOModeler

You can now run an interactor from the Objective menu (in Tools), or run ObjBrowser, etc.

18. Read the documentation

Read the documents in the Concepts section of ObjCore to become familiar with the general Objective-Everything concepts.  Read other documents in this directory to get familiar with ObjWebScript.

Also, make sure that you look at the examples which are included in each Obj<Lang>.framework/Resources/Examples directory.


[previous][contents][next]