symmetryinvestments / autowrap

Wrap existing D code for use in Python, Excel, C#
BSD 3-Clause "New" or "Revised" License
80 stars 16 forks source link

Can't get == to work #268

Open DangerMouseB opened 3 years ago

DangerMouseB commented 3 years ago

Hi Atila, I've pared this right down:

ex.d:

module ex;
export struct Ex{
    int id;
}
export bool exEquals(Ex exA, Ex exB) {return exA == exB;}

app.d:

import autowrap.python;
mixin(
    wrapAll(
        LibraryName("_bits"),
        Modules(
            "ex"
        )
    )
);

dub.sdl:

name "_bits"
targetType "dynamicLibrary"

configuration "osx" {
    dependency "autowrap:python" path=".../repos/github/symmetryinvestments/autowrap"
    platforms "osx"
    subConfiguration "autowrap:python" "env"             // the python38 configuration doesn't work for me
}

buildType "debug" {
    postBuildCommands "mv lib_bits.dylib _bits.so" platform="osx"
    preBuildCommands "rm -f lib_bits.dylib" platform="osx"
    preBuildCommands "rm -f _bits.so" platform="osx"
}

test_ex.py

from _bits import Ex, exEquals

print(Ex(1) == Ex(1))
print(exEquals(Ex(1), Ex(1)))

% python3 test_ex.py False True

I've tried adding opEquals to the struct. I had a quick look through the autowrap code and couldn't see opEquals anywhere though did find some occurrences of opCmp.

Could you double check if it's missing?

I'm on macos (the latest) + using autowrap cloned from github + dub --version -> DUB version 1.23.0, built on Sep 22 2020.

atilaneves commented 3 years ago

I don't see how to get it to work with the default pyd backend of autowrap (which is what autowrap:python is under the covers). I've looked at the docs and I think the only way out there is to define opCmp. A workaround is to use the pynih backend after #270 gets merged.

DangerMouseB commented 3 years ago

Understood, thank you.