JuliaInterop / CxxWrap.jl

Package to make C++ libraries available in Julia
Other
418 stars 67 forks source link

Enums and call operator #171

Closed ahumenberger closed 4 years ago

ahumenberger commented 4 years ago

I have the following C++ code which basically consists of the examples for enums and call operators:

#include "jlcxx/jlcxx.hpp"

enum MyEnum
{
  EnumValA,
  EnumValB
};

template<> struct jlcxx::IsBits<MyEnum> : std::true_type {};

struct CallOperator
{
  int operator()() const
  {
    return 43;
  }
};

JLCXX_MODULE define_julia_module(jlcxx::Module& mod)
{
    mod.add_bits<MyEnum>("MyEnum", jlcxx::julia_type("CppEnum"));
    mod.set_const("EnumValA", EnumValA);
    mod.set_const("EnumValB", EnumValB);

    mod.add_type<CallOperator>("CallOperator").method(&CallOperator::operator());
}

Then within Julia MyModule.EnumValA yields (Core.Compiler.UseRef(:((Core.getfield)(%11, 1)), 4), nothing).

However, when swapping the order, that is, doing add_type<CallOperator> before add_bits<MyEnum> then everything is fine.

ahumenberger commented 4 years ago

This might be related to #155.

barche commented 4 years ago

I think this should be fixed on the master version, which should be released as v0.9 soon.