On 9/14/07, <b class="gmail_sendername">Pertti Kellomäki</b> <<a href="mailto:pertti.kellomaki@tut.fi">pertti.kellomaki@tut.fi</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am exposing a largish library using Py++ and Boost.Python, and I'm<br>running into a bit of a problem when I try to expose it in manageable<br>parts. I've tried to condense the problem below.<br><br>One module contains class NIT:
<br><br>==================================================<br>class NIT : public IT {<br>public:<br> static NIT& instance();<br>//...<br>}<br>==================================================<br><br>which is exposed by Py++ as follows:
<br><br>==================================================<br>struct NIT_wrapper : TT::NIT, bp::wrapper< TT::NIT > {<br>//...<br>};<br><br>BOOST_PYTHON_MODULE(mach){<br> bp::class_< NIT_wrapper,<br> bp::bases< TT::IT >,
<br> boost::noncopyable ><br> ( "NIT", bp::no_init )<br> .def("instance"<br> , (::TT::NIT & (*)( ))<br> ( &::TT::NIT::instance )<br>
, bp::return_value_policy< bp::reference_existing_object<br> >() )<br> .staticmethod( "instance" );<br> //...<br>==================================================<br><br>In another module, there is a member function that uses NIT as a default
<br>value:<br><br>==================================================<br>class I {<br>public:<br> I(const TT::IT& iT = TT::NIT::instance());<br> //...<br>}<br>==================================================<br>
<br>This is exposed by Py++ as follows:<br><br>==================================================<br>BOOST_PYTHON_MODULE(program){<br> bp::class_< TTAProgram::I,<br> boost::noncopyable ><br> ( "I",
<br> bp::init< bp::optional< TT::IT const & > ><br> (( bp::arg("iT")<br> =TT::NIT::instance( ) )) )<br> //...<br>==================================================
<br><br>Importing the "mach" Python extension as<br><br> import TCE.base.mach<br><br>succeeds, but<br><br> import TCE.base.program<br><br>results in the error message<br><br> Traceback (most recent call last):
<br> File "<stdin>", line 1, in <module><br> TypeError: No to_python (by-value) converter found<br> for C++ type: TTAMachine::NullInstructionTemplate<br><br>If I remove the default value from the signature, the problem
<br>disappears. Any ideas how to fix this?</blockquote><div><br>This is a Boost.Python limitation: you can't register function with default argument - it requires the type of the argument to be already registered. By importing the module
TCE.base.mach you register the relevant class.<br><br>Take a look on next link:<br><a href="http://language-binding.net/pyplusplus/documentation/functions/default_args.html">http://language-binding.net/pyplusplus/documentation/functions/default_args.html
</a><br><br>HTH<br></div></div><br><br clear="all"><br>-- <br>Roman Yakovenko<br>C++ Python language binding<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>