Help with reflection?

Kapps via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 10:43:12 PDT 2014


On Friday, 10 October 2014 at 17:00:01 UTC, bitwise wrote:
> Hey, I am trying to put together a basic reflection system, but 
> I've run into a problem. I'm not sure if this is a bug or not.
>
> I am trying to store method information about a class. So 
> basically, I am using Traits to go through all members of the 
> class, and then trying to create delegates to each member. 
> Then, at runtime, the function will be dynamically invoked by 
> changing the ".ptr" property of the delegate, and calling it.
>
> These are the errors I am getting from these 3 lines from the 
> code below:
>
> //del.ptr = null;
> -Error: CTFE internal error: unsupported assignment del.ptr = 
> null (TestD)
>
> //del.funcptr = mixin("&T." ~ member);
> -Error: CTFE internal error: unsupported assignment del.funcptr 
> = & someFunction (TestD)
> -Also, why has 'T' been removed after mixin?
>
> //del.funcptr = mixin("&SomeClass." ~ member);
> -Error: CTFE internal error: unsupported assignment del.funcptr 
> = & someFunction (TestD)

Without looking too much at your code, the internal error seems 
to definitely imply a bug, I recommend reporting it on the issue 
tracker.

Also, I made a Reflection module as well, you may find some of 
the code useful (such as getting methods at compile-time and 
invoking at run-time): 
https://shardsoft.com/stash/projects/SHARD/repos/shardtools/browse/source/ShardTools/Reflection.d?until=45ded3019f3f05d7b68e5746d34da1de7433ccf6#1299 
(links to a specific commit, after that I started trying to unify 
runtime and compile-time reflection into one API which gave me 
some troubles). It can get a bit complicated depending on what 
your needs are, as you would need to deal with vtables and 
interfaces depending on what you want to support. My 
implementation definitely isn't perfect, but works for my usage.


More information about the Digitalmars-d mailing list