py cxx callable

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon May 10 10:24:44 EDT 2004


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





More information about the Python-list mailing list