On 2012-12-17 02:39, F i L wrote:
My goal is this, to have an XML file:

     <!-- scene.xml -->
     <scene>
         <object class="Person" event="greet"/>
     </scene>

and a D file:

     module person;

     import std.stdio;

     class Person
     {
         void greet() {
             writeln("hello");
         }
     }

and then another D file:

     module main;

     import person;
     import std.xml;
     import std.file;

     static class Engine
     {
         static void delegate() event;
         static void callEvent() { event(); }
     }

     void main() {
         auto doc = new Document(read("scene.xml"));
         auto className = /* find class name in xml file */;
         auto eventName = /* find event name in xml file */;
         auto obj = Object.factory(className);

         Engine.event = /* get 'eventName' void in 'obj' */;

         for (/* some loop */) { Engine.callEvent(); }
     }

So yeah, basically is is possible to create a general object, then look
at it's members at runtime? Through maybe a .classinfo or something? Or
is this level of runtime reflection simply not supported in D (yet)? If
so, what are my best alternative options here?

For the serialization part you could have a look at Orange:

https://github.com/jacob-carlborg/orange

It won't handle the dynamic methods though.

--
/Jacob Carlborg

Reply via email to