简体   繁体   English

Emscripten-使用Module.cwrap检索由c函数设置的数组值

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

We have a "little c" library compiled to javascript via emscripten. 我们有一个通过emscripten编译为javascript的“小c”库。 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. c库中的许多函数都会修改传入的数组。从javascript级别访问这些数组的机制并不明显。

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. 使用Module.cwrap并调用正确导出的函数(例如EXPORTED_FUNCTIONS="['_myFunc'] )很简单,但是对c侧计算的变量的唯一访问似乎是从该函数返回。如果我们返回从c方面指向数组的指针,如何从javascript端访问数组并不明显。

If we indicate that Module.cwrap has a returnType of array how would the c function called return an array? 如果我们指出Module.cwrap有一个array的returnType,那么c函数如何调用返回一个数组?

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. 基本上你需要知道你的类型的内存布局(我假设你使用的是c风格的数组),这应该是紧凑的值。

And then use the described functions on the JS side. 然后在JS端使用所描述的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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