Hi,

Before getting to the main topic, let me give some context to avoid the XY 
problem:

I am trying to implement a package for wrapping C++ classes, and now hit 
the stage where I want to do, on the Julia side:

wrapped_cpp_object.somefield = newvalue

In doing so, appropriate methods should be called to propagate newvalue to 
the value stored in the object on the C++ side. This may be some setter 
method, or just directly setting a value on a public data member. Reading 
https://github.com/JuliaLang/julia/issues/1974 it seems there is currently 
no easy way of doing that in Julia, unless I missed something obvious.

The solution I came up with so far is described in the following test 
(stand-alone Julia code):
https://github.com/barche/CppWrapper/blob/master/test/property.jl

The basic idea is to store pointers to methods and data in the parameters 
of a parametric type, and then overload convert to call the appropriate 
getter or setter. As demonstrated by the test, this works for setting a 
field, effectively behaving as if setfield! were overloaded for my 
purposes. The generation of the parameter values (i.e. the pointers) can be 
handled on the C++ side and would be transparent to the users of the 
classes.

My main concern with this solution is that each wrapped object has a 
different type parametrization, so this potentially yields a huge number of 
types that need to be tracked.

Is the Julia parametric type system designed to handle this kind of 
scenario, or am I better off abandoning this solution, resorting to methods 
to do any field manipulations on C++ types?

Reply via email to