Comments (6)
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.
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.
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.
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.
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.
Is it solved? Closing for the moment. Feel free to reopen.
from wasmer-python.
Related Issues (20)
- Error print?
- Is wasmer-python avaliable for ubuntu 20.04, x86_64 ?
- Failt to execute TiDB
- Error print the result?
- Register allocation error
- Fail to load the module?
- wasi Runtime error?
- No error report?
- RuntimeError: RuntimeError: val is not reference HOT 1
- The Windows is not supported by wasmer-python?
- How to set the pre-open directory when perform wasi program?
- Wasmer-python doesn't support multiple wasi versions.
- `RuntimeError: RuntimeError: WASI exited with code: 0`
- The stuck occurs during execution.
- Provide abi3 Wheels HOT 1
- Publishing fake versions is confusing
- Use maturin container (or even action) for manylinux builds HOT 1
- Embed packages example on website doesn't work.
- When do you plan to release version 1.1.1 to pypi? HOT 6
- Broken on Python 3.12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmer-python.