These are chat archives for ChaiScript/ChaiScript

26th
Oct 2016
lucas-sarie
@lucas-sarie
Oct 26 2016 14:07

@lefticus I have try to implement the constructor but I have a little trouble, I have add the following code in vector_type

 // Constructeur vector(int n, T v)
          if (typeid(VectorType) == typeid(std::vector<Boxed_Value>))
          {
              m->eval(R"(
                        def Vector::Vector(int c, x)
                        {
                          this.reserve(c)
                          for (var i = 0; i < c; ++i)
                          {
                            this.push_back(clone(x))
                          }
                                                }

                        def Vector::assign(int c, x)
                        {
                          this.reserve(c)
                          for (var i = 0; i < c; ++i)
                          {
                            this.push_back(clone(x))
                          }
                        } )"
                    );
          }
          else
            m->add(constructor<VectorType(int, VectorType::value_type)>(), type);
          m->add(fun([](VectorType& v, int n) { v.reserve(n); }), "reserve");

But when I call Vector(10, 1) I have the following error : "Error with function dispatch with function 'Vector' (const int, const int) ... overloads avalaible ... (int, Object)
Whereas when I call assign it works well... Do you understand why ?

lucas-sarie
@lucas-sarie
Oct 26 2016 15:58
In all case I test several implementations, the faster is :
var pixelBuffer = Vector()
pixelBuffer.reserve(width * height * 3)
for(var i = 0; i < width * height * 3; ++i)
{
  pixelBuffer.push_back(char(0))
}