[Dlang-internal] How do I find and call a function in a module I only know during runtime?

Jacob Carlborg via Dlang-internal dlang-internal at puremagic.com
Mon Dec 26 12:01:03 PST 2016


On 2016-12-26 19:45, Andrei Alexandrescu wrote:
> Say I have a module "a" that wants to call a function "void fun()" in
> another module "b". The name "b" is not known until runtime, i.e. it's
> read from the console. (Really the name is obtained by iterating foreach
> (m; ModuleInfo)).
>
> How do I get fun()'s address (or the null pointer if it doesn't exist)?

Perhaps use "dlopen" on the executable and then use "dlsym" and pass in 
the mangled name.

-- 
/Jacob Carlborg


More information about the Dlang-internal mailing list