Extract code of function
Aphex
Aphex at mail.com
Sun May 26 18:16:17 UTC 2019
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.
More information about the Digitalmars-d-learn
mailing list