On Tuesday, 12 July 2016 at 08:34:03 UTC, Kagamin wrote:
Store a wrapper instead of the actual function:
void wrapper(alias F)(string[] args)
{
(convert args to F arguments) and invoke
}
cmd.func = &wrapper!someFunc;
string[] args;
cmd.func(args);
Thanks that is clever. Never would have tho
Store a wrapper instead of the actual function:
void wrapper(alias F)(string[] args)
{
(convert args to F arguments) and invoke
}
cmd.func = &wrapper!someFunc;
string[] args;
cmd.func(args);
Here's the basic code I'm playing with:
struct MyCmd
{
Variant func;
// Has other members.
}
MyCmd[string] functions_;
void addCommand(T)(const string name, T func)
{
MyCmd cmd;
cmd.func = Variant(func);
functions_[name] = cmd;
}
void process(string[] a