py cxx callable

Discussion in 'Python' started by John Hunter, May 10, 2004.

  1. John Hunter

    John Hunter Guest

    I am using pycxx 5.2.2. and am trying to write a callable class. The
    docs suggest you need to override

    virtual Object call( const Object &, const Object & );

    in your extension and call supportcall in your init_type function, eg

    void XYFunc::init_type()
    {
    behaviors().name("XYFunc");
    behaviors().doc("Map x,y -> x,y");
    behaviors().supportCall();
    }

    I have a couple of questions:

    * what are the two Object arguments to call? I would have expected
    the signature to be

    virtual Object call( const Py::Tuple& args);

    * For testing, I defined a do nothing call, that just prints to std
    out

    class XYFunc : public Py::pythonExtension<XYFunc> {
    public:
    static void init_type(void);
    Py::Object call(const Py::Object &o1, const Py::Object &o2) {
    std::cout << "you rang" << std::endl;
    return Py::Object();
    }
    };

    but I get the following error when I try and test it


    >>> from myext import XYFunc
    >>> x, y = 1,2
    >>> func = XYFunc()
    >>> func()


    Traceback (most recent call last):
    File "_transforms_test.py", line 7, in ?
    func()
    TypeError: CXX: type error.

    Ditto when I pass func(x,y), func((x,y)) etc...

    Any insight? I couldn't find any examples in distro that actually use
    callable.

    JDH
    John Hunter, May 10, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maincc
    Replies:
    5
    Views:
    631
    Richard Herring
    Jul 22, 2004
  2. John Hunter

    operator double() surprise in cxx

    John Hunter, Apr 30, 2004, in forum: Python
    Replies:
    7
    Views:
    345
    =?iso-8859-1?q?Beno=EEt_Dejean?=
    Apr 30, 2004
  3. John Hunter

    inheritance and cxx

    John Hunter, May 13, 2004, in forum: Python
    Replies:
    0
    Views:
    305
    John Hunter
    May 13, 2004
  4. exiquio
    Replies:
    2
    Views:
    514
    exiquio
    Oct 7, 2008
  5. Ulrich Eckhardt
    Replies:
    6
    Views:
    89
    Peter Otten
    Jul 12, 2013
Loading...

Share This Page