开发者

Wrapping C++ Dynamic Arrays in Scripting Languages coded in C++

I have a minimal scripting language (without arrays) built in C++ used as glue for Monte Carlo simulations. I make use of a library of wrapped c/c++ functions to extent my language, normally something like this:

extern "C" double myWrappedMathFunction(double argument){...}

Now, I would like add dynamic arrays and wrap some functions from the C++ STL Vector container. My idea is to construct STL vectors using function calls from my scripting language. All vectors would be of doubles. For example calling vecIni(vectorName) would create an empty (or some initial default dimension) vector named vectorName.

What would b开发者_运维问答e the best way to construct these vectors in a scripting language coded in C++?


The best way is to use std::vector itself to represent the dynamic arrays. Probably you can add some syntax to represent array literals in the scripting language:

v1 = {3.4, 5.67} // an array initialized with two values.
v2 = {} // an empty array.

The above script should translate to the following C++ code:

std::vector<double> v1;
v1.push_back(3.4);
v1.push_back(5.67);

std::vector<double> v2;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜