summaryrefslogtreecommitdiff
path: root/ipl/packs/loadfuncpp/examples/jmexample.cpp
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-01-28 19:02:21 +0000
committerIgor Pashev <pashev.igor@gmail.com>2013-01-28 19:02:21 +0000
commitd78e6c19ff93964183950f846868ade625e6b537 (patch)
treef2d588a9646c8496db23d3fe868d7dce4f7dfa83 /ipl/packs/loadfuncpp/examples/jmexample.cpp
parentf944578414d5adc0c6c3fb22ad5808077444a410 (diff)
parentf627f77f23d1497c9e1f4269b5c8812d12b42f18 (diff)
downloadicon-d78e6c19ff93964183950f846868ade625e6b537.tar.gz
Merge tag 'upstream/9.5.0'
Upstream version 9.5.0
Diffstat (limited to 'ipl/packs/loadfuncpp/examples/jmexample.cpp')
-rw-r--r--ipl/packs/loadfuncpp/examples/jmexample.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/ipl/packs/loadfuncpp/examples/jmexample.cpp b/ipl/packs/loadfuncpp/examples/jmexample.cpp
new file mode 100644
index 0000000..a367fd5
--- /dev/null
+++ b/ipl/packs/loadfuncpp/examples/jmexample.cpp
@@ -0,0 +1,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);
+}
+
+