From f627f77f23d1497c9e1f4269b5c8812d12b42f18 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Mon, 28 Jan 2013 19:02:21 +0000 Subject: Imported Upstream version 9.5.0 --- ipl/packs/loadfuncpp/examples/extwidget.cpp | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ipl/packs/loadfuncpp/examples/extwidget.cpp (limited to 'ipl/packs/loadfuncpp/examples/extwidget.cpp') 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 + +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; +} + -- cgit v1.2.3