summaryrefslogtreecommitdiff
path: root/ipl/packs/loadfuncpp/examples/extwidget.cpp
blob: bb42364bc6feac3cf09ab8f330632cb87c812e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}