D and reflection
Kapps via Digitalmars-d
digitalmars-d at puremagic.com
Wed May 7 11:24:22 PDT 2014
On Wednesday, 7 May 2014 at 16:51:10 UTC, amehat wrote:
> Hello everyone,
>
> I'm working on porting a java library in D, and I stuck on a
> class because it works with the reflection.
>
> From what I've read on prowiki
> (http://www.prowiki.org/wiki4d/wiki.cgi?LanguagesVersusD), D
> can not do reflection, it is limited to the Run-Time Type
> Information (RTTI ) (http://dlang.org/traits.html).
>
> Here is the piece of code that blocks me:
>
> static {
> Class clazz = this.class;
>
> auto accessible2Args = new Callback(clazz,
> "accessibleProc", 2);
> auto proc2Args = accessible2Args.getAddress();
> if (proc2Args === 0) {
> (...)
> }
> (...)
> }
>
> I am looking for a workaround that I have not found yet.
> If someone an idea on the subject, I'm interested.
>
> Thank you to you.
You can generate reflection data at compile-time to use at
runtime.
For an example, you can take a look at
https://shardsoft.com/stash/projects/SHARD/repos/shardtools/browse/source/ShardTools/Reflection.d
(docs: https://shardsoft.com/docs/ShardTools/Reflection.html). I
wouldn't use the file/repo directly, but feel free to take
anything you find useful from it.
More information about the Digitalmars-d
mailing list