メモ

void call(int delegate(int num) func) {
  printf("%d\n", func(10));
}

void call(int function(int num) func) {
  printf("%d\n", func(20));
}

class Hoge {
  int foo(int num) {
    return num;
  }

  int OnInit(int num) {
    printf("call OnInit\n%d\n", num);
    return 0;
  }
}

int delegate(int num) closure_delegate = null;

extern(C)
void call_closure() {
  if (closure_delegate) {
    closure_delegate(30);
  }
  else {
    throw new Exception(`クロージャが設定されていません`);
  }
}

extern(C) alias void function() TClosure;
void handler(TClosure closure) {
  closure();
}

void main() {
  call(
    delegate int(int num) {
      return num;
    }
  );

  Hoge hoge = new Hoge;
  call(&hoge.foo);

  //closure_delegate = &hoge.OnInit;
  handler(&call_closure);
}