Giter VIP home page Giter VIP logo

Comments (6)

Mec-iS avatar Mec-iS commented on July 17, 2024 2

you may find some hints on how to pass sequences in my article: https://dev.to/tuned/memory-views-handling-strings-48h7

Did I compile the rust code to the right target?

yes, also double-check that your crate is defined as dynlib in the .toml file.

The problem is in the return type. You cannot return a Vec as there is no such type in WebAssembly. What you can return is an address for the cell at which the array starts, and by knowing the length you can read all its elements in the WebAssembly memory view. See this example. The Python methods used to perform memory assignment are here. Also there is information about in the README.

from wasmer-python.

hskang9 avatar hskang9 commented on July 17, 2024

Thank you @Mec-iS. will adding &Vec <-> &str converter to the rust wrapper code and making argument and return value types to hexstrings enable me to use the exported function with one string argument?

from wasmer-python.

hskang9 avatar hskang9 commented on July 17, 2024
class Instance(object):
    """
    `Instance` is a Python class that represents a WebAssembly instance.
    
    # Examples
    
    ```python
    from wasmer import Instance
    
    instance = Instance(wasm_bytes)
    ```
    """
    def __init__(self, wasm_bytes): # real signature unknown; restored from __doc__
        pass

    @staticmethod # known case of __new__
    def __new__(*args, **kwargs): # real signature unknown
        """ Create and return a new object.  See help(type) for accurate signature. """
        pass

    exports = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """The `exports` getter."""

    memory = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """The `memory` getter."""

When I looked at the wasmer.py file, it just uses the built-in class initialization and put wasm_bytes as an argument. Does python language support wasm from its compiler?

from wasmer-python.

Hywan avatar Hywan commented on July 17, 2024

Does python language support wasm from its compiler?

Are you asking if a Python program can be compiled to WebAssembly? Or are you asking if a Python runtime already exists as a WebAssembly module?

from wasmer-python.

Mec-iS avatar Mec-iS commented on July 17, 2024

Thank you @Mec-iS. will adding &Vec <-> &str converter to the rust wrapper code and making argument and return value types to hexstrings enable me to use the exported function with one string argument?

It sounds easier to create a Python function in your glue code that accept two arguments: a list/bytestring and an instance; and return the position of the starting cell and the length of the array in the instance's memory view. Once you have these two bits of information you can pass both as const* u8 to the Wasm function.

from wasmer-python.

Hywan avatar Hywan commented on July 17, 2024

Is it solved? Closing for the moment. Feel free to reopen.

from wasmer-python.

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.