Paolo Invernizzi
Joined: 20 Jul 2006 Posts: 17
|
Posted: Wed Nov 28, 2007 9:01 am Post subject: Wrapping D Object |
|
|
Hi Kirk,
Just to know if I've understood everything...
- I've wrapped some classes, let's say DButton.
- I instantiate the wrapped class from Python; A PydObject with inside a d_obj pointer to the D class is instantiated.
- I've wrapped a function that take a DButton object. The object is seen in the functions as an istance of class DButton allocated at memory Z;
- I've wrapped a function that take a Object object. I call the function with the same button python instance, and inside it the object is an instance of Object BUT at different address (but the d_obj is not the same?)
As a test, I've wrapped the standard Phobos Object and wrapped a function that accept a PydObject directly, then uses the WrapPyObject_AsObject!(Object)(pydobj.ptr) to extract the Phobos object, and this time the address is correct. Morale: it seems that automatic parameters conversion is not working if the D object to unwrap is a plain Phobos object. Some bug in the templates?
Cheers, and code as example below!
PS... can you contact me at paoloinvernizzi @ fastwebnet DOT it ? I'm on OSX...
Code: |
class DButton {
this(){
writefln("Inside DButton ctor:%x",cast(void*)(this));
}
}
void test_button(DButton o){ writefln("DButton->%x",cast(void*)(o)); }
void test_object(Object o){ writefln("Object->%x",cast(void*)(o)); }
void test_pydobject(PydObject o){ writefln("ManualUnwrap->%x",cast(void*)( WrapPyObject_AsObject!(Object)(o.ptr) )); }
...
def!(test_button);
def!(test_object);
def!(test_pydobject);
wrap_class!(DButton);
wrap_class!(Object);
Python...
b = DButton() # Inside DButton ctor:1006E80
test_button(b) # DButton->1006E80
test_object(b) # Object->10003B0 <<<<<==== ???
test_pydobject(b) # ManualUnwrap->1006E80
|
|
|