macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Embedding F-Script into Cocoa Applications

by Philippe Mougin
07/12/2002

As we already saw in the previous articles in this series, F-Script can be used as a stand-alone application that dynamically loads your Objective-C classes and enables you to access them either interactively or using scripts. In this article, we'll explore the opposite possibility: including F-Script in your own applications.

All F-Script functionalities are available through components that can be integrated into applications. This enables you to:

  • Program all or part of an application using the F-Script language.
  • Offer a scripting environment within your applications, allowing users to manipulate your business objects and to automate processes.
  • Interface F-Script with other tools.

Because F-Script and Cocoa share the same object model, integration is easy and advanced.

The Main Classes in the F-Script Integration API

The F-Script runtime is integrated into an application via a certain number of Objective-C classes, which are provided with F-Script in the form of a framework (FScript.framework). The following table illustrates the main characteristics of these classes in terms of integration.


Name:

FSInterpreter

Role:

Each instance of this class represents a complete F-Script interpreter (workspace included). An application may instantiate any number of interpreters.

Main Features:

  • Executes the F-Script code contained in an NSString.
  • Searches for the object associated with a certain identifier in the workspace.
  • Assigns an object to an identifier in the workspace.
  • Lets you know the identifiers defined in the workspace.

Name:

FSInterpreterResult

Role:

Represents the result of an execution of F-Script code by an FSInterpreter.

Main Features:

  • Lets you know the execution status of the F-Script code, i.e. syntax error, execution error or success.
  • In the event of an error, lets you retrieve information on this error: human readable description, location in the code, block call-stacks.
  • If successful, lets you get the result of the execution.

Name:

FSInterpreterView

Role:

A graphical component, a subclass of NSView, which provides F-Script with a command line interface. An FSInterpreterView has its own interpreter and F-Script workspace and can thus be used directly without requiring any other configuration.

Main Features:

  • Can be integrated into a Cocoa view hierarchy.
  • Manages user interaction in command line mode. Various functions: copy/paste, command history, choice of fonts, graphical signaling of errors, etc.
  • Lets you insert an F-Script command programmatically.
  • Lets you transmit a message to the user.
  • Lets you retrieve the associated interpreter (an FSInterpreter instance).

Name:

System

Role:

Enables access (from both Objective-C and F-Script) to various services of the F-Script interpreter. The runtime creates a System instance per interpreter and associates it with the identifier "sys" in the interpreter's workspace.

Main Features:

  • Can build a block object in the associated workspace from an NSString containing F-Script code.
  • Lets you open a graphical F-Script object browser.
  • Lets you save/reload a workspace.
  • Obtains the list of all the variables defined in the associated workspace.

Name:

Block

Role:

A block represents a script (in other words, a piece of F-Script code that can have arguments, local variables and bindings to other objects).

Main Features:

  • Executes itself (throwing an exception in the event of an error).
  • Manages a graphical interface for code editing.

Name:

FSNSString

Role:

A category of NSString.

Main Features:

  • Builds a block from F-Script code represented by the NSString object.

A program wishing to use this API should use FScript.framework and the following import directive:

#import <FScript/FScript.h>

In order to use the F-Script framework from your own applications you will likely need to put it into one of these standard locations for frameworks on Mac OS X:

~/Library/Frameworks
/Library/Frameworks
/Network/Library/Frameworks
/System/Library/Frameworks

You can also directly bundle the framework into your application. This way, you will be able to ship a self-contained solution.

Pages: 1, 2, 3

Next Pagearrow