pikapython/package/PikaStdLib/PikaStdLib_RangeObj.c

30 lines
802 B
C
Raw Normal View History

2021-12-28 01:21:47 +08:00
#include "PikaObj.h"
Arg* PikaStdLib_RangeObj___iter__(PikaObj* self) {
return arg_setPtr(NULL, "", TYPE_OBJECT, self);
}
Arg* PikaStdLib_RangeObj___next__(PikaObj* self) {
2022-01-04 19:11:47 +08:00
int a1 = args_getInt(self->list, "a1");
int a2 = args_getInt(self->list, "a2");
int a3 = args_getInt(self->list, "a3");
2021-12-28 01:21:47 +08:00
int start = 0;
int end = 0;
int foot = 1;
/* only start and end */
if (-999999999 == a3) {
start = a1;
end = a2;
}
/* start */
2022-01-04 19:11:47 +08:00
int iter_i = args_getInt(self->list, "iter_i");
2021-12-28 01:21:47 +08:00
/* iter_i is not inited */
if (-999999999 == iter_i) {
iter_i = start;
}
/* exit */
if (iter_i >= end) {
return arg_setNull(NULL);
}
2022-01-04 19:11:47 +08:00
args_setInt(self->list, "iter_i", iter_i + foot);
2021-12-28 01:21:47 +08:00
return arg_setInt(NULL, "", iter_i);
}