« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Examples

Usage

var increment(var args) {
  struct Int* i = get(args, $I(0));
  i->val++;
  return NULL;
}

var x = $I(0);
show(x); /* 0 */
call($(Function, increment), x);
show(x); /* 1 */

Usage 2

var hello_person(var args) {
  print("Hello %$!", get(args, $I(0)));
  return NULL;
}

call($(Function, hello_person), $S("Dan"));

Usage 3

var add_print(var args) {
  int64_t fst = c_int(get(args, $I(0)));
  int64_t snd = c_int(get(args, $I(1)));
  println("%i + %i = %i", $I(fst), $I(snd), $I(fst+snd));
  return NULL;
}

call($(Function, add_print), $I(10), $I(21));

Function


Function Object

The Function type allows C function pointers to be treated as Cello objects. They can be passed around, stored, and manipulated. Only C functions of the type var(*)(var) can be stored as a Function type and when called the arguments will be wrapped into an iterable and passed as the first argument, typically in the form of a tuple.

Definition

struct Function {
  var (*func)(var);
};

Derives

Implements

  • Callcall
  • Docname brief description definition

Back