1
#include "pycxx_iter.hxx"
3
#include "CXX/Objects.hxx"
5
void IterT::init_type() {
6
behaviors().name("IterT");
7
behaviors().doc("IterT(ini_count)");
8
// you must have overwritten the virtual functions
9
// Py::Object iter() and Py::Object iternext()
10
behaviors().supportIter(); // set entries in the Type Table
11
behaviors().supportRepr();
12
add_varargs_method("reversed",&IterT::reversed,"reversed()");
15
class MyIterModule : public Py::ExtensionModule<MyIterModule> {
18
MyIterModule() : Py::ExtensionModule<MyIterModule>("pycxx_iter") {
20
add_varargs_method("IterT",&MyIterModule::new_IterT,"IterT(from,last)");
21
initialize("MyIterModule documentation"); // register with Python
24
virtual ~MyIterModule() {}
27
Py::Object new_IterT(const Py::Tuple& args) {
28
if (args.length() != 2) {
29
throw Py::RuntimeError("Incorrect # of args to IterT(from,to).");
31
return Py::asObject(new IterT(Py::Int(args[0]),Py::Int(args[1])));
35
extern "C" void initpycxx_iter() {
36
// the following constructor call registers our extension module
37
// with the Python runtime system
38
static MyIterModule* IterTest = new MyIterModule;