Re: How to create GTK+ apps with Glade and D on windows

2019-05-31 Thread Aphex via Digitalmars-d-learn

On Friday, 31 May 2019 at 18:47:06 UTC, Obsidian Jackal wrote:
I'm new to D and want to create GTK+ apps. I have Visual 
Studio, Glade, the Gtk+ runtime, DMD, and DUB installed. What 
steps, guides, or advice should I follow to be able to be able 
to use these tools together to make a sane app?.

I wrote some D code that parses a glade interface file and 
converts it in to easily accessible D code.

You use the ID field in glade to specify the D object name.

Go to github's gtkD to find a reference to it in issues. It's not 
perfect and might require a little work figuring it out but it 
works out nice once you get it set up.

It's basically used like

class App : GtkBase!("Interface.Glade")

and then App will have all the objects ID's as objects.

e.g., if you have a label in the glade interface with ID label, 


is the gtkD object for that label.

Re: Extract code of function

2019-05-26 Thread Aphex via Digitalmars-d-learn

On Sunday, 26 May 2019 at 17:46:35 UTC, Andrey wrote:

Is it possible to extract code of some function into string 
variable using CT reflextion?

For example:

int test(bool flag)
return flag ? 100 : getRandom();

enum string code = GetFunctionCode!test; // "return flag ? 100 
: getRandom();"

You can hack this by using import(filename) and importing the 
file. If you had a good D parser you could potentially do this 
safely. You must use the -J switch though.

Instantiate templated class at runtime

2019-05-26 Thread Aphex via Digitalmars-d-learn
I have been using Orange SerDes library for an application and 
have run in to a major hurdle. I have the need to SerDes a 
templated class. It seems Orange can only Serialize the class but 
when it attempts to deserialize it at runtime it cannot build the 

It represents the type in the output as `Issue1.Y!string.Y` which 
doesn't even seem right but regardless, it cannot seem to create 
a new instance of Y!T.

I realize that the templates do not probably exist at runtime for 
instantiation and so this is impossible, but Y!string surely does 
exist since I create an object with it(although if separate paths 
exist I could see how it could be an issue).

I need to be able to create such classes because it seems to be 
the only limitation of deseralizing templates:

If, for example, I modify the instance creation code(in 

Object newInstance (string name)
auto classInfo = ClassInfo.find(name);

if (!classInfo)

if (name == "Issue1.Y!string")
import Issue1;
return new Y!string;
if (name == "Issue1.Y!int")
import Issue1;
return new Y!int;

		throw new Exception("Cannot find runtime class information for 
`"~name~"` to instantiate!");

return null;

return newInstance(classInfo);

and manually create the classes then everything seems to work 

I have a few questions:

1. Is it possible to have a runtime class and struct creator 
function that can deal with templates. It doesn't seem like it 
should be that big a deal. One only needs to actually know the 
size of class and that will depend on the template parameter 
sizes, which if they are known then everything is known?

2. Is the output or Orange for templated classes correct? 
"Issue1.Y!string.Y" or should it be "Issue1.Y!string"? Else this 
is a bug that I'll need to track down and fix.

3. I figure that 1 might be a bit off so I will have to hack the 
code to create a factory to build the various templated types 
I'll use. This is not ideal.

In any case, my feeling is that ClassInfo should handle templated 
classes too.

-- MWE 

import std.stdio;

import orange.serialization.Serializable : nonSerialized;
import std.file;
import orange.serialization._, orange.serialization.archives._;

class C
int x = 53;

class Y(T) : C
T x;


int main()

auto archive = new XmlArchive!(char); // create an XML archive
	auto serializer = new Serializer(archive); // create the 


C c = new C();

C[] ya;
auto yi = new Y!int;
yi.x = 22;
auto ys = new Y!string;
ys.x = "sfda";
ya ~= yi;
ya ~= ys;

auto slfp = `test.xml`;
if (!false && exists(slfp))

auto f =;
auto ud = archive.untypedData;

ya = serializer.deserialize!(C[])(ud);

} else
// write xml file
std.file.write(slfp, cast(byte[])serializer.serialize(ya));

return 0;