How do I wrap class with public member variables using CxxWrap.jl?

Thanks to barche and others I was able to start making good progress using CxxWrap.jl.

I do still have one blocking question: how can I wrap a class which has public member variables whose values are supposed to be changed from outside during runtime? And what if these member variables are actually pointers to objects of other classes?

To illustrate my question I pasted simple code from a VC++ console application below. Question is, how can I expose “complex” and “complexcalc” using CxxWrap to Julia in a DLL project.

BTW I know the classes are organized a bit awkwardly… This is just a simplified example. In reality I am using a third party VC++ DLL that I have no access to source code except the header file necessary to use the exposed classes.

Thanks!!

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

class complex
{
public:
	double r, i;
	
	double sq_mod(void) {
		return r*r + i*i;
	}
};

class complexcalc
{
public:
	complex *a;
	complex *b;

	double sum_sq_mod(void) {
		return a->sq_mod() + b->sq_mod();
	};
};


int main()
{
	complex a, b;
	a.r = 0.5;
	a.i = 0.6;
	b.r = 2.5;
	b.i = 3.6;

	complexcalc mycalc;
	mycalc.a = &a;
	mycalc.b = &b;

	double result = mycalc.sum_sq_mod();
	printf("The result is: %f\n\n", result);
	printf("Press Enter to exit.");
	getchar();

	return 0;
}

The easiest way would be to add accessor functions, using a C++ lambda for example:

mod.method("get_r", [] (const complex& c) { return c.r; });
mod.method("set_r", [] (complex& c, double r) { c.r = r; });

If the classes are “plain old data” they can also be passed directly to ccall using a struct that mirrors the layout in Julia, but I’m not sure if that’s the case with the member functions here.

Note that for pure CxxWrap question it’s preferable to create an issue on the CxxWrap github.

Thanks, that works! Will ask further questions, if any comes up, on github.