Load dynamic libraries with no hand-written bindings!
Paul Backus
snarwin at gmail.com
Tue Sep 6 16:50:16 UTC 2022
On Tuesday, 6 September 2022 at 16:03:03 UTC, Andrej Mitrovic
wrote:
> ```d
> struct Tuple(_FuncType, string _Name) {
> alias FuncType = _FuncType;
> enum Name = _Name;
> }
>
> /* Get the function pointer type of an actual function */
> template FuncType(alias symbol) {
> ReturnType!symbol function(Parameters!symbol) func;
> alias FuncType = SetFunctionAttributes!(typeof(func),
> functionLinkage!symbol,
> functionAttributes!(typeof(func)));
> }
>
> /* Get a sequence of (Function type, Name) belonging to the
> provided module */
> template GetFunctionList(alias Module) {
> alias GetFunctionList = AliasSeq!();
> static foreach (idx, member; __traits(allMembers, Module)) {
> static if (isFunction!(__traits(getMember, Module,
> member))) {
> GetFunctionList = AliasSeq!(GetFunctionList,
> Tuple!(FuncType!(__traits(getMember, Module,
> member)), member));
> }
> }
> }
>```
Haven't tested, but I think you may be able to simplify this by
replacing
FuncType!(__traits(getMember, Module, member))
with
typeof(&__traits(getMember, Module, member))
...which would let you eliminate the `FuncType` template entirely.
More information about the Digitalmars-d
mailing list