Load dynamic libraries with no hand-written bindings!

Steven Schveighoffer schveiguy at gmail.com
Tue Sep 6 16:56:16 UTC 2022


On 9/6/22 12:35 PM, Adam D Ruppe wrote:
> On Tuesday, 6 September 2022 at 16:28:18 UTC, Steven Schveighoffer wrote:
>> Nice! I wonder if it can be used to generate static bindings as well? 
>> As in, just use it to spit out a D module with the proper 
>> function/struct definitions?
> 
> I'm sure you could set it up, but the point of importc is that there's 
> no benefit to doing that anymore...

Well, importC doesn't work for everything. Just like dstep doesn't.

So generating a static binding allows you to both avoid lots of 
boilerplate work, but also allows you to get a complete binding for the 
things that importC cannot do.

Also, dstep requires libclang, importC would not.

You could have, in an importC shim, a way to expose all the things that 
aren't exposed (e.g. you have some #defines, just put them in a const 
array, and then you can introspect them to generate proper enums).

I might try this with raylib to see how it works. One thing you won't 
get is comments though...

-Steve


More information about the Digitalmars-d mailing list