Function pointer from mangled name at runtime?

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 1 12:49:46 PDT 2017


If I have the mangled name of a module-scoped D template function 
as a string, is there a way to check for it's presence in the 
symbol table, and retrieve the function pointer at runtime?


Example:

`
module mine;
class Test { }
`


`
module reflection;
class RuntimeInfo {
     string name();
}

class RuntimeInfoImpl(T) {
     string name() { return T.stringof; }
}

RuntimeInfo getRTInfo(T)() {
     static const(RuntimeInfo) info = new RuntimeInfoImpl!T();
     return info;
}

RuntimeInfo getRTInfo(string qualifiedName) {
     // determine mangle of `getRTInfo` with template parameter 
'qualifiedName'
     // retrieve function pointer from symbol table and call it to 
retrive the `RuntimeInfo`
}
`

So for every symbol on which `getRTInfo(T)()` is used, there 
should be an entry in the symbol table, right? (I will have a 
method in place to enforce it's instantiation)

And if I was provided with the fully qualified name of a class 
like `mine.Test`, I should be able to determine how that function 
was manged, right?

So can I then look that symbol/string up at runtime and somehow 
retrieve the function pointer so I can call it?

Is it actually, or even technically possible to implement 
getRTInfo(string) above?

   Thanks



More information about the Digitalmars-d mailing list