Function definition

To define functions, you will be using the function keyword, followed by the function name in prefix.suffix notation (or simply suffix for a function local the connection), and the parameters between brackets (or an open/close bracket () if there is no parameters). You can use return to return a value or to exit from the function, like in C:

function adding(x,y) {
  z = x+y;
  return z;
};
function print(x) {
  echo x;
  if (x<0)
    return
  else
    echo sqrt(x);
};

Note that there must be a semicolon or another command separator after the function definition, since defining a function is a command like any other command in URBI.

The parameters are always local to the function call. Non-global (i.e. without prefix) variables in the function body are also local to the function call. Consider the following example:

a=4;
b=5;
function display(b) {
  display_b:b; // b is local
  var a=b; // creates a local variable a
  display_a:a;
};
display(10);a:a;b:b;
[139464:display_b] 10.000000
[139464:display_a] 10.000000
[139464:a] 4.000000
[139464:b] 5.000000

A good idea is to put all your functions in a separate file like "myfunc.u", and load them with the load command: load("myfunc.u"); This can be done from the URBI.INI file for example, or when you actually need them.

To undef a function, simply use:

delete myfunction;