www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Parsing a string to instantiate classes at runtime

reply Marduk <mardukbp mac.com> writes:
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.
Nov 27 2016
parent reply ag0aep6g <anonymous example.com> writes:
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.
Nov 27 2016
parent reply Marduk <mardukbp mac.com> writes:
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.
Nov 27 2016
next sibling parent reply ag0aep6g <anonymous example.com> writes:
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.
Nov 27 2016
parent Marduk <mardukbp mac.com> writes:
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.
Nov 28 2016
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
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
Nov 28 2016
parent reply Marduk <mardukbp mac.com> writes:
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.
Nov 28 2016
parent Jacob Carlborg <doob me.com> writes:
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
Nov 28 2016