[C++-sig] Re: Is it possible to expose functions with variable argument lists?
David Abrahams
dave at boost-consulting.com
Fri Feb 13 18:52:37 CET 2004
GameGuy <gameguy at eastlink.ca> writes:
> Hello.
> I have been using PYSTE and Boost.Python to wrap a C++ library for use in Python. Very nice stuff.
>
> I have reached a stumbling block though: There are several methods in
> this library that have an ellipsis in their method declarations. Eg:
>
> class Foo
> {
> virtual void method(const char* bar, ... ) const = 0;
> };
>
> Which I think can be wrapped with Boost.Python in the following way:
>
> struct Foo_Wrapper : Foo
> {
> // ...
>
> virtual void method(const char* p0, ... ) const {
> va_list args;
> va_start(args, p0);
> call_method< void >(self, "method", p0, args);
> }
> };
>
> // ...
>
> class_< Foo, Foo_Wrapper >("Foo", init< >())
> .def("method", &Foo::method)
> ;
>
>
> I saw it done this way in another library. I haven't verified that it
> works or not yet as I can't compile it yet (running into MSVC7
> issues).
>
> Has anyone else had experience wrapping functions with variable argument lists?
> Will this work in Boost.Python?
Short answer: no, this doesn't work.
Longer answer: you can't really get this to work in Boost.Python
because it relies on being able to deduce the expected C++ types of
arguments.
Longer answer still: you might be able use
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to wrap this method for
specific sequences of arguments.
http://tinyurl.com/2wptk
But now that I look I think it'll fail for the same reason. I think
the need to use call_method internally might give you problems, too.
I think your best bet might be to use the facilities of
http://www.boost.org/libs/python/doc/v2/raw_function.html
> Is it worth extending PYSTE to handle these cases? (It doesn't currently)
>
>
> Thank you for any assistance,
> ~Shaun
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list