forked from jjhbw/barcode-scanner-webassembly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.js
21 lines (16 loc) · 972 Bytes
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mergeInto(LibraryManager.library, {
js_output_result: function (symbol, data, polygon, polygon_size) {
// function provided by Emscripten to convert WASM heap string pointers to JS strings.
const UTF8ToString = Module['UTF8ToString'];
// Note: new TypedArray(someBuffer) will create a new view onto the same memory chunk,
// while new TypedArray(someTypedArray) will copy the data so the original can be freed.
const resultView = new Int32Array(Module.HEAP32.buffer, polygon, polygon_size * 2);
const coordinates = new Int32Array(resultView);
// call the downstream processing function that should have been set by the client code
const downstreamProcessor = Module['processResult'];
if (downstreamProcessor == null) {
throw new Error("No downstream processing function set")
}
downstreamProcessor(UTF8ToString(symbol), UTF8ToString(data), coordinates)
}
});