www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Pyd: class initializer with delegate as argument not working

I'm trying to add a delegate as an argument in the initializer, but the 
blank initializer is getting called instead.

// D
import std.stdio;
import pyd.pyd;
import python;

alias int delegate(char[]) CallbackDg;

class Test {
 CallbackDg cbdg;

 this() {
  writefln("Init, no callback");
 }

 this(CallbackDg cbdg) {
  writefln("Init with callback: ", cbdg);
  this.cbdg = cbdg;
 }

 void setCb(CallbackDg cb) {
  writefln("Setting callback");
  this.cbdg = cb;
 }

 void testcb() {
  writefln("Test callback, callback: ", cbdg !is null);
  if (cbdg !is null)
   writefln("Ret: ", cbdg("Got this one?"));
 }
}

extern(C) void PydMain() {
 module_init();

 wrap_class!(
  Test
  , Init!(void function(CallbackDg))
  , Def!(Test.setCb)
  , Def!(Test.testcb)
 );
}




// Python
from test import Test

def cb(msg):
 print msg
 return 80

print "init Test with callback"
t = Test(cb)
t.testcb()
t.setCb(cb)
t.testcb()


// Output
init Test with callback
Init, no callback
Test callback, callback: false
Setting callback
Test callback, callback: true
Got this one?
Ret: 80 
Jul 20 2007