summaryrefslogtreecommitdiff
path: root/ipl/packs/loadfuncpp/examples/extwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ipl/packs/loadfuncpp/examples/extwidget.cpp')
-rw-r--r--ipl/packs/loadfuncpp/examples/extwidget.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/ipl/packs/loadfuncpp/examples/extwidget.cpp b/ipl/packs/loadfuncpp/examples/extwidget.cpp
new file mode 100644
index 0000000..bb42364
--- /dev/null
+++ b/ipl/packs/loadfuncpp/examples/extwidget.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;
+
+#include <cstdio>
+
+class Widget: public external {
+ long state;
+ public:
+ Widget(long x): state(x) {}
+
+ virtual value name() {
+ return "Widget";
+ }
+ virtual external* copy() {
+ return new Widget(state);
+ }
+ virtual value image() {
+ char sbuf[100];
+ sprintf(sbuf, "Widget_%ld(%ld)", id, state);
+ return value(NewString, sbuf);
+ }
+};
+
+extern "C" int iexample(int argc, value argv[]) {
+ argv[0] = new Widget(99);
+ return SUCCEEDED;
+}
+