pass by reference of map typed struct(CxxWrap.jl)
Hi,
I’m trying to pass the argument by reference from Julia to C++. This argument is simple struct,
so I used map_type
at wrap module difinition.
I am having trouble observing the values of arguments on the Julia side that have been changed on the c++ side.
The following is a minimal example.
What is wrong with it?
c++
struct StructTest{
int a;
};
JLCXX_MODULE define_module(jlcxx::Module& mod)
{
mod.map_type<StructTest>("StructTest");
mod.method("increment", [](StructTest& s){
s.a += 10;
std::cout << "increment : s.a = " << s.a << std::endl;
return s; // The object is copied and returned for testing purposes.
});
}
julia
module CxxTest
struct StructTest
a::Int32
end
@wrapmodule(lib_path, :define_module)
function __init__()
@initcxx
end
end
Execution Result
julia> using CxxTest
julia> s = CxxTest.StructTest(10)
CxxTest.StructTest(10)
julia> CxxTest.increment(s)
increment : s.a = 20 # works correctly in the c++ side
CxxTest.StructTest(20) # The return value is also correct.
julia> s.a # The value have not changed.
10