Code Monkey home page Code Monkey logo

Comments (10)

autodidaddict avatar autodidaddict commented on May 22, 2024 1

Ok I'll see what I can come up with. Thanks again :)

from wasmi.

pepyakin avatar pepyakin commented on May 22, 2024

Unfortunately, I can't provide an example that focused on precisely this.

You can take a look on this test.

The basic idea is similar to the JS example. Just return a memory instance when the module imports it, still retaining a reference to it.

from wasmi.

autodidaddict avatar autodidaddict commented on May 22, 2024

Okay I'll take a look at those tests and see if I can duplicate the sample. I didn't know that resolve_memory was a thing, so this definitely gets me closer. Thanks!

from wasmi.

autodidaddict avatar autodidaddict commented on May 22, 2024

What I am struggling with is the demo I linked to shows using a pointer directly as a parameter in the function and doesn't seem to be using the linear memory directly ... like there's some macro magic at play that I can't see.

from wasmi.

pepyakin avatar pepyakin commented on May 22, 2024

No, you right : ) There is no magic because there is no usage of linear memory in the example (because of this I warned you that I can't provide a good example).

I think then better to start with TestHost example. It has a reference to a MemoryInstance. Test host uses the MemoryInstance to implement functions inc_mem and get_mem in it's Externals implementation.

But, unlike the previous example, TestHost doesn't export a memory instance. To actually make it export a memory instance, we can simply use the construction like in the previous example

from wasmi.

autodidaddict avatar autodidaddict commented on May 22, 2024

Whenever I create a Rust lib and put wasm_import_memory at the top, the resulting wasm produced by the compiler still appears to export memory... I don't see a

(import "env" "memory" (memory (;0;) 17))

line like the demos show from the link above.

from wasmi.

pepyakin avatar pepyakin commented on May 22, 2024

Ah, yeah. Try to add #![wasm_import_memory] attribute to the lib.rs of your project.

from wasmi.

autodidaddict avatar autodidaddict commented on May 22, 2024

I do.. my memory is still in an export section at the very bottom of the wat file after I convert it.

from wasmi.

autodidaddict avatar autodidaddict commented on May 22, 2024

I've figured a little bit out... I can access the exported memory with export_by_name. What I'm trying to figure out is how to invoke a function like the one from the SHA1 demo where the digest function returns a string.

from wasmi.

andrewdavidmackenzie avatar andrewdavidmackenzie commented on May 22, 2024

I was struggling to find good examples of doing this also....so empathise!

It's not using an imported linear memory (it's using one created internally, that you specify on getting Module, and then get via export) but this repo of mine trying to figure out the same thing maybe useful to you:

https://github.com/andrewdavidmackenzie/wasmi-string

For my project I don't want to pass/get Strings, but a more complex signature & return, so I advanced that a bit (using serde to serialize/deserialize - which suits my project) and pass anything that can be expressed in Serde to/from a function in the wasm module):

https://github.com/andrewdavidmackenzie/wasm_explore

from wasmi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.