How to use a std:vector with custom objects with ChaiScript?

88 views Asked by At

I'm trying to expose a STL vector of custom objects to chaiscript but no matter what I do, it just gives an exception

Here's the smallest example I could think of. it just passes std::vector<TestClass> to chaiscript and the script should return the size which is 3. Instead it crashes inside ChaiScript with an exception

Unhandled exception at 0x00007FF97D0C4FFC in ConsoleApplication1.exe: Microsoft C++ exception: chaiscript::exception::eval_error at memory location 0x0000005072AFDC10.

#include <iostream>
#include <chaiscript/chaiscript.hpp>

class TestClass
{
public:
    TestClass() {}
    ~TestClass() {}
    bool SomeVariable = true;
};
int main()
{
    std::vector<TestClass> bars(3);

    chaiscript::ChaiScript chai;
    chai.add(chaiscript::user_type<TestClass>(), "TestClass");
    chai.add(chaiscript::fun(&TestClass::SomeVariable), "SomeVariable");
    chai.add(chaiscript::var(&bars), "list");

    auto xx = chai.eval<int>("return list.size();");

    printf("xx = %d\n", xx);
}
0

There are 0 answers