Copyright ©1998 by AAA+ Software Forschungs- und Entwicklungs Ges.m.b.H.  All Rights Reserved.

5 Linking Joy into non-Joy Applications





This section explains how you can link the Joy interpreter into your existing Objective-C or Java project.



Linking Joy to Sketch.app

To show how Joy can be linked into an existing project, we will reuse the Sketch.app example sources provided by Apple:

  1. Copy the directory %NEXT_ROOT%\Developer\Examples\Java\AppKit\Sketch to some other location, e.g. the desktop. %NEXT_ROOT% is the path of your Yellow Box installation (e.g. C:\Apple).
  2. Double click the project file PB.project in your copy of the Sketch sources.
  3. In ProjectBuilder, select the English folder in the Interfaces group. Double click the Draw2Java-windows.nib file.
  4. In InterfaceBuilder, bring up the palettes panel. Select the Joy palette. If you have not loaded Joy.palette into InterfaceBuilder, refer to section 1 of this tutorial.
  5. Drag a JavaScript interpreter object into the nib's document window.


    Figure 1: Sketch's main nib-File with a JavaScript interpreter added.

  6. Double click the MainMenu icon in the nib's document window. The application's menu comes up.  Click on its Tools menu. Go back to the palettes panel and select the Menus palette. Drag a new menu item from the palette into the Tools menu and name it Joy.


    Figure 2: Sketch's menu with a Joy menu item added to the Tools menu.

  7. Ctrl-Drag a connection from the Joy menu item to the Interpreter icon in the nib's document window. Double click the showCommandWindow: action in the Connections inspector.
  8. Save the nib-File.
  9. Back in ProjectBuilder select the Frameworks group. Select the Add Files... item in the Project menu. In the open panel, select the itkJavaScript.framework in the directory %NEXT_ROOT%\Local\Library\Frameworks. Repeat this for itkTcl.framework and itkRuntime.framework.  Bring up the project inspector by selecting Inspector... in the Tools menu.  Add the path $NEXT_ROOT/Local/Library/Frameworks to the Framework Search Order.  Add -Wl,/include:.objc_class_name_NSFramework_itkJavaScript to the Linker Flags.
  10. Select the Build & Run item in the Project Build submenu of ProjectBuilder's Tools menu. This will compile and link the application and start it up with the the new Joy menu item.

You can now use Joy to:

  • Implement new modules of your project in Joy. Just add nib files containing an interpreter object and implement Joy code for that interpreter as shown in section 4 of this tutorial. Note that if you want to run Joy in Developer mode, you need to add the line [ItkTclInterp mainInterp] at the beginning of your JavaScript source code. This is for internal reasons, and will be resolved in future releases.
  • Modify your application at run-time by overwriting existing methods and adding new methods in the Joy command window.
  • Look into the run-time of your application by using the command window's built in application inspector.
The next section shows how the application inspector can be used even for applications you do not have the source code for.