In Delphi, I could call functions dynamically using it's name like this:
TQScrFuncType = function(Args: TQList): TQVar of Object;
TQScriptFunctions = class
function Add(Args: TQList): TQVar;
function Call(MName: String; Args: TQList): TQVar; Virtual;
function TQScriptFunctions.Add(Args: TQList): TQVar;
function TQScriptFunctions.Call(MName: String; Args: TQList): TQVar;
Md.Code := Self.MethodAddress(MName);
Md.Data := Pointer(Self);
Result := TQScrFuncType(Md)(Args);
The TQScriptFunctions.Call could call a function from it's name, I'm trying to port it to D, The D Language.
How do I do this in D, I have the name of a function in a string, and the arguments too, how do I call that function?
What I have tried:
I thought of putting the names and pointers to the functions in arrays, then search the array for that function name, and execute the function through it's pointer. It worked, but the problem is I have over 100 functions, that'll make things harder, and waste memory, and maybe slower (because it'll search for a string in a list of hundreds). Delphi is natively compiled, so is D, there should be a way to do this.