|
Revision 113, 0.9 kB
(checked in by KirkMcDonald, 2 years ago)
|
* Improved Pyd's handling of arrays.
* Added Repr
* Added arraytest
|
| Line | |
|---|
| 1 |
module arraytest; |
|---|
| 2 |
|
|---|
| 3 |
import pyd.pyd; |
|---|
| 4 |
import std.stdio : writefln, writef; |
|---|
| 5 |
import std.string : format, toString; |
|---|
| 6 |
|
|---|
| 7 |
class Foo { |
|---|
| 8 |
int i; |
|---|
| 9 |
this(int j) { i = j; } |
|---|
| 10 |
void bar() { |
|---|
| 11 |
writefln("Foo.bar: %s", i); |
|---|
| 12 |
} |
|---|
| 13 |
char[] toString() { |
|---|
| 14 |
return "{" ~ .toString(i) ~ "}"; |
|---|
| 15 |
} |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
Foo[] global_array; |
|---|
| 19 |
|
|---|
| 20 |
Foo[] get() { |
|---|
| 21 |
writefln("get: %s", global_array); |
|---|
| 22 |
return global_array; |
|---|
| 23 |
} |
|---|
| 24 |
void set(Foo[] a) { |
|---|
| 25 |
writefln("set: a: %s, global: %s", a, global_array); |
|---|
| 26 |
global_array = a; |
|---|
| 27 |
writefln("set: global now: %s", global_array); |
|---|
| 28 |
} |
|---|
| 29 |
Foo test() { |
|---|
| 30 |
return new Foo(10); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
extern(C) void PydMain() { |
|---|
| 34 |
global_array.length = 5; |
|---|
| 35 |
for (int i=0; i<5; ++i) { |
|---|
| 36 |
global_array[i] = new Foo(i); |
|---|
| 37 |
} |
|---|
| 38 |
def!(get); |
|---|
| 39 |
def!(set); |
|---|
| 40 |
def!(test); |
|---|
| 41 |
module_init(); |
|---|
| 42 |
wrap_class!( |
|---|
| 43 |
Foo, |
|---|
| 44 |
Init!(void function(int)), |
|---|
| 45 |
Repr!(Foo.toString), |
|---|
| 46 |
Def!(Foo.bar) |
|---|
| 47 |
); |
|---|
| 48 |
} |
|---|