summaryrefslogtreecommitdiff
path: root/ipl/packs/loadfuncpp/doc/bang.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ipl/packs/loadfuncpp/doc/bang.cpp')
-rw-r--r--ipl/packs/loadfuncpp/doc/bang.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/ipl/packs/loadfuncpp/doc/bang.cpp b/ipl/packs/loadfuncpp/doc/bang.cpp
new file mode 100644
index 0000000..c300169
--- /dev/null
+++ b/ipl/packs/loadfuncpp/doc/bang.cpp
@@ -0,0 +1,35 @@
+
+/* 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;
+ int count;
+
+ addup(): total(0L), count(0) {}
+
+ virtual void takeNext(const value& x) {
+ total = total + x;
+ }
+ virtual bool wantNext(const value& x) {
+ return ++count <= 10;
+ }
+};
+
+extern "C" int sumlist(value argv[]) {
+ addup sum;
+ sum.bang(argv[1]);
+ argv[0] = sum.total;
+ return SUCCEEDED;
+}
+
+