Introspection/Reflection/etc on Linux

J Arrizza cppgent0 at gmail.com
Sat Oct 22 23:59:48 PDT 2011


The idea here was to create a base class. That base class would have a
function register() which took a function name or function pointer, and
create a delegate at compile time. register() would add the delegate  and
the function name as a string into the hash. At runtime, I pass in the
string, get the delegate and invoke the function.

So I need both the function name as a symbol (to create the delegate) and
the function name as a string. In c++ I'd use the preprocessor to convert
the symbol to a string via "#" (stringify).

If D doesn't have this, the callers will have to do:

     register(bob, "bob");

which is a little tedious.

BTW I tried:

   public void register(string name)   {
     auto func = __traits(getMember, this, name);

but __traits() only works at compile time, but variable name is only
available at run-time....

John

On Sat, Oct 22, 2011 at 8:45 PM, Robert Jacques <sandford at jhu.edu> wrote:

> On Sat, 22 Oct 2011 21:17:09 -0400, J Arrizza <cppgent0 at gmail.com> wrote:
>
>  This would be easier with "stringify":
>>     register(bob, #bob);
>>
>> Anything like that in D?
>>
>> John
>>
>
> What do you mean by "stringify"? Wouldn't register!bob be superior?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20111022/61fd7dfc/attachment.html>


More information about the Digitalmars-d mailing list