简体   繁体   中英

Emscripten- retrieving array values set by c function with Module.cwrap

We have a "little c" library compiled to javascript via emscripten. Many functions in the c library modify arrays that are passed in. It is not obvious what the mechanism is to access those arrays from the javascript level.

Using Module.cwrap and calling a function that is correctly exported (eg EXPORTED_FUNCTIONS="['_myFunc'] ) is straightforward, but the only access to variables calculated on the c side appears to be in the return from this function. If we return a pointer to an array from the c side, it is not obvious how to access the array from the javascript side.

If we indicate that Module.cwrap has a returnType of array how would the c function called return an array?

There is a description here . Basically you need to know the memory layout of your type (I assume you are using c-style arrays), which should be tight packed values.

And then use the described functions on the JS side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM