ChaiScript does support pointers and pointers to pointers to some extent. However, what you are doing with the
** is actually double-dereferencing your pointer and adding the very first object of your array to ChaiScript.
I am a bit confused as to what you intend to do, since that is a
**. Are you trying to add an array of pointers? Or a pointer to an array?
There are solutions to get either working, but the best thing to do, the most memory safe option that would work the best with ChaiScript, is to use a vector:
for (int i = 0; i < N; ++i)
objectVec.push_back(chaiscript::var(std::ref(*objects[i]))); // this would push_back a reference given **objects (ChaiScript likes references better than pointers)
objectVec.push_back(chaiscript::var(objects[i])); // this would push_back a pointer given **objects
objectVec.push_back(chaiscript::var(*objects[i])); // this would push_back a copy given **objects
chai.add(objectVec, "objects"); // copies vector
// or if you want to share objectVec with your C++ code
chai.add(std::ref(objectVec), "objects"); // chaiscript shares the reference with C++
In general, I strongly suggest you move away from using raw pointers and raw arrays in your C++.
std::vector provides the same performance for element access and can grow and can destroy itself properly. Similarly for
std::unique_ptr: automatically managed and the same performance as a raw pointer for dereferencing of the value.
If for some reason you absolutely must pass a pointer into ChaiScript and treat that as an array inside your script, let me know. There are methods of handling that also.