Index: boost/python/object_core.hpp =================================================================== --- boost/python/object_core.hpp (revision 39929) +++ boost/python/object_core.hpp (working copy) @@ -42,6 +42,13 @@ namespace boost { namespace python { +namespace detail { + +class kwds_proxy; +class args_proxy; + +} + namespace converter { template struct arg_to_python; @@ -99,6 +106,13 @@ # define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, )) # include BOOST_PP_ITERATE() + detail::args_proxy operator* () const; + + object operator()(detail::args_proxy const &args) const; + object operator()(detail::args_proxy const &args, + detail::kwds_proxy const &kwds) const; + + // truth value testing // operator bool_type() const; @@ -410,6 +424,60 @@ // implementation // +namespace detail { +class call_proxy +{ +public: + call_proxy(object target) : m_target(target) {} + operator object() const { return m_target;} + + private: + object m_target; +}; + +class kwds_proxy : public call_proxy +{ +public: + kwds_proxy(object o = object()) : call_proxy(o) {} +}; +class args_proxy : public call_proxy +{ +public: + args_proxy(object o) : call_proxy(o) {} + kwds_proxy operator* () const { return kwds_proxy(*this);} +}; +} + +template +detail::args_proxy api::object_operators::operator* () const +{ + object_cref2 x = *static_cast(this); + return detail::args_proxy(x); +} + +template +object api::object_operators::operator()(detail::args_proxy const &args) const +{ + U const& self = *static_cast(this); + PyObject *result = PyObject_Call(get_managed_object(self, tag), + args.operator object().ptr(), + 0); + return object(detail::new_reference(result)); + +} + +template +object api::object_operators::operator()(detail::args_proxy const &args, + detail::kwds_proxy const &kwds) const +{ + U const& self = *static_cast(this); + PyObject *result = PyObject_Call(get_managed_object(self, tag), + args.operator object().ptr(), + kwds.operator object().ptr()); + return object(detail::new_reference(result)); + +} + inline object::object() : object_base(python::incref(Py_None)) {} Index: libs/python/test/object.cpp =================================================================== --- libs/python/test/object.cpp (revision 39929) +++ libs/python/test/object.cpp (working copy) @@ -123,6 +123,11 @@ return !y[key]; } +object test_call(object c, object args, object kwds) +{ + return c(*args, **kwds); +} + bool check_string_slice() { object s("hello, world"); @@ -324,6 +329,8 @@ def("test_item", test_item); def("test_not_item", test_not_item); + def("test_call", test_call); + def("check_binary_operators", check_binary_operators); def("check_inplace", check_inplace); def("check_string_slice", check_string_slice); Index: libs/python/test/object.py =================================================================== --- libs/python/test/object.py (revision 39929) +++ libs/python/test/object.py (working copy) @@ -15,6 +15,10 @@ 'hello, world!' >>> number() 42 +>>> def print_args(*args, **kwds): +... print args, kwds +>>> test_call(print_args, (0, 1, 2, 3), {'a':'A'}) +(0, 1, 2, 3) {'a': 'A'} >>> test('hi') 1