Objective-Everything Release 5. Copyright ©1994-1998 by TipTop Software, Inc. All Rights Reserved.
This section describes miscellaneous Objective-Framework resource files.
ObjCore.selmap in ObjCore.framework/Resources specifies selector mappings. Selector mappings are used in Python and Perl. See the ObjPython and ObjPerl language references and ObjCore.framework/Resources/ObjCore.selmap for the description of the .selmap file format.
ObjCore.conmap in ObjCore.framework/Resources specifies constructor mappings. Constructor mappings are used in Python. See the ObjPython language reference and ObjCore.framework/Resources/ObjCore.conmap for the description of the .conmap file format.
CFun files contain C function, global, constant, and type specifications (signatures). These specifications facilitate direct interoperability between the Objective-Everything languages and the compiled C code. CFun files are automatically loaded at runtime.
See ObjCore.framework/Resources/ObjCore.cfun for description of the .cfun file format.
At startup, Objective-Everything loads a .cfun file from every Objective module that is initialized.
In addition to the .cfun files provided by the Objective modules, you can include your own CFun declarations in standard library directories: /Network/Library/CFun/load.cfun, /Local/Library/CFun/load.cfun, ~/Library/CFun/load.cfun. These files can #include api's defined other *.cfun files.
Moreover, at runtime, you can declare additional C functions, globals, and types in the standard C syntax using the cdefine and cinclude commands.
Finally, CFun files are also loaded from every loaded bundle when ObjAppKit starts up. As a consequence of this, in order to make C functions, globals, and types defined in a framework or a bundle available for use from Objective-Everything, you can simply include appropriate CFun specifications in file YourFramework.framework/Resources/YourFramework.cfun.
You can use cdefine and cinclude commands in your favorite Objective language to create CFun function/global/type signatures appropriate for inclusion in a .cfun file. See the language-specific documentation for description of the cdefine and cinclude commands.
In ObjTcl, generate text in .cfun format from a C include file (.h):
Python | cinclude('<path-to-include-file>', out=1, no_def=1) |
Tcl | cinclude -out -no_def <path-to-include-file> |
Perl | cinclude '<path-to-include-file>', {'out'=>1, 'no_def'=>1}; |
The Carbon API is essentially just a C api which you can directly access from any of the Objective-Everything languages. The carbon API is provided in ObjCore.framework/Resources/Carbon.cfun
When the system is in the "active" mode (see below), for each loaded language, the standard library locations:
/Network/Library/<Lang> /Local/Library/<Lang> ~/Library/<Lang>
and language resource paths in all framework and bundles that comprise the application:
ABC.framework/Resources/<Lang> XYZ.bundle/Resources/<Lang>
are added to the language library search path. Here, <Lang> is Py, Tcl, Perl, etc.
As a consequence of this you can simply include implementation files in Py, Tcl, or Perl resource subdirectories.
Create file ~/Library/Py/mymodule.py with content:
print "Running ObjPy mymodule" def hello(): print "Hello from ObjPy mymodule"
Run ObjShell.app (or any other application with Objective-Everything linked/loaded in), open a Python interactor window (Objective->Interact->Interactor and select Python). Type:
py% import mymodule Running ObjPy mymodule py% mymodule.hello() Hello from ObjPy mymodule
In a similar manner to the library path setup mechanism, when the system is in the "active" mode, for all loaded language, any init.lang files (where lang is py, tcl, or py) found in the standard library locations and in the language resource paths in all bundles and frameworks that comprise the application are executed.
In addition, when the appkit starts running, any init_appkit.lang files are executed. Finally, if file load.lang exists in any of the searched directories, the appropriate language is loaded, and the contents of the file are executed.
As a consequence of this, in order to have any startup scripts executed, you can simply create load.lang, init.lang, or init_appkit.lang files in approriate Library or bundle directory.
Craete file ~/Library/Tcl/init.tcl:
puts "Running [info script]";
Creete file ~/Library/Tcl/init_appkit.tcl:
NSRunAlertPanel "Tcl" "Hello World!" [nil] [nil] [nil]
Create file ~/Library/Tcl/init_xyz.tcl:
puts "Running [info script]"
Create file ~/Library/Perl/init_appkit.pl:
use ObjPerl; C::NSRunAlertPanel('Perl','Hello World!',nil,nil,nil);
Create file ~/Library/Py/load.py:
print "Running ~/Library/Py/load.py"
Create file ~/Library/Py/init.py:
print "Running ~/Library/Py/init.py"
Create file ~/Library/Py/init_appkit.py:
from ObjPy import * C.NSRunAlertPanel('Python','Hello World!',nil,nil,nil)
Run objtclsh in a terminal window:
objtclsh set auto_path ... # Note that ~/Library/Tcl does not appear in the path. # We are in the "lazy" mode: # Library paths are not set up yet. # Init scripts are not run yet. appkit::run (This will run the main event loop and transition the system into the "active" mode.)Running ~/Library/Py/load.py (Note that ObjPython is dynamically loaded.) Running ~/Library/Py/init.py Running .../Library/Tcl/init.tcl # Panel Tcl: Hello World! appears; i.e.: ~/Library/Tcl/init_appkit.tcl is executed # Panel Python: Hello World! appears. Click Objective->Interact->Interactor and click "Load Perl". # Panel Perl: Hello World! appears. Select Perl.
You can run your own init scripts by invoking [TTInterp runInitScriptName:]. For example, in the Perl interactor window type:
TTInterp->runInitScriptName('init_xyz'); Running .../Library/Tcl/init_xyz.tcl (appears in the terminal/console window)
Make sure that you remove the scripts that you created in this example from Py, Tcl, and Perl subdirectories in ~/Library/.
Any files which are found in /Network/Library/Scripts, /Local/Library/Scripts, ~/Library/Scripts, or in the Resources/Scripts subdirectory of any frameworks or bundles that comprise an application are automatically attached to menu items in submenu Objective->Script.
Create file ~/Library/Scripts/HelloPerl.pl with contents:
use ObjPerl; C::NSRunAlertPanel('Perl Script',"Hello World!!!",nil,nil,nil);
Run ObjShell.app, or any other application with Objective-Everything linked/loaded in. Click Objective->Script->HelloPerl. The alert panel appears.
By default, the Objective-Everything system is in the "lazy" mode. In the lazy mode, only .cfun files */Library/CFun/load.cfun and Obj*.framework/Resources/*.cfun are loaded. CFun specs from bundles, language library paths and language init scripts from bundles are NOT loaded, set up, and executed. This is not done for performance reasons. (In order to load CFun stuff and run init scripts, the system would have to search all bundles for relevant resources. Accessing NSBundles is slow.) Hence, by default, the system starts up in the "lazy" mode. For example, when you run objtclsh in a shell window, objtclsh is in the "lazy" mode.
In the "active" mode, for all bundles that comprise the application, the system automatically loads cfun specs, sets up all language library paths, runs init scripts, and loads menu-attached scripts, as described above. To transition from "lazy" to "active" mode you can explicitly invoke:
[TTInterp setupForAllBundles];
or, you can target a specific interpreter:
[[TTObjPyInterp getDefaultInterp] addAllBundleLibraryPaths];
Also, the system will automatically transition into the "active" mode when a bundle is dynamically loaded, or when AppKit initializes (i.e., when NSApp starts running). These operations are costly, and the Objective-Everything system takes advantage of this in order to initialize the above-mentioned stuff.