Mixin Expressions, can't evalutate string variable
Philippe Sigaud
philippe.sigaud at gmail.com
Thu Aug 5 14:29:18 PDT 2010
On Thu, Aug 5, 2010 at 22:24, Andrej Mitrovic <andrej.mitrovich at gmail.com>wrote:
> Thanks, Steven!
>
> You don't want to know what I'm up to :p.
>
Yes, yes, wo do!
>
> I'm using some traits to find out what kind of parameters a function takes.
> I'm also using a demangler from phobos to find out the name of the function
> (But I can't find any straightforward way to get a name of a function
> without getting back "1D_5std_5funcName" etc, so I just take a hardcoded
> slice).
>
You can get the name of an alias using __traits(identifier, aliasName), like
this for example:
template Name(alias a)
{
enum string Name = __traits(identifier, a);
}
int foo(int i) { return 0;}
import std.stdio;
void main()
{
writeln(Name!foo); // "foo", not "a".
}
As for demangling, how do you do to get mangled names in the first place?
>
> Anyway, I have a template function which takes as it's parameters a
> function (aliased to func), and some arguments (right now just one in my
> hardcoded code). It then creates a string which can be compiled via the
> mixin. It constructs the string by checking the parameter types of func, and
> for any ref or out parameter it detects it appends something like this to a
> string:
> "long var1; long var2; long var3; ".
>
How can you know if a parameter is ref or out?
I remember seeing something about it in Phobos svn, are you using it?
> So anyway, at the calling site I have this:
>
> mixin(unpack!(getTimes)(r"C:\\cookies"));
>
> getTimes() is a Phobos function with the signature:
> getTimes(in char[] name, out d_time ftc, out d_time fta, out d_time ftm)
>
> And now I automatically have var1, var2, and var3 at my disposal.
>
That's fun :)
>
> It was just an exercise for fun but it's cool that things like this are
> possible in D. It would be nice if I could get the actual names of the
> parameters the function takes + the clear name of the function itself, that
> way I'd actually get back variables "ftc, fta, ftm" back)
I'm pretty sure I saw some code to do this. But maybe that was a D1 thing,
using mangled names, too.
in dsource/scrapple?
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100805/f1045e1e/attachment.html>
More information about the Digitalmars-d
mailing list