Thread overview
Parsing a string to instantiate classes at runtime
Nov 27, 2016
Marduk
Nov 27, 2016
ag0aep6g
Nov 27, 2016
Marduk
Nov 27, 2016
ag0aep6g
Nov 29, 2016
Marduk
Nov 28, 2016
Jacob Carlborg
Nov 29, 2016
Marduk
Nov 29, 2016
Jacob Carlborg
November 27, 2016
Dear all,

I would like to write a program that:

1. Receives a string from the UI
2. Parses the string
3. Instantiates classes, whose names are contained in the string, passing parts of the string as constructor arguments.

From my experience with other programming languages, I suppose I need to define an eval function.

I read in an old post in these forums that with a dynamic mixin it is possible to add structures and classes at runtime. I searched "dynamic mixin" but I did not find more information.

Any help will be greatly appreciated.
November 27, 2016
On 11/27/2016 10:02 PM, Marduk wrote:
> I read in an old post in these forums that with a dynamic mixin it is
> possible to add structures and classes at runtime. I searched "dynamic
> mixin" but I did not find more information.

Can you link that post, please? I can't imagine what "dynamic mixin" could refer to.
November 27, 2016
On Sunday, 27 November 2016 at 21:10:30 UTC, ag0aep6g wrote:
> Can you link that post, please? I can't imagine what "dynamic mixin" could refer to.

Sure, it's here: http://forum.dlang.org/post/xmnnsdiuwyjrhkasyuyg@forum.dlang.org

In that thread they also mention Object.factory, but the documentation says that the class must have either no constructor or the default constructor, which is not my case.

November 27, 2016
On 11/27/2016 10:19 PM, Marduk wrote:
> On Sunday, 27 November 2016 at 21:10:30 UTC, ag0aep6g wrote:
>> Can you link that post, please? I can't imagine what "dynamic mixin"
>> could refer to.
>
> Sure, it's here:
> http://forum.dlang.org/post/xmnnsdiuwyjrhkasyuyg@forum.dlang.org

Ok, that's a hypothetical. It's "if D had a 'dynamic mixin', then we could do fancy things with it." D doesn't have a 'dynamic mixin', so you can't do those fancy things, at least not in the envisioned way.
November 28, 2016
On 2016-11-27 22:19, Marduk wrote:

> Sure, it's here:
> http://forum.dlang.org/post/xmnnsdiuwyjrhkasyuyg@forum.dlang.org
>
> In that thread they also mention Object.factory, but the documentation
> says that the class must have either no constructor or the default
> constructor, which is not my case.

It's possible to bypass the constructors [1].

[1] https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L166

-- 
/Jacob Carlborg
November 29, 2016
On Sunday, 27 November 2016 at 21:28:52 UTC, ag0aep6g wrote:

> Ok, that's a hypothetical. It's "if D had a 'dynamic mixin', then we could do fancy things with it." D doesn't have a 'dynamic mixin', so you can't do those fancy things, at least not in the envisioned way.

You are right. I misread.
November 29, 2016
On Monday, 28 November 2016 at 09:33:08 UTC, Jacob Carlborg wrote:

> It's possible to bypass the constructors [1].
>
> [1] https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L166

Aha! Interesting. Thanks.
November 29, 2016
On 2016-11-29 07:46, Marduk wrote:

> Aha! Interesting. Thanks.

Then you can call a custom method that acts as a constructor when the instance is created this way, if there's a need for it.

-- 
/Jacob Carlborg