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

Objective-Everything and ProjectBuilder

Application with NIB file(s) containing Objective-Everything objects

If your application loads a NIB file which contains Objective-Framework objects, you only need to link your application with the ObjCore and the ObjAppKit framework, and, optionally, with other language-specific frameworks.

When the NIB file is loaded at runtime, the appropriate Objective-Everything frameworks will be loaded and initialized. Specifically, any implementation code stored in the nib file will be executed

Managing Objective-Everything Source Code in ProjectBuilder

Step 1

Create an Application project using PB and include ObjCore and ObjAppKit frameworks.  You may also want to link with specific language frameworks.  E.g., if you want to use ObjPython, include the ObjPy framework.

Step 2

If you are linking with specific language frameworks, make sure that you reference a symbol from the framework, so that the framework is actually loaded.  E.g., In MyApp_main.m, do:

#import <ObjPy/ObjPy.h> 

int main(int argc, const char *argv[]) { 
  [TTObjPyInterp class]; 
  return NSApplicationMain(argc, argv); 
} 

Step 3

In order to have Objective-Framework appkit stuff automatically initialized when the application starts up, you may want to change the application class from NSApplication to TTApplication.  Alternatively, if you want to use some other application class, just make sure that you invoke [NSApp initObjectiveStuff] when your application starts up.

The -[NSApplication initObjectiveStuff] method does the following:

  1. Inserts the "Objective" menu in the main application menu.
  2. For each loaded language:
    1. Inserts the language-specific submenu under the "Objective" menu.
    2. For each loaded bundle, adds the bundle library path (e.g., Framework.framework/Resources, Bunde.bundle/Resources, YourApp.app/Resources) to the language library path and executes the appropriate init script (i.e., init.py, init.tcl, ...).

If a language module is dynamically loaded at runtime (rather than being linked with the app at compile time), the above actions are performed when the module is loaded.

Example

Create subdirectory Py and file Py/init_appkit.py with contents:

from ObjPy import *
import AppKit
C.NSRunAlertPanel('ObjPython','Hello from ObjPython!',nil,nil,nil)

Insert directory Py into "Other Resources" in ProjectBuilder.

Also, create subdirectory Perl and file Perl/init_appkit.pl with contents:

use ObjPerl;
C::NSRunAlertPanel('ObjPerl','Hello from ObjPerl!',nil,nil,nil)

and file Perl/load.pl:

use ObjPerl;
print "Running load.pl\n";

Insert directory Perl into "Other Resources".

Also, insert file init_appkit.tcl into "Other Resources" with contents:

NSRunAlertPanel "ObjTcl" "Hello from ObjTcl!" [nil] [nil] [nil] 

Build & run the application. The "Hello from ObjPython!" panel appears as soon as the application starts up since ObjPython is linked with with your app. The "Hello from ObjPerl!" panel also appears because ObjPerl is dynamically loaded by the system because the load.pl file is included.

Click Objective->Interact->Interactor, click "Load Tcl...", and click "Cancel". This will dynamically load ObjTcl, and the "Hello from ObjTcl!" panel will appear.

Tcl, Python, and Perl source code files should be placed under the "Other Resources" category, in subdirectories Tcl, Py, and Perl respectively.

Step 4

When the application is built, the source code files will be included in the application wrapper. At startup, load.*, init.*, and init_appkit.* files will get executed as described above.

Since the language source directories are added to the library path, other source code files are executed either using the language-specific (auto)loading mechanism, or using the Objective-Framework class autoloading mechanism.

Example

Create file Py/mymodule.py with contents:

print "Running ObjPy mymodule"
def hello():
  print "Hello from ObjPy mymodule"

Then, when you build & run the application, in an ObjPython interactor you can do:

py% import mymodule
Running ObjPy mymodule
py% mymodule.hello()
Hello from ObjPy mymodule

Language specific notes: ObjTcl

In Tcl, in order to facilitate autoloadin of procedures and classes, you need to create tclIndex file and include it in directory Tcl/.


[previous][contents][next]