Is it possible to make a library (dll/so) from separated .d files?

Hipreme msnmancini at hotmail.com
Mon Apr 3 11:29:12 UTC 2023


On Monday, 3 April 2023 at 09:08:42 UTC, dog2002 wrote:
> Hello. The title sounds weird, but I try to explain it better.
>
> In Unreal Engine and Unity, source code files don't use main() 
> and other important functions. They have only a class. Like 
> this:
>
> ```
> class SomeClass: someInterface
> {
>     AFunctionFromTheInterface1()
>     {
>
>     }
>
>     AFunctionFromTheInterface2()
>     {
>
>     }
> }
> ```
>
> And then all the source code files will be compiled into a 
> single .dll/.so library, so the game engine can use one in a 
> game.
>
> I don't know what compiler does Unreal Engine use, but it uses 
> C++.
>
> Is it possible to do so in D?


Yes, actually, this is the very same approach I've done for my 
engine, since holding the main function I can take care of boring 
platform details.

For doing that you'll need some way to make your main program 
know about your class. The way I do that is by defining another 
entry function which is always defined enemy you have a game 
project.


You can take a look at 
https://github.com/MrcSnm/HipremeEngine/blob/66618c7783d62107bcaad393d5af5b86c9387b34/api/source/hip/api/package.d#L58


The user uses that engine mixin template, which will add the 
engine entry point to your game script, after that, whenever my 
engine loads the Dll, it will know what function to call and what 
scene it should spawn


More information about the Digitalmars-d-learn mailing list