D and reflection

amehat via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 01:40:18 PDT 2014


On Thursday, 8 May 2014 at 01:52:05 UTC, Domain wrote:
> On Wednesday, 7 May 2014 at 18:24:23 UTC, Kapps wrote:
>> 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.
>
> I think something like this should be included in phobos

Thank you all for your responses and responsiveness.
Indeed, John Colvin, I did not know what forum posted this. The 
next time I would do in D.learn, sorry for this mistake.

Many of your proposal works perfectly. I can continue porting my 
library.


More information about the Digitalmars-d mailing list