digitalmars.D.learn - Extract code of function
- Andrey (4/10) May 26 2019 Hello,
- Jacob Carlborg (4/15) May 26 2019 No, that's not possible.
- Dennis (5/6) May 26 2019 Some hacky solutions are possible by importing a source file as a
- Andrey (2/9) May 26 2019 Interesting solution... Thanks for a hint.
- Aphex (4/15) May 26 2019 You can hack this by using import(filename) and importing the
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
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:No, that's not possible. -- /Jacob Carlborgint test(bool flag) { return flag ? 100 : getRandom(); } enum string code = GetFunctionCode!test; // "return flag ? 100 : getRandom();"
May 26 2019
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
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:Interesting solution... Thanks for a hint.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
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: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.int test(bool flag) { return flag ? 100 : getRandom(); } enum string code = GetFunctionCode!test; // "return flag ? 100 : getRandom();"
May 26 2019