"Gor Gyolchanyan" <[email protected]> wrote in message news:[email protected]... >I was thinking more of a run-time D interpreter as a library solution. > One of D's features could be the ability to interpret itself at > run-time as a script of some sort. Having a compiler as a library > solution would further improve this by generating DLLs from given code > programmatically and return symbols. This would be even better, then > java's dynamic class loading. >
I've actually started work on a way to do this that works by invoking a dmd command line, running the result, and capturing the stdout output. I actually got a very, very basic form of it working (all it can do, IIRC, is perform some processing and then return an integer or a string). This approach has a *very* high overhead cost, so you'd only want to use it for things that are already computationally expenive anyway, but it's technically viable: The function: http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/util/process.d#L49 Example usage: auto x = eval!int(q{ return 42; }); assert(x == 42); auto str = eval!(char[])(q{ return "Test string".dup; }); assert(str == "Test string"); The use of serialization could extend that to other types.
