second-state / WasmEdge-go

The GO language SDK and API for WasmEdge
https://www.secondstate.io/articles/extend-golang-app-with-webassembly-rust/
Apache License 2.0
107 stars 16 forks source link

Examples for calling languages other than Rust and TinyGo? #46

Open purplefox opened 5 months ago

purplefox commented 5 months ago

I've been trying to get WasmEdge to be able to invoke a WASM function compiled in AssemblyScript. I can get it to work by passing simple types (int32, int64) but trying to get it to work with more complex types (e.g. string) is more difficult.

As I understand it the memory for the string argument would need to be allocated/deallocated from within the compiled AssemblyScript - I see this technique is used for the Rust/GoLang examples, but its not clear to me what those allocate/deallocate functions would look like for AssemblyScript, or for other languages (e.g. Python? Java?). Do you have any plans to create some examples for languages other then GoLang and Rust?

hydai commented 5 months ago

We don't have such a plan. The Rust/GoLang examples decode the allocate/deallocate from the compiled wasm. The cost is translating the memory layout between host memory(Python/Java) and guest memory(Wasm).

A new proposal called the component model will allow developers to handle more complex data. We will integrate this instead of spending time on hardcoding conversion.