How Nested Functions Work, part 1
Daniel Keep
daniel.keep.lists at gmail.com
Wed Sep 2 21:41:39 PDT 2009
Jarrett Billingsley wrote:
> ...
>
> void foob(T: Ret function(Args), Ret, Args...)(T func)
> {
> pragma(msg, ParameterTupleOf!(T).stringof);
> static void wtf(ParameterTupleOf!(T) args) {}
> pragma(msg, ParameterTupleOf!(T).stringof);
> }
>
> void blah(int, ref float) {}
>
> void aojkjas()
> {
> foob(&blah);
> }
>
> Okay, look at foob's body. Both pragmas should print out the same thing, no?
>
> They don't.
>
> They print:
>
> (int, ref float)
> (int _param_0, float _param_1)
>
> WHAT. For one, where did the 'ref' go? For two, where did the names
> come from? Also, if you look at typeof(&wtf), it's also missing the
> ref.
Yeah, I've noticed this, too. Parameter tuples are just outright screwed.
> I'd really, really like to replace your entire module with this:
>
> Ret delegate(Args) toDg(T: Ret function(Args), Ret, Args...)(T func)
> {
> struct Wrap
> {
> T mFunc;
>
> Ret call(Args args)
> {
> return (cast(T)this)(args);
> }
> }
>
> Ret delegate(Args) dg;
> Wrap wrap;
> dg.ptr = func;
> dg.funcptr = &wrap.call;
> return dg;
> }
You and me both. That said, this code is ported from an experimental
library for binding D to lua; it used something similar to detect ref
and out and change the function signature (outs became multiple returns,
for example).
More information about the Digitalmars-d
mailing list