| 1 |
// test passing objects to constructors defined in chuck |
| 2 |
|
| 3 |
// class |
| 4 |
class Foo |
| 5 |
{ |
| 6 |
fun Foo( Bar g ) |
| 7 |
{ |
| 8 |
<<< "ref:", Machine.refcount(g), "num:", g.num >>>; |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
class Bar |
| 13 |
{ |
| 14 |
int num; |
| 15 |
|
| 16 |
fun Bar(int n) |
| 17 |
{ |
| 18 |
n => num; |
| 19 |
<<< "@construct:", n >>>; |
| 20 |
} |
| 21 |
|
| 22 |
fun @destruct() |
| 23 |
{ |
| 24 |
<<< "@destruct:", num >>>; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
Bar s(1); |
| 29 |
|
| 30 |
<<< "ref:", Machine.refcount(s) >>>; |
| 31 |
|
| 32 |
// invoke from variable |
| 33 |
Foo foo1(s); |
| 34 |
|
| 35 |
// invoke with new |
| 36 |
Foo foo2( new Bar(2) ); |
| 37 |
|
| 38 |
<<< "ref:", Machine.refcount(s) >>>; |