<div class="gmail_quote">On Wed, Sep 15, 2010 at 22:19, Nick Sabalausky <span dir="ltr">&lt;a@a.a&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
One thing that could be used for that is the eval() function I&#39;ve recently<br>
added to my SemiTwist D Tools library:<br>
<br>
<a href="http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/util/process.d" target="_blank">http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/util/process.d</a><br>
<br>
Example:<br>
-----------------------------<br>
import semitwist.util.all;<br>
void main()<br>
{<br>
    auto x = eval!int(q{ return 21 * 2; }); // String can be<br>
runtime-generated<br>
    assert(x == 42);<br>
<br>
    eval!void( q{ writeln(&quot;Hello World&quot;); }, q{ import std.stdio; } );<br>
}<br></blockquote><div><br></div><div>Oh, interesting! </div><div>I had a look at your code. I like this part:</div><div><br></div><div><span class="Apple-style-span" style="font-family: monospace; font-size: 11.1111px; "><span class="n">code</span> <span class="p">=</span> <span class="n">boilerplate</span><span class="p">.</span><span class="n">format</span><span class="p">(</span><span class="n">imports</span><span class="p">,</span> <span class="n">TRet</span><span class="p">.</span><span class="n">stringof</span><span class="p">,</span> <span class="n">code</span><span class="p">);</span></span></div>
<div><span class="Apple-style-span" style="font-family: monospace; font-size: 11.1111px; "><span class="p"><br></span></span></div><div>Inside boilerplate, I wonder if it&#39;s possible to test for auto ret = _main() inside a static if(is(typeof(  )))? That way, if _main() &#39;returns&#39; a void, the static if won&#39;t check and you know you have a void return value.</div>
<div><br></div><div><br></div><div><font class="Apple-style-span" face="monospace" size="4"><span class="Apple-style-span" style="font-size: 16px;"><br></span></font></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

-----------------------------<br>
<br>
It does require dmd and rdmd to be on the path.<br>
<br>
I hadn&#39;t posted anything about it before because it&#39;s still<br>
rough-around-the-edges and needs polish. For instance, most of the useful<br>
phobos modules aren&#39;t imported by default, and it doesn&#39;t yet support<br>
returning string/wstring/dstring - you have to return char[]/wchar[]/dchar[]<br>
instead and then convert back to string/wstring/dstring (but that shouldn&#39;t<br>
be too hard to fix). Also, on Windows it requires a patched version of rdmd,<br>
which is included with the library (<br>
<a href="http://www.dsource.org/projects/semitwist/browser/trunk/rdmdAlt.d" target="_blank">http://www.dsource.org/projects/semitwist/browser/trunk/rdmdAlt.d</a> ) but eval<br>
doesn&#39;t yet compile it if it isn&#39;t already compiled, and it assumes it&#39;s on<br>
the path (I&#39;ve already solved both of these in the included stbuild program,<br>
I just need to move the solution over into the general library). My ultimate<br>
goal with this is to hack up DMD just enough to make it work at compile-time<br>
(so that *any* arbitrary code can be run at compile-time, albiet more<br>
awkwardly and with much more overhead than ordinary CTFE).<br>
<br>
<br>
<br>
</blockquote></div><br>