Search in sources :

Example 1 with PyRangeIteratorObject

use of org.cafebabepy.runtime.object.iterator.PyRangeIteratorObject in project cafebabepy by cafebabepy.

the class PyRangeType method __iter__.

@DefinePyFunction(name = __iter__)
public PyObject __iter__(PyObject self) {
    if (!this.runtime.isInstance(self, this)) {
        throw this.runtime.newRaiseTypeError("descriptor '__iter__' requires a 'range' object but received a '" + self.getType().getFullName() + "'");
    }
    PyObject start = this.runtime.getattr(self, "start");
    PyObject stop = this.runtime.getattr(self, "stop");
    PyObject step = this.runtime.getattr(self, "step");
    int startInt = ((PyIntObject) start).getIntValue();
    int stopInt = ((PyIntObject) stop).getIntValue();
    int stepInt = ((PyIntObject) step).getIntValue();
    return new PyRangeIteratorObject(this.runtime, startInt, stopInt, stepInt);
}
Also used : PyRangeIteratorObject(org.cafebabepy.runtime.object.iterator.PyRangeIteratorObject) PyObject(org.cafebabepy.runtime.PyObject) PyIntObject(org.cafebabepy.runtime.object.java.PyIntObject) DefinePyFunction(org.cafebabepy.runtime.module.DefinePyFunction)

Aggregations

PyObject (org.cafebabepy.runtime.PyObject)1 DefinePyFunction (org.cafebabepy.runtime.module.DefinePyFunction)1 PyRangeIteratorObject (org.cafebabepy.runtime.object.iterator.PyRangeIteratorObject)1 PyIntObject (org.cafebabepy.runtime.object.java.PyIntObject)1