Convert std::vector<std::string> to chaiscript vector and back?


#1

I fail to convert a std::vector<std::string> to a chaiscript vector and back - what documentation do I not find?

My code looks like this:

std::vector<std:string> vec =  /*...*/
std::string name = "something";
call(name, vec); // function object from chaiscript

When printing the type of vec inside chaiscript:

call(name, vec) {
    print(vec.get_type_info().name());
    // ...
}

I get

St6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE

So I am clearly missing some things.

The setup code for the chaiscript instance is here and the usage of the function is here (I’m a newbie to c++ and this code is messy, I know that).

Would appreciate any pointers to documentation …


#2

Letting ChaiScript know about the type is handy:

chai.add(chaiscript::bootstrap::standard_library::vector_type<std::vector<std::string>>("VectorString"));

#3

Hm. I didn’t realize these things are not added by the default bootstrap process. What things would I also like to add? Are there more “core”/“base” things I should add to the engine?

This solved my issue, thank you very much!


#4

I added vector|int, vector|string, and map|bool…
https://github.com/RobLoach/ChaiLove/blob/master/src/Modules/script.cpp#L63-L66

But there are likely more types I’d move between C++ and ChaiScript. Would be good to move this to a dedicated project with some handy map/vector types. Which ones do you think you’d make use of?


#5

Well… all basetypes + basetypes and vector + basetype and map, where “basetypes” includes bool, all integer types and all floating-point types, string, and of course vector and map itself.


#6

The size of the binary and compile time would explode if std::vector<allthethings> were to be added by default. This is why it was decided to have std::vector<Boxed_Value> which can hold any C++ or ChaiScript defined type.

But the utilities do exist for adding them yourself, as you’ve seen.