Load dynamic libraries with no hand-written bindings!
Paul Backus
snarwin at gmail.com
Wed Sep 7 16:05:44 UTC 2022
On Wednesday, 7 September 2022 at 15:35:29 UTC, Andrej Mitrovic
wrote:
> As mentioned in the previous reply it seems that a function
> typedef trips it up. If there was a way to filter it out,
> that'd be great.
I think the root of the problem here is that
`std.traits.isFunction` does not do exactly what you're assuming
it does. Specifically, it evaluates to `true` for both function
*symbols* and function *types*:
```d
import std.traits;
void fun() {}
static assert(isFunction!fun); // ok
static assert(isFunction!(typeof(fun))); // also ok!
```
In order to filter for just function *symbols*, you need to use a
more elaborate test:
```d
static if (
is(typeof(&__traits(getMember, Module, member))
PtrType)
&& isFunctionPointer!PtrType
) {
GetFunctionList = AliasSeq!(GetFunctionList, PtrType);
}
```
This first checks whether you can take the member's address, and
then, if you can, checks whether the type of that address is a
function pointer. If I use the condition above in your reduced
example, it compiles successfully, and the resulting list does
not include the `typedef`.
More information about the Digitalmars-d
mailing list