What have you done with UDAs?

Alex Parrill via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 22 12:21:01 PDT 2015


On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:
> I never seem to use them for anything, has anyone else done 
> anything interesting with them?

I'm writing a program that can accept subcommands via either the 
command line (ex. `prog mycmd 1 2`) or via a shell. I represent 
each command as a function, use UDAs to store the help text and 
if they can be ran from the command line or shell. The command 
list, full help text, and command dispatcher is generated at 
compile time via templates, CTFE, and static foreach.

An example command:

@("<nanoseconds>") // arguments
@("Sets the amount of time to increment the clock on each 
frame.") // description
@ShellOnly // can't be ran from command line
int cmd_set_time_per_frame(string[] args) {
     // ...
}


More information about the Digitalmars-d mailing list