Calling arbitrary functions at runtime?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 11 14:18:02 PST 2016


On Sunday, 11 December 2016 at 22:00:27 UTC, Kevin Balbas wrote:
> Basically, I need some way to turn an array of strings
> into an argument list at runtime.  Is this possible?

Write (or generate) a helper function that loops over the 
Parameters!Func tuple and populates it from the strings. Call the 
helper function.


// declare your arguments tuple
Parameters!Func args;

// populate the arguments
foreach(idx, ref arg; args) {
    arg = to!(typeof(arg))(string_args[idx]);
}

Func(args); // call the function with that tuple



The free sample of my book: 
https://www.packtpub.com/application-development/d-cookbook has a 
more in-depth example near the end of it.


More information about the Digitalmars-d-learn mailing list