blob: a367fd522e63394c6230e18ad9e6a65bec9979f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* Example of a C++ extension to icon via loadfunc,
* without garbage collection difficulties.
* Type 'make <platform>' to build.
* For available <platform>s type 'make'.
* Carl Sturtivant, 2007/9/25
*/
#include "loadfuncpp.h"
enum { JMUP, JMDOWN };
class sequence: public generator {
long count;
long limit;
int direction;
bool hasNext() {
switch(direction) {
case JMUP:
return count <= limit;
case JMDOWN:
return count >= limit;
default:
return false;
}
}
value giveNext() {
switch(direction) {
case JMUP:
return count++;
case JMDOWN:
return count--;
default:
return nullvalue;
}
}
public:
sequence(value start, value end) {
count = start;
limit = end;
direction = ((count < limit) ? JMUP : JMDOWN);
};
};
extern "C" int jm_test_1(int argc, value argv[]) {
if( argc != 2 ) {
return FAILED;
}
sequence s(argv[1], argv[2]);
return s.generate(argv);
}
|