Home > Articles

Cocoa Language Options

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Other Languages

Objective-C and Java are the two languages most commonly used with Cocoa, but many other languages operate with Cocoa to varying degrees. The languages used with Cocoa fall into two major categories: languages based on C and scripting languages.

ANSI C and C++

As mentioned previously, Cocoa is written in Objective-C, which is based on ANSI C. As a result, other languages that are based on C can be used with Cocoa. There are two strategies for using languages based on C with Cocoa. One strategy is to use only the C interface to the Objective-C runtime and a standard C or C++ compiler. The other is to use an Objective-C or Objective-C++ compiler to compile C or C++ code.

It is possible to write an ANSI C program that uses most features of Cocoa, and compile that program with a standard C compiler. The Objective-C runtime's C interface includes functions for creating and sending messages to Cocoa objects. As a superset of C, the C++ language can use the same techniques to access Cocoa objects.

The easiest way to use Cocoa from C programs is to use the Objective-C compiler to compile the standard C code along with modules containing Objective-C code. Apple provides an Objective-C++ compiler that enables the mixture of C++ code and Objective-C code in the same module.

Scripting Languages

Scripting languages usually have a runtime that can be interfaced with Cocoa. The most popular scripting languages used with Cocoa are AppleScript, TCL, and Python. Apple provides AppleScript Studio along with their other developer tools. AppleScript Studio enables the creation of full-featured Cocoa applications using AppleScript.

A product called Joy from AAA+ Software (http://www.aaa-plus.com) is used to integrate TCL, JavaScript, and other languages with Cocoa. An open source interface between Objective-C and TCL is available at http://www-sfb288.math.tu-berlin.de/oorange/interpretedOC/interpretedOC.html. The Usenix organization provides a technical paper discussing the integration between TCL and Objective-C at http://www.usenix.org/publications/library/proceedings/tcl95/bogdanovich.html.

  • + Share This
  • 🔖 Save To Your Account