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 | |
---|
6 | #include <boost/python/module.hpp> |
---|
7 | #include <boost/python/def.hpp> |
---|
8 | #include <boost/python/long.hpp> |
---|
9 | #include <boost/python/class.hpp> |
---|
10 | #define BOOST_ENABLE_ASSERT_HANDLER |
---|
11 | #include <boost/assert.hpp> |
---|
12 | |
---|
13 | using namespace boost::python; |
---|
14 | |
---|
15 | object new_long() |
---|
16 | { |
---|
17 | return long_(); |
---|
18 | } |
---|
19 | |
---|
20 | long_ longify(object x) |
---|
21 | { |
---|
22 | return long_(x); |
---|
23 | } |
---|
24 | |
---|
25 | object longify_string(char const* s) |
---|
26 | { |
---|
27 | return long_(s); |
---|
28 | } |
---|
29 | |
---|
30 | char const* is_long1(long_& x) |
---|
31 | { |
---|
32 | long_ y = x; |
---|
33 | x += 50; |
---|
34 | BOOST_ASSERT(x == y + 50); |
---|
35 | return "yes"; |
---|
36 | } |
---|
37 | |
---|
38 | int is_long2(char const*) |
---|
39 | { |
---|
40 | return 0; |
---|
41 | } |
---|
42 | |
---|
43 | // tests for accepting objects (and derived classes) in constructors |
---|
44 | // from "Milind Patil" <milind_patil-at-hotmail.com> |
---|
45 | |
---|
46 | struct Y |
---|
47 | { |
---|
48 | Y(boost::python::long_) {} |
---|
49 | }; |
---|
50 | |
---|
51 | BOOST_PYTHON_MODULE(long_ext) |
---|
52 | { |
---|
53 | def("new_long", new_long); |
---|
54 | def("longify", longify); |
---|
55 | def("longify_string", longify_string); |
---|
56 | def("is_long", is_long1); |
---|
57 | def("is_long", is_long2); |
---|
58 | |
---|
59 | class_< Y >("Y", init< boost::python::long_ >()) |
---|
60 | ; |
---|
61 | } |
---|
62 | |
---|
63 | #include "module_tail.cpp" |
---|