How to allow for cloning of value type in vector?

I am passing a vector of a custom type to ChaiScript, std::vector, where:

struct MyPoint
    int x;
    int y;

The problem is, I can’t do this in ChaiScript:

var somePointsVector = getSomePoints();
var point1 = somePointsVector[0];  // crash!

Instead I need to take a reference:

var somePointsVector = getSomePoints();
var point1 := somePointsVector[0];

This wouldn’t be a huge deal, except that ChaiScript throws an uncaught and unhelpful dispatch_error if I do the first thing (and it took me hours to figure out that := was a thing, since it doesn’t seem to be documented anywhere). Returning a single MyPoint from a c++ function works fine, so clearly it’s able to clone it. But it doesn’t want to when it’s an element in a vector. Is it possible accomplish this somehow?

fwiw, this is how I’m binding things:

g_chai->add(chaiscript::user_type<MyPoint>(), "MyPoint");
g_chai->add(chaiscript::fun(&getSomePoints), "getSomePoints");
g_chai->add(chaiscript::bootstrap::standard_library::vector_type<std::vector<MyPoint> >("MyPointVector"));

Try also registering the vector conversion (from a vector<Boxed_Value> to a vector<MyPoint>)…


If that doesn’t help – what is the declaration of your C++ function getPoints()? I assume it just returns std::vector<MyPoint> and takes no arguments?