emscripten-core / emscripten-core/emscripten

Passing std::vector<uint64_t> as parameter

Open
#19,538 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I need to pass a vector as a parameter to an EM_ASYNC_JS function, like so:

```
EM_ASYNC_JS(void, test, (std::vector vec, int vecSize), {
for(let i of vec) { console.log(vec.get(i)); }
});

std::vector vec = {543, 534};
test(vec, vec .size());
```

But i dont get this to work. I tried binding the vector:

```
using namespace emscripten;
EMSCRIPTEN_BINDINGS(module) {
register_vector("VectorBigInt");
}
```
But it seems that the binding does not work with EM_JS?
I also tried passing the vector as emscripten val:

```
EM_ASYNC_JS(void, test, (emscripten::val vec, int vecSize), {
for(let i of vec) { console.log(vec.get(i)); }
});

emscripten::val view{ emscripten::typed_memory_view(vec.size(), vec.data()) };
auto result = emscripten::val::global("BigUint64Array").new_(vec.size());
result.call("set", view);
test(result, vec.size());
```

But in javascript i dont retrieve a BigUint64Array as parameter but just a value of type "number".

Is there a way to do this?

Note: I am also compiling with WASM_BIGINT because of the uint64_t.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.