April 17, 2015
On Fri, 17 Apr 2015 05:30:04 -0400, Jacob Carlborg <doob@me.com> wrote:

> On 2015-04-17 01:25, bitwise wrote:
>
>> Ok, that sounds right. D has no multiple or virtual inheritance, so I
>> guess things should be fine. C# is the same way(single inheritance,
>> interfaces) which is likely designed to avoid these kinds of issues.
>>
>> I would be modifying the offTi() property though, not getMembers().
>> getMembers() actually works right now, although it's kinda useless.
>> Basically, if you put any function named "getMembers" at module scope,
>> the address of that function can be retrieved using
>> ModuleInfo.xgetMembers().
>
> We need a "getMembers" on ClassInfo. Because "typeid" will resolve the dynamic type. The problem is this code:
>
> class Bar {}
> class Foo : Bar {}
>
> void main ()
> {
>      Bar a = new Foo;
>      writeln(typeid(a));
> }
>
> Compile time reflection cannot be used to get the members in this case.
>


Sorry, that's what I meant(using this on classes, not modules). xgetMembers/getMembers seems to be designed so that the caller can write their own getMembers() function, whereas offTi() is designed to return an array that was automatically generated.

offTi() is actually defined in TypeInfo:
https://github.com/D-Programming-Language/druntime/blob/cfcf7480b2faea0af9ab6ddba8e3b0d9f05c4415/src/object_.d#L301

and overridden for TypeInfo_Class:
https://github.com/D-Programming-Language/druntime/blob/cfcf7480b2faea0af9ab6ddba8e3b0d9f05c4415/src/object_.d#L831

but TypeInfo_Class.m_offTi is never populated:
https://github.com/D-Programming-Language/dmd/blob/master/src/toobj.c#L436

So while this code technically works, there will be no output:

class Test {
    int a = 4;
    int b = 5;
    int c = 6;
}

void main()
{
    foreach(const(OffsetTypeInfo) off; typeid(Test).offTi())
        writeln(off.offset);
}
September 27, 2017
On Monday, 30 March 2015 at 01:11:55 UTC, bitwise wrote:
> I came across this post a while back and decided to implement it:
> http://forum.dlang.org/thread/juf7sk$16rl$1@digitalmars.com
>
> My implementation:
> https://github.com/bitwise-github/D-Reflection
>
> The above conversation seemed to stop abruptly, so I went on to assume that no one chose to champion the task.
>
> At the time, I looked around for other conversations or attempts at runtime reflection for D, but couldn't really find anything. I did find the ModuleInfo/reflection stuff in object.d, but it seemed like an effort that may have been abandoned. Also, the above conversation seemed to suggest it should be opt-in, which also made me wonder if the stuff in object.d was abandoned or for a different purpose.
>
> Looking again today, someone seems to have been working on it a bit.. For example, MemberInfo_field and MemberInfo_function were empty last time I checked.
>
> So what's the current state of things?
> Is anybody working on it?
>
> Although MemberInfo_field exists, it doesn't seem to be available from TypeInfo_Class... Is that the eventual goal?
>
> Is there anything I can do to help get things moving?
>
>
> Any comments on my implementation would be welcome as well.
> (https://github.com/bitwise-github/D-Reflection)
>
> main.d shows some general use cases, but basically, if the reflect(T) template is used on a class,
> that class, and any child types will be reflected. Recursive reflection only propagates downward, or else it could leak sideways and unnecessarily reflect several modules.
>
> Most of the reflection information is available at compile time. For example:
>
> enum name = reflectModule!(test).findClass("Test").findField("variable").name;
> pragma(msg, name); // "variable" will be outputted.
>
> To make a module available for runtime reflection, the following can be used:
> mixin(runtimeReflection!test);
>
> At this point, the above example can be rewritten as:
>
> string name = getModuleReflection("tests.test").findClass("Test3").findField("static_variable").name;
> writeln(name);

Hi, your link is not working any more and I really need your implementation.
Gabriel
September 28, 2017
On Wednesday, 27 September 2017 at 20:38:51 UTC, Gheorghe Gabriel wrote:
> On Monday, 30 March 2015 at 01:11:55 UTC, bitwise wrote:
>> [...]
>
> Hi, your link is not working any more and I really need your implementation.
> Gabriel

I took the code down because there were design flaws I had to work out. I've reworked the code significantly at this point. I can throw a copy up on github in a day or two if you need it.

There are still some issues to overcome though, which may or may not be a problem depending on what you're doing.
September 28, 2017
On Thursday, 28 September 2017 at 01:33:35 UTC, bitwise wrote:
> On Wednesday, 27 September 2017 at 20:38:51 UTC, Gheorghe Gabriel wrote:
>> On Monday, 30 March 2015 at 01:11:55 UTC, bitwise wrote:
>>> [...]
>>
>> Hi, your link is not working any more and I really need your implementation.
>> Gabriel
>
> I took the code down because there were design flaws I had to work out. I've reworked the code significantly at this point. I can throw a copy up on github in a day or two if you need it.
>
> There are still some issues to overcome though, which may or may not be a problem depending on what you're doing.

Thank you, I really need it for my project.
I want to load scripts in a 3D scene without compiling an restarting the whole engine.

example:

module game1.player;

class Player : Actor {

    this(string name) {
        super(name)
    }

    ~this() {}

    void jump() { ... }

    @Editable("Slider")("min = 0; max = 5;")
    ushort lives = 5;
}

In this moment I want to load this script and create a scene object.
I should load Player class, then all its public methods, then its public members and check theire attributes.
1 2 3 4 5
Next ›   Last »