1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #include <boost/python/module.hpp>
6 #include "test_class.hpp"
7 #include <boost/python/def.hpp>
8 #include <boost/python/args.hpp>
9 #include <boost/python/tuple.hpp>
10 #include <boost/python/class.hpp>
11 #include <boost/python/overloads.hpp>
12 #include <boost/python/raw_function.hpp>
13 #include <boost/python/return_internal_reference.hpp>
15 using namespace boost::python
;
17 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
18 # define make_tuple boost::python::make_tuple
21 tuple
f(int x
= 1, double y
= 4.25, char const* z
= "wow")
23 return make_tuple(x
, y
, z
);
26 BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads
, f
, 0, 3)
28 typedef test_class
<> Y
;
32 X(int a0
= 0, int a1
= 1) : inner0(a0
), inner1(a1
) {}
33 tuple
f(int x
= 1, double y
= 4.25, char const* z
= "wow")
35 return make_tuple(x
, y
, z
);
38 Y
const& inner(bool n
) const { return n
? inner1
: inner0
; }
44 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_f_overloads
, X::f
, 0, 3)
47 tuple
raw_func(tuple args
, dict kw
)
49 return make_tuple(args
, kw
);
52 BOOST_PYTHON_MODULE(args_ext
)
54 def("f", f
, (arg("x")=1, arg("y")=4.25, arg("z")="wow")
55 , "This is f's docstring"
58 def("raw", raw_function(raw_func
));
60 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1200
61 // MSVC6 gives a fatal error LNK1179: invalid or corrupt file:
62 // duplicate comdat error if we try to re-use the exact type of f
63 // here, so substitute long for int.
64 tuple (*f
)(long,double,char const*) = 0;
66 def("f1", f
, f_overloads("f1's docstring", args("x", "y", "z")));
67 def("f2", f
, f_overloads(args("x", "y", "z")));
68 def("f3", f
, f_overloads(args("x", "y", "z"), "f3's docstring"));
70 class_
<Y
>("Y", init
<int>(args("value"), "Y's docstring"))
71 .def("value", &Y::value
)
72 .def("raw", raw_function(raw_func
))
75 class_
<X
>("X", "This is X's docstring", init
<>(args("self")))
76 .def(init
<int, optional
<int> >(args("self", "a0", "a1")))
78 , "This is X.f's docstring"
79 , args("self","x", "y", "z"))
81 // Just to prove that all the different argument combinations work
82 .def("inner0", &X::inner
, return_internal_reference
<>(), args("self", "n"), "docstring")
83 .def("inner1", &X::inner
, return_internal_reference
<>(), "docstring", args("self", "n"))
85 .def("inner2", &X::inner
, args("self", "n"), return_internal_reference
<>(), "docstring")
86 .def("inner3", &X::inner
, "docstring", return_internal_reference
<>(), args("self", "n"))
88 .def("inner4", &X::inner
, args("self", "n"), "docstring", return_internal_reference
<>())
89 .def("inner5", &X::inner
, "docstring", args("self", "n"), return_internal_reference
<>())
91 .def("f1", &X::f
, X_f_overloads(args("self", "x", "y", "z")))
92 .def("f2", &X::f
, X_f_overloads(args("self", "x", "y", "z"), "f2's docstring"))
93 .def("f2", &X::f
, X_f_overloads(args("x", "y", "z"), "f2's docstring"))
96 def("inner", &X::inner
, "docstring", args("self", "n"), return_internal_reference
<>());
99 #include "module_tail.cpp"