webassembly-example | Binary Executable Format library
kandi X-RAY | webassembly-example Summary
kandi X-RAY | webassembly-example Summary
webassembly-example
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of webassembly-example
webassembly-example Key Features
webassembly-example Examples and Code Snippets
Community Discussions
Trending Discussions on webassembly-example
QUESTION
I'm writing a small C program intended to be compiled to wasm w/ emcc
and run in a web browser. Because wasm exported functions can only accept simple number values as parameter inputs and return values, I need to share memory between the JavaScript API and the compiled WebAssembly code in order to access more complex data types like strings or char
arrays. The problem is that I can't for the life of me figure out how to access WebAssembly linear memory from inside of my C program.
My ultimate goal is to be able to read strings initialized in JavaScript inside of my C program, and then also read strings that are modified/initialized in my C program back in the web browser's JavaScript code.
Here is a basic example of what I'm trying to do:
main.js
...ANSWER
Answered 2017-Oct-14 at 20:20What you need to do is communicate a location within the WebAssembly module that both the C and JavaScript code read / write to.
Here's a simple example that adds a number to each element in array. This is the C code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install webassembly-example
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page