Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module main;
- import std.stdio;
- import orange.serialization._;
- import orange.serialization.archives._;
- alias writeln println;
- enum code = `image({
- id = "image2";
- source = "images/Alpha-blue-trans.png";
- mouseArea({
- id = "mArea2";
- width = 3;// _ => image2.width;
- height = 4;//_ => image2.height;
- onPressedChanged = {
- writeln("onPressedChanged");
- writeln(3/*mArea2.mouseX*/);
- };
- });
- });`;
- void executeScript ()
- {
- mixin(code);
- }
- void main ()
- {
- executeScript();
- writeln(DQuickDsl.serialize());
- }
- struct DQuickDsl
- {
- static string serialize ()
- {
- auto archive = new XmlArchive!(char);
- auto serializer = new Serializer(archive);
- serializer.serialize(root);
- return archive.data;
- }
- }
- class Item
- {
- string id;
- string source;
- int width;
- int height;
- Item[] childern;
- @nonSerialized void delegate () onPressedChanged;
- }
- Item root;
- Item currentItem;
- void image (void delegate () block)
- {
- restore!(currentItem, {
- newItem();
- block();
- });
- }
- void id (string id)
- {
- currentItem.id = id;
- }
- void source (string source)
- {
- currentItem.source = source;
- }
- void mouseArea (void delegate () block)
- {
- restore!(currentItem, {
- newItem();
- block();
- });
- }
- void onPressedChanged (void delegate () block)
- {
- currentItem.onPressedChanged = block;
- }
- void newItem ()
- {
- auto item = new Item;
- if (!root)
- root = item;
- if (currentItem)
- currentItem.childern ~= item;
- currentItem = item;
- }
- void restore (alias var, alias block) ()
- {
- auto tmp = var;
- scope (exit)
- var = tmp;
- block();
- }
- void width (int width)
- {
- currentItem.width = width;
- }
- void height (int height)
- {
- currentItem.height = height;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement