-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an example to show how to read bytes from wasm memory #34
Comments
Hey, I'll be adding docs as part of the 1.0 coming up in the couple of months but maybe I can answer your question in interim. You'll need to get a reference to the memory itself first, this is done by calling:
Provided your module is in fact exporting the memory, the you can call: val memory = exports.filterIsInstance<Memory>().first()
val buffer = ByteArray()
readBytes(store, memory, buffer, pointer, bytesToRead) Theres also a way to create a memory and import it into your module at instantiation time, but its probably easier to just export what you already have. |
Unrelated but does K/Wasm support exporting memory? There's seems to be a very recent issue which mentions importing/exporting memory (https://youtrack.jetbrains.com/issue/KT-73234) |
Yes, it exports the memory (theres only one at present) with the name "memory". You can check for yourself by turning your .wasm file into a .wat file using a cli tool like wasm-tools: wasm-tools parse ./module.wasm You should see an export entry like this: (export "memory" (memory 0)) |
I'd very much appreciate it if you could provide a complete but simple example of how to call a wasm function which takes a ByteArray as input and returns another ByteArray as output. That would open the door for testing chasm with non-trivial code examples. |
No description provided.
The text was updated successfully, but these errors were encountered: