crossbind
GitHub

Strings and vectors

A std::string is a JavaScript string. A std::vector that C++ returns is a vector object, which one helper copies into an array.

split returns a std::vector<std::string>, which arrives as a vector object: size() and get(i) read it, and m.toArray(vector) copies it into an array. m is the module initNative() resolves to, which carries the helpers.

total takes a std::vector<int>, and a function converts a plain array for it. A method's vector parameter needs a vector object, which m.toVector('VectorInt', [1, 2, 3]) builds; the first argument names the vector type.

split's separator is a char, which takes a one-character string.

In a browser app's default Web Worker, vectors cross as plain arrays both ways, so neither helper is needed there.

Try it
Add std::vector<int> range(int from, int to); to native.h, define it in native.cpp, import it and print m.toArray(range(1, 5)).
Open in playgroundRuns without a compile until the C++, Rust, packages or imports change.
Console
Press Run, or Ctrl+Enter, to run main.js.
Type to search every guide page and section.
↑↓ navigate↵ openesc close