Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 26, 2019 Extract code of function | ||||
---|---|---|---|---|
| ||||
Hello,
Is it possible to extract code of some function into string variable using CT reflextion?
For example:
> int test(bool flag)
> {
> return flag ? 100 : getRandom();
> }
>
> enum string code = GetFunctionCode!test; // "return flag ? 100 : getRandom();"
|
May 26, 2019 Re: Extract code of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey | On 2019-05-26 19:46, Andrey wrote: > Hello, > Is it possible to extract code of some function into string variable using CT reflextion? > For example: >> int test(bool flag) >> { >> return flag ? 100 : getRandom(); >> } >> >> enum string code = GetFunctionCode!test; // "return flag ? 100 : getRandom();" No, that's not possible. -- /Jacob Carlborg |
May 26, 2019 Re: Extract code of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey | On Sunday, 26 May 2019 at 17:46:35 UTC, Andrey wrote:
> Hello,
> Is it possible to extract code of some function into string variable using CT reflextion?
> For example:
>> int test(bool flag)
>> {
>> return flag ? 100 : getRandom();
>> }
>>
>> enum string code = GetFunctionCode!test; // "return flag ? 100 : getRandom();"
You can hack this by using import(filename) and importing the file. If you had a good D parser you could potentially do this safely. You must use the -J switch though.
|
May 26, 2019 Re: Extract code of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Sunday, 26 May 2019 at 18:14:23 UTC, Jacob Carlborg wrote: > No, that's not possible. Some hacky solutions are possible by importing a source file as a string and parsing it manually. dglsl actually extracts D function code to put into glsl shaders. Here's the snippet. See: https://github.com/icecocoa6/dglsl/blob/master/source/dglsl/translator.d#L140 |
May 26, 2019 Re: Extract code of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | On Sunday, 26 May 2019 at 18:21:23 UTC, Dennis wrote:
> On Sunday, 26 May 2019 at 18:14:23 UTC, Jacob Carlborg wrote:
>> No, that's not possible.
>
> Some hacky solutions are possible by importing a source file as a string and parsing it manually. dglsl actually extracts D function code to put into glsl shaders. Here's the snippet. See: https://github.com/icecocoa6/dglsl/blob/master/source/dglsl/translator.d#L140
Interesting solution... Thanks for a hint.
|
Copyright © 1999-2021 by the D Language Foundation