In Delphi, I could call functions dynamically using it's name like this:
interface
type
TQScrFuncType = function(Args: TQList): TQVar of Object;
TQScriptFunctions = class
published
function Add(Args: TQList): TQVar;
public
function Call(MName: String; Args: TQList): TQVar; Virtual;
end;
implementation
function TQScriptFunctions.Add(Args: TQList): TQVar;
begin
end;
function TQScriptFunctions.Call(MName: String; Args: TQList): TQVar;
var
Md: TMethod;
begin
Md.Code := Self.MethodAddress(MName);
Md.Data := Pointer(Self);
Result := TQScrFuncType(Md)(Args);
Args.Free;
end;
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.