From: Barry S. <ba...@ba...> - 2008-12-30 20:18:38
|
On 30 Dec 2008, at 16:28, William Newbery wrote: > > You can start with the python object and then get the C++ object > that implements it: > > > ExtensionObject<MyClass> obj( args[0] ); // exception thrown > > if wrong type > > MyClass *p = obj.extensionObject(); // get C++ pointer > > Ok, so basicly I just pass the ExtensionObject<T> around, and can > use th extensionObject() method to get a pointer to the c++ object. > > One thing I cant work out though, what do I construct the > ExtensionObject class with if I have not yet created an object to > store in it? > I need to have the Py::ExtensionObject<Input> input in the D3D > classes deffinition, but I cant actauly create an Input instance > untill later in the constructor > > class D3d : public Py::PythonExtension<D3d> > { > ... > Py::ExtensionObject<Input> input; > ... > } > > D3d::D3d(...) > {//error C2512: 'Py::ExtensionObject<T>' : no appropriate default > constructor available > ...create window and dx stuff > input = new Input(this, hwnd);//cant create the Input instance > untill after some other stuff is created > } In cases like this I use a pointer: Py::ExtensionObject<Input> *input_ptr; and new a Py::ExtensionObject<Input>( input ) when I have it available. You need to create the the Py::Object to pass it back to python like this: Py::ExtensionObject<Input> an_input_object( Py::asObject( new Input(this, hwnd) ) ) ); I've been looking at allowing Py::Object to hold NULL for V6.0.0 - but that targeted at Python 3.0. Barry Barry |