> On Apr 25, 2020, at 13:18, キャロウ マーク <[email protected]> wrote:
> 
> I need an ArrayBuffer, actually a Uint8Array, passed from JS to my C++ class. 
> With embind my c++ class has
> 
>     texture(const emscripten::val& data) {
>            std::vector<uint8_t> bytes{};
>            bytes.resize(data["byteLength"].as<size_t>());
>            emscripten::val memory = 
> emscripten::val::module_property("HEAP8")["buffer"];
>            emscripten::val memoryView = data["constructor"].new_(memory, 
> reinterpret_cast<uintptr_t>(bytes.data()), data["length"].as<uint32_t>());
>            memoryView.call<void>("set", data);
>            ….
>     }
> 
> How to I do the same using webidl_binder?

I managed to get something compiled and linked using the above code. However 
when it is called, from JS `data` is “undefined”.

On this line

ktexture = new Texture(ktxdata);

the debugger shows ktxdata to be as expected. But inside the JS part of the 
constructor:

// Texture
/** @suppress {undefinedVars, duplicate} */function Texture(fileData) {
  if (fileData && typeof fileData === 'object') fileData = fileData.ptr;
  this.ptr = _emscripten_bind_Texture_Texture_1(fileData);
  getCache(Texture)[this.ptr] = this;
};;

the debugger shows fileData is undefined.

So apparently using emscripten::val is not the right way to pass a typed array 
to my C++. Unfortunately

https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html
 
<https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html>

does not say anything about this and the 2 real examples it points to do not 
use ArrayBuffers so they are no help.

Somebody please tell me how to pass in a typed array. I think I’m barking up 
the wrong tree trying to use emscripten::val with webidl_binder. Am I correct? 
How to I deal with objects from the Javascript side?

I wouldn’t be asking these questions if the documentation was adequate.

Regards

    -Mark

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/57685FC9-CBCF-46D3-969F-7AFE705231A8%40callow.im.

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to