Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friendlier "ArgumentText" and "ArgumentHelp" #88

Closed
rmanthorpe opened this issue May 1, 2020 · 3 comments
Closed

Friendlier "ArgumentText" and "ArgumentHelp" #88

rmanthorpe opened this issue May 1, 2020 · 3 comments

Comments

@rmanthorpe
Copy link

Now that D supports UDAs on parameters it would be nice to have an @ExcelArgument UDA that you could use like this:

import xlld;

@Excel(
       HelpTopic("Adds all cells in an array"),
       FunctionHelp("Adds all cells in an array")
)
double FuncAddEverything(
    @ExcelArgument(Description("Array to add"), HelpTopic("url/of/help/topic")) double[][] args
);
@atilaneves
Copy link
Collaborator

I can't find any documentation on actually getting a UDA from a parameter though.

@adamdruppe
Copy link
Collaborator

i have a little aside tucked away in my blog about it:

http://dpldocs.info/this-week-in-d/Blog.Posted_2019_02_11.html#how-to-get-uda-on-a-function-param

...which is the only written thing i'm familiar with. i know at least one other person knows how to do this but i'm not familiar with any other public link on it!

@atilaneves
Copy link
Collaborator

Turns out this does it:

template getParamUDAs(alias fun, size_t paramIdx)
{
    alias P = BetterParams!fun[paramIdx .. paramIdx+1];
    static if(__traits(compiles, __traits(getAttributes, P)))
        alias getParamUDAs = __traits(getAttributes, P);
    else {
        import std.meta: AliasSeq;
        alias getParamUDAs = AliasSeq!();
    }
}


import std.traits: isCallable;
template BetterParams(func...)
if (func.length == 1 && isCallable!func)
{
    import std.traits : FunctionTypeOf;
    static if (is(FunctionTypeOf!func P == __parameters))
        alias BetterParams = P;
    else
        static assert(0, "argument has no parameters");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants