| 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 |
#include <cstdio> |
| 12 |
|
| 13 |
class Widget: public external { |
| 14 |
long state; |
| 15 |
public: |
| 16 |
Widget(long x): state(x) {} |
| 17 |
|
| 18 |
virtual value name() { |
| 19 |
return "Widget"; |
| 20 |
} |
| 21 |
virtual external* copy() { |
| 22 |
return new Widget(state); |
| 23 |
} |
| 24 |
virtual value image() { |
| 25 |
char sbuf[100]; |
| 26 |
sprintf(sbuf, "Widget_%ld(%ld)", id, state); |
| 27 |
return value(NewString, sbuf); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
extern "C" int iexample(int argc, value argv[]) { |
| 32 |
argv[0] = new Widget(99); |
| 33 |
return SUCCEEDED; |
| 34 |
} |
| 35 |
|