[C++-sig] How to use call?
David Abrahams
david.abrahams at rcn.com
Fri Jun 14 20:46:07 CEST 2002
----- Original Message -----
From: "Dave Hawkes" <daveh at cadlink.com>
> I am obviously missing something here but I could not get call to work.
Just
> trying a simple test always seems to throw the 'throw_if_not_registered
> exception'. ie
>
> PyObject *p = python::call(co, &boost::type<PyObject*>());
>
> where co is a callable object (constructor in this case).
You mean a type/class? If it's an __init__ function you'll need an argument
for the object.
That's a very strange way to invoke call<>. Did you look at the simple
example at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/
python/doc/v2/call.html
and the more-complete text at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/
python/doc/v2/callbacks.html
?
Looking at the source probably made you think you were supposed to pass it
the address of a temporary boost::type<> object, but that's just a VC6
workaround. Please look at the docs first and use the source as a last
resort.
> I know the intention here is to copy the lvalue
Huh? Which lvalue?
> and prevent pointer conversions, but if the returned value is a class we
don't want to copy it
> as we loose the benefit of the virtual function overrides.
You seem to think that the result object will be copied no matter what.
That's not right.
If you want to return a pointer or reference, go ahead:
MyClass* p = call<MyClass*>(callable, arg1, arg2, ...);
> Maybe this will
> be fixed when the object work is complete and the return type can be
object.
Not sure what you think that would buy you; you'd still need to get the C++
object out of it.
> For now what is the easiest way to allow the PyObect* through, should I
just
> define a specialised return_from_python converter ?
>
> Obviously I can get round this by using PyEval_CallFunction directly.
Let me know if this is still unclear to you.
-Dave
More information about the Cplusplus-sig
mailing list