Emulating DLL

Craig Craig at Tonsils.com
Mon Mar 18 22:50:57 UTC 2019


Is it possible to create a D module that has functions in it, and 
then use those functions dynamically at run time emulating DLL 
like functionality?

e.g.,

module MyDL;

import Context;
export void foo(Context)
{
    ...
}

and

module UseDL;
import DL;
import Context;

void main()
{
     DL.Load("MyDL.dl");
     DL.foo(new Context);
     DL.Unload();

     // or
     DL.Loadable("MyDL.dl"); // monitors changes and reloads the 
function safely  when a change is detected. This might require 
some work to make safe.
     DL.foo(new Context);
     DL.Unload();
}


(pseudo)

The idea here is to simply be able to call external code that can 
be hotswapped and such. It requires dealing with relocatable 
code, GC, etc.


It would be portable and non-windows specific and just work.

dmd and ldc of course do not output anything that is reasonable 
as they use the traditional non-portable formats. This leads me 
to think that without modifying them, I'd have to extract the 
code from the DLL/SO and deal with all the problems and then 
generate the .dl file.

The idea is to create simple way to "script" D programs and use 
the D compiler to compile the functionality. It won't be as fast 
as an interpreter but it will have full speed.

I'm just not sure what would be the best way to generate the code 
and do the fixing up.

I'd be willing to hack on the dmd compiler to try and get it to 
generate a more sane file for this process if someone could point 
me to some details.



More information about the Digitalmars-d-learn mailing list