blob: 9f60d135bc59bc422277cfdd0e9af5bc18a0b3b3 (
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
|
/* Example of a C++ extension to icon via loadfunc,
* without garbage collection difficulties.
* Type 'make iexample' to build.
* Carl Sturtivant, 2008/3/16
*/
#include "loadfuncpp.h"
using namespace Icon;
struct addup: public iterate {
safe total;
addup(): total((long)0) {}
virtual void takeNext(const value& x) {
total = total + x;
}
};
extern "C" int iexample(int argc, value argv[]) {
addup sum;
sum.every(argv[1], argv[2]);
argv[0] = sum.total;
return SUCCEEDED;
}
|