Debian Codegraph @

ipl/packs/loadfuncpp/doc/bang.cpp

raw
1
2 /* Example of a C++ extension to icon via loadfunc,
3 * without garbage collection difficulties.
4 * Type 'make iexample' to build.
5 * Carl Sturtivant, 2008/3/16
6 */
7
8 #include "loadfuncpp.h"
9 using namespace Icon;
10
11
12
13
14 struct addup: public iterate {
15 safe total;
16 int count;
17
18 addup(): total(0L), count(0) {}
19
20 virtual void takeNext(const value& x) {
21 total = total + x;
22 }
23 virtual bool wantNext(const value& x) {
24 return ++count <= 10;
25 }
26 };
27
28 extern "C" int sumlist(value argv[]) {
29 addup sum;
30 sum.bang(argv[1]);
31 argv[0] = sum.total;
32 return SUCCEEDED;
33 }
34
35