Main Index :

The C.O.F.F.E.E. Language


This page briefly describes the major features of the C.O.F.F.E.E. language. For a complete list of all functions and keywords, please see the reference page.

Variables and types

Variables in C.O.F.F.E.E. are declared using the var keyword:

var foo;
var bar = 5;

All variables are untyped. This means that the compiler doesn't know or care in advance if a variable contains an integer or a polygon object. The type information for a variable is only stored during runtime when a value has been allocated to the variable. See typeof() for a list of all possible types. Objects, arrays and strings are allocated using the new() function:

var object = new(MyObject, firstParameter, secondParameter);

In the SDK, the type of a function parameter is formatted like this: [type] Please note that this is just a way to make it easier to read the function prototypes. The [type] notation is never used in a real C.O.F.F.E.E. file.

Only integers, floats and vectors are stored by value in the variable. Everything else is stored by reference. This means that if one writes code like this

var a = new(array,3);
a[0] = 2;
var b = a;
b[0] = 3;

both a[0] and b[0] will be 3. It is up to each type to provide real copy functions.

See also: sizeof(), const, enum

Memory management

The memory in C.O.F.F.E.E. is conveniently handled by a garbage collector. This means that allocated memory is automatically freed when it's no longer in use. There's no need for a delete keyword.

See also: gc()

Program structure

All the basic C++ and Java program structures can be used in C.O.F.F.E.E. Here is a list of all important keywords, if you need to brush up on them:

return
if - else
do - while
for
break
continue
switch - case

Comments

Comments can be inserted in the code with // or /* */:

// A comment on one line…
/* A comment
   on several
   lines… */

Functions

Functions in C.O.F.F.E.E. are defined and called just like in C++, except that one needn't specify the return type and the type of the arguments:

myFunction(myArgument1, myArgument2)
{
  // Do whatever
  return myReturnValue;
}

main(doc, op)
{
  // Call the function
  myFunction(3, 4);
}

There is also a special kind of function that can have an arbitrary number of parameters. The number of arguments is accessed with _arg(0), and the arguments with _arg(i) where i is the argument index:

myFunction(...)
{
  // Get the argument count
  var argCount = _arg(0);
  println(argCount," arguments were passed:");

  var i;
  for (i = 1; i <= argCount; i++)
  {
    // Print the ith argument
    println("  ",i,": ",_arg(i));
  }
}

main(doc,op)
{
  myFunction("Hello","World","!");
}

Objects and classes

Understanding object-oriented programming is important to be able to use the SDK efficiently. This documentation does not attempt to explain the concept of classes and objects, but rather to show the syntax. If you feel completely lost, reading a book on C++ or Java might be a good idea.

Classes are declared with the class keyword. If you already are familiar with the concept, that page will be enough to use classes in C.O.F.F.E.E. Otherwise, please see above... :-)