Experimental GTK structs-as-references support. Not enabled by default.
[girtod.git] / mixin / Gtk2__MODULE.d
blob909bea00001aaf7e9a606cd661730c72a47a1911
1 void _dumpObj(T)(T o, bool deep=0) {
2 import std.stdio;
3 auto ts = o.tupleof;
4 write(typeid(o), " {");
6 static if (is(typeof(*T)==union)) {
7 write(*o, "}\n");
8 return;
10 else
11 writeln();
13 foreach (i, t; ts) {
14 write(" (", typeid(t), ") ", t);
15 if (deep)
16 static if (is(typeof(*t)))
17 if (ts[i])
18 write(" {", *ts[i], "}");
19 write(i!=ts.length-1 ? "\n" : "\n}\n");
23 // Helpers, used by gtk.init() below.
25 auto argvToC(string argv[]) {
26 alias char* GTK_STRING;
27 GTK_STRING[] c_argv = new GTK_STRING[argv.length];
29 foreach (i, arg; argv)
30 c_argv[i] = cast(GTK_STRING)arg.ptr;
32 return c_argv.ptr;
35 string[] argvFromC(int argc, const(char*)* argv) {
36 import std.string;
37 string[] result = new string[argc];
39 for(int i=0; i<argc; i++) {
40 auto len = indexOf(argv[i][0..int.max], '\0');
41 result[i] = cast(string)argv[i][0..len];
44 return result;
47 // An overload of gtk.init() that works with D strings.
48 // Unlike the original, it does not need to modify the inputs.
49 // Returns a new string array (that can be assigned to the argv
50 // array in the caller).
52 string[] init(string argv[]) {
53 int argc = argv.length;
54 auto c_argv = argvToC(argv);
55 init(&argc, &c_argv);
56 return argvFromC(argc, c_argv);