On Monday, 18 March 2019 at 22:59:12 UTC, Ethan Watson wrote:
On Monday, 18 March 2019 at 22:50:57 UTC, Craig wrote:
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?

On Monday, 18 March 2019 at 22:50:57 UTC, Craig wrote:
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?

I've talked extensively on this topic at DConf over the last few years.

http://dconf.org/2016/talks/watson.html
http://dconf.org/2017/talks/watson.html
http://dconf.org/2018/talks/watson.html

https://github.com/GooberMan/binderoo

It's not a simple thing by any means, there's plenty of little implementation details that you'll need to be aware of. But yes, it's quite possible.

This seems overly complex for what I want and not exactly what I need. I'm looking for simply that simply lets me call functions that exist in an external dynamically accessible file.

In my host code I will use a function like "foo" but that foo will be a function pointer that can point to the external code. I don't need a bunch of bells and whistles or complex ways to accomplish this.

1. Load up external code,
2. Fixup whatever needs fixing up to make the code work properly
3. Point function pointer to code.
4. Call.

For simple functions such as pure functions step 2 can be skipped and hence it is essentially just loading the code in to memory and calling it.

I do get that in general it is more complex but other than relocatable code, initialization, and the GC, it shouldn't require much more work.


For example, with windows I could simply compile to a dll then extract the code, or just use LoadLibrary and it effectively does all the work(steps 1 & 2 & 3).

LoadLibrary is not portable though and seems excessive to do something that should be rather simple unless there is something I'm missing that has to be done that is complex. Relocation is easy if one has the appropriate locations to fix up which are generally included in the binary somewhere. The GC and rt can be initialized easily.

Reply via email to