Search code examples
c++stlchaiscript

ChaiScript and STL


I am trying to use a std::list<arnAddr> (arnAddr being a custom Struct) in a Chai scriptfile. But I get an error during parsing :

Error: "Missing clone or copy constructor for right hand side of equation" With parameters: (NSt3__14listIN3arn7arnAddrENS_9allocatorIS2_EEEE)`

I am adding the following to the chai parser :

ChaiScript interpreter;
interpreter.add(user_type<arnAddr>(), "Address");
interpreter.add(bootstrap::basic_constructors<arnAddr>("Address"));
interpreter.add(constructor<arnAddr(const int, const int)>(), "Address");
interpreter.add(constructor<arnAddr(arnIP, arnPort)>(), "Address");
interpreter.add(fun(&Database::getGroup, database), "group"); 
// std::list<arnAddr>& getGroup(); is the prototype

The script file is very simple and just contains var group = group();

What I get from the error message is, that Chaiscript does not know how to copy construct a std::list<arnAddr>. But how do I fix that?


Solution

  • What about starting like this:

    ChaiScript interpreter;
    interpreter.add(user_type<arnAddr>(), "Address");
    interpreter.add(bootstrap::basic_constructors<arnAddr>("Address"));
    interpreter.add(user_type<std::list<arnAddr> >(), "AddressList");
    interpreter.add(bootstrap::basic_constructors<std::list<arnAddr> >("AddressList"));
    

    This should tell ChaiScript about the container (no, It won't add all the possible containers automaticly - especially the copy constructor is needed)

    Maybe you'd like this as well:

    interpreter.add(bootstrap::::standard_library::list_type<std::list<arnAddr> >("AddressList"));